-
Notifications
You must be signed in to change notification settings - Fork 2
/
parse.go
775 lines (659 loc) · 20 KB
/
parse.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
package dodumap
import (
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"path/filepath"
"slices"
"strconv"
"strings"
"unicode"
"github.com/charmbracelet/log"
"github.com/emirpasic/gods/maps/treebidimap"
gutils "github.com/emirpasic/gods/utils"
)
type PersistentStringKeysMap struct {
Entries *treebidimap.Map `json:"entries"`
NextId int `json:"next_id"`
}
var (
PersistedElements PersistentStringKeysMap
PersistedTypes PersistentStringKeysMap
)
func LoadPersistedElements(persistenceDir string, release string, majorVersion int) error {
var elements []string
var types []string
if release == "dofus3" {
release = "main"
}
dofus3prefix := ""
if majorVersion == 3 {
dofus3prefix = ".dofus3"
}
if persistenceDir == "" {
elementUrl := fmt.Sprintf("https://raw.githubusercontent.com/dofusdude/doduda/main/persistent/elements%s.%s.json", dofus3prefix, release)
elementResponse, err := http.Get(elementUrl)
if err != nil {
log.Fatal(err)
}
elementBody, err := io.ReadAll(elementResponse.Body)
if err != nil {
log.Fatal(err)
}
err = json.Unmarshal(elementBody, &elements)
if err != nil {
log.Fatal(err)
}
itemTypeUrl := fmt.Sprintf("https://raw.githubusercontent.com/dofusdude/doduda/main/persistent/item_types%s.%s.json", dofus3prefix, release)
itemTypeResponse, err := http.Get(itemTypeUrl)
if err != nil {
log.Fatal(err)
}
itemTypeBody, err := io.ReadAll(itemTypeResponse.Body)
if err != nil {
log.Fatal(err)
}
err = json.Unmarshal(itemTypeBody, &types)
if err != nil {
log.Fatal(err)
}
} else {
data, err := os.ReadFile(filepath.Join(persistenceDir, fmt.Sprintf("elements%s.%s.json", dofus3prefix, release)))
if err != nil {
return err
}
err = json.Unmarshal(data, &elements)
if err != nil {
fmt.Println(err)
}
data, err = os.ReadFile(filepath.Join(persistenceDir, fmt.Sprintf("item_types%s.%s.json", dofus3prefix, release)))
if err != nil {
return err
}
err = json.Unmarshal(data, &types)
if err != nil {
fmt.Println(err)
}
}
PersistedElements = PersistentStringKeysMap{
Entries: treebidimap.NewWith(gutils.IntComparator, gutils.StringComparator),
NextId: 0,
}
for _, entry := range elements {
PersistedElements.Entries.Put(PersistedElements.NextId, entry)
PersistedElements.NextId++
}
PersistedTypes = PersistentStringKeysMap{
Entries: treebidimap.NewWith(gutils.IntComparator, gutils.StringComparator),
NextId: 0,
}
for _, entry := range types {
PersistedTypes.Entries.Put(PersistedTypes.NextId, entry)
PersistedTypes.NextId++
}
return nil
}
func PersistElements(elementPath string, itemTypePath string) error {
elements := make([]string, PersistedElements.NextId)
it := PersistedElements.Entries.Iterator()
for it.Next() {
elements[it.Key().(int)] = it.Value().(string)
}
elementsJson, err := json.MarshalIndent(elements, "", " ")
if err != nil {
return err
}
err = os.WriteFile(elementPath, elementsJson, 0644)
if err != nil {
return err
}
types := make([]string, PersistedTypes.NextId)
it = PersistedTypes.Entries.Iterator()
for it.Next() {
types[it.Key().(int)] = it.Value().(string)
}
typesJson, err := json.MarshalIndent(types, "", " ")
if err != nil {
return err
}
err = os.WriteFile(itemTypePath, typesJson, 0644)
if err != nil {
return err
}
return nil
}
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]
numIsSpell := false
if strings.Contains((*langs)["de"].Texts[currentEffect.DescriptionId], "Zauberspruchs #1") || strings.Contains((*langs)["de"].Texts[currentEffect.DescriptionId], "Zaubers #1") {
numIsSpell = true
}
isTitle := false
if strings.Contains((*langs)["en"].Texts[currentEffect.DescriptionId], "Title:") {
isTitle = true
}
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
var value int
diceNum = effect.MinimumValue
diceSide = effect.MaximumValue
value = effect.Value
effectName := (*langs)[lang].Texts[currentEffect.DescriptionId]
if lang == "de" {
effectName = strings.ReplaceAll(effectName, "{~ps}{~zs}", "") // german has error in template
}
if effectName == "#1" { // is spell description from dicenum 1
effectName = "-special spell-"
mappedEffect.Min = 0
mappedEffect.Max = 0
mappedEffect.Type[lang] = effectName
mappedEffect.Templated[lang] = (*langs)[lang].Texts[data.spells[diceNum].DescriptionId]
mappedEffect.IsMeta = true
} else {
templatedName := effectName
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
}
templatedName = SingularPluralFormatter(templatedName, effect.MinimumValue, lang)
if isTitle { // titles are Title: 0 after formatting; TODO move this into the NumSpellFormatter
templatedName = strings.ReplaceAll(templatedName, "0", (*langs)[lang].Texts[data.titles[diceNum].NameMaleId]) // TODO male default, idk how to make it neutral yet
}
effectName = DeleteDamageFormatter(effectName)
effectName = SingularPluralFormatter(effectName, effect.MinimumValue, lang)
if isTitle {
mappedEffect.Min = 0
mappedEffect.Max = 0
mappedEffect.IsMeta = true
} else {
mappedEffect.Min = diceNum
mappedEffect.Max = diceSide
mappedEffect.IsMeta = false
}
mappedEffect.Max = diceSide
mappedEffect.Type[lang] = effectName
mappedEffect.Templated[lang] = templatedName
}
if lang == "en" && mappedEffect.Type[lang] == "" {
break
}
}
if mappedEffect.Type["en"] == "()" || mappedEffect.Type["en"] == "" {
continue
}
mappedEffect.Active = currentEffect.UseInFight
searchTypeEn := mappedEffect.Type["en"]
if mappedEffect.Active {
searchTypeEn += " (Active)"
}
key, foundKey := PersistedElements.Entries.GetKey(searchTypeEn)
if foundKey {
mappedEffect.ElementId = key.(int)
} else {
mappedEffect.ElementId = PersistedElements.NextId
PersistedElements.Entries.Put(PersistedElements.NextId, searchTypeEn)
PersistedElements.NextId++
}
mappedEffect.MinMaxIrrelevant = minMaxRemove
mappedEffects = append(mappedEffects, mappedEffect)
}
if len(mappedEffects) > 0 {
mappedAllEffects = append(mappedAllEffects, mappedEffects)
}
}
if len(mappedAllEffects) == 0 {
return nil
}
return mappedAllEffects
}
// NewNode creates a new Node
func newNode(value string, nodeType NodeType) *ConditionTreeNode {
return &ConditionTreeNode{
Value: value,
Type: nodeType,
Children: []*ConditionTreeNode{},
}
}
// AddChild adds a child node
func (n *ConditionTreeNode) AddChild(child *ConditionTreeNode) {
n.Children = append(n.Children, child)
}
func ParseExpression(exp string) *ConditionTreeNode {
var stack []*ConditionTreeNode
var current *ConditionTreeNode
var operandBuilder strings.Builder
conditionOperators := []rune{'<', '>', '=', '!'}
for _, char := range exp {
if unicode.IsLetter(char) || unicode.IsDigit(char) || slices.Contains(conditionOperators, char) {
operandBuilder.WriteRune(char) // continue building operand
} else {
if operandBuilder.Len() > 0 {
// finalize and add the operand
if current != nil && current.Type == Operator {
current.AddChild(newNode(operandBuilder.String(), Operand))
} else {
current = newNode(operandBuilder.String(), Operand)
}
operandBuilder.Reset()
}
switch char {
case '(':
if current != nil {
stack = append(stack, current)
}
current = nil
case ')':
if len(stack) > 0 {
parent := stack[len(stack)-1]
stack = stack[:len(stack)-1]
parent.AddChild(current)
current = parent
}
case '&', '|': // expression operators
operator := newNode(string(char), Operator)
if current != nil {
operator.AddChild(current)
}
current = operator
}
}
}
if operandBuilder.Len() > 0 {
if current != nil && current.Type == Operator {
current.AddChild(newNode(operandBuilder.String(), Operand))
} else {
current = newNode(operandBuilder.String(), Operand)
}
}
return current
}
func atomicCondition(expression string, langs *map[string]LangDict, data *JSONGameData) (bool, MappedMultilangCondition) {
operators := []string{"<", ">", "=", "!"}
var out MappedMultilangCondition
out.Templated = make(map[string]string)
foundCond := false
for _, operator := range operators { // try every known operator against it
if strings.Contains(expression, operator) {
foundConditionElement := ConditionWithOperator(expression, operator, langs, &out, data)
if foundConditionElement {
foundCond = true
break
}
}
}
return foundCond, out
}
func removeUnsupportedExpressions(node *ConditionTreeNode, langs *map[string]LangDict, data *JSONGameData) *ConditionTreeNode {
if node == nil {
return nil
}
// If the node is an operand and not supported, return nil
validCond, _ := atomicCondition(node.Value, langs, data)
if node.Type == Operand && !validCond {
return nil
}
// Process children
var validChildren []*ConditionTreeNode
for _, child := range node.Children {
processedChild := removeUnsupportedExpressions(child, langs, data)
if processedChild != nil {
validChildren = append(validChildren, processedChild)
}
}
node.Children = validChildren
return node
}
func simplifyTree(node *ConditionTreeNode) *ConditionTreeNode {
if node == nil {
return nil
}
// Process children
var validChildren []*ConditionTreeNode
for _, child := range node.Children {
processedChild := simplifyTree(child)
if processedChild != nil {
validChildren = append(validChildren, processedChild)
}
}
node.Children = validChildren
// If an operator node has only one child, replace it with its child
if node.Type == Operator && len(node.Children) == 1 {
return node.Children[0]
}
// when no children in operator, return nil
if node.Type == Operator && len(node.Children) == 0 {
return nil
}
return node
}
func buildMappedConditionTree(out **ConditionTreeNodeMapped, root *ConditionTreeNode, langs *map[string]LangDict, data *JSONGameData) {
if root == nil {
return
}
if root.Type == Operand {
foundCond, mappedCond := atomicCondition(root.Value, langs, data)
if !foundCond {
log.Fatal("condition not found, should be handled before")
}
if *out == nil {
*out = new(ConditionTreeNodeMapped)
}
(*out).Value = &mappedCond
(*out).IsOperand = true
return
} else if root.Type == Operator {
if *out == nil {
*out = new(ConditionTreeNodeMapped)
}
(*out).IsOperand = false
if root.Value == "&" {
(*out).Relation = new(string)
*(*out).Relation = "and"
} else if root.Value == "|" {
(*out).Relation = new(string)
*(*out).Relation = "or"
} else {
log.Fatal("unknown operator")
}
(*out).Children = make([]*ConditionTreeNodeMapped, len(root.Children))
for i, child := range root.Children {
childOut := new(*ConditionTreeNodeMapped)
buildMappedConditionTree(childOut, child, langs, data)
(*out).Children[i] = *childOut
}
return
} else {
log.Fatal("unknown node type")
}
}
func PrintTree(node *ConditionTreeNode, level int) {
if node == nil {
return
}
fmt.Printf("%s%s\n", strings.Repeat(" ", level*2), node.Value)
for _, child := range node.Children {
PrintTree(child, level+1)
}
}
func buildHistoricAndConnectionArray(mappedTree *ConditionTreeNodeMapped, out *[]MappedMultilangCondition) {
if mappedTree == nil {
return
}
if mappedTree.IsOperand {
*out = append(*out, *mappedTree.Value)
return
}
if *mappedTree.Relation == "and" {
for _, child := range mappedTree.Children {
buildHistoricAndConnectionArray(child, out)
}
}
}
func ParseCondition(condition string, langs *map[string]LangDict, data *JSONGameData) ([]MappedMultilangCondition, *ConditionTreeNodeMapped) {
if condition == "" || (!strings.Contains(condition, "&") && !strings.Contains(condition, "|") && !strings.Contains(condition, "<") && !strings.Contains(condition, ">")) {
return nil, nil
}
// parse into ast
tree := ParseExpression(condition)
// strip tree to only known conditions
tree = removeUnsupportedExpressions(tree, langs, data)
tree = simplifyTree(tree)
if tree == nil {
return nil, nil
}
// convert to mapped tree
mappedTree := new(*ConditionTreeNodeMapped)
buildMappedConditionTree(mappedTree, tree, langs, data)
if *mappedTree == nil {
log.Fatal("mapped tree is nil")
}
// for historical reasons, still return the old format but only for &-connected conditions
// check the tree and combine all children that are connected with & to a single array
var mappedConditions []MappedMultilangCondition
buildHistoricAndConnectionArray(*mappedTree, &mappedConditions)
if len(mappedConditions) == 0 {
mappedConditions = nil
}
return mappedConditions, *mappedTree
}
// TODO: previous "conditions" convert to only be with simple & operator
type HasId interface {
GetID() int
}
func CleanJSON(jsonStr string) string {
jsonStr = strings.ReplaceAll(jsonStr, "NaN", "null")
jsonStr = strings.ReplaceAll(jsonStr, "\"null\"", "null")
jsonStr = strings.ReplaceAll(jsonStr, " ", " ")
return jsonStr
}
func ParseRawDataPart[T HasId](fileSource string, result chan map[int]T, dir string) {
file, err := os.ReadFile(filepath.Join(dir, fileSource))
if err != nil {
fmt.Print(err)
}
fileStr := CleanJSON(string(file))
var fileJson []T
err = json.Unmarshal([]byte(fileStr), &fileJson)
if err != nil {
fmt.Println(err)
}
items := make(map[int]T)
for _, item := range fileJson {
items[item.GetID()] = item
}
result <- items
}
func ParseRawData(dir string) *JSONGameData {
var data JSONGameData
itemChan := make(chan map[int]JSONGameItem)
itemTypeChan := make(chan map[int]JSONGameItemType)
itemSetsChan := make(chan map[int]JSONGameSet)
itemEffectsChan := make(chan map[int]JSONGameEffect)
itemBonusesChan := make(chan map[int]JSONGameBonus)
itemRecipesChang := make(chan map[int]JSONGameRecipe)
spellsChan := make(chan map[int]JSONGameSpell)
spellTypesChan := make(chan map[int]JSONGameSpellType)
areasChan := make(chan map[int]JSONGameArea)
mountsChan := make(chan map[int]JSONGameMount)
breedsChan := make(chan map[int]JSONGameBreed)
mountFamilyChan := make(chan map[int]JSONGameMountFamily)
npcsChan := make(chan map[int]JSONGameNPC)
titlesChan := make(chan map[int]JSONGameTitle)
questsChan := make(chan map[int]JSONGameQuest)
questObjectivesChan := make(chan map[int]JSONGameQuestObjective)
questStepRewardsChan := make(chan map[int]JSONGameQuestStepRewards)
questCategoriesChan := make(chan map[int]JSONGameQuestCategory)
questStepsChan := make(chan map[int]JSONGameQuestStep)
almanaxCalendarsChan := make(chan map[int]JSONGameAlamanaxCalendar)
go func() {
ParseRawDataPart("npcs.json", npcsChan, dir)
}()
go func() {
ParseRawDataPart("mount_family.json", mountFamilyChan, dir)
}()
go func() {
ParseRawDataPart("breeds.json", breedsChan, dir)
}()
go func() {
ParseRawDataPart("mounts.json", mountsChan, dir)
}()
go func() {
ParseRawDataPart("areas.json", areasChan, dir)
}()
go func() {
ParseRawDataPart("spell_types.json", spellTypesChan, dir)
}()
go func() {
ParseRawDataPart("spells.json", spellsChan, dir)
}()
go func() {
ParseRawDataPart("recipes.json", itemRecipesChang, dir)
}()
go func() {
ParseRawDataPart("items.json", itemChan, dir)
}()
go func() {
ParseRawDataPart("item_types.json", itemTypeChan, dir)
}()
go func() {
ParseRawDataPart("item_sets.json", itemSetsChan, dir)
}()
go func() {
ParseRawDataPart("bonuses.json", itemBonusesChan, dir)
}()
go func() {
ParseRawDataPart("effects.json", itemEffectsChan, dir)
}()
go func() {
ParseRawDataPart("titles.json", titlesChan, dir)
}()
go func() {
ParseRawDataPart("quests.json", questsChan, dir)
}()
go func() {
ParseRawDataPart("quest_objectives.json", questObjectivesChan, dir)
}()
go func() {
ParseRawDataPart("quest_step_rewards.json", questStepRewardsChan, dir)
}()
go func() {
ParseRawDataPart("quest_categories.json", questCategoriesChan, dir)
}()
go func() {
ParseRawDataPart("almanax.json", almanaxCalendarsChan, dir)
}()
go func() {
ParseRawDataPart("quest_steps.json", questStepsChan, dir)
}()
data.Items = <-itemChan
close(itemChan)
data.bonuses = <-itemBonusesChan
close(itemBonusesChan)
data.effects = <-itemEffectsChan
close(itemEffectsChan)
data.ItemTypes = <-itemTypeChan
close(itemTypeChan)
data.Sets = <-itemSetsChan
close(itemSetsChan)
data.Recipes = <-itemRecipesChang
close(itemRecipesChang)
data.spells = <-spellsChan
close(spellsChan)
data.spellTypes = <-spellTypesChan
close(spellTypesChan)
data.areas = <-areasChan
close(areasChan)
data.Mounts = <-mountsChan
close(mountsChan)
data.classes = <-breedsChan
close(breedsChan)
data.MountFamilys = <-mountFamilyChan
close(mountFamilyChan)
data.npcs = <-npcsChan
close(npcsChan)
data.titles = <-titlesChan
close(titlesChan)
data.quests = <-questsChan
close(questsChan)
data.questObjectives = <-questObjectivesChan
close(questObjectivesChan)
data.questStepRewards = <-questStepRewardsChan
close(questStepRewardsChan)
data.questCategories = <-questCategoriesChan
close(questCategoriesChan)
data.almanaxCalendars = <-almanaxCalendarsChan
close(almanaxCalendarsChan)
data.questSteps = <-questStepsChan
close(questStepsChan)
return &data
}
func ParseLangDict(langCode string, dir string) LangDict {
var err error
dataPath := filepath.Join(dir, "languages")
var data LangDict
data.IdText = make(map[int]int)
data.Texts = make(map[int]string)
data.NameText = make(map[string]int)
langFile, err := os.ReadFile(filepath.Join(dataPath, langCode+".json"))
if err != nil {
fmt.Print(err)
}
langFileStr := CleanJSON(string(langFile))
var langJson JSONLangDict
err = json.Unmarshal([]byte(langFileStr), &langJson)
if err != nil {
fmt.Println(err)
}
for key, value := range langJson.IdText {
keyParsed, err := strconv.Atoi(key)
if err != nil {
fmt.Println(err)
}
data.IdText[keyParsed] = value
}
for key, value := range langJson.Texts {
keyParsed, err := strconv.Atoi(key)
if err != nil {
fmt.Println(err)
}
data.Texts[keyParsed] = value
}
data.NameText = langJson.NameText
return data
}
func ParseRawLanguages(dir string) map[string]LangDict {
data := make(map[string]LangDict)
for _, lang := range Languages {
data[lang] = ParseLangDict(lang, dir)
}
return data
}