From fa51443a305cfb8eba1e2021e4bd3f77fe336ea6 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Fri, 12 May 2023 00:20:28 +0200 Subject: Clean up objective handling. --- events.txt | 4 +++ play.html | 1 + play.js | 106 +++++++++++++++++++++++++++++++++---------------------------- rules.js | 67 ++++++++++++++++++++++++-------------- 4 files changed, 106 insertions(+), 72 deletions(-) diff --git a/events.txt b/events.txt index 77f03a6..22260fc 100644 --- a/events.txt +++ b/events.txt @@ -5,8 +5,12 @@ CARD 1 - Jules Ducatel asm clear_undo() if (game.round < 4) + asm log("Commune Objective:") + asm logi("C" + game.red_objective) goto "reveal_commune_objective" else + asm log("Commune hand:") + asm { for (let c of game.red_hand) logi("C" + c) } goto "reveal_commune_hand" endif ops 1 MILITARY diff --git a/play.html b/play.html index 2c451cc..cf44eb9 100644 --- a/play.html +++ b/play.html @@ -53,6 +53,7 @@ body.Versailles header.your_turn { background-color: skyblue; } } #hand { min-width: 1060px } +#hand.censorship { min-width: 1330px } #commune_cards { min-width: 790px } #versailles_cards { min-width: 790px } #set_aside { min-width: 790px } diff --git a/play.js b/play.js index 0c8c5fc..62566fc 100644 --- a/play.js +++ b/play.js @@ -230,60 +230,64 @@ function on_click_disc(evt) { } } +function create(t, p, ...c) { + let e = document.createElement(t) + Object.assign(e, p) + e.append(c) + return e +} + function build_user_interface() { let elt document.getElementById("red_momentum").addEventListener("mousedown", on_click_red_momentum) document.getElementById("blue_momentum").addEventListener("mousedown", on_click_blue_momentum) - ui.red_objective_back = document.createElement("div") - ui.red_objective_back.className = "card card_objective_back" - ui.blue_objective_back = document.createElement("div") - ui.blue_objective_back.className = "card card_objective_back" + ui.objective_back = [ + create("div", { className: "card card_objective_back" }), + create("div", { className: "card card_objective_back" }), + create("div", { className: "card card_objective_back" }), + create("div", { className: "card card_objective_back" }), + ] for (let c = 1; c <= 41 + 12; ++c) { - elt = ui.cards[c] = document.createElement("div") - elt.className = `card card_${c}` - elt.my_card = c - elt.addEventListener("click", on_click_card) + elt = ui.cards[c] = create("div", { + className: `card card_${c}`, + my_card: c, + onmousedown: on_click_card + }) } for (let i = 0; i < 36; ++i) { - elt = ui.cubes[i] = document.createElement("div") - if (i < 18) - elt.className = "piece cube red" - else - elt.className = "piece cube blue" - elt.my_cube = i - elt.addEventListener("mousedown", on_click_cube) + elt = ui.cubes[i] = create("div", { + className: (i < 18) ? "piece cube red" : "piece cube blue", + my_cube: i, + onmousedown: on_click_cube, + }) document.getElementById("pieces").appendChild(elt) } for (let i = 0; i < 4; ++i) { - elt = ui.discs[i] = document.createElement("div") - if (i < 2) - elt.className = "piece disc red" - else - elt.className = "piece disc blue" - elt.my_disc = i + 36 - elt.addEventListener("mousedown", on_click_disc) + elt = ui.discs[i] = create("div", { + className: (i<2) ? "piece disc red" : "piece disc blue", + my_disc: i + 36, + onmousedown: on_click_disc + }) document.getElementById("pieces").appendChild(elt) } for (let i = 0; i < space_count; ++i) { let name = space_names[i] let [x, y, w, h] = boxes[name] - elt = ui.spaces[i] = document.createElement("div") - elt.className = "space" - elt.my_space = i - elt.my_name = name - elt.addEventListener("mousedown", on_click_space) - elt.addEventListener("mouseenter", on_focus_space) - elt.addEventListener("mouseleave", on_blur) - elt.style.top = (y-1) + "px" - elt.style.left = (x-1) + "px" - elt.style.width = (w+2) + "px" - elt.style.height = (h+2) + "px" + elt = ui.spaces[i] = create("div", { + className: "space", + my_space: i, + my_name: name, + onmousedown: on_click_space, + onmouseenter: on_focus_space, + onmouseleave: on_blur, + style: `top: ${y-1}px;left:${x-1}px;width:${w+2}px;height:${h+2}px` + }) space_layout_cube[i] = { x: x + Math.round(w/2), y: y + Math.round(h*1/2) } space_layout_disc[i] = { x: x + w, y: y + h } document.getElementById("spaces").appendChild(elt) @@ -380,6 +384,20 @@ function on_log(text) { return p } +function on_update_objective(parent, objective) { + if (typeof objective === "object") { + for (let c of objective) + parent.appendChild(ui.cards[c]) + } else if (objective === 1) { + parent.appendChild(ui.objective_back[0]) + } else if (objective === 2) { + parent.appendChild(ui.objective_back[0]) + parent.appendChild(ui.objective_back[1]) + } else if (objective > 2) { + parent.appendChild(ui.cards[objective]) + } +} + function on_update() { if (view.initiative === "Commune") document.getElementById("commune_info").textContent = "\u2756" @@ -402,35 +420,25 @@ function on_update() { ui.military_vp.className = `piece cylinder purple vp${5+view.military_vp}` ui.political_vp.className = `piece cylinder orange vp${5+view.political_vp}` + document.querySelector("body").classList.toggle("censorship", view.censorship === 1) + document.getElementById("hand").replaceChildren() document.getElementById("discard").replaceChildren() document.getElementById("set_aside").replaceChildren() - - // document.getElementById("final").replaceChildren() - // document.getElementById("objective").replaceChildren() - document.getElementById("commune_cards").replaceChildren() document.getElementById("versailles_cards").replaceChildren() if (view.red_final) document.getElementById("commune_cards").appendChild(ui.cards[view.red_final]) + on_update_objective(document.getElementById("commune_cards"), view.red_objective) + if (view.blue_final) document.getElementById("versailles_cards").appendChild(ui.cards[view.blue_final]) - - if (view.red_objective === 0) - document.getElementById("commune_cards").appendChild(ui.red_objective_back) - else - for (let c of view.red_objective) - document.getElementById("commune_cards").appendChild(ui.cards[c]) - - if (view.blue_objective === 0) - document.getElementById("versailles_cards").appendChild(ui.blue_objective_back) - else - for (let c of view.blue_objective) - document.getElementById("versailles_cards").appendChild(ui.cards[c]) + on_update_objective(document.getElementById("versailles_cards"), view.blue_objective) if (view.discard) document.getElementById("discard").appendChild(ui.cards[view.discard]) + if (view.hand) for (let c of view.hand) document.getElementById("hand").appendChild(ui.cards[c]) diff --git a/rules.js b/rules.js index 729e2a8..9b7f42d 100644 --- a/rules.js +++ b/rules.js @@ -321,11 +321,11 @@ function objective_card_space(c) { } function commune_objective_card() { - return game.red_objective[0] + return game.red_objective } function versailles_objective_card() { - return game.blue_objective[0] + return game.blue_objective } function commune_objective_space() { @@ -908,7 +908,7 @@ function start_round() { log_h1("Round " + game.round) let n = 4 - if (game.scenario === "Censorship") + if (game.censorship) n = 5 for (let i = 0; i < n; ++i) { @@ -916,10 +916,8 @@ function start_round() { game.blue_hand.push(draw_strategy_card()) } - for (let i = 0; i < 2; ++i) { - game.red_objective.push(game.objective_deck.pop()) - game.blue_objective.push(game.objective_deck.pop()) - } + game.red_objective = [ game.objective_deck.pop(), game.objective_deck.pop() ] + game.blue_objective = [ game.objective_deck.pop(), game.objective_deck.pop() ] game.active = "Both" game.state = "choose_objective_card" @@ -941,14 +939,14 @@ states.choose_objective_card = { }, card(c, player) { if (player === COMMUNE) - game.red_objective = [ c ] + game.red_objective = c else - game.blue_objective = [ c ] - if (game.red_objective.length === 1 && game.blue_objective.length === 1) + game.blue_objective = c + if (typeof game.red_objective === "number" && typeof game.blue_objective === "number") end_choose_objective_card() - else if (game.red_objective.length === 1) + else if (typeof game.red_objective === "number") game.active = VERSAILLES - else if (game.blue_objective.length === 1) + else if (typeof game.blue_objective === "number") game.active = COMMUNE else game.active = "Both" @@ -994,7 +992,7 @@ function end_initiative_phase() { game.active = game.initiative if (game.round === 4) goto_final_crisis_events() - else if (game.scenario === "Censorship") + else if (game.censorship) goto_censorship_phase() else goto_strategy_phase() @@ -1123,7 +1121,7 @@ states.play_card = { }, momentum() { push_undo() - if (game.scenario === "Censorship") + if (game.censorship) recycle_card(game.what) else discard_card(game.what) @@ -1517,6 +1515,7 @@ states.operations_place = { game.count -= 2 else game.count -= 1 + log("Placed in S" + s + ".") place_cube(s) resume_operations_place() }, @@ -1835,11 +1834,11 @@ states.objective_card_scoring = { function goto_objective_card_events() { if (!is_commune_control(commune_objective_space())) { log("Removed C" + commune_objective_card()) - game.red_objective = [] + game.red_objective = 0 } if (!is_versailles_control(versailles_objective_space())) { log("Removed C" + versailles_objective_card()) - game.blue_objective = [] + game.blue_objective = 0 } resume_objective_card_events() } @@ -1871,7 +1870,7 @@ states.objective_card_events = { }, card(c) { if (c === commune_objective_card()) { - game.red_objective = [] + game.red_objective = 0 game.red_fulfilled += 1 game.active = COMMUNE log_h2(COMMUNE) @@ -1879,7 +1878,7 @@ states.objective_card_events = { goto_play_event(c) } if (c === versailles_objective_card()) { - game.blue_objective = [] + game.blue_objective = 0 game.blue_fulfilled += 1 game.active = VERSAILLES log_h2(VERSAILLES) @@ -2698,7 +2697,7 @@ states.vm_move = { states.reveal_commune_objective = { prompt() { - view.prompt = "Revealing Commune player's Objective Card." + event_prompt("Revealing Commune player's Objective Card.") view.red_objective = game.red_objective view.actions.done = 1 }, @@ -2709,7 +2708,7 @@ states.reveal_commune_objective = { states.reveal_commune_hand = { prompt() { - view.prompt = "Revealing Commune player's hand." + event_prompt("Revealing Commune player's hand.") view.hand = game.red_hand view.actions.done = 1 }, @@ -2720,7 +2719,7 @@ states.reveal_commune_hand = { states.general_louis_valentin = { prompt() { - event_prompt("Remove a red cube from up to 2 different Paris spaces where you are present.") + event_prompt("Remove 1 from up to 2 different Paris spaces where present.") view.actions.skip = 1 for (let s of game.vm.spaces) if (can_remove_cube(s)) @@ -2741,7 +2740,8 @@ states.general_louis_valentin = { } function init_karl_marx() { - // clear_undo() + clear_undo() + // Draw cards into hand in case a reshuffle is triggered. game.red_hand.push(draw_strategy_card()) game.red_hand.push(draw_strategy_card()) game.red_hand.push(draw_strategy_card()) @@ -2819,7 +2819,6 @@ states.freemason_parade = { exports.setup = function (seed, scenario, options) { game = { seed: seed, - scenario: scenario, log: [], undo: [], active: null, @@ -2905,6 +2904,11 @@ exports.setup = function (seed, scenario, options) { log_h1("Red Flag Over Paris") + if (scenario === "Censorship") { + log_h2("Censorship") + game.censorship = 1 + } + for (let c = 1; c <= 41; ++c) if (c !== 17 && c !== 34) game.strategy_deck.push(c) @@ -2974,6 +2978,19 @@ exports.view = function(state, player) { set_aside: 0, } + if (game.censorship) + view.censorship = 1 + + if (typeof game.red_objective === "object") + view.red_objective = 2 + else if (game.red_objective > 0) + view.red_objective = 1 + + if (typeof game.blue_objective === "object") + view.blue_objective = 2 + else if (game.blue_objective > 0) + view.blue_objective = 1 + if (player === COMMUNE) { view.hand = game.red_hand view.set_aside = game.red_set_aside @@ -3211,8 +3228,12 @@ const CODE = [] CODE[1] = [ // Jules Ducatel [ vm_asm, ()=>clear_undo() ], [ vm_if, ()=>(game.round < 4) ], + [ vm_asm, ()=>log("Commune Objective:") ], + [ vm_asm, ()=>logi("C" + game.red_objective) ], [ vm_goto, "reveal_commune_objective" ], [ vm_else ], + [ vm_asm, ()=>log("Commune hand:") ], + [ vm_asm, ()=>{ for (let c of game.red_hand) logi("C" + c) } ], [ vm_goto, "reveal_commune_hand" ], [ vm_endif ], [ vm_ops, 1, MILITARY ], -- cgit v1.2.3