|
| 1 | +_G.RandomContract = _G.RandomContract or {} |
| 2 | + |
| 3 | +local RandomContract = _G.RandomContract |
| 4 | + |
| 5 | +RandomContract.ModPath = RandomContract.ModPath or ModPath or "RandomContract/" |
| 6 | +RandomContract.SavePath = RandomContract.SavePath or ((SavePath or "") .. "RandomContract.json") |
| 7 | + |
| 8 | +RandomContract.VERSION = 1 |
| 9 | +RandomContract.LOBBY_ITEM_ID = "menu_roll_contract" |
| 10 | +RandomContract.MENU_ID = "random_contract_options" |
| 11 | +RandomContract.STEALTH_MENU_ID = "random_contract_stealth_options" |
| 12 | +RandomContract.LOUD_MENU_ID = "random_contract_loud_options" |
| 13 | +RandomContract.HEIST_POLICY_MENU_ID = "random_contract_heist_policy_options" |
| 14 | +RandomContract.POLICY_GLOBAL_EXCLUDE_MENU_ID = "random_contract_policy_global_exclude_options" |
| 15 | +RandomContract.POLICY_TACTIC_MENU_ID = "random_contract_policy_tactic_options" |
| 16 | +RandomContract.POLICY_STEALTH_PRESET_MENU_ID = "random_contract_policy_stealth_preset_options" |
| 17 | +RandomContract.POLICY_LOUD_PRESET_MENU_ID = "random_contract_policy_loud_preset_options" |
| 18 | +RandomContract.DEFAULT_HISTORY_LIMIT = 5 |
| 19 | +RandomContract.MIN_HISTORY_LIMIT = 0 |
| 20 | +RandomContract.MAX_HISTORY_LIMIT = 30 |
| 21 | +RandomContract.HISTORY_LIMIT = RandomContract.DEFAULT_HISTORY_LIMIT |
| 22 | +RandomContract.SESSION_HISTORY_KEY = "random_contract_recent_history" |
| 23 | +RandomContract.DEFAULT_DIFFICULTY = "sm_wish" |
| 24 | +RandomContract.SELECT_COOLDOWN_SECONDS = 0.15 |
| 25 | +RandomContract.LOBBY_SYNC_COALESCE_SECONDS = 0.35 |
| 26 | +RandomContract.STEALTH_SEARCH_INPUT_ID = "random_contract_stealth_search" |
| 27 | +RandomContract.LOUD_SEARCH_INPUT_ID = "random_contract_loud_search" |
| 28 | +RandomContract.POLICY_GLOBAL_EXCLUDE_SEARCH_INPUT_ID = "random_contract_policy_global_exclude_search" |
| 29 | +RandomContract.POLICY_TACTIC_SEARCH_INPUT_ID = "random_contract_policy_tactic_search" |
| 30 | +RandomContract.POLICY_STEALTH_PRESET_SEARCH_INPUT_ID = "random_contract_policy_stealth_preset_search" |
| 31 | +RandomContract.POLICY_LOUD_PRESET_SEARCH_INPUT_ID = "random_contract_policy_loud_preset_search" |
| 32 | +RandomContract.HEIST_VISIBLE_CALLBACK_PREFIX = "random_contract_heist_visible_" |
| 33 | + |
| 34 | +RandomContract.recent_history = RandomContract.recent_history or {} |
| 35 | +RandomContract.menu_search = RandomContract.menu_search or {} |
| 36 | + |
| 37 | +RandomContract.DIFFICULTIES = { |
| 38 | + { id = "normal", text_id = "menu_difficulty_normal", label_text_id = "random_contract_label_difficulty_normal", fallback = "Normal" }, |
| 39 | + { id = "hard", text_id = "menu_difficulty_hard", label_text_id = "random_contract_label_difficulty_hard", fallback = "Hard" }, |
| 40 | + { id = "overkill", text_id = "menu_difficulty_very_hard", label_text_id = "random_contract_label_difficulty_very_hard", fallback = "Very Hard" }, |
| 41 | + { id = "overkill_145", text_id = "menu_difficulty_overkill", label_text_id = "random_contract_label_difficulty_overkill", fallback = "Overkill" }, |
| 42 | + { id = "easy_wish", text_id = "menu_difficulty_easy_wish", label_text_id = "random_contract_label_difficulty_mayhem", fallback = "Mayhem" }, |
| 43 | + { id = "overkill_290", text_id = "menu_difficulty_apocalypse", label_text_id = "random_contract_label_difficulty_death_wish", fallback = "Death Wish" }, |
| 44 | + { id = "sm_wish", text_id = "menu_difficulty_sm_wish", label_text_id = "random_contract_label_difficulty_death_sentence", fallback = "Death Sentence" } |
| 45 | +} |
| 46 | + |
| 47 | +local function merge_defaults(target, defaults) |
| 48 | + for key, value in pairs(defaults) do |
| 49 | + if type(value) == "table" then |
| 50 | + target[key] = target[key] or {} |
| 51 | + merge_defaults(target[key], value) |
| 52 | + elseif target[key] == nil then |
| 53 | + target[key] = value |
| 54 | + end |
| 55 | + end |
| 56 | +end |
| 57 | + |
| 58 | +local function read_json_file(path) |
| 59 | + if not path or not json or type(json.decode) ~= "function" then |
| 60 | + return nil |
| 61 | + end |
| 62 | + |
| 63 | + local file = io.open(path, "r") |
| 64 | + |
| 65 | + if not file then |
| 66 | + return nil |
| 67 | + end |
| 68 | + |
| 69 | + local data = file:read("*all") |
| 70 | + file:close() |
| 71 | + |
| 72 | + if not data then |
| 73 | + return nil |
| 74 | + end |
| 75 | + |
| 76 | + local ok, decoded = pcall(json.decode, data) |
| 77 | + |
| 78 | + if ok and type(decoded) == "table" then |
| 79 | + return decoded |
| 80 | + end |
| 81 | +end |
| 82 | + |
| 83 | +RandomContract.DEFAULT_JOB_POLICY = { |
| 84 | + extra_candidates = {}, |
| 85 | + eligibility = {}, |
| 86 | + recommended_exclusions = { |
| 87 | + stealth = {}, |
| 88 | + loud = {} |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | +RandomContract.JobPolicyPath = RandomContract.JobPolicyPath or (RandomContract.ModPath .. "data/job_policy.json") |
| 93 | +RandomContract.JobPolicy = RandomContract.JobPolicy or read_json_file(RandomContract.JobPolicyPath) or {} |
| 94 | +merge_defaults(RandomContract.JobPolicy, RandomContract.DEFAULT_JOB_POLICY) |
| 95 | + |
| 96 | +for _, module_name in ipairs({ |
| 97 | + "common/util", |
| 98 | + "common/settings", |
| 99 | + "contracts/policy", |
| 100 | + "contracts/jobs", |
| 101 | + "contracts/pool", |
| 102 | + "common/runtime", |
| 103 | + "network/authority", |
| 104 | + "lobby/view", |
| 105 | + "lobby/sync", |
| 106 | + "contracts/selection", |
| 107 | + "lobby/text", |
| 108 | + "lobby/label", |
| 109 | + "lobby/menu_items", |
| 110 | + "lobby/marker", |
| 111 | + "lobby/item", |
| 112 | + "lobby/input", |
| 113 | + "menu/search", |
| 114 | + "menu/setup", |
| 115 | + "menu/difficulty", |
| 116 | + "menu/tactic", |
| 117 | + "menu/settings", |
| 118 | + "menu/localization", |
| 119 | + "menu/populate", |
| 120 | + "menu/build", |
| 121 | + "menu/callbacks" |
| 122 | +}) do |
| 123 | + dofile(RandomContract.ModPath .. "modules/" .. module_name .. ".lua") |
| 124 | +end |
| 125 | + |
| 126 | +return RandomContract |
0 commit comments