|
2 | 2 | utils = {} |
3 | 3 | local json = require("json") |
4 | 4 |
|
| 5 | +-- ========================================================================== |
| 6 | +-- Game State Extraction |
| 7 | +-- ========================================================================== |
| 8 | + |
5 | 9 | ---Extracts the current game state including game info, hand, and jokers |
6 | 10 | ---@return GameStateResponse The complete game state |
7 | 11 | function utils.get_game_state() |
@@ -65,6 +69,10 @@ function utils.get_game_state() |
65 | 69 | } |
66 | 70 | end |
67 | 71 |
|
| 72 | +-- ========================================================================== |
| 73 | +-- Debugging Utilities |
| 74 | +-- ========================================================================== |
| 75 | + |
68 | 76 | ---Converts a Lua table to JSON string with depth limiting to prevent infinite recursion |
69 | 77 | ---@param obj any The object to convert to JSON |
70 | 78 | ---@param depth? number Maximum depth to traverse (default: 3) |
@@ -103,4 +111,19 @@ function utils.table_to_json(obj, depth) |
103 | 111 | return json.encode(sanitized) |
104 | 112 | end |
105 | 113 |
|
| 114 | +-- Load debug |
| 115 | +local success, dpAPI = pcall(require, "debugplus-api") |
| 116 | + |
| 117 | +if success and dpAPI.isVersionCompatible(1) then |
| 118 | + local debugplus = dpAPI.registerID("balatrobot") |
| 119 | + debugplus.addCommand({ |
| 120 | + name = "env", |
| 121 | + shortDesc = "Get game state", |
| 122 | + desc = "Get the current game state, useful for debugging", |
| 123 | + exec = function(args, _, _) |
| 124 | + debugplus.logger.log('{"name": "' .. args[1] .. '", "G": ' .. utils.table_to_json(G.GAME, 2) .. "}") |
| 125 | + end, |
| 126 | + }) |
| 127 | +end |
| 128 | + |
106 | 129 | return utils |
0 commit comments