mirror of
https://github.com/goonstation/goonstation-2016.git
synced 2026-05-18 06:29:01 +01:00
dc4217b498
this is all very alpha please don't hate me too much if i fucked it up
32 lines
1.1 KiB
Plaintext
32 lines
1.1 KiB
Plaintext
var/global/list/string_cache
|
|
|
|
/proc/strings(filename as text, key as text, var/accept_absent = 0)
|
|
var/list/fileList
|
|
if(!string_cache)
|
|
string_cache = new
|
|
if(!(filename in string_cache))
|
|
if(fexists("strings/[filename]"))
|
|
string_cache[filename] = list()
|
|
var/list/stringsList = list()
|
|
fileList = dd_file2list("strings/[filename]")
|
|
var/lineCount = 0
|
|
for(var/s in fileList)
|
|
lineCount++
|
|
if (!s)
|
|
continue
|
|
|
|
stringsList = splittext(s, "@=")
|
|
if(stringsList.len != 2)
|
|
CRASH("Invalid string list in strings/[filename] - line: [lineCount]")
|
|
if(findtext(stringsList[2], "@,"))
|
|
string_cache[filename][stringsList[1]] = splittext(stringsList[2], "@,")
|
|
else
|
|
string_cache[filename][stringsList[1]] = stringsList[2] // Its a single string!
|
|
else
|
|
CRASH("file not found: strings/[filename]")
|
|
if((filename in string_cache) && (key in string_cache[filename]))
|
|
return string_cache[filename][key]
|
|
else if (accept_absent) //Don't crash, just return null. It's fine. Honest
|
|
return null
|
|
else
|
|
CRASH("strings list not found: strings/[filename], index=[key]") |