Spell migriert

This commit is contained in:
2025-07-27 23:50:19 +02:00
parent c5484432dc
commit 40835e02a7
18 changed files with 112 additions and 97 deletions
+1 -1
View File
@@ -215,7 +215,7 @@ func GetLearnSpellCost(c *gin.Context) {
respondWithError(c, http.StatusBadRequest, err.Error())
return
}
var spell gsmaster.Spell
var spell models.Spell
if err := spell.First(s.Name); err != nil {
respondWithError(c, http.StatusBadRequest, "can not find speel in gsmaster: "+err.Error())
return
+1 -1
View File
@@ -535,7 +535,7 @@ func getSkillInfo(skillName, skillType string) skillInfo {
}
func getSpellInfo(spellName string) skillInfo {
var spell gsmaster.Spell
var spell models.Spell
if err := spell.First(spellName); err != nil {
return skillInfo{Category: "unknown", Difficulty: "unknown"}
}
+3 -3
View File
@@ -2,14 +2,14 @@ package character
import (
"bamort/database"
"bamort/gsmaster"
"bamort/models"
)
// getSpellCategory ermittelt die Zaubergruppe für einen gegebenen Zaubernamen
// Wenn es sich um einen Zauber handelt, wird die Kategorie zurückgegeben
// Andernfalls wird der ursprüngliche Name zurückgegeben
func getSpellCategory(name string) string {
var spell gsmaster.Spell
var spell models.Spell
if err := database.DB.Where("name = ?", name).First(&spell).Error; err != nil {
// Kein Zauber gefunden, ursprünglichen Namen verwenden
return name
@@ -22,7 +22,7 @@ func getSpellCategory(name string) string {
// isSpell prüft, ob der gegebene Name ein Zauber ist
func isSpell(name string) bool {
var spell gsmaster.Spell
var spell models.Spell
err := database.DB.Where("name = ?", name).First(&spell).Error
return err == nil
}
+2 -3
View File
@@ -2,7 +2,6 @@ package character
import (
"bamort/database"
"bamort/gsmaster"
"bamort/models"
"bamort/skills"
)
@@ -59,7 +58,7 @@ func createTestSkillData() error {
}
// GSM Test-Spell erstellen
gsmSpell := gsmaster.Spell{
gsmSpell := models.Spell{
LookupList: models.LookupList{
GameSystem: "midgard",
Name: "Macht über das Selbst",
@@ -82,5 +81,5 @@ func cleanupTestSkillData() {
database.DB.Where("name = ?", "Menschenkenntnis").Delete(&skills.Fertigkeit{})
database.DB.Where("name = ?", "Macht über das Selbst").Delete(&skills.Zauber{})
database.DB.Where("name = ?", "Menschenkenntnis").Delete(&models.Skill{})
database.DB.Where("name = ?", "Macht über das Selbst").Delete(&gsmaster.Spell{})
database.DB.Where("name = ?", "Macht über das Selbst").Delete(&models.Spell{})
}
-2
View File
@@ -16,8 +16,6 @@ func MigrateStructure(db ...*gorm.DB) error {
}
err := targetDB.AutoMigrate(
&Spell{},
&Equipment{},
&Weapon{},
&Container{},
+7 -7
View File
@@ -156,7 +156,7 @@ func GetMasterData(c *gin.Context) {
type dtaStruct struct {
Skills []models.Skill `json:"skills"`
Weaponskills []models.WeaponSkill `json:"weaponskills"`
Spell []Spell `json:"spells"`
Spell []models.Spell `json:"spells"`
Equipment []Equipment `json:"equipment"`
Weapons []Weapon `json:"weapons"`
SkillCategories []string `json:"skillcategories"`
@@ -165,7 +165,7 @@ func GetMasterData(c *gin.Context) {
var dta dtaStruct
var err error
var ski models.Skill
var spe Spell
var spe models.Spell
if err := database.DB.Find(&dta.Skills).Error; err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to retrieve Skills"})
return
@@ -283,23 +283,23 @@ func GetMDSkillCategories(c *gin.Context) {
}
func GetMDSpells(c *gin.Context) {
getMDItems[Spell](c)
getMDItems[models.Spell](c)
}
func GetMDSpell(c *gin.Context) {
getMDItem[Spell](c)
getMDItem[models.Spell](c)
}
func UpdateMDSpell(c *gin.Context) {
updateMDItem[Spell](c)
updateMDItem[models.Spell](c)
}
func AddSpell(c *gin.Context) {
addMDItem[Spell](c)
addMDItem[models.Spell](c)
}
func DeleteMDSpell(c *gin.Context) {
deleteMDItem[Spell](c)
deleteMDItem[models.Spell](c)
}
func GetMDEquipments(c *gin.Context) {
+2 -2
View File
@@ -14,7 +14,7 @@ import (
type exportData struct {
Skills []models.Skill `json:"skills"`
WeaponSkills []models.WeaponSkill `json:"weapon_skills"`
Spells []Spell `json:"spells"`
Spells []models.Spell `json:"spells"`
Equipments []Equipment `json:"equipments"`
Weapons []Weapon `json:"weapons"`
Containers []Container `json:"containers"`
@@ -25,7 +25,7 @@ type exportData struct {
func Export(filePath string) error {
var skills []models.Skill
var weaponSkills []models.WeaponSkill
var spells []Spell
var spells []models.Spell
var equipments []Equipment
var weapons []Weapon
var containers []Container
+2 -1
View File
@@ -1,6 +1,7 @@
package gsmaster
import (
"bamort/models"
"fmt"
)
@@ -543,7 +544,7 @@ func contains(slice []string, item string) bool {
// GetSpellInfo returns the school and level of a spell from the database
func GetSpellInfo(spellName string) (string, int, error) {
// Create a Spell instance to search in the database
var spell Spell
var spell models.Spell
// Search for the spell in the database
err := spell.First(spellName)
+2 -2
View File
@@ -747,7 +747,7 @@ func TestGetSpellInfo(t *testing.T) {
MigrateStructure()
// Create minimal test spell data for our test
testSpells := []Spell{
testSpells := []models.Spell{
{
LookupList: models.LookupList{
GameSystem: "midgard",
@@ -853,7 +853,7 @@ func TestCalcSpellLernCostWithRewards(t *testing.T) {
MigrateStructure()
// Create minimal test spell data for our test
testSpells := []Spell{
testSpells := []models.Spell{
{
LookupList: models.LookupList{
GameSystem: "midgard",
+1 -1
View File
@@ -95,7 +95,7 @@ func CalculateSpellLearnCost(spell string, class string) (int, error) {
loadLevelingConfig()
}
var spl Spell
var spl models.Spell
if err := spl.First(spell); err != nil {
return 0, errors.New("unbekannter Zauberspruch")
}
+2 -63
View File
@@ -10,6 +10,7 @@ import (
var dbPrefix = "gsm"
/*
type Spell struct {
models.LookupList
Bonus int `json:"bonus"`
@@ -24,6 +25,7 @@ type Spell struct {
Ursprung string `json:"ursprung"`
Category string `gorm:"default:normal" json:"category"`
}
*/
type Equipment struct {
models.LookupList
@@ -52,69 +54,6 @@ type Believe struct {
models.LookupList
}
func (object *Spell) TableName() string {
return dbPrefix + "_" + "spells"
}
func (stamm *Spell) Create() error {
gameSystem := "midgard"
stamm.GameSystem = gameSystem
err := database.DB.Transaction(func(tx *gorm.DB) error {
// Save the main character record
if err := tx.Create(&stamm).Error; err != nil {
return fmt.Errorf("failed to save LookupSpell: %w", err)
}
return nil
})
return err
}
func (stamm *Spell) First(name string) error {
gameSystem := "midgard"
err := database.DB.First(&stamm, "game_system=? AND name = ?", gameSystem, name).Error
if err != nil {
// zauber found
return err
}
return nil
}
func (object *Spell) FirstId(value uint) error {
gameSystem := "midgard"
err := database.DB.First(&object, "game_system=? AND id = ?", gameSystem, value).Error
if err != nil {
// zauber found
return err
}
return nil
}
func (object *Spell) Save() error {
err := database.DB.Save(&object).Error
if err != nil {
// zauber found
return err
}
return nil
}
func (object *Spell) GetSpellCategories() ([]string, error) {
var categories []string
gameSystem := "midgard"
result := database.DB.Model(&Spell{}).
Where("game_system=? and category is not null", gameSystem).
Distinct().
Pluck("category", &categories)
if result.Error != nil {
return nil, result.Error
}
return categories, nil
}
func (object *Equipment) TableName() string {
return dbPrefix + "_" + "equipments"
}
@@ -302,12 +302,12 @@ func TestImportSpell2GSMaster(t *testing.T) {
assert.Equal(t, "", skill.Wirkungsziel)
assert.Equal(t, 0, skill.Reichweite)
//}
skill2 := gsmaster.Spell{}
skill2 := models.Spell{}
erro = skill2.First("Angst")
assert.NoError(t, erro, "Expected no error when finding Record by name")
assert.Equal(t, 1, int(skill.ID))
skill3 := gsmaster.Spell{}
skill3 := models.Spell{}
erro = skill3.FirstId(1)
assert.NoError(t, erro, "Expected no error when finding Record by ID")
assert.Equal(t, "Angst", skill3.Name)
+2 -3
View File
@@ -2,7 +2,6 @@ package importer
import (
"bamort/character"
"bamort/gsmaster"
"bamort/models"
"fmt"
)
@@ -51,8 +50,8 @@ func CheckSkill(fertigkeit *Fertigkeit, autocreate bool) (*models.Skill, error)
return &stammF, nil
}
func CheckSpell(zauber *Zauber, autocreate bool) (*gsmaster.Spell, error) {
stammF := gsmaster.Spell{}
func CheckSpell(zauber *Zauber, autocreate bool) (*models.Spell, error) {
stammF := models.Spell{}
//err := database.DB.First(&stammF, "system=? AND name = ?", gameSystem, zauber.Name).Error
err := stammF.First(zauber.Name)
+2 -2
View File
@@ -264,8 +264,8 @@ func TransformImportWaffenFertigkeit2GSDMaster(object *Waffenfertigkeit) (*model
return &gsmobj, nil
}
func TransformImportSpell2GSDMaster(object *Zauber) (*gsmaster.Spell, error) {
gsmobj := gsmaster.Spell{}
func TransformImportSpell2GSDMaster(object *Zauber) (*models.Spell, error) {
gsmobj := models.Spell{}
err := gsmobj.First(object.Name)
// if found check if we need to adjust masterdata
+1 -1
View File
@@ -73,7 +73,7 @@ func TestGetMasterData(t *testing.T) {
type dtaStruct struct {
Skills []models.Skill `json:"skills"`
Weaponskills []models.WeaponSkill `json:"weaponskills"`
Spell []gsmaster.Spell `json:"spells"`
Spell []models.Spell `json:"spells"`
Equipment []gsmaster.Equipment `json:"equipment"`
Weapons []gsmaster.Weapon `json:"weapons"`
}
+2 -2
View File
@@ -145,7 +145,7 @@ func copyAllDataToTestDB(liveDB, testDB *gorm.DB) (map[string]int, error) {
}
stats["gsmaster_weapon_skills"] = count
count, err = copyTableDataWithCount(liveDB, testDB, &gsmaster.Spell{})
count, err = copyTableDataWithCount(liveDB, testDB, &models.Spell{})
if err != nil {
return stats, err
}
@@ -472,7 +472,7 @@ func getTestDataStatistics(db *gorm.DB) (map[string]int64, error) {
"users": &user.User{},
"characters": &character.Char{},
"gsmaster_skills": &models.Skill{},
"gsmaster_spells": &gsmaster.Spell{},
"gsmaster_spells": &models.Spell{},
"gsmaster_equipment": &gsmaster.Equipment{},
"skills_fertigkeiten": &skills.Fertigkeit{},
"skills_waffenfertigkeiten": &skills.Waffenfertigkeit{},
+1 -1
View File
@@ -18,8 +18,8 @@ func MigrateStructure(db ...*gorm.DB) error {
err := targetDB.AutoMigrate(
&Skill{},
&WeaponSkill{},
&Spell{},
/*
&Spell{},
&Equipment{},
&Weapon{},
&Container{},
+79
View File
@@ -54,6 +54,21 @@ type WeaponSkill struct {
Skill
}
type Spell struct {
LookupList
Bonus int `json:"bonus"`
Stufe int `json:"level"`
AP string `gorm:"default:1" json:"ap"`
Art string `gorm:"default:Gestenzauber" json:"art"`
Zauberdauer string `gorm:"default:10 sec" json:"zauberdauer"`
Reichweite string `json:"reichweite"` // in m
Wirkungsziel string `json:"wirkungsziel"`
Wirkungsbereich string `json:"wirkungsbereich"`
Wirkungsdauer string `json:"wirkungsdauer"`
Ursprung string `json:"ursprung"`
Category string `gorm:"default:normal" json:"category"`
}
func (object *LookupList) Create() error {
gameSystem := "midgard"
object.GameSystem = gameSystem
@@ -246,3 +261,67 @@ func (object *WeaponSkill) Save() error {
}
return nil
}
func (object *Spell) TableName() string {
var dbPrefix = "gsm"
return dbPrefix + "_" + "spells"
}
func (stamm *Spell) Create() error {
gameSystem := "midgard"
stamm.GameSystem = gameSystem
err := database.DB.Transaction(func(tx *gorm.DB) error {
// Save the main character record
if err := tx.Create(&stamm).Error; err != nil {
return fmt.Errorf("failed to save LookupSpell: %w", err)
}
return nil
})
return err
}
func (stamm *Spell) First(name string) error {
gameSystem := "midgard"
err := database.DB.First(&stamm, "game_system=? AND name = ?", gameSystem, name).Error
if err != nil {
// zauber found
return err
}
return nil
}
func (object *Spell) FirstId(value uint) error {
gameSystem := "midgard"
err := database.DB.First(&object, "game_system=? AND id = ?", gameSystem, value).Error
if err != nil {
// zauber found
return err
}
return nil
}
func (object *Spell) Save() error {
err := database.DB.Save(&object).Error
if err != nil {
// zauber found
return err
}
return nil
}
func (object *Spell) GetSpellCategories() ([]string, error) {
var categories []string
gameSystem := "midgard"
result := database.DB.Model(&Spell{}).
Where("game_system=? and category is not null", gameSystem).
Distinct().
Pluck("category", &categories)
if result.Error != nil {
return nil, result.Error
}
return categories, nil
}