Skip to content

Commit

Permalink
unity finish
Browse files Browse the repository at this point in the history
  • Loading branch information
stelzo committed Nov 25, 2024
1 parent f2daa66 commit 444fbd5
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 9 deletions.
13 changes: 10 additions & 3 deletions mapping_unity.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ func MapItemsUnity(data *JSONGameDataUnity, langs *map[string]LangDictUnity) []M
PersistedTypes.NextId++
}

mappedItems[idx].UsedInRecipes = item.RecipeIds.Array
if len(item.RecipeIds.Array) > 0 {
mappedItems[idx].UsedInRecipes = item.RecipeIds.Array
}
effectsArr := make([][]*JSONGameItemPossibleEffectUnity, 1)
effectsArr[0] = item.PossibleEffects
allEffectResult := ParseEffectsUnity(data, effectsArr, langs)
Expand All @@ -76,7 +78,9 @@ func MapItemsUnity(data *JSONGameDataUnity, langs *map[string]LangDictUnity) []M
mappedItems[idx].CriticalHitBonus = item.CriticalHitBonus
mappedItems[idx].ApCost = item.ApCost
mappedItems[idx].MaxCastPerTurn = item.MaxCastPerTurn
mappedItems[idx].DropMonsterIds = item.DropMonsterIds.Array
if len(item.DropMonsterIds.Array) > 0 {
mappedItems[idx].DropMonsterIds = item.DropMonsterIds.Array
}
mappedItems[idx].HasParentSet = item.ItemSetId != -1
if mappedItems[idx].HasParentSet {
mappedItems[idx].ParentSet.Id = item.ItemSetId
Expand Down Expand Up @@ -244,7 +248,10 @@ func MapSetsUnity(data *JSONGameDataUnity, langs *map[string]LangDictUnity) []Ma
mappedSet.ItemIds = set.ItemIds
parseEffects := ParseEffectsUnity(data, set.Effects, langs)

mappedSet.Effects = ParseItemComboUnity(parseEffects)
parseCombi := ParseItemComboUnity(parseEffects)
if len(parseCombi) > 0 {
mappedSet.Effects = parseCombi
}

allItemsCosmetic := len(set.ItemIds) > 0

Expand Down
6 changes: 3 additions & 3 deletions parse_unity.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ func ParseEffectsUnity(data *JSONGameDataUnity, allEffects [][]*JSONGameItemPoss
if templatedName == "" { // found effect that should be discarded for now
break
}
templatedName = SingularPluralFormatter(templatedName, effect.MinimumValue, lang)
templatedName = SingularPluralFormatterUnity(templatedName, effect.MinimumValue, lang)

if isTitle { // titles are Title: 0 after formatting; TODO move this into the NumSpellFormatter
maleTitleNum, err := strconv.Atoi(data.titles[diceNum].NameMaleId) // TODO male default, idk how to make it neutral yet
Expand All @@ -483,8 +483,8 @@ func ParseEffectsUnity(data *JSONGameDataUnity, allEffects [][]*JSONGameItemPoss
templatedName = strings.ReplaceAll(templatedName, "0", replTitle)
}

effectName = DeleteDamageFormatter(effectName)
effectName = SingularPluralFormatter(effectName, effect.MinimumValue, lang)
effectName = DeleteDamageFormatterUnity(effectName)
effectName = SingularPluralFormatterUnity(effectName, 1, lang) // singularize the effect name for comparisons

if isTitle {
mappedEffect.Min = 0
Expand Down
85 changes: 82 additions & 3 deletions templating_unity.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,92 @@ package dodumap

import (
"fmt"
"log"
"regexp"
"slices"
"strconv"
"strings"

"github.com/charmbracelet/log"
)

func DeleteDamageFormatterUnity(input string) string {
input, regex := PrepareAndCreateRangeRegexUnity(input, false)
if strings.Contains(input, "+#1{{~1~2 to }} level #2") {
return "level"
}

input = strings.ReplaceAll(input, "#1{{~1~2 -}}#2", "#1{{~1~2 - }}#2") // bug from ankama
input = regex.ReplaceAllString(input, "")

input = strings.ReplaceAll(input, "{{~1~2 to }}", "")
input = DeleteReplacer(input)
input = strings.ReplaceAll(input, " ", " ")

input = strings.TrimSpace(input)
return input
}

func SingularPluralFormatterUnity(input string, amount int, lang string) string {
str := input
str = strings.ReplaceAll(str, "{{~s}}", "") // avoid only s without what to append
str = strings.ReplaceAll(str, "{{~p}}", "") // same

// delete unknown z
unknownZRegex := regexp.MustCompile("{{~z[^}]*}}")
str = unknownZRegex.ReplaceAllString(str, "")

var indicator rune

if amount > 1 {
indicator = 'p'
} else {
indicator = 's'
}

indicators := []rune{'s', 'p'}
var regexps []*regexp.Regexp
for _, indicatorIt := range indicators {
regex := fmt.Sprintf("{{~%c([^}]*)}}", indicatorIt) // capturing with everything inside ()
regexExtract := regexp.MustCompile(regex)
regexps = append(regexps, regexExtract)

// if lang == "es" || lang == "pt" {
if indicatorIt != indicator {
continue
}

if lang == "de" {
regexExtract.ReplaceAllString(str, "") // german templating is just a mess so remove it
continue
}

extractedEntries := regexExtract.FindAllStringSubmatch(str, -1)
for _, extracted := range extractedEntries {
str = strings.ReplaceAll(str, extracted[0], extracted[1])
}
}

for _, regexIt := range regexps {
str = regexIt.ReplaceAllString(str, "")
}

return str
}

func PrepareAndCreateRangeRegexUnity(input string, extract bool) (string, *regexp.Regexp) {
var regexStr string
combiningWords := "(und|et|and|bis|to|a|à|-|auf)"
if extract {
regexStr = fmt.Sprintf("{{~1~2 (%s [-,+]?)}}", combiningWords)
} else {
regexStr = fmt.Sprintf("[-,+]?#1{{~1~2 %s [-,+]?}}#2", combiningWords)
}

concatRegex := regexp.MustCompile(regexStr)

return PrepareTextForRegex(input), concatRegex
}

func ConditionWithOperatorUnity(input string, operator string, langs *map[string]LangDictUnity, out *MappedMultilangCondition, data *JSONGameDataUnity) bool {
partSplit := strings.Split(input, operator)
rawElement := ElementFromCode(partSplit[0])
Expand All @@ -17,7 +96,7 @@ func ConditionWithOperatorUnity(input string, operator string, langs *map[string
}
out.Element = partSplit[0]
out.Value, _ = strconv.Atoi(partSplit[1])
for _, lang := range Languages {
for _, lang := range LanguagesUnity {
langStr := (*langs)[lang].Texts[rawElement]

if lang == "en" {
Expand Down Expand Up @@ -75,7 +154,7 @@ func NumSpellFormatterUnity(input string, lang string, gameData *JSONGameDataUni

delValue := false

input, concatRegex := PrepareAndCreateRangeRegex(input, true)
input, concatRegex := PrepareAndCreateRangeRegexUnity(input, true)
var numSigned bool
var sideSigned bool
var ptSideSigned bool
Expand Down

0 comments on commit 444fbd5

Please sign in to comment.