diff options
Diffstat (limited to 'rules.js')
-rw-r--r-- | rules.js | 77 |
1 files changed, 50 insertions, 27 deletions
@@ -4521,43 +4521,66 @@ function pop_summary_i() { let c63_logged = false; for (let [n, msg] of game.summary) { - console.log('msg', msg) + console.log('msg', msg); + + // Special case: Log C63 only once if (msg === "(-1 op due to C63)") { - if (!c63_logged) { - logi(msg); - c63_logged = true; - } - continue; - } - // Extract the space identifier (e.g., %67) from the message - let space_match = msg.match(/%\d+/); - let space = space_match ? space_match[0] : "unknown"; - console.log('msg', msg, 'space_match', space_match) - // Extract any details (e.g., £CU to £CC) from the message - let details_match = msg.match(/\(.*?\)$/); - let details = details_match ? details_match[0] : ""; - - // Update or initialize the entry for the space - if (!grouped_summary.has(space)) { - grouped_summary.set(space, { total: 0, details }); - } - let entry = grouped_summary.get(space); + if (!c63_logged) { + logi(msg); + c63_logged = true; + } + continue; + } + + // Direct log for messages like C50, C123 + if (/^C\d{1,3}$/.test(msg)) { + logi(msg); + continue; + } + + // Extract the space identifier (e.g., %33) and type (e.g., "in" or "from") + let space_match = msg.match(/(in|from) (%\d+)/); + if (!space_match) continue; // Skip if no valid match + + let type = space_match[1]; + let space = space_match[2]; + + // Extract additional details (e.g., £DC .to £UU) + let details_match = msg.match(/\((.*?)\)$/); + let details = details_match ? details_match[1] : ""; + + // Split the details into "start" and "end" parts + let [start, end] = details.split(" .to "); + + // Group by type and space + let key = `${type} ${space}`; + if (!grouped_summary.has(key)) { + grouped_summary.set(key, { total: 0, start: "", end: "" }); + } + let entry = grouped_summary.get(key); entry.total += n; - // Always keep the most specific details (non-empty) - if (details) { - entry.details = details; + // Update the start only if it's not already set + if (start && !entry.start) { + entry.start = start; + } + + // Always update the end with the most recent value + if (end) { + entry.end = end; } } // Log the grouped results - for (let [space, { total, details }] of grouped_summary) { - logi(`${total} in ${space} ${details}`); + for (let [key, { total, start, end }] of grouped_summary) { + let details = start && end ? ` (${start} .to ${end})` : ""; + logi(`${total} ${key}${details}`); } } + + // Clear the summary after logging game.summary = []; -} - +} function do_log_summary() { |