-
Notifications
You must be signed in to change notification settings - Fork 6
/
dlcsupport.lua
163 lines (136 loc) · 4.05 KB
/
dlcsupport.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
MAIN_GAME = 0
REIGN_OF_GIANTS = 1
DONT_STARVE_TOGETHER_APPID = 322330
DONT_STARVE_APPID = 219740
NO_DLC_TABLE = {REIGN_OF_GIANTS=false}
ALL_DLC_TABLE = {REIGN_OF_GIANTS=true}
MENU_DLC_LIST = {}
DLC_LIST = {REIGN_OF_GIANTS}
RegisteredDLC = {}
ActiveDLC = {}
----------------------- locals ------------------------------------------
local function AddPrefab(prefabName)
for i,v in pairs(PREFABFILES) do
if v==prefabName then
return
end
end
PREFABFILES[#PREFABFILES+1] = prefabName
end
local function GetDLCPrefabFiles(filename)
print("Load "..filename)
local fn, r = loadfile(filename)
assert(fn, "Could not load file ".. filename)
if type(fn) == "string" then
assert(false, "Error loading file "..filename.."\n"..fn)
end
assert( type(fn) == "function", "Prefab file doesn't return a callable chunk: "..filename)
local ret = fn()
return ret
end
local function RegisterPrefabs(index)
local dlcPrefabFilename = string.format("scripts/DLC%03d_prefab_files",index)
local dlcprefabfiles = GetDLCPrefabFiles(dlcPrefabFilename)
for i,v in pairs(dlcprefabfiles) do
AddPrefab(v)
end
end
-- Load the base prefablist and merge in all additional prefabs for the DLCs
local function ReloadPrefabList()
for i,v in pairs(RegisteredDLC) do
RegisterPrefabs(i)
end
end
----------------------- globals ------------------------------------------
function RegisterAllDLC()
for i=1,10 do
local filename = string.format("scripts/DLC%04d",i)
local fn, r = loadfile(filename)
if (type(fn) == "function") then
local ret = fn()
RegisteredDLC[i] = ret
else
RegisteredDLC[i] = nil
end
end
ReloadPrefabList()
end
function RegisterDLC( index )
for i=1,10 do
RegisteredDLC[i] = nil
end
local filename = string.format("scripts/DLC%04d",index)
local fn, r = loadfile(filename)
if (type(fn) == "function") then
local ret = fn()
RegisteredDLC[index] = ret
else
RegisteredDLC[index] = nil
end
ReloadPrefabList()
end
-- This one is somewhat important, it can be used to load prefabs that are not referenced by any prefab and thus not loaded
function InitAllDLC()
for i,v in pairs(RegisteredDLC) do
if v.Setup then
v.Setup()
end
end
end
function InitDLC(index)
if RegisteredDLC[index].Setup then
RegisteredDLC[index].Setup()
end
end
function GetActiveCharacterList()
return JoinArrays(DST_CHARACTERLIST, MODCHARACTERLIST)
end
function GetSelectableCharacterList()
-- NOTES(JBK): Players are not allowed to pick SEAMLESSSWAP_CHARACTERLIST and must be done through in game methods.
return ExceptionArrays(JoinArrays(DST_CHARACTERLIST, MODCHARACTERLIST), SEAMLESSSWAP_CHARACTERLIST)
end
function GetFEVisibleCharacterList()
local all = {}
for i,character in ipairs(DST_CHARACTERLIST) do
local add_char = true
if character == "wonkey" and TheGenericKV:GetKV("wonkey_played") ~= "played" then --only show wonkey if we've played him
add_char = false
end
if add_char then
table.insert( all, character )
end
end
return all
end
function DisableDLC(index)
TheSim:SetDLCEnabled(index,false)
end
function EnableExclusiveDLC(index)
DisableAllDLC()
EnableDLC(index)
end
function EnableDLC(index)
TheSim:SetDLCEnabled(index,true)
end
function IsDLCEnabled(index)
return TheSim:IsDLCEnabled(index)
end
function IsDLCInstalled(index)
return TheSim:IsDLCInstalled(index)
end
function EnableAllDLC()
for i,v in pairs(DLC_LIST) do
EnableDLC(v)
end
end
function DisableAllDLC()
for i,v in pairs(DLC_LIST) do
DisableDLC(v)
end
end
function EnableAllMenuDLC()
DisableAllDLC()
for i,v in pairs(MENU_DLC_LIST) do
EnableDLC(v)
end
end