summaryrefslogtreecommitdiff
path: root/play.js
diff options
context:
space:
mode:
authorTor Andersson <tor@ccxvii.net>2023-06-21 12:58:29 +0200
committerTor Andersson <tor@ccxvii.net>2023-07-07 18:39:37 +0200
commitf32d40bd233555f956d58ffe398218aa2c9cf633 (patch)
tree44f6799df89b68577980e61890253ae8939b14a8 /play.js
parente374b1ef04542fdfd57a035011f2895560829fd7 (diff)
downloadtime-of-crisis-f32d40bd233555f956d58ffe398218aa2c9cf633.tar.gz
Barbarian invasions.
Diffstat (limited to 'play.js')
-rw-r--r--play.js88
1 files changed, 24 insertions, 64 deletions
diff --git a/play.js b/play.js
index 4b767bc..3e06369 100644
--- a/play.js
+++ b/play.js
@@ -594,26 +594,11 @@ function register_action(target, action, id) {
}
function on_click_action(evt, target) {
- if (evt.button === 0) {
- /*
- if (typeof target.my_stack === "number") {
- evt.stopPropagation()
- if (focus_stack(target.my_stack))
- if (!send_action(target.my_action, target.my_id))
- blur_stack()
- } else {
- */
+ if (evt.button === 0)
if (send_action(target.my_action, target.my_id))
evt.stopPropagation()
- //}
- }
}
-document.getElementById("map").addEventListener("mousedown", function (evt) {
- if (evt.button === 0)
- blur_stack()
-})
-
function create_building(region, className, xoff, yoff) {
let [ x, y, w, h ] = LAYOUT_SUPPORT[region]
let e = create_thing({ className })
@@ -712,36 +697,13 @@ function on_init() {
}
let stack_count = new Array(21).fill(0)
-let stack_focus = -1
-let stack_cache = []
-
-function focus_stack(id) {
- if (stack_focus !== id) {
- // if (view.selected_general === undefined) send_action("general", id)
- stack_focus = id
- on_update()
- let stack = stack_cache[id]
- return stack && stack.length <= 1
- }
- return true
-}
-
-function blur_stack() {
- if (stack_focus >= 0) {
- stack_focus = -1
- on_update()
- }
-}
function layout_stack(id, list, region, in_capital) {
let [ x, y, w, h ] = LAYOUT_XY[region]
- let dx = 6
- let dy = 6
+ let dx = 8
+ let dy = 8
let z = 1
- if (id >= 0)
- stack_cache[id] = list
-
x += w >> 1
y += h >> 1
@@ -772,7 +734,8 @@ function layout_stack(id, list, region, in_capital) {
dy = 16
}
- for (let item of list) {
+ for (let i = list.length - 1; i >= 0; --i) {
+ let item = list[i]
item.style.left = x + "px"
item.style.top = y + "px"
item.style.zIndex = z
@@ -812,9 +775,6 @@ function layout_governor_unavailable(e, color, ix) {
function on_update() {
let player_count = view.legacy.length
- for (let i = 0; i < 24; ++i)
- stack_cache[i] = null
-
ui.body.classList.toggle("p2", player_count === 2)
ui.body.classList.toggle("p3", player_count === 3)
ui.body.classList.toggle("p4", player_count === 4)
@@ -949,10 +909,10 @@ function on_update() {
active_barbarians.push(ui.barbarians[id])
}
}
- if (active_barbarians.length > 0)
- layout_stack(-1, active_barbarians, region, false)
if (inactive_barbarians.length > 0)
layout_stack(-1, inactive_barbarians, region, false)
+ if (active_barbarians.length > 0)
+ layout_stack(-1, active_barbarians, region, false)
}
}
@@ -975,7 +935,7 @@ function on_update() {
let mcastra = has_militia_castra(region)
if (mcastra) {
show(ui.mcastra[region])
- layout_stack(-1, [ ui.militia[region], ui.mcastra[region] ], region, true)
+ layout_stack(-1, [ ui.mcastra[region], ui.militia[region] ], region, true)
} else {
hide(ui.mcastra[region])
layout_stack(-1, [ ui.militia[region] ], region, true)
@@ -1007,32 +967,32 @@ function on_update() {
if (region < 21) {
let stack = []
- if (has_militia(region) && inside)
- stack.push(ui.militia[region])
-
- for (let tribe = 0; tribe < TRIBE_COUNT[player_count]; ++tribe) {
- for (let id = first_barbarian[tribe]; id <= last_barbarian[tribe]; ++id) {
- let loc = get_barbarian_location(id)
- if (loc === army)
- stack.push(ui.barbarians[id])
- }
+ if (castra) {
+ show(ui.castra[pi][ai])
+ stack.push(ui.castra[pi][ai])
+ } else {
+ hide(ui.castra[pi][ai])
}
+ stack.push(e)
+
for (let i = 0; i < 33; ++i) {
let loc = get_legion_location(i)
if (loc === army)
stack.push(ui.legions[i])
}
- stack.push(e)
-
- if (castra) {
- show(ui.castra[pi][ai])
- stack.push(ui.castra[pi][ai])
- } else {
- hide(ui.castra[pi][ai])
+ for (let tribe = 0; tribe < TRIBE_COUNT[player_count]; ++tribe) {
+ for (let id = first_barbarian[tribe]; id <= last_barbarian[tribe]; ++id) {
+ let loc = get_barbarian_location(id)
+ if (loc === army)
+ stack.push(ui.barbarians[id])
+ }
}
+ if (has_militia(region) && inside)
+ stack.push(ui.militia[region])
+
if (inside)
layout_stack(pi * 6 + ai, stack, region, true)
else