h1-mod/data/ui_scripts/custom_depot/__init__.lua

140 lines
3.9 KiB
Lua
Raw Normal View History

if game:issingleplayer() then
2022-07-03 12:43:10 -04:00
return
end
-- from mpdepotbase.lua, global definition isn't working
InventoryCurrencyType = {
LaunchCredits = 1,
Credits = 2,
Parts = 3,
CoDPoints = 4,
Bonus = 5,
Max = 6
}
2022-07-01 03:22:54 -04:00
custom_depot = {
collection_details_menu = nil,
data = {
currencies = {
2022-07-03 15:52:47 -04:00
launchCredits = 0, -- LaunchCredits
credits = 0, -- Credits
parts = 0, -- Parts
codPoints = 0, -- CoDPoints
bonus = 0 -- Bonus
2022-07-01 03:22:54 -04:00
},
items = {},
2022-07-02 18:56:21 -04:00
reward_splashes = {},
has_accepted_mod_eula = false,
2022-07-03 12:43:10 -04:00
has_seen_mod_eula = false
2022-07-01 03:22:54 -04:00
},
directory_path = "h1-mod",
2022-07-01 03:22:54 -04:00
file_name = "depot_save.json",
file_path = nil,
functions = {}
2022-07-01 03:22:54 -04:00
}
custom_depot.file_path = string.format("%s/%s", custom_depot.directory_path, custom_depot.file_name)
custom_depot.get_function = function(function_name)
if not function_name or not custom_depot.functions[function_name] then
return nil
end
return custom_depot.functions[function_name]
end
custom_depot.functions["save_depot_data"] = function()
2022-07-03 15:52:47 -04:00
io.writefile(custom_depot.file_path, json.encode(custom_depot.data), false)
2022-07-01 03:22:54 -04:00
end
custom_depot.functions["load_depot_data"] = function()
if not io.directoryexists(custom_depot.directory_path) then
io.createdirectory(custom_depot.directory_path)
2022-07-01 03:22:54 -04:00
end
if not io.fileexists(custom_depot.file_path) then
custom_depot.get_function("save_depot_data")()
end
custom_depot.data = json.decode(io.readfile(custom_depot.file_path))
end
2022-07-03 15:52:47 -04:00
local function convert_currency_to_string(type)
if type == InventoryCurrencyType.LaunchCredits then
return "launchCredits"
elseif type == InventoryCurrencyType.Credits then
return "credits"
elseif type == InventoryCurrencyType.Parts then
return "parts"
elseif type == InventoryCurrencyType.CoDPoints then
return "codPoints"
elseif type == InventoryCurrencyType.Bonus then
return "bonus"
end
end
2022-07-01 03:22:54 -04:00
custom_depot.functions["add_currency"] = function(currency_type, amount)
2022-07-03 15:52:47 -04:00
local type = convert_currency_to_string(currency_type)
custom_depot.data.currencies[type] = custom_depot.data.currencies[type] + amount
2022-07-01 03:22:54 -04:00
end
custom_depot.functions["remove_currency"] = function(currency_type, amount)
2022-07-03 15:52:47 -04:00
local type = convert_currency_to_string(currency_type)
custom_depot.data.currencies[type] = custom_depot.data.currencies[type] - amount
2022-07-01 03:22:54 -04:00
end
custom_depot.functions["get_currency"] = function(currency_type)
local type = convert_currency_to_string(currency_type)
if not currency_type or not custom_depot.data.currencies[type] then
2022-07-01 03:22:54 -04:00
return nil
end
return custom_depot.data.currencies[type]
2022-07-01 03:22:54 -04:00
end
custom_depot.functions["add_item"] = function(item, value)
custom_depot.data.items[item] = value
end
custom_depot.functions["has_item"] = function(item)
return custom_depot.data.items[item] ~= nil
end
custom_depot.functions["add_reward_splash"] = function(item, value)
custom_depot.data.reward_splashes[item] = value
end
custom_depot.functions["has_reward_splash"] = function(item)
return custom_depot.data.reward_splashes[item] ~= nil
end
2022-07-02 18:56:21 -04:00
custom_depot.functions["has_accepted_mod_eula"] = function()
return custom_depot.data.has_accepted_mod_eula
end
custom_depot.functions["set_has_accepted_mod_eula"] = function(value)
custom_depot.data.has_accepted_mod_eula = value
custom_depot.get_function("save_depot_data")()
end
custom_depot.functions["has_seen_mod_eula"] = function()
return custom_depot.data.has_seen_mod_eula
end
custom_depot.functions["set_has_seen_mod_eula"] = function(value)
custom_depot.data.has_seen_mod_eula = value
custom_depot.get_function("save_depot_data")()
end
2022-07-01 03:22:54 -04:00
custom_depot.get_function("load_depot_data")()
2022-07-03 12:43:10 -04:00
if Engine.InFrontend() then
2022-07-03 12:43:10 -04:00
require("mod_eula")
require("depot_override")
end
if not Engine.InFrontend() then
2022-07-03 12:43:10 -04:00
require("scoreboard_override")
end