summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriainp5 <iain.pearce.ip@gmail.com>2024-12-19 13:23:32 +0000
committeriainp5 <iain.pearce.ip@gmail.com>2024-12-19 13:23:32 +0000
commit0b59dd5f8838987e98563d57d15f34cc3e623792 (patch)
treea979d097ee93f75f7aa73f3ea12a0fd71e70167d
parent22f7eb6d92afecaf48452089dfcafb74b4f1f169 (diff)
download1989-dawn-of-freedom-0b59dd5f8838987e98563d57d15f34cc3e623792.tar.gz
Update pop_summary do deal with different messages
-rw-r--r--rules.js77
1 files changed, 50 insertions, 27 deletions
diff --git a/rules.js b/rules.js
index 17a3249..20d8194 100644
--- a/rules.js
+++ b/rules.js
@@ -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() {