From 8ef352cc37335291bd4401033e57c1e6040971ec Mon Sep 17 00:00:00 2001 From: stelzo Date: Sat, 23 Mar 2024 17:45:17 +0100 Subject: [PATCH 1/3] data integrity bugs --- go.mod | 12 ++++----- go.sum | 12 +++++++++ mapping.go | 14 ++++++---- mapping_test.go | 39 ++++++++++++++++++---------- parse.go | 46 +++++++++++++++++++++++++++++++-- parse_types.go | 68 +++++++++++++++++++++++++++++-------------------- templating.go | 45 +++++++++++++++++++++++++++----- 7 files changed, 175 insertions(+), 61 deletions(-) diff --git a/go.mod b/go.mod index ed9002e..f0f8177 100644 --- a/go.mod +++ b/go.mod @@ -3,20 +3,20 @@ module github.com/dofusdude/dodumap go 1.21 require ( - github.com/charmbracelet/log v0.3.1 + github.com/charmbracelet/log v0.4.0 github.com/emirpasic/gods v1.18.1 ) require ( github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect - github.com/charmbracelet/lipgloss v0.9.1 // indirect + github.com/charmbracelet/lipgloss v0.10.0 // indirect github.com/go-logfmt/logfmt v0.6.0 // indirect github.com/lucasb-eyer/go-colorful v1.2.0 // indirect - github.com/mattn/go-isatty v0.0.19 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.15 // indirect github.com/muesli/reflow v0.3.0 // indirect github.com/muesli/termenv v0.15.2 // indirect - github.com/rivo/uniseg v0.4.4 // indirect - golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect - golang.org/x/sys v0.13.0 // indirect + github.com/rivo/uniseg v0.4.7 // indirect + golang.org/x/exp v0.0.0-20240318143956-a85f2c67cd81 // indirect + golang.org/x/sys v0.18.0 // indirect ) diff --git a/go.sum b/go.sum index 4c1622e..ade6fdb 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,12 @@ github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiE github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= github.com/charmbracelet/lipgloss v0.9.1 h1:PNyd3jvaJbg4jRHKWXnCj1akQm4rh8dbEzN1p/u1KWg= github.com/charmbracelet/lipgloss v0.9.1/go.mod h1:1mPmG4cxScwUQALAAnacHaigiiHB9Pmr+v1VEawJl6I= +github.com/charmbracelet/lipgloss v0.10.0 h1:KWeXFSexGcfahHX+54URiZGkBFazf70JNMtwg/AFW3s= +github.com/charmbracelet/lipgloss v0.10.0/go.mod h1:Wig9DSfvANsxqkRsqj6x87irdy123SR4dOXlKa91ciE= github.com/charmbracelet/log v0.3.1 h1:TjuY4OBNbxmHWSwO3tosgqs5I3biyY8sQPny/eCMTYw= github.com/charmbracelet/log v0.3.1/go.mod h1:OR4E1hutLsax3ZKpXbgUqPtTjQfrh1pG3zwHGWuuq8g= +github.com/charmbracelet/log v0.4.0 h1:G9bQAcx8rWA2T3pWvx7YtPTPwgqpk7D68BX21IRW8ZM= +github.com/charmbracelet/log v0.4.0/go.mod h1:63bXt/djrizTec0l11H20t8FDSvA4CRZJ1KH22MdptM= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= @@ -13,6 +17,8 @@ github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69 github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= @@ -25,10 +31,16 @@ github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= +github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo= +golang.org/x/exp v0.0.0-20240318143956-a85f2c67cd81 h1:6R2FC06FonbXQ8pK11/PDFY6N6LWlf9KlzibaCapmqc= +golang.org/x/exp v0.0.0-20240318143956-a85f2c67cd81/go.mod h1:CQ1k9gNrJ50XIzaKCRR2hssIjF07kZFEiieALBM/ARQ= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= +golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/mapping.go b/mapping.go index 8cc270f..e2dd698 100644 --- a/mapping.go +++ b/mapping.go @@ -7,7 +7,7 @@ import ( "strings" ) -var Languages = []string{"de", "en", "es", "fr", "it", "pt"} +var Languages = []string{"fr", "en", "de", "es", "it", "pt"} func MapSets(data *JSONGameData, langs *map[string]LangDict) []MappedMultilangSet { var mappedSets []MappedMultilangSet @@ -15,7 +15,7 @@ func MapSets(data *JSONGameData, langs *map[string]LangDict) []MappedMultilangSe var mappedSet MappedMultilangSet mappedSet.AnkamaId = set.Id mappedSet.ItemIds = set.ItemIds - mappedSet.Effects = ParseEffects(data, set.Effects, langs) + mappedSet.Effects = ParseItemCombo(set.Effects, ParseEffects(data, set.Effects, langs)) highestLevel := 0 for _, item := range set.ItemIds { @@ -78,7 +78,9 @@ func MapMounts(data *JSONGameData, langs *map[string]LangDict) []MappedMultilang mappedMount.FamilyName[lang] = (*langs)[lang].Texts[data.MountFamilys[mount.FamilyId].NameId] } - allEffectResult := ParseEffects(data, [][]JSONGameItemPossibleEffect{mount.Effects}, langs) + effectsArr := make([][]*JSONGameItemPossibleEffect, 1) + effectsArr[0] = mount.Effects + allEffectResult := ParseEffects(data, effectsArr, langs) if len(allEffectResult) > 0 { mappedMount.Effects = allEffectResult[0] } @@ -120,7 +122,7 @@ func MapAlmanax(data *JSONGameData, langs *map[string]LangDict) []MappedMultilan } } if !found { - log.Fatal(fmt.Sprintf("Could not find almanax calendar for NPC %d", questObjectiveNpc)) + log.Fatalf("Could not find almanax calendar for NPC %d", questObjectiveNpc) } var mappedNPCAlmanax MappedMultilangNPCAlmanax @@ -206,7 +208,9 @@ func MapItems(data *JSONGameData, langs *map[string]LangDict) []MappedMultilangI } mappedItems[idx].UsedInRecipes = item.RecipeIds - allEffectResult := ParseEffects(data, [][]JSONGameItemPossibleEffect{item.PossibleEffects}, langs) + effectsArr := make([][]*JSONGameItemPossibleEffect, 1) + effectsArr[0] = item.PossibleEffects + allEffectResult := ParseEffects(data, effectsArr, langs) if len(allEffectResult) > 0 { mappedItems[idx].Effects = allEffectResult[0] } diff --git a/mapping_test.go b/mapping_test.go index f0ac428..71ea859 100644 --- a/mapping_test.go +++ b/mapping_test.go @@ -341,7 +341,8 @@ func TestParseNumSpellNameFormatterItSpecial(t *testing.T) { diceNum := 100 diceSide := 233 value := 0 - output, _ := NumSpellFormatter(input, "it", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false) + frNumSigned := 2 + output, _ := NumSpellFormatter(input, "it", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false, &frNumSigned, &frNumSigned) if output != "Ottieni: 100 - 233 kama" { t.Errorf("output is not as expected: %s", output) @@ -361,7 +362,8 @@ func TestParseNumSpellNameFormatterItSpecialSwitch(t *testing.T) { diceNum := 100 diceSide := 36 value := 0 - output, _ := NumSpellFormatter(input, "it", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false) + frNumSigned := 2 + output, _ := NumSpellFormatter(input, "it", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false, &frNumSigned, &frNumSigned) if output != "36: +100 EP" { t.Errorf("output is not as expected: %s", output) @@ -381,7 +383,8 @@ func TestParseNumSpellNameFormatterLearnSpellLevel(t *testing.T) { diceNum := 0 diceSide := 0 value := 1746 - output, _ := NumSpellFormatter(input, "de", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false) + frNumSigned := 2 + output, _ := NumSpellFormatter(input, "de", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false, &frNumSigned, &frNumSigned) if output != "Stufe 1746 des Zauberspruchs erlernen" { t.Errorf("output is not as expected: %s", output) @@ -393,7 +396,8 @@ func TestParseNumSpellNameFormatterLearnSpellLevel1(t *testing.T) { diceNum := 0 diceSide := 1 value := 0 - output, _ := NumSpellFormatter(input, "de", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false) + frNumSigned := 2 + output, _ := NumSpellFormatter(input, "de", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false, &frNumSigned, &frNumSigned) if output != "Stufe 1 des Zauberspruchs erlernen" { t.Errorf("output is not as expected: %s", output) @@ -405,7 +409,8 @@ func TestParseNumSpellNameFormatterDeNormal(t *testing.T) { diceNum := 100 diceSide := 233 value := 0 - output, _ := NumSpellFormatter(input, "de", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false) + frNumSigned := 2 + output, _ := NumSpellFormatter(input, "de", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false, &frNumSigned, &frNumSigned) if output != "100 bis 233 Kamagewinn" { t.Errorf("output is not as expected: %s", output) @@ -417,7 +422,8 @@ func TestParseNumSpellNameFormatterMultiValues(t *testing.T) { diceNum := 1 diceSide := 2 value := 0 - output, _ := NumSpellFormatter(input, "de", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false) + frNumSigned := 2 + output, _ := NumSpellFormatter(input, "de", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false, &frNumSigned, &frNumSigned) if output != "Erfolgschance zwischen 1 und 2%" { t.Errorf("output is not as expected: %s", output) @@ -427,7 +433,8 @@ func TestParseNumSpellNameFormatterMultiValues(t *testing.T) { diceNum = 1 diceSide = 2 value = 0 - output, _ = NumSpellFormatter(input, "de", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false) + frNumSigned = 2 + output, _ = NumSpellFormatter(input, "de", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false, &frNumSigned, &frNumSigned) if output != "Erfolgschance zwischen -1 und -2%" { t.Errorf("output is not as expected: %s", output) @@ -439,7 +446,8 @@ func TestParseNumSpellNameFormatterVitaRange(t *testing.T) { diceNum := 0 diceSide := 300 value := 0 - output, _ := NumSpellFormatter(input, "de", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, true) + frNumSigned := 2 + output, _ := NumSpellFormatter(input, "de", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, true, &frNumSigned, &frNumSigned) if output != "0 bis 300 Vitalität" { t.Errorf("output is not as expected: %s", output) @@ -451,7 +459,8 @@ func TestParseNumSpellNameFormatterSingle(t *testing.T) { diceNum := 1 diceSide := 0 value := 0 - output, _ := NumSpellFormatter(input, "de", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false) + frNumSigned := 2 + output, _ := NumSpellFormatter(input, "de", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false, &frNumSigned, &frNumSigned) if output != "Austauschbar ab: 1" { t.Errorf("output is not as expected: %s", output) @@ -463,7 +472,8 @@ func TestParseNumSpellNameFormatterMinMax(t *testing.T) { diceNum := 2 diceSide := 5 value := 6 - output, _ := NumSpellFormatter(input, "de", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false) + frNumSigned := 2 + output, _ := NumSpellFormatter(input, "de", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false, &frNumSigned, &frNumSigned) if output != "Verbleib. Anwendungen: 5 / 6" { t.Errorf("output is not as expected: %s", output) } @@ -474,7 +484,8 @@ func TestParseNumSpellNameFormatterSpellDiceNum(t *testing.T) { diceNum := 15960 diceSide := 0 value := 0 - output, _ := NumSpellFormatter(input, "de", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false) + frNumSigned := 2 + output, _ := NumSpellFormatter(input, "de", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false, &frNumSigned, &frNumSigned) if output != "Zauberwurf: Mauschelei" { t.Errorf("output is not as expected: %s", output) @@ -486,8 +497,9 @@ func TestParseNumSpellNameFormatterEffectsRange(t *testing.T) { diceNum := 25 diceSide := 50 value := 0 + frNumSigned := 2 - output, _ := NumSpellFormatter(input, "de", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false) + output, _ := NumSpellFormatter(input, "de", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false, &frNumSigned, &frNumSigned) if output != "-25 bis -50 Luftschaden" { t.Errorf("output is not as expected: %s", output) } @@ -498,8 +510,9 @@ func TestParseNumSpellNameFormatterMissingWhite(t *testing.T) { diceNum := 1 diceSide := 0 value := 0 + frNumSigned := 2 - output, _ := NumSpellFormatter(input, "de", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false) + output, _ := NumSpellFormatter(input, "de", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false, &frNumSigned, &frNumSigned) if output != "1 level" { t.Errorf("output is not as expected: %s", output) } diff --git a/parse.go b/parse.go index 1361c9c..dd56549 100644 --- a/parse.go +++ b/parse.go @@ -140,12 +140,52 @@ func PersistElements(elementPath string, itemTypePath string) error { return nil } -func ParseEffects(data *JSONGameData, allEffects [][]JSONGameItemPossibleEffect, langs *map[string]LangDict) [][]MappedMultilangEffect { +func ParseItemCombo(rawEffects [][]*JSONGameItemPossibleEffect, effects [][]MappedMultilangEffect) [][]MappedMultilangSetEffect { + var mappedEffects [][]MappedMultilangSetEffect + i := 0 + for itemComboCounter, effectsPerCombo := range rawEffects { + var mappedEffectsPerCombo []MappedMultilangSetEffect + + j := 0 + for _, effect := range effectsPerCombo { + if effect == nil { + continue + } + + parsedEffects := effects[i] + parsedEffect := parsedEffects[j] + setEffect := MappedMultilangSetEffect{ + Min: parsedEffect.Min, + Max: parsedEffect.Max, + Type: parsedEffect.Type, + Templated: parsedEffect.Templated, + Active: parsedEffect.Active, + ElementId: parsedEffect.ElementId, + IsMeta: parsedEffect.IsMeta, + MinMaxIrrelevant: parsedEffect.MinMaxIrrelevant, + ItemCombination: uint(itemComboCounter + 1), + } + mappedEffectsPerCombo = append(mappedEffectsPerCombo, setEffect) + j += 1 + } + if len(mappedEffectsPerCombo) > 0 { + mappedEffects = append(mappedEffects, mappedEffectsPerCombo) + i += 1 + } + } + return mappedEffects +} + +func ParseEffects(data *JSONGameData, allEffects [][]*JSONGameItemPossibleEffect, langs *map[string]LangDict) [][]MappedMultilangEffect { var mappedAllEffects [][]MappedMultilangEffect for _, effects := range allEffects { var mappedEffects []MappedMultilangEffect for _, effect := range effects { + if effect == nil { + continue + } + var mappedEffect MappedMultilangEffect currentEffect := data.effects[effect.EffectId] @@ -162,6 +202,8 @@ func ParseEffects(data *JSONGameData, allEffects [][]JSONGameItemPossibleEffect, mappedEffect.Type = make(map[string]string) mappedEffect.Templated = make(map[string]string) var minMaxRemove int + var frNumSigned int = 2 // unset + var frSideSigned int = 2 // unset for _, lang := range Languages { var diceNum int var diceSide int @@ -187,7 +229,7 @@ func ParseEffects(data *JSONGameData, allEffects [][]JSONGameItemPossibleEffect, mappedEffect.IsMeta = true } else { templatedName := effectName - templatedName, minMaxRemove = NumSpellFormatter(templatedName, lang, data, langs, &diceNum, &diceSide, &value, currentEffect.DescriptionId, numIsSpell, currentEffect.UseDice) + templatedName, minMaxRemove = NumSpellFormatter(templatedName, lang, data, langs, &diceNum, &diceSide, &value, currentEffect.DescriptionId, numIsSpell, currentEffect.UseDice, &frNumSigned, &frSideSigned) if templatedName == "" { // found effect that should be discarded for now break } diff --git a/parse_types.go b/parse_types.go index 43fe142..91f77f6 100644 --- a/parse_types.go +++ b/parse_types.go @@ -46,11 +46,11 @@ type MappedMultilangSetReverseLink struct { } type MappedMultilangSet struct { - AnkamaId int `json:"ankama_id"` - Name map[string]string `json:"name"` - ItemIds []int `json:"items"` - Effects [][]MappedMultilangEffect `json:"effects"` - Level int `json:"level"` + AnkamaId int `json:"ankama_id"` + Name map[string]string `json:"name"` + ItemIds []int `json:"items"` + Effects [][]MappedMultilangSetEffect `json:"effects"` + Level int `json:"level"` } type MappedMultilangMount struct { @@ -66,6 +66,18 @@ type MappedMultilangCharacteristic struct { Name map[string]string `json:"name"` } +type MappedMultilangSetEffect struct { + Min int `json:"min"` + Max int `json:"max"` + Type map[string]string `json:"type"` + MinMaxIrrelevant int `json:"min_max_irrelevant"` + Templated map[string]string `json:"templated"` + ElementId int `json:"element_id"` + IsMeta bool `json:"is_meta"` + Active bool `json:"active"` + ItemCombination uint `json:"item_combination"` +} + type MappedMultilangEffect struct { Min int `json:"min"` Max int `json:"max"` @@ -232,10 +244,10 @@ func (i JSONGameItemPossibleEffect) GetID() int { } type JSONGameSet struct { - Id int `json:"id"` - ItemIds []int `json:"items"` - NameId int `json:"nameId"` - Effects [][]JSONGameItemPossibleEffect `json:"effects"` + Id int `json:"id"` + ItemIds []int `json:"items"` + NameId int `json:"nameId"` + Effects [][]*JSONGameItemPossibleEffect `json:"effects"` } func (i JSONGameSet) GetID() int { @@ -279,21 +291,21 @@ type JSONGameItem struct { NameId int `json:"nameId"` Level int `json:"level"` - PossibleEffects []JSONGameItemPossibleEffect `json:"possibleEffects"` - RecipeIds []int `json:"recipeIds"` - Pods int `json:"realWeight"` - ParseEffects bool `json:"useDice"` - EvolutiveEffectIds []int `json:"evolutiveEffectIds"` - DropMonsterIds []int `json:"dropMonsterIds"` - ItemSetId int `json:"itemSetId"` - Criteria string `json:"criteria"` - CriticalHitBonus int `json:"criticalHitBonus"` - TwoHanded bool `json:"twoHanded"` - MaxCastPerTurn int `json:"maxCastPerTurn"` - ApCost int `json:"apCost"` - Range int `json:"range"` - MinRange int `json:"minRange"` - CriticalHitProbability int `json:"criticalHitProbability"` + PossibleEffects []*JSONGameItemPossibleEffect `json:"possibleEffects"` + RecipeIds []int `json:"recipeIds"` + Pods int `json:"realWeight"` + ParseEffects bool `json:"useDice"` + EvolutiveEffectIds []int `json:"evolutiveEffectIds"` + DropMonsterIds []int `json:"dropMonsterIds"` + ItemSetId int `json:"itemSetId"` + Criteria string `json:"criteria"` + CriticalHitBonus int `json:"criticalHitBonus"` + TwoHanded bool `json:"twoHanded"` + MaxCastPerTurn int `json:"maxCastPerTurn"` + ApCost int `json:"apCost"` + Range int `json:"range"` + MinRange int `json:"minRange"` + CriticalHitProbability int `json:"criticalHitProbability"` } func (i JSONGameItem) GetID() int { @@ -312,10 +324,10 @@ func (i JSONGameBreed) GetID() int { } type JSONGameMount struct { - Id int `json:"id"` - FamilyId int `json:"familyId"` - NameId int `json:"nameId"` - Effects []JSONGameItemPossibleEffect `json:"effects"` + Id int `json:"id"` + FamilyId int `json:"familyId"` + NameId int `json:"nameId"` + Effects []*JSONGameItemPossibleEffect `json:"effects"` } func (i JSONGameMount) GetID() int { diff --git a/templating.go b/templating.go index 3b8c386..c2a793d 100644 --- a/templating.go +++ b/templating.go @@ -95,8 +95,8 @@ func SingularPluralFormatter(input string, amount int, lang string) string { return str } -func ElementFromCode(code string) int { - code = strings.ToLower(code) +func ElementFromCode(codeUndef string) int { + code := strings.ToLower(codeUndef) switch code { case "cs": @@ -112,7 +112,11 @@ func ElementFromCode(code string) int { case "cw": return 501946 // "Wisdom" case "pk": - return 422874 // "Set-Bonus" + if codeUndef == "PK" { + return 66438 // "Kamas" + } else { + return 422874 // "Set-Bonus" + } case "pl": return 837224 // "Mindestens Stufe %1" case "cm": @@ -144,7 +148,7 @@ func ConditionWithOperator(input string, operator string, langs *map[string]Lang if rawElement == -1 { return false } - out.Element = strings.ToLower(partSplit[0]) + out.Element = partSplit[0] out.Value, _ = strconv.Atoi(partSplit[1]) for _, lang := range Languages { langStr := (*langs)[lang].Texts[rawElement] @@ -190,7 +194,7 @@ func ConditionWithOperator(input string, operator string, langs *map[string]Lang } // NumSpellFormatter returns info about min max with in. -1 "only_min", -2 "no_min_max" -func NumSpellFormatter(input string, lang string, gameData *JSONGameData, langs *map[string]LangDict, diceNum *int, diceSide *int, value *int, effectNameId int, numIsSpell bool, useDice bool) (string, int) { +func NumSpellFormatter(input string, lang string, gameData *JSONGameData, langs *map[string]LangDict, diceNum *int, diceSide *int, value *int, effectNameId int, numIsSpell bool, useDice bool, frNumSigned *int, frSideSigned *int) (string, int) { diceNumIsSpellId := *diceNum > 12000 || numIsSpell diceSideIsSpellId := *diceSide > 12000 valueIsSpellId := *value > 12000 @@ -206,7 +210,30 @@ func NumSpellFormatter(input string, lang string, gameData *JSONGameData, langs delValue := false input, concatRegex := PrepareAndCreateRangeRegex(input, true) - numSigned, sideSigned := ParseSigness(input) + var numSigned bool + var sideSigned bool + var ptSideSigned bool + _, ptSideSigned = ParseSigness(input) + if *frNumSigned != 2 || *frSideSigned != 2 { // 2 is unset, 0 is false, 1 is true + numSigned = *frNumSigned == 1 + sideSigned = *frSideSigned == 1 + } else { + if lang == "fr" { + numSigned, sideSigned = ParseSigness(input) + if numSigned { + *frNumSigned = 1 + } else { + *frNumSigned = 0 + } + if sideSigned { + *frSideSigned = 1 + } else { + *frSideSigned = 0 + } + } else { + log.Fatalf("frNumSigned and frSideSigned must be set for %s", lang) + } + } concatEntries := concatRegex.FindAllStringSubmatch(input, -1) if *diceSide == 0 { // only replace #1 with dice_num @@ -239,7 +266,11 @@ func NumSpellFormatter(input string, lang string, gameData *JSONGameData, langs diceSideStr = (*langs)[lang].Texts[gameData.spells[*diceSide].NameId] //del_dice_side = true } else { - diceSideStr = fmt.Sprint(*diceSide) + if sideSigned && lang == "pt" && !ptSideSigned { + diceSideStr = fmt.Sprintf("-%d", *diceSide) + } else { + diceSideStr = fmt.Sprint(*diceSide) + } } input = strings.ReplaceAll(input, "#2", diceSideStr) } From 6b924c20a9a9e1ceace2f23f16e3988646971b15 Mon Sep 17 00:00:00 2001 From: stelzo Date: Sat, 23 Mar 2024 17:56:45 +0100 Subject: [PATCH 2/3] fix fr sign --- mapping_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mapping_test.go b/mapping_test.go index 71ea859..d7d4a40 100644 --- a/mapping_test.go +++ b/mapping_test.go @@ -341,7 +341,7 @@ func TestParseNumSpellNameFormatterItSpecial(t *testing.T) { diceNum := 100 diceSide := 233 value := 0 - frNumSigned := 2 + frNumSigned := 0 // unsigned output, _ := NumSpellFormatter(input, "it", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false, &frNumSigned, &frNumSigned) if output != "Ottieni: 100 - 233 kama" { From e1ab6159b646f32473eea775563e2ff51bdefb86 Mon Sep 17 00:00:00 2001 From: stelzo Date: Sat, 23 Mar 2024 18:04:17 +0100 Subject: [PATCH 3/3] non fr pre-sign --- mapping_test.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/mapping_test.go b/mapping_test.go index d7d4a40..0eaf97d 100644 --- a/mapping_test.go +++ b/mapping_test.go @@ -362,7 +362,7 @@ func TestParseNumSpellNameFormatterItSpecialSwitch(t *testing.T) { diceNum := 100 diceSide := 36 value := 0 - frNumSigned := 2 + frNumSigned := 0 output, _ := NumSpellFormatter(input, "it", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false, &frNumSigned, &frNumSigned) if output != "36: +100 EP" { @@ -383,7 +383,7 @@ func TestParseNumSpellNameFormatterLearnSpellLevel(t *testing.T) { diceNum := 0 diceSide := 0 value := 1746 - frNumSigned := 2 + frNumSigned := 0 output, _ := NumSpellFormatter(input, "de", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false, &frNumSigned, &frNumSigned) if output != "Stufe 1746 des Zauberspruchs erlernen" { @@ -396,7 +396,7 @@ func TestParseNumSpellNameFormatterLearnSpellLevel1(t *testing.T) { diceNum := 0 diceSide := 1 value := 0 - frNumSigned := 2 + frNumSigned := 0 output, _ := NumSpellFormatter(input, "de", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false, &frNumSigned, &frNumSigned) if output != "Stufe 1 des Zauberspruchs erlernen" { @@ -409,7 +409,7 @@ func TestParseNumSpellNameFormatterDeNormal(t *testing.T) { diceNum := 100 diceSide := 233 value := 0 - frNumSigned := 2 + frNumSigned := 0 output, _ := NumSpellFormatter(input, "de", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false, &frNumSigned, &frNumSigned) if output != "100 bis 233 Kamagewinn" { @@ -422,7 +422,7 @@ func TestParseNumSpellNameFormatterMultiValues(t *testing.T) { diceNum := 1 diceSide := 2 value := 0 - frNumSigned := 2 + frNumSigned := 0 output, _ := NumSpellFormatter(input, "de", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false, &frNumSigned, &frNumSigned) if output != "Erfolgschance zwischen 1 und 2%" { @@ -433,7 +433,7 @@ func TestParseNumSpellNameFormatterMultiValues(t *testing.T) { diceNum = 1 diceSide = 2 value = 0 - frNumSigned = 2 + frNumSigned = 0 output, _ = NumSpellFormatter(input, "de", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false, &frNumSigned, &frNumSigned) if output != "Erfolgschance zwischen -1 und -2%" { @@ -446,7 +446,7 @@ func TestParseNumSpellNameFormatterVitaRange(t *testing.T) { diceNum := 0 diceSide := 300 value := 0 - frNumSigned := 2 + frNumSigned := 0 output, _ := NumSpellFormatter(input, "de", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, true, &frNumSigned, &frNumSigned) if output != "0 bis 300 Vitalität" { @@ -459,7 +459,7 @@ func TestParseNumSpellNameFormatterSingle(t *testing.T) { diceNum := 1 diceSide := 0 value := 0 - frNumSigned := 2 + frNumSigned := 0 output, _ := NumSpellFormatter(input, "de", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false, &frNumSigned, &frNumSigned) if output != "Austauschbar ab: 1" { @@ -472,7 +472,7 @@ func TestParseNumSpellNameFormatterMinMax(t *testing.T) { diceNum := 2 diceSide := 5 value := 6 - frNumSigned := 2 + frNumSigned := 0 output, _ := NumSpellFormatter(input, "de", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false, &frNumSigned, &frNumSigned) if output != "Verbleib. Anwendungen: 5 / 6" { t.Errorf("output is not as expected: %s", output) @@ -484,7 +484,7 @@ func TestParseNumSpellNameFormatterSpellDiceNum(t *testing.T) { diceNum := 15960 diceSide := 0 value := 0 - frNumSigned := 2 + frNumSigned := 0 output, _ := NumSpellFormatter(input, "de", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false, &frNumSigned, &frNumSigned) if output != "Zauberwurf: Mauschelei" { @@ -497,7 +497,7 @@ func TestParseNumSpellNameFormatterEffectsRange(t *testing.T) { diceNum := 25 diceSide := 50 value := 0 - frNumSigned := 2 + frNumSigned := 0 output, _ := NumSpellFormatter(input, "de", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false, &frNumSigned, &frNumSigned) if output != "-25 bis -50 Luftschaden" { @@ -510,7 +510,7 @@ func TestParseNumSpellNameFormatterMissingWhite(t *testing.T) { diceNum := 1 diceSide := 0 value := 0 - frNumSigned := 2 + frNumSigned := 0 output, _ := NumSpellFormatter(input, "de", TestingData, &TestingLangs, &diceNum, &diceSide, &value, 0, false, false, &frNumSigned, &frNumSigned) if output != "1 level" {