forked from OceanRamen/BU-CB-DEV
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchallenge_handler.lua
More file actions
49 lines (41 loc) · 1.46 KB
/
challenge_handler.lua
File metadata and controls
49 lines (41 loc) · 1.46 KB
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
local lovely = require("lovely")
local nativefs = require("nativefs")
local function get_chal_files(directory)
local files = {}
local items = nativefs.getDirectoryItems(directory)
for _, item in ipairs(items) do
if item:match("%.lua$") then
table.insert(files, item)
end
end
return files
end
local directory = ChallengeMod.PATH .. "Challenges/"
local lua_files = get_chal_files(directory)
local CustomChallenges = {}
for _, file in ipairs(lua_files) do
local file_path = directory .. "/" .. file
local challenge = dofile(file_path)
-- print(ChallengeMod.Helper.inspectDepth(challenge))
table.insert(CustomChallenges, challenge)
end
-- print(inspectDepth(CustomChallenges))
table.sort(CustomChallenges, function(a, b)
return a.DATE_CREATED < b.DATE_CREATED
end)
function ChallengeMod.localizeChalNames()
for i, v in ipairs(CustomChallenges) do
v.DATA.name = v.NAME
v.DATA.id = "cm_mod_" .. v.NAME:gsub("%s+", "_") .. "_1"
table.insert(v.DATA.rules.custom, {id="cm_credit", value=v.DESIGNER})
table.insert(v.DATA.rules.custom, { id = "cm_VERSION", value = v.VERSION})
G.localization.misc.challenge_names[v.DATA.id] = v.DATA.name
end
if not ChallengeMod.RELEASE then
G.localization.misc.v_text.ch_c_cm_VERSION = {"{C:purple}VERSION: #1#{}"}
end
G.localization.misc.v_text.ch_c_cm_credit = { "Designed by: {C:green}#1#{}" }
end
for i, v in pairs(CustomChallenges) do
table.insert(G.CHALLENGES, #G.CHALLENGES + 1, v.DATA)
end