From 43b982a084620a81f5e092ef474ce9fec085a211 Mon Sep 17 00:00:00 2001 From: Derek Smart Date: Wed, 19 Feb 2020 22:40:14 -0500 Subject: [PATCH 1/2] HP Fixes #16 Signed-off-by: Derek Smart --- internal/app/characters/Lavitz.go | 4 ++-- internal/app/characters/Shana.go | 4 ++-- internal/app/storage/Slot.go | 26 ++++++++++++++++++++++++-- internal/app/ui/Form.go | 31 +++++++++++++++++++++---------- 4 files changed, 49 insertions(+), 16 deletions(-) diff --git a/internal/app/characters/Lavitz.go b/internal/app/characters/Lavitz.go index 8594e78..592ebc6 100644 --- a/internal/app/characters/Lavitz.go +++ b/internal/app/characters/Lavitz.go @@ -8,8 +8,8 @@ func Lavitz() Character { return Character{ ID: 1, Name: "Lavitz", - XP: common.Attribute{0x584,4,true}, - HP: common.Attribute{0x534,2,true}, //TODO map this + XP: common.Attribute{0x558,4,true}, + HP: common.Attribute{0x560,2,true}, Weapon: common.Attribute{0x56C,1,false}, Helmet: common.Attribute{0x56D,1,false}, Chest: common.Attribute{0x56E,1,false}, diff --git a/internal/app/characters/Shana.go b/internal/app/characters/Shana.go index 54b1e5b..00c8109 100644 --- a/internal/app/characters/Shana.go +++ b/internal/app/characters/Shana.go @@ -8,8 +8,8 @@ func Shana() Character { return Character{ ID: 2, Name: "Shana", - XP: common.Attribute{0x558,4,true}, - HP: common.Attribute{0x560,2,true}, + XP: common.Attribute{0x584,4,true}, + HP: common.Attribute{0x58C,2,true}, Weapon: common.Attribute{0x598,1,false}, Helmet: common.Attribute{0x599,1,false}, Chest: common.Attribute{0x59A,1,false}, diff --git a/internal/app/storage/Slot.go b/internal/app/storage/Slot.go index 94f93e9..68ce539 100644 --- a/internal/app/storage/Slot.go +++ b/internal/app/storage/Slot.go @@ -15,7 +15,7 @@ func (s *Slot) GetValueByAttribute(a common.Attribute) int { if a.Bytes == 1 { return int(b[0]) } else { - if a.Reversed == true { + if a.Reversed { return int(binary.LittleEndian.Uint16(b)) } else { return int(binary.BigEndian.Uint16(b)) @@ -24,5 +24,27 @@ func (s *Slot) GetValueByAttribute(a common.Attribute) int { } func (s *Slot) SetValueAtLocation(a common.Attribute, val int) { - s.Data[a.Location] = byte(val) + b := make([]byte, a.Bytes) + if a.Reversed { + switch a.Bytes { + case 2: + binary.LittleEndian.PutUint16(b, uint16(val)) + case 4: + binary.LittleEndian.PutUint32(b, uint32(val)) + default: + b[0] = byte(val) + } + } else { + switch a.Bytes { + case 2: + binary.BigEndian.PutUint16(b, uint16(val)) + case 4: + binary.BigEndian.PutUint32(b, uint32(val)) + default: + b[0] = byte(val) + } + } + for i := 0; i < a.Bytes; i++ { + s.Data[a.Location + i] = b[i] + } } \ No newline at end of file diff --git a/internal/app/ui/Form.go b/internal/app/ui/Form.go index 5e05b8e..b396846 100644 --- a/internal/app/ui/Form.go +++ b/internal/app/ui/Form.go @@ -10,6 +10,7 @@ import ( "fyne.io/fyne/dialog" "fyne.io/fyne/layout" "fyne.io/fyne/widget" + "strconv" ) var dart = characters.Dart() @@ -47,8 +48,18 @@ func createPartyForm(s *storage.Slot) *fyne.Container { widget.NewLabel("Party"), s1, s2, s3) } -func createCharacterBox(b *widget.Box, c characters.Character, w inventory.Inventory, s *storage.Slot) { +func createCharacterBox(b *widget.Box, c characters.Character, w inventory.Inventory, s *storage.Slot, window fyne.Window) { b.Append(widget.NewLabel(c.Name)) + + b.Append(widget.NewLabel("HP")) + hp := widget.NewEntry() + hp.SetPlaceHolder(strconv.Itoa(s.GetValueByAttribute(c.HP))) + hp.OnChanged = func(v string) { + i, _ := strconv.Atoi(v) + s.SetValueAtLocation(c.HP, i) + } + b.Append(hp) + b.Append(widget.NewLabel("Weapon")) b.Append(createCharSelect(w, c.Weapon, s)) b.Append(widget.NewLabel("Armor")) @@ -72,23 +83,23 @@ func CreateForm(slot *storage.Slot, card *storage.Card, w fyne.Window) *fyne.Con }, } box1 := widget.NewVBox() - createCharacterBox(box1, dart, inventory.Swords(), slot) + createCharacterBox(box1, dart, inventory.Swords(), slot, w) box2 := widget.NewVBox() - createCharacterBox(box2, shana, inventory.Bows(), slot) + createCharacterBox(box2, shana, inventory.Bows(), slot, w) box3 := widget.NewVBox() - createCharacterBox(box3, lavitz, inventory.Spears(), slot) + createCharacterBox(box3, lavitz, inventory.Spears(), slot, w) box4 := widget.NewVBox() - createCharacterBox(box4, rose, inventory.Daggers(), slot) + createCharacterBox(box4, rose, inventory.Daggers(), slot, w) box5 := widget.NewVBox() - createCharacterBox(box5, haschel, inventory.Knuckles(), slot) + createCharacterBox(box5, haschel, inventory.Knuckles(), slot, w) box6 := widget.NewVBox() - createCharacterBox(box6, albert, inventory.Spears(), slot) + createCharacterBox(box6, albert, inventory.Spears(), slot, w) box7 := widget.NewVBox() - createCharacterBox(box7, meru, inventory.Maces(), slot) + createCharacterBox(box7, meru, inventory.Maces(), slot, w) box8 := widget.NewVBox() - createCharacterBox(box8, kongol, inventory.Axes(), slot) + createCharacterBox(box8, kongol, inventory.Axes(), slot, w) box9 := widget.NewVBox() - createCharacterBox(box9, miranda, inventory.Bows(), slot) + createCharacterBox(box9, miranda, inventory.Bows(), slot, w) chars := fyne.NewContainerWithLayout(layout.NewGridLayout(9), box1, box2, box3, box4, box5, box6, box7, box8, box9) From e15c7d8d88b8fbaf19119db303caaab5cc966829 Mon Sep 17 00:00:00 2001 From: Derek Smart Date: Wed, 19 Feb 2020 22:46:40 -0500 Subject: [PATCH 2/2] make charEntry reusable Signed-off-by: Derek Smart --- internal/app/ui/Form.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/internal/app/ui/Form.go b/internal/app/ui/Form.go index b396846..84f8291 100644 --- a/internal/app/ui/Form.go +++ b/internal/app/ui/Form.go @@ -40,6 +40,16 @@ func createPosSelect(n []string, a common.Attribute, ad common.Attribute, s *sto return r } +func createCharEntry(a common.Attribute, s *storage.Slot) *widget.Entry { + e := widget.NewEntry() + e.SetPlaceHolder(strconv.Itoa(s.GetValueByAttribute(a))) + e.OnChanged = func(v string) { + i, _ := strconv.Atoi(v) + s.SetValueAtLocation(a, i) + } + return e +} + func createPartyForm(s *storage.Slot) *fyne.Container { s1 := createPosSelect(characters.GetCharacterNames(), common.First(), common.FirstDisplay(), s) s2 := createPosSelect(characters.GetCharacterNames(), common.Second(), common.SecondDisplay(), s) @@ -52,13 +62,7 @@ func createCharacterBox(b *widget.Box, c characters.Character, w inventory.Inven b.Append(widget.NewLabel(c.Name)) b.Append(widget.NewLabel("HP")) - hp := widget.NewEntry() - hp.SetPlaceHolder(strconv.Itoa(s.GetValueByAttribute(c.HP))) - hp.OnChanged = func(v string) { - i, _ := strconv.Atoi(v) - s.SetValueAtLocation(c.HP, i) - } - b.Append(hp) + b.Append(createCharEntry(c.HP, s)) b.Append(widget.NewLabel("Weapon")) b.Append(createCharSelect(w, c.Weapon, s))