forked from taichunmin/dont-starve-together-game-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdlcsupport.lua
148 lines (122 loc) · 3.3 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
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 GetOfficialCharacterList()
return DST_CHARACTERLIST
end
function GetActiveCharacterList()
return JoinArrays(GetOfficialCharacterList(), MODCHARACTERLIST)
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