-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathparse_teleports.lua
104 lines (82 loc) · 2.38 KB
/
parse_teleports.lua
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
assert("Lua 5.3" == _VERSION)
assert(arg[1], "\n\n[ERROR] no input file\n\n")
assert(arg[2], "\n\n[ERROR] no language file\n")
assert(arg[3], "\n\n[ERROR] no output file\n")
local LANG = dofile(arg[2])
local OUT = assert(io.open(arg[3], "w+"))
local owr = function(fmt, ...)
local str = string.format(fmt, ...)
OUT:write(str)
end
local COFF = 0.01
--[[
lua gar5_parser.lua World_Teleporter.sec
-> World_Teleporter.sec.lua
lua parse_teleports.lua <World_Teleporter.sec.lua> <lang.lua> <teleport.js>
-> for Leaflet
--]]
local teleport = {}
local used_lang = {}
local function hash(str)
local hash = 5381
for i = 1, #str do
hash = (hash * 33 + str:byte(i)) & 0xffffffff
end
used_lang[hash] = true
return hash
end
dofile(arg[1])
local w = World_Teleporter
local data = w["class gCEmbeddedLayer"]
.data["class gCEmbeddedLayer"]["gEEntityType_Game"]["class eCScene"]
.data["class eCScene"]["class eCDynamicEntity"]
.data["class eCEntity"].eCEntity2
for i = 1, #data do
local d = data[i]["class eCDynamicEntity"].data
local cD = d["class eCDynamicEntity"]
local cE = d["class eCEntity"]
local l = cE.eCEntity1[3] and cE.eCEntity1[3]["class gCMapLocation_PS"].prop
local pos = cD.bb_mid
table.remove(pos, 2)
pos[1] = pos[1] * COFF
pos[2] = pos[2] * COFF
local id = cE.string1
local title = l and l["Title"] or "none"
title = hash(title:lower())
table.insert(pos, "\"" .. id .. "\"")
table.insert(pos, ("0x%08X"):format(title))
table.insert(teleport, pos)
end
local lang = {}
for k, _ in pairs(used_lang) do
local str = LANG[k]
if not str then str = "---" end
table.insert(lang, {k, str})
end
used_lang = nil
table.sort(lang, function(a, b) return a[1] < b[1] end)
-- lang array
owr("var lang = [];\n")
for i = 1, #lang do
local l = lang[i]
owr("lang[0x%08X] = %q;\n", l[1], l[2])
end
owr("\nvar arr_teleport = [\n")
for i = 1, #teleport do
owr("[ " .. table.concat(teleport[i], ", ") .. " ],\n")
end
owr("];\n")
owr([=[
init_marker.push(
function () {
for (var i = 0; i < arr_teleport.length; i++) {
var m = arr_teleport[i];
var pop = lang[m[3]] + "<br /><i>" + m[2] + "</i>";
L.marker( [ m[1], m[0] ], { title: lang[m[3]], icon: icon["teleport"] } )
.bindPopup(pop).addTo(layer["teleport"]);
};
arr_teleport = null;
}
);
]=])
OUT:close()