158 lines
5.1 KiB
Lua
158 lines
5.1 KiB
Lua
utils = include("sv_utils.lua")
|
|
config = include("sv_config.lua")
|
|
symbtoms_list = include("sv_symbtom_list.lua")
|
|
Symbtom = include("sv_symbtom.lua")
|
|
Disease = include("sv_disease.lua")
|
|
|
|
local settings = {}
|
|
|
|
utils.path_create(config.settings_path)
|
|
|
|
if not file.Exists(config.settings_path, "DATA")
|
|
then
|
|
local default_config = {}
|
|
default_config.diseases = {}
|
|
file.Write(config.settings_path, util.TableToJSON(default_config, true))
|
|
end
|
|
|
|
local data = file.Read(config.settings_path)
|
|
data = util.JSONToTable(data)
|
|
|
|
if data.diseases == nil
|
|
then
|
|
print(config.settings_path .. "file error")
|
|
return nil
|
|
end
|
|
|
|
settings.diseases = {}
|
|
|
|
for i, disease in ipairs(data.diseases)
|
|
do
|
|
local name = ""
|
|
local symbtoms_by_stages = {}
|
|
local contamination_methods = {}
|
|
local transmission_zone_stages = {}
|
|
local stages_duration = {}
|
|
|
|
if (disease.name == nil)
|
|
then
|
|
print("[SKIP] missing name in the " .. i .. " disease")
|
|
return nil
|
|
end
|
|
name = disease.name
|
|
|
|
if (disease.symbtoms_by_stages == nil)
|
|
then
|
|
print("[SKIP] missing symbtoms_by_stages in " .. name .." disease")
|
|
continue
|
|
end
|
|
table.insert(symbtoms_by_stages, {})
|
|
for y, stage in ipairs(disease.symbtoms_by_stages)
|
|
do
|
|
symbtoms_by_stages[y] = {}
|
|
|
|
for j, symbtom in ipairs(stage)
|
|
do
|
|
if symbtom.name == nil
|
|
then
|
|
print("[ERROR] missing name in the " .. j .. " symbtom of the " .. y .. " stage of the " .. name .. " disease")
|
|
return nil
|
|
end
|
|
if symbtoms_list[symbtom.name] == nil
|
|
then
|
|
print("[ERROR] " .. symbtom.name .. " unknown symbtom in the " .. j .. " symbtom of the " .. y .. " stage of the " .. name .. " disease")
|
|
return nil
|
|
end
|
|
if symbtom.level == nil
|
|
then
|
|
print("[ERROR] missing level in the " .. j .. " symbtom (" .. symbtom.name ..") of the " .. y .. " stage of the " .. name .. " disease")
|
|
return nil
|
|
end
|
|
if type(symbtom.level) != "number" or 0 > symbtom.level or symbtom.level > 1
|
|
then
|
|
print("[ERROR] invalid level in the " .. j .. " symbtom (" .. symbtom.name ..") of the " .. y .. " stage of the " .. name .. " disease")
|
|
return nil
|
|
end
|
|
if symbtom.delay == nil
|
|
then
|
|
print("[ERROR] missing delay in the " .. j .. " symbtom (" .. symbtom.name ..") of the " .. y .. " stage of the " .. name .. " disease")
|
|
return nil
|
|
end
|
|
if type(symbtom.delay) != "number"
|
|
then
|
|
print("[ERROR] invalid delay in the " .. j .. " symbtom (" .. symbtom.name ..") of the " .. y .. " stage of the " .. name .. " disease")
|
|
return nil
|
|
end
|
|
table.insert(symbtoms_by_stages[y], Symbtom:new(symbtom.name, symbtoms_list[symbtom.name], symbtom.level, symbtom.delay))
|
|
end
|
|
end
|
|
|
|
if disease.contaminations_method == nil
|
|
then
|
|
print("[SKIP] missing contamination_method in the " .. name .. " disease")
|
|
continue
|
|
end
|
|
for k, contamination_method in ipairs(disease.contaminations_method)
|
|
do
|
|
if contamination_method.name == nil
|
|
then
|
|
print("[SKIP] missing name in the " .. k .. " contamination_method of the " .. name .. " disease")
|
|
break
|
|
end
|
|
if contamination_method.chance == nil
|
|
then
|
|
print("[SKIP] missing chance in the " .. contamination_method.name .. " contaminations_method of the " .. name .. " disease")
|
|
break
|
|
end
|
|
end
|
|
contamination_methods = disease.contamination_methods
|
|
|
|
if disease.transmission_zone_stages == nil
|
|
then
|
|
print("[SKIP] missing transmission_zone_stages in the " .. name .. " disease")
|
|
continue
|
|
end
|
|
for k, transmission_zone_stage in ipairs(disease.transmission_zone_stages)
|
|
do
|
|
if type(transmission_zone_stage) != "number"
|
|
then
|
|
print("[SKIP] non number " .. k .. " transmission_zone_stages in the " .. name)
|
|
break
|
|
end
|
|
end
|
|
transmission_zone_stages = disease.transmission_zone_stages
|
|
|
|
|
|
if disease.stages_duration == nil
|
|
then
|
|
print("[SKIP] missing stages_duration in the " .. name .. " disease")
|
|
continue
|
|
end
|
|
for k, stage_duration in ipairs(disease.stages_duration)
|
|
do
|
|
if type(stage_duration) != "number"
|
|
then
|
|
print("[SKIP] non number " .. k .. " stages_duration in the " .. name)
|
|
break
|
|
end
|
|
end
|
|
stages_duration = disease.stages_duration
|
|
|
|
table.insert(settings.diseases, Disease:new(name, symbtoms_by_stages, contamination_methods, transmission_zone_stages, stages_durations))
|
|
end
|
|
|
|
print("[OK] settings")
|
|
|
|
---name string? the name of the disease
|
|
function settings.getDiseaseByName(name)
|
|
for _, disease in ipairs(settings.diseases)
|
|
do
|
|
if disease.name == name
|
|
then
|
|
return disease
|
|
end
|
|
end
|
|
return nil
|
|
end
|
|
|
|
return settings |