forked from taichunmin/dont-starve-together-game-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdlcsupport_strings.lua
102 lines (91 loc) · 3.98 KB
/
dlcsupport_strings.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
USE_PREFIX = {} -- A table of which strings use prefixes and which use suffixes when constructing names in EntityScript
USE_PREFIX[STRINGS.SMOLDERINGITEM] = true
USE_PREFIX[STRINGS.WITHEREDITEM] = true
USE_PREFIX[STRINGS.WET_PREFIX.FOOD] = true
USE_PREFIX[STRINGS.WET_PREFIX.CLOTHING] = true
USE_PREFIX[STRINGS.WET_PREFIX.TOOL] = true
USE_PREFIX[STRINGS.WET_PREFIX.FUEL] = true
USE_PREFIX[STRINGS.WET_PREFIX.GENERIC] = true
USE_PREFIX[STRINGS.WET_PREFIX.WETGOOP] = true -- Special case using inst.wet_prefix set on wet goop to WET_PREFIX.WETGOOP
USE_PREFIX[STRINGS.NAMES.WETGOOP] = true -- Special case using inst.wet_prefix set on wet goop to WET_PREFIX.WETGOOP
USE_PREFIX[STRINGS.WET_PREFIX.RABBITHOLE] = true -- Special case using inst.wet_prefix on rabbit hole set to WET_PREFIX.RABBITHOLE
USE_PREFIX[STRINGS.NAMES.RABBITHOLE] = true -- Special case using inst.wet_prefix on rabbit hole set to WET_PREFIX.RABBITHOLE
local function TryGuaranteeCoverage(item, usePrefix)
-- Look for item in the STRINGS.NAMES table
local name = nil
for i,v in pairs(STRINGS.NAMES) do
if item == v then
-- If we find it, save the key so we can look for that key in the STRINGS.WET_PREFIX table
name = i
break
end
end
if name and STRINGS.WET_PREFIX[name] then USE_PREFIX[STRINGS.WET_PREFIX[name]] = usePrefix end
-- And vice versa for prefix
local prefix = nil
for i,v in pairs(STRINGS.WET_PREFIX) do
if item == v then
prefix = i
break
end
end
if prefix and STRINGS.NAMES[prefix] then USE_PREFIX[STRINGS.NAMES[prefix]] = usePrefix end
-- Now check if the value is a key itself in either of the tables. If so, add its value to USES_PREFIX
if STRINGS.NAMES[string.upper(item)] then USE_PREFIX[STRINGS.NAMES[string.upper(item)]] = usePrefix end
if STRINGS.WET_PREFIX[string.upper(item)] then USE_PREFIX[STRINGS.WET_PREFIX[string.upper(item)]] = usePrefix end
end
-- Check if the item uses a prefix or a suffix
local function UsesPrefix(item)
if type(item) == "string" then
return USE_PREFIX[item]
end
end
-- Use this to make all adjectives into suffixes
function MakeAllSuffixes(fn)
if type(fn) ~= "function" then
fn = false
end
for k, v in pairs(USE_PREFIX) do
USE_PREFIX[k] = fn
end
end
-- Use this to make all adjectives into prefixes
function MakeAllPrefixes(fn)
if type(fn) ~= "function" then
fn = true
end
for k, v in pairs(USE_PREFIX) do
USE_PREFIX[k] = fn
end
end
-- Use this to specify whether a particular item should use a prefix or a suffix
-- This can also be used to add a new item to the USE_PREFIX table
function SetUsesPrefix(item, usePrefix)
if type(item) == "string" and usePrefix ~= nil then
USE_PREFIX[item] = usePrefix
TryGuaranteeCoverage(item, usePrefix)
end
end
function ConstructAdjectivedName(inst, name, adjective)
-- Pull the real name based on the prefab if we have only been handed that for some reason
if name == nil and inst ~= nil and inst.prefab ~= nil then
name = STRINGS.NAMES[string.upper(inst.prefab)]
end
-- Adjective is stronger binding: we only want to base it off the name for special cases (in which case the adjective won't be in the table)
local usePrefix = UsesPrefix(adjective)
if usePrefix == nil then
usePrefix = UsesPrefix(name)
end
-- First check if USES_PREFIX for this thing is a function
if type(usePrefix) == "function" then
-- If so, try the function, but only use the result if it returns a string
local tryfunction = usePrefix(inst, name, adjective)
if type(tryfunction) == "string" then
return tryfunction
end
end
-- If we don't have a string yet (either the entry in the table wasn't a function or the function returned a bad value), try the table value directly
return usePrefix ~= false
and (adjective.." "..name)
or (name.." "..adjective)
end