Skip to content

Commit

Permalink
Fix weapon bonus save state issue; bump the version number to 5.19.1
Browse files Browse the repository at this point in the history
  • Loading branch information
richardwilkes committed Dec 29, 2023
1 parent 85fb3c3 commit d68d8f7
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 75 deletions.
2 changes: 1 addition & 1 deletion build.sh
Expand Up @@ -26,7 +26,7 @@ for arg in "$@"; do
--dist|-d)
EXTRA_BUILD_FLAGS="-a -trimpath"
EXTRA_LD_FLAGS="-s -w"
RELEASE="5.19.0"
RELEASE="5.19.1"
DIST=1
case $(uname -s) in
Darwin*)
Expand Down
12 changes: 6 additions & 6 deletions model/gurps/entity.go
Expand Up @@ -852,13 +852,13 @@ func (e *Entity) AddNamedWeaponBonusesFor(nameQualifier, usageQualifier string,
}

func addWeaponBonusToMap(bonus *WeaponBonus, dieCount int, tooltip *xio.ByteBuffer, m map[*WeaponBonus]bool) {
savedLevel := bonus.LeveledAmount.Level
savedDieCount := bonus.LeveledAmount.DieCount
bonus.LeveledAmount.DieCount = fxp.From(dieCount)
bonus.LeveledAmount.Level = bonus.DerivedLevel()
savedLevel := bonus.WeaponLeveledAmount.Level
savedDieCount := bonus.WeaponLeveledAmount.DieCount
bonus.WeaponLeveledAmount.DieCount = fxp.From(dieCount)
bonus.WeaponLeveledAmount.Level = bonus.DerivedLevel()
bonus.AddToTooltip(tooltip)
bonus.LeveledAmount.Level = savedLevel
bonus.LeveledAmount.DieCount = savedDieCount
bonus.WeaponLeveledAmount.Level = savedLevel
bonus.WeaponLeveledAmount.DieCount = savedDieCount
m[bonus] = true
}

Expand Down
4 changes: 2 additions & 2 deletions model/gurps/general_settings.go
Expand Up @@ -117,8 +117,8 @@ func NewGeneralSettings() *GeneralSettings {
// NewGeneralSettingsFromFile loads new settings from a file.
func NewGeneralSettingsFromFile(fileSystem fs.FS, filePath string) (*GeneralSettings, error) {
var data struct {
GeneralSettings `json:",inline"`
OldLocation *GeneralSettings `json:"general"`
GeneralSettings
OldLocation *GeneralSettings `json:"general"`
}
if err := jio.LoadFromFS(context.Background(), fileSystem, filePath, &data); err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion model/gurps/profile.go
Expand Up @@ -36,7 +36,7 @@ type ProfileRandom struct {

// Profile holds the profile information for an NPC.
type Profile struct {
ProfileRandom `json:",inline"`
ProfileRandom
PlayerName string `json:"player_name,omitempty"`
Title string `json:"title,omitempty"`
Organization string `json:"organization,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions model/gurps/sheet_settings.go
Expand Up @@ -90,8 +90,8 @@ func FactorySheetSettings() *SheetSettings {
// NewSheetSettingsFromFile loads new settings from a file.
func NewSheetSettingsFromFile(fileSystem fs.FS, filePath string) (*SheetSettings, error) {
var data struct {
SheetSettings `json:",inline"`
OldLocation *SheetSettings `json:"sheet_settings"`
SheetSettings
OldLocation *SheetSettings `json:"sheet_settings"`
}
if err := jio.LoadFromFS(context.Background(), fileSystem, filePath, &data); err != nil {
return nil, err
Expand Down
12 changes: 6 additions & 6 deletions model/gurps/weapon.go
Expand Up @@ -542,10 +542,10 @@ func (w *Weapon) collectWeaponBonuses(dieCount int, tooltip *xio.ByteBuffer, all
func (w *Weapon) extractWeaponBonus(f Feature, set map[*WeaponBonus]bool, allowedFeatureTypes map[feature.Type]bool, dieCount fxp.Int, tooltip *xio.ByteBuffer) {
if allowedFeatureTypes[f.FeatureType()] {
if bonus, ok := f.(*WeaponBonus); ok {
savedLevel := bonus.LeveledAmount.Level
savedDieCount := bonus.LeveledAmount.DieCount
bonus.LeveledAmount.Level = bonus.DerivedLevel()
bonus.LeveledAmount.DieCount = dieCount
savedLevel := bonus.WeaponLeveledAmount.Level
savedDieCount := bonus.WeaponLeveledAmount.DieCount
bonus.WeaponLeveledAmount.Level = bonus.DerivedLevel()
bonus.WeaponLeveledAmount.DieCount = dieCount
switch bonus.SelectionType {
case wsel.WithRequiredSkill:
case wsel.ThisWeapon:
Expand All @@ -566,8 +566,8 @@ func (w *Weapon) extractWeaponBonus(f Feature, set map[*WeaponBonus]bool, allowe
default:
errs.Log(errs.New("unknown selection type"), "type", int(bonus.SelectionType))
}
bonus.LeveledAmount.Level = savedLevel
bonus.LeveledAmount.DieCount = savedDieCount
bonus.WeaponLeveledAmount.Level = savedLevel
bonus.WeaponLeveledAmount.DieCount = savedDieCount
}
}
}
Expand Down
34 changes: 17 additions & 17 deletions model/gurps/weapon_bonus.go
Expand Up @@ -27,17 +27,17 @@ var _ Bonus = &WeaponBonus{}

// WeaponBonus holds the data for an adjustment to weapon damage.
type WeaponBonus struct {
Type feature.Type `json:"type"`
Percent bool `json:"percent,omitempty"`
SwitchTypeValue bool `json:"switch_type_value,omitempty"`
SelectionType wsel.Type `json:"selection_type"`
SwitchType wswitch.Type `json:"switch_type,omitempty"`
NameCriteria StringCriteria `json:"name,omitempty"`
SpecializationCriteria StringCriteria `json:"specialization,omitempty"`
RelativeLevelCriteria NumericCriteria `json:"level,omitempty"`
UsageCriteria StringCriteria `json:"usage,omitempty"`
TagsCriteria StringCriteria `json:"tags,alt=category,omitempty"`
LeveledAmount WeaponLeveledAmount `json:",inline"`
Type feature.Type `json:"type"`
Percent bool `json:"percent,omitempty"`
SwitchTypeValue bool `json:"switch_type_value,omitempty"`
SelectionType wsel.Type `json:"selection_type"`
SwitchType wswitch.Type `json:"switch_type,omitempty"`
NameCriteria StringCriteria `json:"name,omitempty"`
SpecializationCriteria StringCriteria `json:"specialization,omitempty"`
RelativeLevelCriteria NumericCriteria `json:"level,omitempty"`
UsageCriteria StringCriteria `json:"usage,omitempty"`
TagsCriteria StringCriteria `json:"tags,alt=category,omitempty"`
WeaponLeveledAmount
BonusOwner
}

Expand Down Expand Up @@ -185,7 +185,7 @@ func newWeaponBonus(t feature.Type) *WeaponBonus {
Compare: AnyString,
},
},
LeveledAmount: WeaponLeveledAmount{Amount: fxp.One},
WeaponLeveledAmount: WeaponLeveledAmount{Amount: fxp.One},
}
}

Expand All @@ -202,13 +202,13 @@ func (w *WeaponBonus) Clone() Feature {

// AdjustedAmount implements Bonus.
func (w *WeaponBonus) AdjustedAmount() fxp.Int {
return w.LeveledAmount.AdjustedAmount()
return w.WeaponLeveledAmount.AdjustedAmount()
}

// AdjustedAmountForWeapon returns the adjusted amount for the given weapon.
func (w *WeaponBonus) AdjustedAmountForWeapon(wpn *Weapon) fxp.Int {
w.LeveledAmount.DieCount = fxp.From(wpn.Damage.BaseDamageDice().Count)
return w.LeveledAmount.AdjustedAmount()
w.WeaponLeveledAmount.DieCount = fxp.From(wpn.Damage.BaseDamageDice().Count)
return w.WeaponLeveledAmount.AdjustedAmount()
}

// FillWithNameableKeys implements Feature.
Expand All @@ -235,7 +235,7 @@ func (w *WeaponBonus) ApplyNameableKeys(m map[string]string) {

// SetLevel implements Bonus.
func (w *WeaponBonus) SetLevel(level fxp.Int) {
w.LeveledAmount.Level = level
w.WeaponLeveledAmount.Level = level
}

// AddToTooltip implements Bonus.
Expand All @@ -248,7 +248,7 @@ func (w *WeaponBonus) AddToTooltip(buffer *xio.ByteBuffer) {
if w.Type == feature.WeaponSwitch {
fmt.Fprintf(&buf, "%v set to %v", w.SwitchType, w.SwitchTypeValue)
} else {
buf.WriteString(w.LeveledAmount.Format(w.Percent))
buf.WriteString(w.WeaponLeveledAmount.Format(w.Percent))
buf.WriteString(i18n.Text(" to "))
switch w.Type {
case feature.WeaponBonus:
Expand Down
6 changes: 3 additions & 3 deletions model/gurps/weapon_damage.go
Expand Up @@ -221,16 +221,16 @@ func (w *WeaponDamage) ResolvedDamage(tooltip *xio.ByteBuffer) string {
for _, bonus := range w.Owner.collectWeaponBonuses(base.Count, tooltip, feature.WeaponBonus, feature.WeaponDRDivisorBonus) {
switch bonus.Type {
case feature.WeaponBonus:
bonus.LeveledAmount.DieCount = fxp.From(base.Count)
bonus.WeaponLeveledAmount.DieCount = fxp.From(base.Count)
amt := bonus.AdjustedAmountForWeapon(w.Owner)
if bonus.Percent {
percentDamageBonus += amt
} else {
if adjustForPhoenixFlame {
if bonus.LeveledAmount.PerLevel {
if bonus.WeaponLeveledAmount.PerLevel {
amt = amt.Div(fxp.Two)
}
if bonus.LeveledAmount.PerDie {
if bonus.WeaponLeveledAmount.PerDie {
amt = amt.Div(fxp.Two)
}
}
Expand Down
41 changes: 5 additions & 36 deletions model/gurps/weapon_leveled_amount.go
Expand Up @@ -15,47 +15,16 @@ import (
"fmt"

"github.com/richardwilkes/gcs/v5/model/fxp"
"github.com/richardwilkes/json"
"github.com/richardwilkes/toolbox/i18n"
)

// WeaponLeveledAmount holds an amount that can be either a fixed amount, or an amount per level and/or per die.
type WeaponLeveledAmount struct {
Level fxp.Int
DieCount fxp.Int
Amount fxp.Int
PerLevel bool
PerDie bool
}

// MarshalJSON marshals to JSON.
func (l *WeaponLeveledAmount) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
Amount fxp.Int `json:"amount"`
PerLevel bool `json:"leveled,omitempty"`
PerDie bool `json:"per_die,omitempty"`
}{
Amount: l.Amount,
PerLevel: l.PerLevel,
PerDie: l.PerDie,
})
}

// UnmarshalJSON unmarshals from JSON.
func (l *WeaponLeveledAmount) UnmarshalJSON(data []byte) error {
var input struct {
Amount fxp.Int `json:"amount"`
PerLevel bool `json:"leveled"`
PerDie bool `json:"per_die"`
OldPerDie bool `json:"per_level"`
}
if err := json.Unmarshal(data, &input); err != nil {
return err
}
l.Amount = input.Amount
l.PerLevel = input.PerLevel
l.PerDie = input.PerDie || input.OldPerDie
return nil
Level fxp.Int `json:"-"`
DieCount fxp.Int `json:"-"`
Amount fxp.Int `json:"amount"`
PerLevel bool `json:"leveled,omitempty"`
PerDie bool `json:"per_die,alt=per_level,omitempty"`
}

// AdjustedAmount returns the amount, adjusted for level, if requested.
Expand Down
2 changes: 1 addition & 1 deletion ux/features_panel.go
Expand Up @@ -344,7 +344,7 @@ func (p *featuresPanel) createSpellPointBonusPanel(f *gurps.SpellPointBonus) *un

func (p *featuresPanel) createWeaponBonusPanel(f *gurps.WeaponBonus) *unison.Panel {
panel := p.createBasePanel(f)
p.addWeaponLeveledModifierLine(panel, f, &f.LeveledAmount)
p.addWeaponLeveledModifierLine(panel, f, &f.WeaponLeveledAmount)
panel.AddChild(unison.NewPanel())
wrapper := unison.NewPanel()
var criteriaPopup *unison.PopupMenu[string]
Expand Down

0 comments on commit d68d8f7

Please sign in to comment.