Skip to content

Commit

Permalink
Merge pull request #7 from dofusdude/dofuslab-bugs
Browse files Browse the repository at this point in the history
Fix data integrity bugs
  • Loading branch information
stelzo authored Mar 23, 2024
2 parents 8052102 + e1ab615 commit 1b9df55
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 61 deletions.
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
12 changes: 12 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -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=
Expand All @@ -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=
14 changes: 9 additions & 5 deletions mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ 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
for _, set := range data.Sets {
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 {
Expand Down Expand Up @@ -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]
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
}
Expand Down
39 changes: 26 additions & 13 deletions mapping_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := 0 // unsigned
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)
Expand All @@ -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 := 0
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)
Expand All @@ -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 := 0
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)
Expand All @@ -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 := 0
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)
Expand All @@ -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 := 0
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)
Expand All @@ -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 := 0
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)
Expand All @@ -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 = 0
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)
Expand All @@ -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 := 0
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)
Expand All @@ -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 := 0
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)
Expand All @@ -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 := 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)
}
Expand All @@ -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 := 0
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)
Expand All @@ -486,8 +497,9 @@ func TestParseNumSpellNameFormatterEffectsRange(t *testing.T) {
diceNum := 25
diceSide := 50
value := 0
frNumSigned := 0

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)
}
Expand All @@ -498,8 +510,9 @@ func TestParseNumSpellNameFormatterMissingWhite(t *testing.T) {
diceNum := 1
diceSide := 0
value := 0
frNumSigned := 0

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)
}
Expand Down
46 changes: 44 additions & 2 deletions parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand All @@ -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
Expand All @@ -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
}
Expand Down
Loading

0 comments on commit 1b9df55

Please sign in to comment.