Skip to content

Commit

Permalink
Merge pull request #24 from mcred/develop
Browse files Browse the repository at this point in the history
Fixes #16
  • Loading branch information
mcred authored Feb 20, 2020
2 parents 7e87fe7 + e15c7d8 commit 02cd191
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 16 deletions.
4 changes: 2 additions & 2 deletions internal/app/characters/Lavitz.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
4 changes: 2 additions & 2 deletions internal/app/characters/Shana.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
26 changes: 24 additions & 2 deletions internal/app/storage/Slot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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]
}
}
35 changes: 25 additions & 10 deletions internal/app/ui/Form.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fyne.io/fyne/dialog"
"fyne.io/fyne/layout"
"fyne.io/fyne/widget"
"strconv"
)

var dart = characters.Dart()
Expand Down Expand Up @@ -39,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)
Expand All @@ -47,8 +58,12 @@ 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"))
b.Append(createCharEntry(c.HP, s))

b.Append(widget.NewLabel("Weapon"))
b.Append(createCharSelect(w, c.Weapon, s))
b.Append(widget.NewLabel("Armor"))
Expand All @@ -72,23 +87,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)
Expand Down

0 comments on commit 02cd191

Please sign in to comment.