toontown-client: Now reads DNA files for vismap.
This commit is contained in:
parent
4d566e1da9
commit
003105fa12
|
|
@ -12,7 +12,6 @@ whitelist/
|
|||
.idea
|
||||
venv/
|
||||
*.json
|
||||
!otpgo/config/vismap.json
|
||||
!win32/.vscode/tasks.json
|
||||
!linux/.vscode/tasks.json
|
||||
!darwin/.vscode/tasks.json
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -0,0 +1,67 @@
|
|||
local filepath = require("filepath")
|
||||
|
||||
function searchForDNAFiles()
|
||||
local dnaFiles = {}
|
||||
|
||||
-- TODO: Custom search path
|
||||
local foundFiles = filepath.glob('../resources/phase_*/dna/*.dna')
|
||||
for _, file in ipairs(foundFiles) do
|
||||
-- Skip storage files as they have no visgroups.
|
||||
if not string.find(file, "storage") then
|
||||
table.insert(dnaFiles, file)
|
||||
end
|
||||
end
|
||||
return dnaFiles
|
||||
end
|
||||
|
||||
|
||||
function parseDNAFile(filename, vismap)
|
||||
local file = assert(io.open(filename, "r"), string.format("Failed to open DNA file \"%s\"", filename))
|
||||
|
||||
-- Extract the zone id from the filename if there is any (_2100.dna, _2200.dna, etc.)
|
||||
local zoneId = filename:match("_(%d+)%.dna$")
|
||||
|
||||
local currentGroup = nil
|
||||
local depth = 0
|
||||
|
||||
for line in file:lines() do
|
||||
-- Trim whitespace
|
||||
line = line:match("^%s*(.-)%s*$")
|
||||
|
||||
-- Detect visgroup start
|
||||
local groupId = line:match('visgroup%s+"(.-)"%s*%[')
|
||||
if groupId then
|
||||
-- Split the ":" character if there is any
|
||||
groupId = string.split(groupId, ":")[1]
|
||||
currentGroup = groupId
|
||||
vismap[currentGroup] = {}
|
||||
depth = 1
|
||||
elseif currentGroup then
|
||||
-- Track nested brackets
|
||||
if line:find("%[") then depth = depth + 1 end
|
||||
if line:find("%]") then depth = depth - 1 end
|
||||
|
||||
-- Extract visible entries
|
||||
local visibles = line:match('vis%s*%[(.-)%]')
|
||||
if visibles then
|
||||
for id in visibles:gmatch('"(.-)"') do
|
||||
-- Split the ":" character if there is any
|
||||
id = string.split(id, ":")[1]
|
||||
table.insert(vismap[currentGroup], tonumber(id))
|
||||
end
|
||||
end
|
||||
|
||||
-- End of visgroup
|
||||
if depth == 0 then
|
||||
if not table.find(vismap[currentGroup], tonumber(currentGroup)) then
|
||||
table.insert(vismap[currentGroup], tonumber(currentGroup))
|
||||
end
|
||||
if zoneId and not table.find(vismap[currentGroup], tonumber(zoneId)) then
|
||||
table.insert(vismap[currentGroup], 1, tonumber(zoneId))
|
||||
end
|
||||
currentGroup = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
file:close()
|
||||
end
|
||||
|
|
@ -6,23 +6,17 @@ local date = require('date')
|
|||
-- Load Utils:
|
||||
dofile("lua/Utils.lua")
|
||||
|
||||
-- Read vismap:
|
||||
function readVismap()
|
||||
local json = require("json")
|
||||
local io = require("io")
|
||||
-- Load DNAParser:
|
||||
dofile("lua/DNAParser.lua")
|
||||
|
||||
-- TODO: Custom path.
|
||||
f, err = io.open("config/vismap.json", "r")
|
||||
assert(not err, err)
|
||||
-- Generate vismap from DNA files:
|
||||
local dnaFiles = searchForDNAFiles()
|
||||
|
||||
decoder = json.new_decoder(f)
|
||||
result, err = decoder:decode()
|
||||
f:close()
|
||||
assert(not err, err)
|
||||
return result
|
||||
VISMAP = {}
|
||||
for _, filePath in ipairs(dnaFiles) do
|
||||
print(string.format('ToontownClient: Reading DNA File \"%s\"', filePath))
|
||||
parseDNAFile(filePath, VISMAP)
|
||||
end
|
||||
|
||||
VISMAP = readVismap()
|
||||
print("ToontownClient: Vismap successfully loaded.")
|
||||
|
||||
-- Read account bridge:
|
||||
|
|
|
|||
|
|
@ -8,6 +8,21 @@ function string.upperFirst(str)
|
|||
return string.gsub(str, "^%l", string.upper)
|
||||
end
|
||||
|
||||
function string.split(s, sep)
|
||||
local fields = {}
|
||||
-- Default separator is a space if not provided
|
||||
sep = sep or " "
|
||||
-- The pattern matches one or more characters that are NOT the separator
|
||||
local pattern = string.format("([^%s]+)", sep)
|
||||
|
||||
-- Iterate over all matches and insert them into the table
|
||||
for match in string.gmatch(s, pattern) do
|
||||
table.insert(fields, match)
|
||||
end
|
||||
|
||||
return fields
|
||||
end
|
||||
|
||||
function table.shallow_copy(t)
|
||||
local t2 = {}
|
||||
for k, v in pairs(t) do
|
||||
|
|
@ -15,3 +30,12 @@ function table.shallow_copy(t)
|
|||
end
|
||||
return t2
|
||||
end
|
||||
|
||||
function table.find(t, value)
|
||||
for i, v in ipairs(t) do
|
||||
if v == value then
|
||||
return i
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue