+ hp feature now working as intended

This commit is contained in:
itsig0
2024-03-23 16:21:05 +01:00
parent b12688c718
commit 201b993974
6 changed files with 258 additions and 73 deletions

View File

@@ -15,6 +15,18 @@ type TrackerData struct {
ManaRegen string
}
type DamageData struct {
Values string
SavingThrow string
Errors string
}
var dd = DamageData {
Values: "",
SavingThrow: "",
Errors: "",
}
templ Show(hx bool, td TrackerData){
@layout.Base(hx){
<div class="container">
@@ -41,15 +53,40 @@ templ Show(hx bool, td TrackerData){
<div class="grid">
<div>
<h3>TP</h3>
@hp()
@Hp(dd)
</div>
<div>
<h3>Mana</h3>
@mana()
@Mana()
</div>
</div>
</div>
<script>
document.addEventListener("DOMContentLoaded", (event) => {
document.body.addEventListener("htmx:beforeSwap", function(evt){
if (evt.detail.xhr.status === 422){
evt.detail.shouldSwap = true;
evt.detail.isError = false;
}
});
document.body.addEventListener("HPUpdated", function() {
var input = document.getElementById('damageInput');
input.value = "";
input.removeAttribute('aria-invalid');
var errorMessage = document.getElementById('damageError');
if (errorMessage) {
errorMessage.parentNode.removeChild(errorMessage);
}
var savingthrow = document.getElementById('savingthrow');
savingthrow.checked = false;
});
})
</script>
}
}
@@ -63,7 +100,7 @@ templ TrackerColumn(td TrackerData){
@HPTracker(td)
</div>
<div class="progress">
<div id="manaBar" class="progress">
@ManaTracker(td)
</div>
@@ -127,44 +164,67 @@ templ baseStats(){
</details>
}
templ hp(){
templ Hp(dd DamageData){
<form id="damageInputs" hx-post="/hp-mana-tracker/damage" hx-target="#hpBar">
<form hx-post="/hp-mana-tracker/damage" hx-target="#hpBar">
<fieldset role="group">
<button class="secondary" name="damage" value="true">
-
</button>
<input name="damageInput" type="number"/>
<input
id="damageInput"
name="damageInput"
type="number"
placeholder="Schaden/Heilung"
required
if dd.Errors != "" {
aria-invalid="true"
}
value={dd.Values}
/>
<button class="secondary" name="heal" value="true">
+
</button>
</fieldset>
if dd.Errors != "" {
<small id="damageError" class="error-helper">{dd.Errors}</small>
}
<fieldset>
<label for="savingthrow">
<input id="savingthrow" name="savingthrow" type="checkbox" role="switch"/>
<input id="savingthrow" name="savingthrow" type="checkbox" role="switch"
if dd.SavingThrow != "" {
checked
}
/>
Verteidigungswurf
</label>
</fieldset>
</form>
}
templ mana(){
<fieldset role="group">
templ Mana(){
<form hx-post="/hp-mana-tracker/mana" hx-target="#manaBar">
<fieldset role="group">
<button class="secondary" name="use" hx-get="/hp-mana-tracker/check">
-
</button>
<button class="secondary" name="use">
-
</button>
<input type="number" placeholder="" min="0" value="0"/>
<input name="manaInput" type="number" placeholder="" min="0" value="0"/>
<button class="secondary" name="add">
+
</button>
<button class="secondary" name="add">
+
</button>
</fieldset>
</fieldset>
</form>
}

View File

@@ -26,6 +26,18 @@ type TrackerData struct {
ManaRegen string
}
type DamageData struct {
Values string
SavingThrow string
Errors string
}
var dd = DamageData{
Values: "",
SavingThrow: "",
Errors: "",
}
func Show(hx bool, td TrackerData) templ.Component {
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
@@ -65,7 +77,7 @@ func Show(hx bool, td TrackerData) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = hp().Render(ctx, templ_7745c5c3_Buffer)
templ_7745c5c3_Err = Hp(dd).Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -73,7 +85,7 @@ func Show(hx bool, td TrackerData) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = mana().Render(ctx, templ_7745c5c3_Buffer)
templ_7745c5c3_Err = Mana().Render(ctx, templ_7745c5c3_Buffer)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -160,7 +172,7 @@ func HPTracker(td TrackerData) templ.Component {
var templ_7745c5c3_Var5 string
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(td.HP)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/hptracker/tracker.templ`, Line: 72, Col: 43}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/hptracker/tracker.templ`, Line: 109, Col: 43}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
if templ_7745c5c3_Err != nil {
@@ -173,7 +185,7 @@ func HPTracker(td TrackerData) templ.Component {
var templ_7745c5c3_Var6 string
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(td.HPBase)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/hptracker/tracker.templ`, Line: 72, Col: 55}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/hptracker/tracker.templ`, Line: 109, Col: 55}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
if templ_7745c5c3_Err != nil {
@@ -227,7 +239,7 @@ func ManaTracker(td TrackerData) templ.Component {
var templ_7745c5c3_Var9 string
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(td.Mana)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/hptracker/tracker.templ`, Line: 77, Col: 47}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/hptracker/tracker.templ`, Line: 114, Col: 47}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
if templ_7745c5c3_Err != nil {
@@ -240,7 +252,7 @@ func ManaTracker(td TrackerData) templ.Component {
var templ_7745c5c3_Var10 string
templ_7745c5c3_Var10, templ_7745c5c3_Err = templ.JoinStringErrs(td.ManaBase)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/hptracker/tracker.templ`, Line: 77, Col: 61}
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/hptracker/tracker.templ`, Line: 114, Col: 61}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var10))
if templ_7745c5c3_Err != nil {
@@ -320,7 +332,7 @@ func baseStats() templ.Component {
})
}
func hp() templ.Component {
func Hp(dd DamageData) templ.Component {
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
if !templ_7745c5c3_IsBuffer {
@@ -337,27 +349,78 @@ func hp() templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if !templ_7745c5c3_IsBuffer {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
if dd.Errors != "" {
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 21)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
return templ_7745c5c3_Err
})
}
func mana() templ.Component {
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
if !templ_7745c5c3_IsBuffer {
templ_7745c5c3_Buffer = templ.GetBuffer()
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 22)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var14 := templ.GetChildren(ctx)
if templ_7745c5c3_Var14 == nil {
templ_7745c5c3_Var14 = templ.NopComponent
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(dd.Values))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
ctx = templ.ClearChildren(ctx)
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 21)
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 23)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if dd.Errors != "" {
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 24)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var14 string
templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(dd.Errors)
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `view/hptracker/tracker.templ`, Line: 195, Col: 67}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 25)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 26)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if dd.SavingThrow != "" {
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 27)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 28)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
if !templ_7745c5c3_IsBuffer {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
}
return templ_7745c5c3_Err
})
}
func Mana() templ.Component {
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
if !templ_7745c5c3_IsBuffer {
templ_7745c5c3_Buffer = templ.GetBuffer()
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
}
ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var15 := templ.GetChildren(ctx)
if templ_7745c5c3_Var15 == nil {
templ_7745c5c3_Var15 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
templ_7745c5c3_Err = templ.WriteWatchModeString(templ_7745c5c3_Buffer, 29)
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}