L0laapk3 / FactorioMaps

L0laapk3's FactorioMaps mod
https://mods.factorio.com/mod/L0laapk3_FactorioMaps
Other
119 stars 22 forks source link

Can't run the mod with unicode strings in the tag names #51

Closed Ptitlaby closed 4 years ago

Ptitlaby commented 4 years ago

Hello,

I encountered an issue where I was unable to use the script if the map have tag names which include unicode characters.

When creating the autorun.lua script, you end up with text like that :

["text"] = "\u00c0 d\u00e9truire",
["last_user"] = "ptitlaby",
["force"] = "player"

which can't be parsed by lua as far as it seems.

I found a workaround for my case, modifying the file auto.py around the step "building autorun.lua" :

Old code :

mapInfoLua = re.sub(r'"([^"]+)" *:', lambda m: '["'+m.group(1)+'"] = ', f.read().replace("[", "{").replace("]", "}"))

New code :

mapInfoLuaJSON = json.loads(f.read())
mapInfoLua = json.dumps(mapInfoLuaJSON, ensure_ascii=False)
mapInfoLua = re.sub(r'"([^"]+)" *:', lambda m: '["'+m.group(1)+'"] = ',mapInfoLua.replace("[", "{").replace("]", "}"))

I'm not sure how good this work around is