summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2024-11-11 15:51:55 +0100
committerTor Andersson <tor@ccxvii.net>2024-11-11 15:51:55 +0100
commit26721bd0947120cc4715235c9593de2147aaa23c (patch)
tree42bfdc7c6e4b340fd622b01a33ad93bdd81b18bd
parent38e6f1157655d74ef879fbe2f80d9716f910093b (diff)
downloadmaria-26721bd0947120cc4715235c9593de2147aaa23c.tar.gz
Add and use map_filter helper (and fix glitch).
-rw-r--r--rules.js21
1 files changed, 10 insertions, 11 deletions
diff --git a/rules.js b/rules.js
index 30bee2f..c0a9af3 100644
--- a/rules.js
+++ b/rules.js
@@ -3768,13 +3768,7 @@ states.combat_target = {
game.defender = game.pos[p]
- // TODO: map_filter
- for (let i = 0; i < game.combat.length; i += 2) {
- if (game.combat[i] === game.attacker && game.combat[i+1] === game.defender) {
- array_remove_pair(game.combat, i)
- break
- }
- }
+ game.combat = map_filter(game.combat, (atk, def) => atk !== game.attacker || def !== game.defender)
goto_resolve_combat()
},
@@ -4356,10 +4350,7 @@ function goto_retroactive_conquest() {
}
})
- // TODO: map_filter
- for (let i = 0; i < game.retro.length; i += 2)
- if (game.retro[i+1] === game.power)
- array_remove_pair(game.retro, i)
+ game.retro = map_filter(game.retro, (s,pow) => pow !== game.power)
log_conquest(conq)
@@ -7238,6 +7229,14 @@ function map_for_each(map, f) {
f(map[i], map[i+1])
}
+function map_filter(map, f) {
+ let out = []
+ for (let i = 0; i < map.length; i += 2)
+ if (f(map[i], map[i+1]))
+ out.push(map[i], map[i+1])
+ return out
+}
+
function map_group_by(items, callback) {
let groups = []
if (typeof callback === "function") {