added GameSystemID to LearnCost
This commit is contained in:
@@ -106,5 +106,8 @@ func CalculateImprovementCost(skill string, class string, currentSkillLevel int)
|
||||
lCost.Stufe = currentSkillLevel + 1
|
||||
lCost.Ep = neededLE * epPerTE
|
||||
lCost.Money = lCost.Ep
|
||||
gs := models.GetGameSystem(lCost.GameSystemId, lCost.GameSystem)
|
||||
lCost.GameSystemId = gs.ID
|
||||
lCost.GameSystem = gs.Name
|
||||
return &lCost, nil
|
||||
}
|
||||
|
||||
@@ -35,12 +35,14 @@ type LookupList struct {
|
||||
}
|
||||
|
||||
type LearnCost struct {
|
||||
Stufe int `json:"stufe"`
|
||||
LE int `json:"le"`
|
||||
TE int `json:"te"`
|
||||
Ep int `json:"ep"`
|
||||
Money int `json:"money"`
|
||||
PP int `json:"pp"`
|
||||
GameSystem string `gorm:"column:game_system;index;default:midgard" json:"game_system"`
|
||||
GameSystemId uint `json:"game_system_id,omitempty"`
|
||||
Stufe int `json:"stufe"`
|
||||
LE int `json:"le"`
|
||||
TE int `json:"te"`
|
||||
Ep int `json:"ep"`
|
||||
Money int `json:"money"`
|
||||
PP int `json:"pp"`
|
||||
}
|
||||
|
||||
type Skill struct {
|
||||
@@ -452,6 +454,22 @@ func (object *Spell) BeforeSave(tx *gorm.DB) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (object *LearnCost) ensureGameSystem() {
|
||||
gs := GetGameSystem(object.GameSystemId, object.GameSystem)
|
||||
object.GameSystemId = gs.ID
|
||||
object.GameSystem = gs.Name
|
||||
}
|
||||
|
||||
func (object *LearnCost) BeforeCreate(tx *gorm.DB) error {
|
||||
object.ensureGameSystem()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (object *LearnCost) BeforeSave(tx *gorm.DB) error {
|
||||
object.ensureGameSystem()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (object *Equipment) ensureGameSystem() {
|
||||
gs := GetGameSystem(object.GameSystemId, object.GameSystem)
|
||||
object.GameSystemId = gs.ID
|
||||
|
||||
@@ -1800,12 +1800,14 @@ func TestGSMaster_EdgeCases(t *testing.T) {
|
||||
|
||||
func TestLearnCost_StructFields(t *testing.T) {
|
||||
learnCost := LearnCost{
|
||||
Stufe: 3,
|
||||
LE: 10,
|
||||
TE: 5,
|
||||
Ep: 100,
|
||||
Money: 50,
|
||||
PP: 2,
|
||||
GameSystem: "midgard",
|
||||
GameSystemId: 1,
|
||||
Stufe: 3,
|
||||
LE: 10,
|
||||
TE: 5,
|
||||
Ep: 100,
|
||||
Money: 50,
|
||||
PP: 2,
|
||||
}
|
||||
|
||||
assert.Equal(t, 3, learnCost.Stufe)
|
||||
@@ -1816,6 +1818,29 @@ func TestLearnCost_StructFields(t *testing.T) {
|
||||
assert.Equal(t, 2, learnCost.PP)
|
||||
}
|
||||
|
||||
func TestLearnCost_EnsureGameSystem_DefaultsToMidgard(t *testing.T) {
|
||||
setupGSMasterTestDB(t)
|
||||
|
||||
lc := LearnCost{}
|
||||
lc.ensureGameSystem()
|
||||
|
||||
assert.Equal(t, "midgard", lc.GameSystem)
|
||||
assert.NotZero(t, lc.GameSystemId)
|
||||
}
|
||||
|
||||
func TestLearnCost_EnsureGameSystem_UsesProvidedGameSystem(t *testing.T) {
|
||||
setupGSMasterTestDB(t)
|
||||
|
||||
gs := &GameSystem{Code: "TST-LC", Name: "Test LearnCost"}
|
||||
require.NoError(t, database.DB.Create(gs).Error)
|
||||
|
||||
lc := LearnCost{GameSystemId: gs.ID}
|
||||
lc.ensureGameSystem()
|
||||
|
||||
assert.Equal(t, gs.ID, lc.GameSystemId)
|
||||
assert.Equal(t, gs.Name, lc.GameSystem)
|
||||
}
|
||||
|
||||
// TestSkill_Create_DefaultImprovable verifies that new skills get Improvable=true by default
|
||||
func TestSkill_Create_DefaultImprovable(t *testing.T) {
|
||||
database.SetupTestDB(true)
|
||||
|
||||
Reference in New Issue
Block a user