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.Stufe = currentSkillLevel + 1
|
||||||
lCost.Ep = neededLE * epPerTE
|
lCost.Ep = neededLE * epPerTE
|
||||||
lCost.Money = lCost.Ep
|
lCost.Money = lCost.Ep
|
||||||
|
gs := models.GetGameSystem(lCost.GameSystemId, lCost.GameSystem)
|
||||||
|
lCost.GameSystemId = gs.ID
|
||||||
|
lCost.GameSystem = gs.Name
|
||||||
return &lCost, nil
|
return &lCost, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,12 +35,14 @@ type LookupList struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type LearnCost struct {
|
type LearnCost struct {
|
||||||
Stufe int `json:"stufe"`
|
GameSystem string `gorm:"column:game_system;index;default:midgard" json:"game_system"`
|
||||||
LE int `json:"le"`
|
GameSystemId uint `json:"game_system_id,omitempty"`
|
||||||
TE int `json:"te"`
|
Stufe int `json:"stufe"`
|
||||||
Ep int `json:"ep"`
|
LE int `json:"le"`
|
||||||
Money int `json:"money"`
|
TE int `json:"te"`
|
||||||
PP int `json:"pp"`
|
Ep int `json:"ep"`
|
||||||
|
Money int `json:"money"`
|
||||||
|
PP int `json:"pp"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Skill struct {
|
type Skill struct {
|
||||||
@@ -452,6 +454,22 @@ func (object *Spell) BeforeSave(tx *gorm.DB) error {
|
|||||||
return nil
|
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() {
|
func (object *Equipment) ensureGameSystem() {
|
||||||
gs := GetGameSystem(object.GameSystemId, object.GameSystem)
|
gs := GetGameSystem(object.GameSystemId, object.GameSystem)
|
||||||
object.GameSystemId = gs.ID
|
object.GameSystemId = gs.ID
|
||||||
|
|||||||
@@ -1800,12 +1800,14 @@ func TestGSMaster_EdgeCases(t *testing.T) {
|
|||||||
|
|
||||||
func TestLearnCost_StructFields(t *testing.T) {
|
func TestLearnCost_StructFields(t *testing.T) {
|
||||||
learnCost := LearnCost{
|
learnCost := LearnCost{
|
||||||
Stufe: 3,
|
GameSystem: "midgard",
|
||||||
LE: 10,
|
GameSystemId: 1,
|
||||||
TE: 5,
|
Stufe: 3,
|
||||||
Ep: 100,
|
LE: 10,
|
||||||
Money: 50,
|
TE: 5,
|
||||||
PP: 2,
|
Ep: 100,
|
||||||
|
Money: 50,
|
||||||
|
PP: 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal(t, 3, learnCost.Stufe)
|
assert.Equal(t, 3, learnCost.Stufe)
|
||||||
@@ -1816,6 +1818,29 @@ func TestLearnCost_StructFields(t *testing.T) {
|
|||||||
assert.Equal(t, 2, learnCost.PP)
|
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
|
// TestSkill_Create_DefaultImprovable verifies that new skills get Improvable=true by default
|
||||||
func TestSkill_Create_DefaultImprovable(t *testing.T) {
|
func TestSkill_Create_DefaultImprovable(t *testing.T) {
|
||||||
database.SetupTestDB(true)
|
database.SetupTestDB(true)
|
||||||
|
|||||||
Reference in New Issue
Block a user