|
| 1 | +-- _ |
| 2 | +-- | | |
| 3 | +-- _____ _| | _____ ___ _ __ |
| 4 | +-- / __\ \ /\ / / |/ / _ \/ _ \ '_ \ |
| 5 | +-- \__ \\ V V /| < __/ __/ |_) | |
| 6 | +-- |___/ \_/\_/ |_|\_\___|\___| .__/ |
| 7 | +-- | | |
| 8 | +-- |_| |
| 9 | +-- https://github.com/swkeep |
| 10 | +local selected_test = 1 |
| 11 | +local test_refs = {} |
| 12 | +local global_test_refs = {} |
| 13 | +local global_status = "" |
| 14 | +local active_emoji_template = '|<span style="filter: hue-rotate(300deg);">%s</span>' |
| 15 | +local inactive_emoji_template = '|<span style="filter: hue-rotate(150deg);">%s</span>' |
| 16 | +local emoji_numbers = { |
| 17 | + "1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣" |
| 18 | +} |
| 19 | + |
| 20 | +local test_slots = { |
| 21 | + front = { |
| 22 | + vector4(795.23, -3008.43, -69.41, 89.31), |
| 23 | + vector4(795.2, -3002.94, -69.41, 89.9), |
| 24 | + vector4(795.17, -2996.87, -69.41, 89.18) |
| 25 | + }, |
| 26 | + middle = { |
| 27 | + vector4(800.21, -3008.53, -69.41, 90.93), |
| 28 | + vector4(800.93, -3003.08, -69.41, 89.2), |
| 29 | + vector4(800.55, -2996.81, -69.41, 90.42) |
| 30 | + }, |
| 31 | + back = { |
| 32 | + vector4(806.36, -3008.67, -69.41, 90.76), |
| 33 | + vector4(806.75, -3002.84, -69.41, 90.15), |
| 34 | + vector4(806.96, -2997.04, -69.41, 89.18) |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +local function execute_in_thread(fn) |
| 39 | + if type(fn) ~= "function" then return false end |
| 40 | + CreateThread(fn) |
| 41 | +end |
| 42 | + |
| 43 | +local function load_selected_test() |
| 44 | + if not selected_test then return false end |
| 45 | + execute_in_thread(test_refs[selected_test].init) |
| 46 | +end |
| 47 | + |
| 48 | +local function unload_selected_test() |
| 49 | + if not selected_test then return false end |
| 50 | + execute_in_thread(test_refs[selected_test].cleanup) |
| 51 | +end |
| 52 | + |
| 53 | +local function update_global_status() |
| 54 | + global_status = '' |
| 55 | + for index, ref in pairs(global_test_refs) do |
| 56 | + if ref.active then |
| 57 | + global_status = global_status .. active_emoji_template:format(emoji_numbers[index]) |
| 58 | + else |
| 59 | + global_status = global_status .. inactive_emoji_template:format(emoji_numbers[index]) |
| 60 | + end |
| 61 | + end |
| 62 | + global_status = global_status .. "|" |
| 63 | +end |
| 64 | + |
| 65 | +function InternalGetTestSlot(slot_name, index) return test_slots[slot_name][index] end |
| 66 | + |
| 67 | +function InternalRegisterTest(init_fn, cleanup_fn, name, display_name, icon, description, badge) |
| 68 | + test_refs[#test_refs + 1] = { |
| 69 | + name = name, |
| 70 | + display_name = display_name, |
| 71 | + description = description, |
| 72 | + badge = badge, |
| 73 | + init = init_fn, |
| 74 | + cleanup = cleanup_fn, |
| 75 | + icon = icon |
| 76 | + } |
| 77 | +end |
| 78 | + |
| 79 | +function InternalRegisterGlobalTest(init_fn, cleanup_fn, name, display_name, icon) |
| 80 | + global_test_refs[#global_test_refs + 1] = { |
| 81 | + name = name, |
| 82 | + display_name = display_name, |
| 83 | + init = init_fn, |
| 84 | + cleanup = cleanup_fn, |
| 85 | + icon = icon |
| 86 | + } |
| 87 | +end |
| 88 | + |
| 89 | +CreateThread(function() |
| 90 | + if not DEVMODE then return end |
| 91 | + Wait(250) |
| 92 | + table.sort(test_refs, function(a, b) return a.name < b.name end) |
| 93 | + |
| 94 | + local test_menu_options = { |
| 95 | + { |
| 96 | + template = [[ |
| 97 | +<div class="menu-cell menu-span2" style="display:flex; justify-content:space-between; flex-direction:column; align-items:center; padding:10px; gap:16px;"> |
| 98 | + <div class="menu-label" style="font-weight:bold; color:#fff; font-size:1.8rem;">Payment Method</div> |
| 99 | + <div class="menu-value" style="color:#00ffcc; font-size:3rem;">{{active_menu}}</div> |
| 100 | +</div> |
| 101 | +]], |
| 102 | + bind = function() |
| 103 | + return { active_menu = test_refs[selected_test].display_name } |
| 104 | + end |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + for index, test in pairs(test_refs) do |
| 109 | + test_menu_options[#test_menu_options + 1] = { |
| 110 | + label = ("[%02d] %s"):format(index, test.display_name), |
| 111 | + description = test.description, |
| 112 | + badge = test.badge, |
| 113 | + icon = test.icon, |
| 114 | + action = function() |
| 115 | + if selected_test == index then |
| 116 | + warn('Test already selected') |
| 117 | + return |
| 118 | + end |
| 119 | + unload_selected_test() |
| 120 | + selected_test = index |
| 121 | + load_selected_test() |
| 122 | + exports['interactionMenu']:refresh() |
| 123 | + end |
| 124 | + } |
| 125 | + end |
| 126 | + |
| 127 | + if selected_test then load_selected_test() end |
| 128 | + |
| 129 | + local global_menu_options = { |
| 130 | + { |
| 131 | + template = [[ |
| 132 | +<div class="menu-cell menu-span2" style="display:flex; flex-direction:column; align-items:center; padding:10px; gap:8px; background:rgba(50,50,50,0.85); border-radius:8px; border:1px solid #444;"> |
| 133 | + <div class="menu-label" style="font-weight:bold; color:#fff; font-size:1.4rem;">Global Test Status</div> |
| 134 | + <div class="menu-value" style="font-size:2rem; color:#ffcc00;">{{status}}</div> |
| 135 | +</div> |
| 136 | +]], |
| 137 | + bind = function() |
| 138 | + return { status = global_status } |
| 139 | + end |
| 140 | + } |
| 141 | + } |
| 142 | + |
| 143 | + for _, global_ref in pairs(global_test_refs) do |
| 144 | + global_menu_options[#global_menu_options + 1] = { |
| 145 | + label = global_ref.display_name, |
| 146 | + description = global_ref.description, |
| 147 | + icon = global_ref.icon, |
| 148 | + action = function() |
| 149 | + global_ref.active = not global_ref.active |
| 150 | + if global_ref.active then |
| 151 | + execute_in_thread(global_ref.init) |
| 152 | + else |
| 153 | + execute_in_thread(global_ref.cleanup) |
| 154 | + end |
| 155 | + update_global_status() |
| 156 | + exports['interactionMenu']:refresh() |
| 157 | + end |
| 158 | + } |
| 159 | + end |
| 160 | + |
| 161 | + update_global_status() |
| 162 | + |
| 163 | + exports['interactionMenu']:paginatedMenu { |
| 164 | + itemsPerPage = 11, |
| 165 | + offset = vector3(0, 0, 0), |
| 166 | + rotation = vector3(-20, 0, -90), |
| 167 | + position = vector4(785.6, -2999.2, -68.5, 271.65), |
| 168 | + theme = 'theme-2', |
| 169 | + width = "100%", |
| 170 | + zone = { |
| 171 | + type = 'sphere', |
| 172 | + position = vector3(784.54, -2999.8, -69.0), |
| 173 | + radius = 1.25, |
| 174 | + useZ = true, |
| 175 | + debugPoly = Config.debugPoly |
| 176 | + }, |
| 177 | + suppressGlobals = true, |
| 178 | + options = test_menu_options |
| 179 | + } |
| 180 | + |
| 181 | + exports['interactionMenu']:paginatedMenu { |
| 182 | + itemsPerPage = 10, |
| 183 | + offset = vector3(0, 0, 0), |
| 184 | + rotation = vector3(-20, 0, -90), |
| 185 | + position = vector3(785.5, -2996.2, -69.0), |
| 186 | + theme = 'theme-2', |
| 187 | + width = "100%", |
| 188 | + zone = { |
| 189 | + type = 'sphere', |
| 190 | + position = vector3(784.54, -2996.85, -69.0), |
| 191 | + radius = 1.25, |
| 192 | + useZ = true, |
| 193 | + debugPoly = Config.debugPoly |
| 194 | + }, |
| 195 | + suppressGlobals = true, |
| 196 | + options = global_menu_options |
| 197 | + } |
| 198 | + |
| 199 | + AddEventHandler('onResourceStop', function(resource) |
| 200 | + if resource ~= GetCurrentResourceName() then return end |
| 201 | + if selected_test then test_refs[selected_test].cleanup() end |
| 202 | + end) |
| 203 | +end) |
0 commit comments