diff options
Diffstat (limited to 'play.js')
-rw-r--r-- | play.js | 1804 |
1 files changed, 914 insertions, 890 deletions
@@ -1,890 +1,914 @@ -
-const seed = 'none'
-const scenario = 'standard'
-const options = 'none'
-//const rules = require("./rules")
-
-const last_card = 110
-const last_power_card = 52
-let hover_timeout
-const height = 65
-const width = 105
-const toolbar = document.getElementById('toolbar')
-const vpMarker = document.getElementById('vp')
-const counters = document.getElementById('counters')
-
-const countries= ['Poland', 'Hungary', 'East_Germany', 'Bulgaria', 'Czechoslovakia', 'Romania']
-
-/*const aside_events = [
- "honecker",
- "st_nicholas_church",
- "helsinki_final_act",
- "eco_glasnost",
- "we_are_the_people",
- "foreign_currency_debt_burden",
- "li_peng",
- "austria_hungary_border_reopened",
- "grenztruppen",
- "presidential_visit",
- "securitate",
- "laslzo_tokes",
- "stand_fast",
- "elena",
- "new_years_eve_party"
-]*/
-const board_events = [2, 9, 69, 97]
-const box_events = [ 15, 24, 26, 39, 48, 49, 53, 58, 59, 65, 70, 73, 100, 101, 104 ]
-let box_events_showing = false
-let show_discard = false
-
-const overlay = document.getElementById('overlay');
-const spaceNameElement = document.getElementById('space-name');
-const spaceCharacteristicsElement = document.getElementById('space-characteristics');
-
-
-// Event listener to track mouse movement over the map
- document.querySelector('.map').addEventListener('mousemove', function(event) {
- const x = event.offsetX; // X-coordinate of mouse relative to container
- const y = event.offsetY; // Y-coordinate of mouse relative to container
- spaceCharacteristicsElement.innerText = `X: ${x}, Y: ${y}`;
- })
-
-
- // Create map areas dynamically based on coordinates
-
- function create_ui() {
-
-// CREATE MAP
-
- spaces.forEach((space) => {
-
-
- if (space && space.box) {
-
- //CREATE SPACES
- const { x, y} = space.box;
- const spaceArea = document.createElement('div');
- spaceArea.classList.add('space-area', space.country)
- spaceArea.id=`space_${space.space_id}`;
- spaceArea.style.left = x + 'px';
- spaceArea.style.top = y + 'px';
- spaceArea.style.width = width + 'px';
- spaceArea.style.height = height + 'px';
- spaceArea.style.zIndex = 2;
- spaceArea.my_space = space.name_unique;
- spaceArea.addEventListener('mousedown', on_click_space);
-
- //CREATE DEMOCRATIC INFLUENCE MARKERS FOR EACH SPACE
- const dem_img = document.createElement('div')
- dem_img.classList.add('demInfl', space.country)
- dem_img.style.display = 'none'
- dem_img.id=`${space.name_unique}_demInfl`
- dem_img.style.zIndex = 1
- dem_img.my_space = space.name_unique;
- dem_img.addEventListener('mousedown', on_click_space);
- spaceArea.appendChild(dem_img)
-
- //CREATE DEMOCRATIC INFLUENCE VALUES
- const demInflValue = document.createElement('p')
- demInflValue.className='demInflValue'
- demInflValue.style.display = 'none'
- demInflValue.id=`${space.name_unique}_demInflValue`
- demInflValue.innerText=space.demInfl
- demInflValue.style.zIndex = 1
- demInflValue.my_space = space.name_unique;
- demInflValue.addEventListener('mousedown', on_click_space);
- spaceArea.appendChild(demInflValue)
-
- //CREATE COMMUNIST INFLUENCE MARKERS FOR EACH SPACE
- const com_img = document.createElement('div')
- com_img.className='comInfl'
- com_img.style.display='none'
- com_img.id=`${space.name_unique}_comInfl`
- com_img.style.zIndex = 1
- com_img.my_space = space.name_unique;
- com_img.addEventListener('mousedown', on_click_space);
- spaceArea.appendChild(com_img)
-
- //CREATE COMMUNIST INFLUENCE VALUES
- const comInflValue = document.createElement('p')
- comInflValue.className='comInflValue'
- comInflValue.style.display='none'
- comInflValue.id=`${space.name_unique}_comInflValue`
- comInflValue.innerText=space.comInfl
- comInflValue.style.zIndex = 1
- comInflValue.my_space = space.name_unique;
- comInflValue.addEventListener('mousedown', on_click_space);
- spaceArea.appendChild(comInflValue)
- //}
-
- counters.appendChild(spaceArea);
- }
- });
-
-// CREATE CARDS
-
- const is_mobile = window.matchMedia("(pointer: coarse)").matches
-
- for (let c = 1; c <= last_card; ++c) {
-
- const hand_card = document.createElement('img');
- hand_card.classList.add('hand_card')
- hand_card.id=`card_${c}`;
- hand_card.src = `cards/e${c}.gif`
- hand_card.my_card = c;
- hand_card.addEventListener('click', on_click_card);
-
- if(!is_mobile) {
- hand_card.addEventListener('mouseenter', () => {
- hover_timeout = setTimeout(() => {
- hand_card.classList.add('zoom');
- }, 500) })
- hand_card.addEventListener('mouseleave', () => {
- clearTimeout(hover_timeout);
- hand_card.classList.remove('zoom');
- });
- }
-
- ui.cards.push(hand_card);
- }
-
-
-
- for (let card of power_cards) {
- if (!card) continue;
- const power_card = document.createElement('img');
- power_card.classList.add('power_card');
- power_card.id = `power_card_${card.number}`;
- power_card.src = `cards_2/${card.url}.gif`;
- power_card.my_card = card.number;
- power_card.addEventListener('mousedown', on_click_card);
- ui.power_cards.push(power_card);
- }
-}
-
-// POP UP CARD MENU
-
-var card_action_menu = Array.from(document.getElementById("popup").querySelectorAll("li[data-action]")).map(e => e.dataset.action)
-
-console.log('card_action_menu', card_action_menu)
-
-function show_popup_menu(evt, menu_id, target_id, title) {
- let menu = document.getElementById(menu_id)
- console.log('show_popup_menu called with evt',evt, 'menu_id',menu_id, 'target_id', target_id, 'title', title)
-
- let show = false
- console.log(`menu.querySelectorAll("li")`, menu.querySelectorAll("li"))
- for (let item of menu.querySelectorAll("li")) {
- let action = item.dataset.action
- console.log('item', item, 'action', action)
- if (action) {
- //console.log('in if action')
- if (is_card_action(action, target_id)) {
- console.log('in is_card_action',)
- show = true
- item.classList.add("action")
- item.classList.remove("disabled")
- item.onclick = function () {
- send_action(action, target_id)
- hide_popup_menu()
- evt.stopPropagation()
- }
- } else {
- item.classList.remove("action")
- item.classList.add("disabled")
- item.onclick = null
- }
- }
- }
-
- if (show) {
- menu.onmouseleave = hide_popup_menu
- menu.style.display = "block"
- if (title) {
- let item = menu.querySelector("li.title")
- if (item) {
- item.onclick = hide_popup_menu
- item.textContent = title
- }
- }
-
- let w = menu.clientWidth
- let h = menu.clientHeight
- let x = Math.max(5, Math.min(evt.clientX - w / 2, window.innerWidth - w - 5))
- let y = Math.max(5, Math.min(evt.clientY - 12, window.innerHeight - h - 40))
- menu.style.left = x + "px"
- menu.style.top = y + "px"
-
- evt.stopPropagation()
- } else {
- menu.style.display = "none"
- }
-}
-
-function hide_popup_menu() {
- document.getElementById("popup").style.display = "none"
- document.getElementById("popup_ceh_check").style.display = "none"
- document.getElementById("popup_opp_event").style.display = "none"
- document.getElementById("popup_tst_7").style.display = "none"
- document.getElementById("popup_tst_8").style.display = "none"
- document.getElementById("popup_tst_7_8").style.display = "none"
-}
-
-
-function is_card_enabled(card) {
- if (view.actions) {
- if (card_action_menu.some(a => view.actions[a] && view.actions[a].includes(card)))
- return true
- if (view.actions.card_select && view.actions.card_select.includes(card))
- return true
- if (view.actions.card && view.actions.card.includes(card))
- return true
- }
- return false
-}
-
-// SUPPORTING FUNCTIONS
-
-function on_click_space(evt) {
- if (evt.button === 0) {
- const space = evt.target.my_space;
- //console.log('on_click_space_called with space:', space);
- if (send_action('infl', space)) {
- evt.stopPropagation();
- } else if (send_action('sc', space)) {
- //console.log('send_action with sc:', space);
- evt.stopPropagation();
- } else {
- // console.log('send_action failed for space:', space);
- }
- }
- //hide_popup_menu();
-}
-
-function on_click_card(evt) {
- const card = evt.target.my_card;
- console.log('on_click_card_called with card:', card);
- if (is_action('card', card)) {
- console.log('in action card')
- if (send_action('card', card)) {
- evt.stopPropagation();
- }
- }
- //First check for TST special powers
- else if (is_card_action('card_tst_7', card)) {
- if (is_card_action('card_tst_8', card)) {
- show_popup_menu(evt, "popup_tst_7_8", card, cards[card].name)
- } else {
- show_popup_menu(evt, "popup_tst_7", card, cards[card].name)
- }
- }
- else if (is_card_action('card_tst_8', card)) {
- show_popup_menu(evt, "popup_tst_8", card, cards[card].name)
- }
-
- //Check for Common European Home
- else if (is_card_action('card_ceh', card)) {
- show_popup_menu(evt, "popup_ceh_check", card, cards[card].name)
- } else if (is_card_action('card_opp_event', card)) {
- console.log('in action card_opp_event')
- show_popup_menu(evt, "popup_opp_event", card, cards[card].name)
- }
- else {
- console.log('in action card_my_event')
- show_popup_menu(evt, "popup", card, cards[card].name)
- }
-}
-
-function is_action(action) {
- //console.log('is_action called with: ', action)
- console.log('view.actions', view.actions)
- if (view.actions && view.actions[action])
- return true
- return false
-}
-
-function is_card_action(action, card) {
- console.log('is_card_action called with action', action, 'card', card)
- console.log('view.actions', view.actions, 'view.actions[action]', view.actions[action])
- if (view.actions && view.actions[action] && view.actions[action].includes(card))
- return true
- return false
-}
-
-function on_log(text) { // eslint-disable-line no-unused-vars
-
- let p = document.createElement("div")
-
-
-/*
- let last_text = last_log_entry ? last_log_entry.split(' ') : []
- console.log('last text', last_text, 'text', text.split(' ')[3])
- if (last_text[0] === 'Added' && last_text[4] === text.split(' ')[4]) {
- let new_influence = parseInt(last_text[1]) + 1
- new_text = `Added ${new_influence} influence in ${last_text[4]}`
- console.log('new_influence', new_influence, 'new_text', new_text)
- } */
-
-
- if (text.match(/^>/)) {
- text = text.substring(1)
- p.className = 'i'
- }
-
- text = text.replace(/_/g, ' ')
- text = text.replace(/C(\d+)/g, sub_card_name)
- text = text.replace(/P(\d+)/g, sub_power_card_name)
- text = text.replace(/V(\d+)/g, sub_power_card_value)
- text = text.replace(/%(\d+)/g, sub_space_name)
-
-
- if (text.match(/^\.h1/)) {
- text = text.substring(4)
- p.className = 'h1'
- }
- else if (text.match(/^\.h2d/)) {
- text = text.substring(5)
- p.className = 'h2 dem'
- }
- else if (text.match(/^\.h2c/)) {
- text = text.substring(5)
- p.className = 'h2 com'
- }
- else if (text.match(/^\.h2/)) {
- text = text.substring(4)
- p.className = 'h2'
- }
- else if (text.match(/^\.h3/)) {
- text = text.substring(4)
- p.className = 'h3'
- }
-
- //console.log('view.log', view.log)
- /*console.log('new text', text)
- if (last_log_entry_text) {
- console.log('log = text', last_log_entry_text === text)
- }
-
-*/
- p.innerHTML = text
- return p
-}
-
-let ui = {
- favicon: document.getElementById('favicon'),
- player: [
- document.getElementById("role_Democrat"),
- document.getElementById("role_Communist"),
- ],
- cards: [ null ],
- power_cards: [null],
- dem_hand_count: document.getElementById("role_stat_dem"),
- com_hand_count: document.getElementById("role_stat_com"),
- deck_length: document.getElementById("deck_length"),
- played_card: 0,
- table_panel: document.getElementById("table_panel"),
- hand_panel: document.getElementById("hand_panel"),
- turn: document.getElementById("turn-tracker"),
- round: document.getElementById("action-round-tracker"),
- stability: document.getElementById("stability-track"),
- dem_TST: document.getElementById("dem-TST"),
- com_TST: document.getElementById("com-TST"),
- vp: document.getElementById("vp"),
- spaces: document.getElementsByClassName("space-area")
-
-}
-
-
-function on_update() {
- //console.log('on_update called')
- //console.log('view.valid_spaces: ', view.valid_spaces)
- //console.log('view.actions: ', view.actions)
- //console.log('view.power_cards:', view.power_cards)
- document.querySelectorAll('[id^="space_"].selected').forEach(spaceElement => {spaceElement.classList.remove('selected');});
- document.getElementById("power_hand")?.querySelectorAll('.selected').forEach(cardElement => {cardElement.classList.remove('selected');});
- view.valid_spaces.forEach(space_id => {
- const spaceElementId = `space_${space_id}`;
- const spaceElement = document.getElementById(spaceElementId);
-
- if (spaceElement) {
- spaceElement.classList.add('selected');
- }
- });
-
- //Check influence values
-
- for (let i = 1; i < spaces.length; i ++) {
-
- const space = spaces[i]
- const demInfl = view.demInfl[i]
- const comInfl = view.comInfl[i]
- //console.log('piece', piece)
- //console.log('space', space)
- const dem_marker = document.getElementById(`${space.name_unique}_demInfl`);
- const dem_number = document.getElementById(`${space.name_unique}_demInflValue`);
- const com_marker = document.getElementById(`${space.name_unique}_comInfl`);
- const com_number = document.getElementById(`${space.name_unique}_comInflValue`);
-
- dem_number.innerText=demInfl
- if (demInfl > 0) {
- dem_marker.style.display = 'block';
- dem_number.style.display = 'block';
-
- if (demInfl > 9) {
- dem_number.classList.remove('demInflValue')
- dem_number.classList.add('demInflValue_10')
- } else {
- dem_number.classList.add('demInflValue')
- dem_number.classList.remove('demInflValue_10')
- }
-
- if(check_dem_control(demInfl, comInfl, space)){
- dem_marker.classList.add('controlled')
- dem_number.classList.add('outlined_text')
- dem_marker.classList.remove('uncontrolled')
- } else {
- dem_marker.classList.add('uncontrolled')
- dem_marker.classList.remove('controlled')
- dem_number.classList.remove('outlined_text')
- }
- } else {
- dem_marker.style.display = 'none';
- dem_number.style.display = 'none';
- }
- com_number.innerText=comInfl
- if (comInfl > 0) {
- com_marker.style.display = 'block';
- com_number.style.display = 'block';
-
- if (comInfl > 9) {
- com_number.classList.remove('comInflValue')
- com_number.classList.add('comInflValue_10')
- } else {
- com_number.classList.add('comInflValue')
- com_number.classList.remove('comInflValue_10')
- }
-
- if(check_com_control(demInfl, comInfl, space)){
- com_marker.classList.add('controlled')
- com_number.classList.add('controlled')
- com_marker.classList.remove('uncontrolled')
- com_number.classList.remove('uncontrolled')
- } else {
- com_marker.classList.add('uncontrolled')
- com_number.classList.add('uncontrolled')
- com_marker.classList.remove('controlled')
- com_number.classList.remove('controlled')
- }
- } else {
- com_marker.style.display = 'none';
- com_number.style.display = 'none';
- }
-
- }
-
-// UPDATE COUNTRY MARKERS
- for (let i = 0; i < countries.length; i++) {
- const country = countries[i];
- const marker = document.getElementById(country)
- const times_held = document.getElementById(`${country}_times_held`)
-
- if (view.revolutions[find_country_index(country)]) {
- marker.classList.add('revolution')
- marker.classList.remove('held')
- marker.style.display = 'block'
- times_held.classList.add('outlined_text')
- times_held.classList.remove('hide')
- } else if (view.times_held[find_country_index(country)] > 0 ) {
- //console.log('setting ', country)
- marker.classList.add('held')
- marker.style.display = 'block'
- times_held.classList.remove('hide')
- times_held.innerHTML = view.times_held[find_country_index(country)]
- }
- else {marker.style.display = 'none'}
- }
-
-// UPDATE ASIDE
- if (view.is_pwr_struggle) {
- ui.dem_hand_count.innerText = `${view.democrat_power_hand} Power cards`
- ui.com_hand_count.innerText = `${view.communist_power_hand} Power cards`
- } else{
- ui.dem_hand_count.innerText = `${view.democrat_hand} cards in hand`
- ui.com_hand_count.innerText = `${view.communist_hand} cards in hand`
- }
- ui.deck_length.innerText = `${view.strategy_deck} cards`
-
-// UPDATE HAND
- document.getElementById("hand").replaceChildren()
- document.getElementById("played_card").replaceChildren()
-
- if (view.hand.length && view.is_pwr_struggle === false) {
- document.getElementById("hand_panel").classList.remove("hide")
- for (let c of view.hand) {
- let card = ui.cards[c]
- document.getElementById("hand").appendChild(card);
- if (view.valid_cards.includes(c)) {
- card.classList.add('selected')
- } else {
- card.classList.remove('selected')
- }
- card.classList.remove('discard_card')
- }
- } else {
- document.getElementById("hand_panel").classList.add("hide")
- }
-
-// UPDATE DISCARD
-document.getElementById("discard").replaceChildren()
-if (!view.is_pwr_struggle) {
- for (let c of view.strategy_discard) {
- let discard_card = ui.cards[c]
- document.getElementById("discard").appendChild(discard_card)
- discard_card.classList.add('discard_card')
- discard_card.classList.remove('selected')
- }
-} else if (view.is_pwr_struggle) {
- for (let c of view.strategy_discard) {
- let discard_card = ui.power_cards[c]
- document.getElementById("discard").appendChild(discard_card)
- discard_card.classList.add('discard_card')
- discard_card.classList.remove('selected')
- }
-}
-
-// DISCARD FOR EVENTS
-console.log('view.discard',view.discard)
-if(view.discard) {
- //document.getElementById("discard").replaceChildren()
- document.getElementById("discard_panel").classList.remove("hide")
- for (let c of view.strategy_discard) {
- let discard_card = ui.cards[c]
- document.getElementById("discard").appendChild(discard_card)
- discard_card.classList.add('discard_card')
- if (view.valid_cards.includes(c)) {
- discard_card.classList.add('selected')
- } else {
- discard_card.classList.remove('selected')
- }
- }
-} else {
- if (!show_discard) {
- document.getElementById("discard_panel").classList.add("hide")
- }
-}
-
-// UPDATE PERMANENTLY REMOVED CARDS
-document.getElementById("removed").replaceChildren()
-for (let c of view.strategy_removed) {
- let discard_card = ui.cards[c]
- document.getElementById("removed").appendChild(discard_card)
- discard_card.classList.add('discard_card')
- discard_card.classList.remove('selected')
-}
-
-
-// PLAYED CARD PANEL
-if (view.played_card > 0) {
- document.getElementById("played_card_panel").classList.remove("hide")
- document.getElementById("played_card").appendChild(ui.cards[view.played_card]);
-} else {
- document.getElementById("played_card_panel").classList.add("hide")
-}
-
-// TABLE CARDS PANEL
-document.getElementById("table_cards").replaceChildren()
-if (view.table_cards.length > 0) {
- document.getElementById("table_panel").classList.remove("hide")
- for (let c of view.table_cards) {
- let card = ui.cards[c]
- document.getElementById("table_cards").appendChild(card);
- card.classList.remove("hand_card")
- card.classList.add('event_card');
- }
- } else {
- document.getElementById("table_panel").classList.add("hide")
-}
-
-// OPPONENT HAND
-document.getElementById("opp_hand").replaceChildren()
-if (!view.is_pwr_struggle) {
- if (view.show_opp_hand && view.opp_hand.length >0) {
- document.getElementById("opp_hand_panel").classList.remove("hide")
- for (let c of view.opp_hand) {
- let card = ui.cards[c]
- //console.log('power_card:', power_card)
- document.getElementById("opp_hand").appendChild(card);
- card.classList.remove('discard_card')
- }
- } else {
- document.getElementById("opp_hand_panel").classList.add("hide")
- }
-} else {
- if (view.show_opp_hand && view.opp_hand.length >0) {
- document.getElementById("opp_hand_panel").classList.remove("hide")
- for (let c of view.opp_hand) {
- let card = ui.power_cards[c]
- //console.log('power_card:', power_card)
- document.getElementById("opp_hand").appendChild(card);
- card.classList.remove('discard_card')
- }
- } else {
- document.getElementById("opp_hand_panel").classList.add("hide")
- }
-}
-
-// POWER STRUGGLE HAND
- document.getElementById("power_hand").replaceChildren()
-
- if (view.power_hand.length && view.is_pwr_struggle) {
- document.getElementById("power_panel").classList.remove("hide")
- for (let c of view.power_hand) {
- let power_card = ui.power_cards[c]
- document.getElementById("power_hand").appendChild(power_card);
- if (view.valid_cards.includes(c)) {
- power_card.classList.add('selected');
- }
- }
- } else {
- document.getElementById("power_panel").classList.add("hide")
- }
-
-// CEAUSESCU
-
-if (view.ceausescu_cards && view.ceausescu_cards.length > 0 && view.is_pwr_struggle === true) {
- document.getElementById("ceausescu_panel").classList.remove("hide")
- for (let c of view.ceausescu_cards) {
- let power_card = ui.power_cards[c]
- document.getElementById("ceausescu_hand").appendChild(power_card);
- }
-} else {
- document.getElementById("ceausescu_panel").classList.add("hide")
-}
-
-// SAMIZDAT CARD
-if (view.samizdat > 0 ) {
- let samizdat_card = ui.cards[view.samizdat]
- document.getElementById("samizdat_panel").classList.remove("hide")
- document.getElementById("samizdat_card").appendChild(samizdat_card)
-} else {
- document.getElementById("samizdat_panel").classList.add("hide")
-}
-
-// UPDATE BOARD MARKERS
- ui.turn.className = `t${view.turn}`
- if (view.round_player === 'Democrat') {
- ui.round.className = `dem-action-round-tracker r${view.round}`
- } else {
- ui.round.className = `com-action-round-tracker r${view.round}`
- }
- ui.stability.className = `s${view.stability}`
- ui.dem_TST.className = `tst${view.dem_tst}`
- ui.com_TST.className = `tst${view.com_tst}`
- if (view.vp >= -20 && view.vp <= 20) {
- ui.vp.className = `vp${view.vp}`
- } else if (view.vp > 20) {
- ui.vp.className = `vp21`
- } else if (view.vp < -20) {
- ui.vp.className = `vp-21`
- }
-
-//console.log('strategy discard: ', view.strategy_discard)
-//console.log('valid spaces: ', view.valid_spaces)
-
-//console.log('view.persistent_events', view.persistent_events)
-
-// UPDATE EVENT MARKERS ON THE BOARD
-
-for (let id of board_events) {
- let marker = document.getElementById(`event_${id}`)
- //console.log('event', id, marker)
- if (view.persistent_events.includes(id)) {
- marker.style.display = 'block'
- } else {
- marker.style.display = 'none'
- }
-}
-
-
-// UPDATE EVENT MARKERS BELOW THE BOARD
-
-for (let id of box_events) {
- let marker = document.getElementById(`event_${id}`)
- //console.log('event', id, marker)
- if (view.persistent_events.includes(id)) {
- marker.style.display = 'block'
- } else {
- marker.style.display = 'none'
- }
-}
-
-
-// CHECK WHETHER ANY EVENT MARKERS ARE SHOWING IN THE EVENTS BOX
-box_events_showing = false
-for (let id of box_events) {
- if (view.persistent_events.includes(id)) {
- box_events_showing = true;
- }
-/*
- //Special check for events which are not true/false
- if (view.persistent_events['foreign_currency_debt_burden'] !== '') {
- aside_events_showing = true
- }
- if (view.persistent_events['stand_fast'] !== '') {
- aside_events_showing = true
- }
- */
-}
-
-if (box_events_showing) {
- document.getElementById('events_panel').classList.remove("hide")
-} else {
- document.getElementById('events_panel').classList.add("hide")
-}
-
-let systematization = document.getElementById('event_69')
-if (view.persistent_events.includes(69)) {
- systematization.style.left = (spaces[view.systematization].box.x +20) + 'px';
- systematization.style.top = spaces[view.systematization].box.y + 'px';
-}
-
-let tyrant = document.getElementById('event_97')
-if (view.persistent_events.includes(97)) {
- tyrant.style.left = (spaces[view.the_tyrant_is_gone].box.x - 41) + 'px';
- tyrant.style.top = (spaces[view.the_tyrant_is_gone].box.y + 23) + 'px';
-} else {tyrant.style.display = 'none'}
-
- action_button("yes", "Yes")
- action_button("no", "No")
- action_button("start", "Start")
- action_button("check", "Check held cards")
- action_button("tst_7", "Cancel opponent event")
- action_button("tst_8", "Event and operations")
- action_button("end", "End Game")
- action_button("continue", "Continue playing")
- action_button("east_germany", "East Germany")
- action_button("poland", "Poland")
- action_button("czechoslovakia", "Czechoslovakia")
- action_button("hungary", "Hungary")
- action_button("romania", "Romania")
- action_button("bulgaria", "Bulgaria")
- action_button("extra", "Take action round")
- action_button("pass", "Pass")
- action_button("remove", "Remove SPs")
- action_button("add", "Add SPs")
- action_button("ops", "Operations")
- action_button("discard", "Discard")
- action_button("strike", "Strike")
- action_button("march", "March")
- action_button("rally", "Rally in the Square")
- action_button("petition", "Petition")
- action_button("bonus", "Calculate VP bonus")
- action_button("scoring", "Score country")
- action_button("retain", "Retain Power")
- action_button("surrender", "Surrender Power")
- action_button("take", "Take Power")
- action_button("concede", "Concede")
- action_button("struggle", "Begin power struggle")
- action_button("raise", "Raise the stakes")
- action_button("draw", "Draw cards")
- action_button("scoring", "Scoring")
- action_button("event", "Event")
- action_button("opp_event", "Resolve opponent event")
- action_button("influence", "Place SPs")
- action_button("support_check", "Support Checks")
- action_button("tst", "Tiananmen Square Track")
- action_button("roll", "Roll a die")
- action_button("done", "Done")
- action_button("undo", "Undo")
-
-console.log('view.strategy_deck', view.strategy_deck)
-}
-
-// =========================== LOG FUNCTIONS ==============================================
-
-function sub_card_name(match, p1) {
- let x = p1 | 0
- return `<span class="card_name" onmouseenter="on_focus_card_tip(${x})" onmouseleave="on_blur_card_tip()">${cards[x].name}</span>`
-}
-
-function sub_power_card_name(match, p1) {
- let x = p1 | 0
- return `<span class="card_name">${power_cards[x].name}</span>`
-}
-
-function sub_power_card_value(match, p1) {
- let x = p1 | 0
- return `<span class="card_name">${x}</span>`
-}
-
-function sub_space_name(match, p1) {
- let x = p1 | 0
- let id = spaces[x].space_id
- let name = spaces[x].name_unique
- return `<span class="space_tip" onmouseenter="on_focus_space_tip(${id})" onmouseleave="on_blur_space_tip(${id})" onclick="on_click_space_tip(${id})">${name}</span>`
-}
-
-function sub_die(match) {
- return die[match] || match
-}
-
-// =========================== VISUAL FUNCTIONS ==========================================#
-
-function on_focus_card_tip(card_number) {
- document.getElementById("tooltip").className = "card card_" + card_number
-}
-
-function on_blur_card_tip() {
- document.getElementById("tooltip").classList = "card hide"
-}
-
-function on_focus_space_tip(id) {
- space = document.getElementById(`space_${id}`)
- space.classList.add("tip")
-}
-
-function on_click_space_tip(id) {
- space = document.getElementById(`space_${id}`)
- scroll_into_view(space)
-}
-
-function on_blur_space_tip(id) {
- space = document.getElementById(`space_${id}`)
- space.classList.remove("tip")
-}
-
-function toggle_pieces() {
- document.getElementById("pieces").classList.toggle("hide")
-}
-
-
-function toggle_discard() {
- if (show_discard) {
- show_discard = false
- } else {
- show_discard = true
- }
- document.getElementById("discard_panel").classList.toggle("hide")
-}
-
-function toggle_removed() {
- document.getElementById("removed_panel").classList.toggle("hide")
-}
-
-function check_dem_control(demInfl, comInfl, space) {
- if ((demInfl - comInfl) >= space.stability) {
- return true
- } else{ false}
-}
-
-function check_com_control(demInfl, comInfl, space) {
- if ((comInfl - demInfl) >= space.stability) {
- return true
- } else{ false}
-}
-
-function find_country_index(country) {
- return countries.indexOf(country)
-}
-
-create_ui()
+"use strict" + +// vim:set foldmethod=marker: + +/* global view, roles, send_action, action_button, scroll_into_view */ +/* global spaces, cards, power_cards */ + +// BEGIN CONST {{{ + +// SPACES +const S_SCHWERIN = 0 +const S_ROSTOCK = 1 +const S_BERLIN = 2 +const S_GERMAN_WRITERS = 3 +const S_WALTER_ULBRICHT_ACADEMY = 4 +const S_LUTHERAN_CHURCH = 5 +const S_MAGDEBURG = 6 +const S_HALLE = 7 +const S_LEIPZIG = 8 +const S_ERFURT = 9 +const S_KARL_MARX_STADT = 10 +const S_DRESDEN = 11 +const S_SZCZECIN = 12 +const S_GDANSK = 13 +const S_BYDGOSZCZ = 14 +const S_POZNAN = 15 +const S_WARSZAWA = 16 +const S_BIALYSTOK = 17 +const S_WROCLAW = 18 +const S_CATHOLIC_CHURCH_POLAND = 19 +const S_LODZ = 20 +const S_KATOWICE = 21 +const S_KRAKOW = 22 +const S_LUBLIN = 23 +const S_JAGIELLONIAN_UNIVERSITY = 24 +const S_POLISH_WRITERS = 25 +const S_PLZEN = 26 +const S_CESKE_BUDEJOVICE = 27 +const S_PRAHA = 28 +const S_CHARLES_UNIVERSITY = 29 +const S_CZECH_WRITERS = 30 +const S_BRNO = 31 +const S_OSTRAVA = 32 +const S_BRATISLAVA = 33 +const S_CATHOLIC_CHURCH_CZECHOSLOVAKIA = 34 +const S_PRESOV = 35 +const S_KOSICE = 36 +const S_CATHOLIC_CHURCH_HUNGARY = 37 +const S_GYOR = 38 +const S_TATABANYA = 39 +const S_MISKOLC = 40 +const S_DEBRECEN = 41 +const S_SZOMBATHELY = 42 +const S_SZEKESFEHERVAR = 43 +const S_BUDAPEST = 44 +const S_HUNGARIAN_WRITERS = 45 +const S_EOTVOS_LORAND_UNIVERSITY = 46 +const S_SZEGED = 47 +const S_PECS = 48 +const S_TIMISOARA = 49 +const S_CLUJ_NAPOCA = 50 +const S_TARGU_MURES = 51 +const S_IASI = 52 +const S_BABES_BOLYAI_UNIVERSITY = 53 +const S_ROMANIAN_WRITERS = 54 +const S_HARGHITA_COVASNA = 55 +const S_BRASOV = 56 +const S_ORTHODOX_CHURCH_ROMANIA = 57 +const S_PLOIESTI = 58 +const S_CRAIOVA = 59 +const S_BUCURESTI = 60 +const S_GALATI = 61 +const S_CONSTANTA = 62 +const S_PLEVEN = 63 +const S_ORTHODOX_CHURCH_BULGARIA = 64 +const S_RUSE = 65 +const S_SOFIA_UNIVERSITY = 66 +const S_SOFIA = 67 +const S_STARA_ZAGORA = 68 +const S_RAZGRAD = 69 +const S_BURGAS = 70 +const S_VARNA = 71 +const S_BULGARIAN_WRITERS = 72 +const S_PLOVDIV = 73 +const S_SLIVEN = 74 + +// CARDS +const C_LEGACY_OF_MARTIAL_LAW = 1 +const C_SOLIDARITY_LEGALIZED = 2 +const C_WALESA = 3 +const C_MICHNIK = 4 +const C_GENERAL_STRIKE = 5 +const C_BROUGHT_IN_FOR_QUESTIONING = 6 +const C_STATE_RUN_MEDIA = 7 +const C_PRUDENCE = 8 +const C_THE_WALL = 9 +const C_CULT_OF_PERSONALITY = 10 +const C_DISSIDENT_ARRESTED = 11 +const C_APPARATCHIKS = 12 +const C_STASI = 13 +const C_GORBACHEV_CHARMS_THE_WEST = 14 +const C_HONECKER = 15 +const C_NOMENKLATURA = 16 +const C_ROUNDTABLE_TALKS = 17 +const C_POSZGAY_DEFENDS_THE_REVOLUTION = 18 +const C_PAPAL_VISIT = 19 +const C_DEUTSCHE_MARKS = 20 +const C_COMMON_EUROPEAN_HOME = 21 +const C_POWER_STRUGGLE_POLAND = 22 +const C_POWER_STRUGGLE_HUNGARY = 23 +const C_ST_NICHOLAS_CHURCH = 24 +const C_PERESTROIKA = 25 +const C_HELSINKI_FINAL_ACT = 26 +const C_CONSUMERISM = 27 +const C_FACTORY_PARTY_CELLS = 28 +const C_JAN_PALACH_WEEK = 29 +const C_TEAR_GAS = 30 +const C_INTELLIGENTSIA = 31 +const C_PEASANT_PARTIES = 32 +const C_SAJUDIS = 33 +const C_FIDESZ = 34 +const C_HEAL_OUR_BLEEDING_WOUND = 35 +const C_DASH_FOR_THE_WEST = 36 +const C_NAGY_REBURIED = 37 +const C_THE_JULY_CONCEPT = 38 +const C_ECO_GLASNOST = 39 +const C_HUNGARIAN_DEMOCRATIC_FORUM = 40 +const C_CEAUSESCU = 41 +const C_POWER_STRUGGLE_EAST_GERMANY = 42 +const C_POWER_STRUGGLE_BULGARIA = 43 +const C_INFLATIONARY_CURRENCY = 44 +const C_SOVIET_TROOP_WITHDRAWALS = 45 +const C_GOODBYE_LENIN = 46 +const C_BULGARIAN_TURKS_EXPELLED = 47 +const C_WE_ARE_THE_PEOPLE = 48 +const C_FOREIGN_CURRENCY_DEBT_BURDEN = 49 +const C_THE_SINATRA_DOCTRINE = 50 +const C_40TH_ANNIVERSARY_CELEBRATION = 51 +const C_NORMALIZATION = 52 +const C_LI_PENG = 53 +const C_THE_CROWD_TURNS_AGAINST_CEAUSESCU = 54 +const C_POWER_STRUGGLE_CZECHOSLOVAKIA = 55 +const C_FOREIGN_TELEVISION = 56 +const C_CENTRAL_COMMITTEE_RESHUFFLE = 57 +const C_AUSTRIA_HUNGARY_BORDER_REOPENED = 58 +const C_GRENZTRUPPEN = 59 +const C_TOXIC_WASTE = 60 +const C_THE_MONDAY_DEMONSTRATIONS = 61 +const C_YAKOVLEV_COUNSELS_GORBACHEV = 62 +const C_GENSCHER = 63 +const C_LEGACY_OF_1968 = 64 +const C_PRESIDENTIAL_VISIT = 65 +const C_NEW_FORUM = 66 +const C_REFORMER_REHABILITATED = 67 +const C_KLAUS_AND_KOMAREK = 68 +const C_SYSTEMATIZATION = 69 +const C_SECURITATE = 70 +const C_KISS_OF_DEATH = 71 +const C_PEASANT_PARTIES_REVOLT = 72 +const C_LASZLO_TOKES = 73 +const C_FRG_EMBASSIES = 74 +const C_EXIT_VISAS = 75 +const C_WARSAW_PACT_SUMMIT = 76 +const C_SAMIZDAT = 77 +const C_WORKERS_REVOLT = 78 +const C_THE_THIRD_WAY = 79 +const C_NEPOTISM = 80 +const C_THE_BALTIC_WAY = 81 +const C_SPITZEL = 82 +const C_MODROW = 83 +const C_BREAKAWAY_BALTIC_REPUBLICS = 84 +const C_TANK_COLUMN_TANK_MAN = 85 +const C_THE_WALL_MUST_GO = 86 +const C_KOHL_PROPOSES_REUNIFICATION = 87 +const C_ADAMEC = 88 +const C_DOMINO_THEORY = 89 +const C_CIVIC_FORUM = 90 +const C_MY_FIRST_BANANA = 91 +const C_BETRAYAL = 92 +const C_SHOCK_THERAPY = 93 +const C_UNION_OF_DEMOCRATIC_FORCES = 94 +const C_POWER_STRUGGLE_ROMANIA = 95 +const C_THE_CHINESE_SOLUTION = 96 +const C_THE_TYRANT_IS_GONE = 97 +const C_POLITBURO_INTRIGUE = 98 +const C_LIGACHEV = 99 +const C_STAND_FAST = 100 +const C_ELENA = 101 +const C_NATIONAL_SALVATION_FRONT = 102 +const C_GOVERNMENT_RESIGNS = 103 +const C_NEW_YEARS_EVE_PARTY = 104 +const C_PUBLIC_AGAINST_VIOLENCE = 105 +const C_SOCIAL_DEMOCRATIC_PLATFORM_ADOPTED = 106 +const C_MASSACRE_IN_TIMISOARA = 107 +const C_ARMY_BACKS_REVOLUTION = 108 +const C_KREMLIN_COUP = 109 +const C_MALTA_SUMMIT = 110 + +// END CONST }}} +// BEGIN LAYOUT {{{ +var LAYOUT = { + "Babes-Bolyai University": [958,1529,127,75], + "Berlin": [329,148,127,75], + "Bialystok": [1202,436,127,76], + "Brasov": [1339,1556,127,75], + "Bratislava": [539,1013,127,76], + "Brno": [521,904,127,76], + "Bucuresti": [1186,1837,127,76], + "Budapest": [809,1249,127,76], + "Bulgarian Writers": [838,2192,127,76], + "Burgas": [1289,2152,127,76], + "Bydgoszcz": [872,388,127,76], + "Catholic Church, Czechoslovakia": [692,1010,127,75], + "Catholic Church, Hungary": [409,1126,127,76], + "Catholic Church, Poland": [802,558,127,75], + "Ceske Budejovice": [260,765,127,77], + "Charles University": [491,677,128,76], + "Cluj-Napoca": [970,1429,127,76], + "Constanta": [1443,1925,127,76], + "Craiova": [977,1793,127,76], + "Czech Writers": [573,773,127,76], + "Debrecen": [1000,1192,127,76], + "Dresden": [343,479,127,76], + "Eotvos Lorand University": [658,1314,127,76], + "Erfurt": [38,455,127,76], + "Galati": [1409,1778,127,76], + "Gdansk": [896,277,127,76], + "German Writers": [81,239,127,76], + "Gyor": [560,1129,127,76], + "Halle": [231,357,127,75], + "Harghita/Covasna": [1186,1560,127,75], + "Hungarian Writers": [452,1322,127,76], + "Iasi": [1369,1395,127,76], + "Jagiellonian University": [870,867,127,76], + "Karl-Marx-Stadt": [184,492,127,75], + "Katowice": [733,723,127,76], + "Kosice": [995,1037,127,76], + "Krakow": [911,761,127,76], + "Leipzig": [387,379,127,76], + "Lodz": [959,620,127,76], + "Lublin": [1124,754,127,76], + "Lutheran Church": [391,271,127,76], + "Magdeburg": [79,352,127,75], + "Miskolc": [851,1146,127,76], + "Orthodox Church, Bulgaria": [1130,1956,127,76], + "Orthodox Church, Romania": [1094,1700,127,76], + "Ostrava": [673,868,127,75], + "Pecs": [626,1406,127,75], + "Pleven": [979,1948,127,76], + "Ploiesti": [1356,1671,127,76], + "Plovdiv": [987,2209,127,75], + "Plzen": [211,615,127,76], + "Polish Writers": [1051,883,127,75], + "Poznan": [671,452,127,76], + "Praha": [412,782,127,75], + "Presov": [844,1010,127,75], + "Razgrad": [1219,2057,127,76], + "Romanian Writers": [947,1625,127,75], + "Rostock": [299,53,127,76], + "Ruse": [1277,1956,127,76], + "Schwerin": [148,86,127,76], + "Sliven": [1144,2251,127,75], + "Sofia": [983,2098,127,76], + "Sofia University": [828,2095,127,76], + "Stara Zagora": [1133,2153,127,75], + "Szczecin": [574,263,127,75], + "Szeged": [812,1364,127,76], + "Szekesfehervar": [571,1223,127,75], + "Szombathely": [410,1224,127,76], + "Targu Mures": [1169,1443,127,76], + "Tatabanya": [706,1126,127,75], + "Timisoara": [767,1531,127,76], + "Varna": [1387,2051,127,76], + "Walter Ulbricht Academy": [234,240,127,76], + "Warszawa": [1032,490,127,75], + "Wroclaw": [595,565,127,75], + "action_1": [708,143,48,44], + "action_8": [1080,143,47,43], + "country_bulgaria": [915,1999,46,41], + "country_czechoslovakia": [463,624,44,39], + "country_east_germany": [560,160,43,37], + "country_hungary": [1034,1319,44,39], + "country_poland": [1188,292,44,39], + "country_romania": [1287,1349,44,39], + "event_solidarity_legalized": [779,270,44,43], + "event_the_wall": [222,179,40,41], + "tst_com_1": [53,2257,47,47], + "tst_com_7": [469,2257,47,47], + "tst_com_8": [556,2257,47,47], + "tst_dem_1": [53,2128,47,47], + "tst_dem_7": [469,2128,47,47], + "tst_dem_8": [556,2128,47,47], + "turn_1": [655,81,47,48], + "turn_10": [1133,80,48,48], + "ussr_1": [1381,1080,48,48], + "ussr_2": [1381,1134,48,48], + "ussr_3": [1381,1188,48,48], + "ussr_4": [1381,1243,48,48], + "ussr_5": [1381,1297,48,48], + "vp_0": [843,2425,55,51], + "vp_1": [883,2395,55,50], + "vp_19": [1440,2395,55,50], + "vp_2": [913,2455,56,51], + "vp_20": [1471,2455,55,51], + "vp_neg_1": [803,2455,56,51], + "vp_neg_19": [246,2456,55,50], + "vp_neg_2": [772,2395,56,51], + "vp_neg_20": [215,2395,55,51], +} +// END LAYOUT }}} + +let action_register = [] + +function register_action(target, action, id) { + target.my_action = action + target.my_id = id + target.onmousedown = on_click_action + action_register.push(target) +} + +function is_action(action, arg) { + return !!(view.actions && view.actions[action] && view.actions[action].includes(arg)) +} + +function on_click_action(evt) { + if (evt.button === 0) + send_action(evt.target.my_action, evt.target.my_id) +} + +const last_space = 74 +const last_card = 110 +const last_power_card = 52 + +const board_events = [ + C_SOLIDARITY_LEGALIZED, + C_THE_WALL, + C_SYSTEMATIZATION, + C_THE_TYRANT_IS_GONE +] + +const box_events = [ + C_HONECKER, + C_ST_NICHOLAS_CHURCH, + C_HELSINKI_FINAL_ACT, + C_ECO_GLASNOST, + C_WE_ARE_THE_PEOPLE, + C_FOREIGN_CURRENCY_DEBT_BURDEN, + C_LI_PENG, + C_AUSTRIA_HUNGARY_BORDER_REOPENED, + C_GRENZTRUPPEN, + C_PRESIDENTIAL_VISIT, + C_SECURITATE, + C_LASZLO_TOKES, + C_STAND_FAST, + C_ELENA, + C_NEW_YEARS_EVE_PARTY, +] + +const ui = { + favicon: document.getElementById("favicon"), + turn_info: document.getElementById("turn_info"), + + turn: document.getElementById("marker_turn"), + round: document.getElementById("marker_action_round"), + stability: document.getElementById("marker_stability_track"), + dem_tst: document.getElementById("marker_dem_tst"), + com_tst: document.getElementById("marker_com_tst"), + vp: document.getElementById("marker_vp"), + + event_reminder_list: document.getElementById("event_reminder_list"), + + played_card: document.getElementById("played_card"), + hand: document.getElementById("hand"), + power_hand: document.getElementById("power_hand"), + power_discard: document.getElementById("power_discard"), + opp_hand: document.getElementById("opp_hand"), + securitate: document.getElementById("securitate"), + discard: document.getElementById("discard"), + removed: document.getElementById("removed"), + persistent: document.getElementById("persistent"), + + ceausescu_hand: document.getElementById("ceausescu_hand"), + samizdat_card: document.getElementById("samizdat_card"), +} + +function create_country(id, name) { + let [ x, y, w, h ] = LAYOUT[name] + let xc = Math.round(x + w / 2) + let yc = Math.round(y + h / 2) + + let e = document.createElement("div") + e.className = "marker demInfl" + e.style.left = xc - 25 + "px" + e.style.top = yc - 25 + "px" + ui.countries[id] = e + document.getElementById("markers").appendChild(e) +} + +const INF_DX = 33 +const INF_DY = 10 + +function create_ui() { + ui.layout_xy = [] + ui.spaces = [] + ui.dem_inf = [] + ui.com_inf = [] + ui.dem_inf2 = [] + ui.com_inf2 = [] + ui.dem_inf3 = [] + ui.com_inf3 = [] + + for (let s = 0; s <= last_space; ++s) { + let info = spaces[s] + let [ x, y, w, h ] = LAYOUT[info.ascii_name] + let xc = Math.round(x + w / 2) + let yc = Math.round(y + h / 2) + x -= 6 + y -= 6 + w += 12 + h += 12 + + ui.layout_xy[s] = [ xc, yc ] + + let space_e = document.createElement("div") + register_action(space_e, "space", s) + space_e.className = "space " + info.country + space_e.style.left = x + "px" + space_e.style.top = y + "px" + space_e.style.width = w + "px" + space_e.style.height = h + "px" + ui.spaces[s] = space_e + + let com_e = document.createElement("div") + com_e.className = "marker comInfl hide" + com_e.style.left = xc + 32 - 25 + "px" + com_e.style.top = yc + 12 - 25 + "px" + ui.com_inf[s] = com_e + + let com_e2 = document.createElement("div") + com_e2.className = "marker comInfl hide" + com_e2.style.left = xc + 32 - 25 + INF_DX + "px" + com_e2.style.top = yc + 12 - 25 + INF_DY + "px" + ui.com_inf2[s] = com_e2 + + let com_e3 = document.createElement("div") + com_e3.className = "marker comInfl hide" + com_e3.style.left = xc + 32 - 25 + 5 + INF_DX + "px" + com_e3.style.top = yc + 12 - 25 + 5 + INF_DY + "px" + ui.com_inf3[s] = com_e3 + + let dem_e = document.createElement("div") + dem_e.className = "marker demInfl hide" + dem_e.style.left = xc - 32 - 25 + "px" + dem_e.style.top = yc + 12 - 25 + "px" + ui.dem_inf[s] = dem_e + + let dem_e2 = document.createElement("div") + dem_e2.className = "marker demInfl hide" + dem_e2.style.left = xc - 32 - 25 - INF_DX + "px" + dem_e2.style.top = yc + 12 - 25 + INF_DY + "px" + ui.dem_inf2[s] = dem_e2 + + let dem_e3 = document.createElement("div") + dem_e3.className = "marker demInfl hide" + dem_e3.style.left = xc - 32 - 25 - 5 - INF_DX + "px" + dem_e3.style.top = yc + 12 - 25 + 5 + INF_DY + "px" + ui.dem_inf3[s] = dem_e3 + + document.getElementById("spaces").append(space_e) + document.getElementById("markers").appendChild(com_e) + document.getElementById("markers").appendChild(com_e2) + document.getElementById("markers").appendChild(com_e3) + document.getElementById("markers").appendChild(dem_e) + document.getElementById("markers").appendChild(dem_e2) + document.getElementById("markers").appendChild(dem_e3) + } + + ui.cards = [] + for (let c = 1; c <= last_card; ++c) { + const card_e = document.createElement("div") + register_action(card_e, "card", c) + card_e.className = "card event_" + c + ui.cards[c] = card_e + } + + ui.power_cards = [] + for (let c = 1; c <= last_power_card; ++c) { + const power_card_e = document.createElement("div") + register_action(power_card_e, "power_card", c) + power_card_e.className = "card power_card power_" + c + ui.power_cards[c] = power_card_e + } + ui.events = [] + for (let id of box_events) { + ui.events[id] = document.createElement("div") + ui.events[id].id = "event_" + id + ui.events[id].className = "marker event aside" + } + for (let id of board_events) { + ui.events[id] = document.createElement("div") + ui.events[id].id = "event_" + id + ui.events[id].className = "marker event" + document.getElementById("markers").appendChild(ui.events[id]) + } + + ui.countries = [] + create_country(0, "country_poland") + create_country(1, "country_hungary") + create_country(2, "country_east_germany") + create_country(3, "country_bulgaria") + create_country(4, "country_czechoslovakia") + create_country(5, "country_romania") +} + +function layout_turn_marker() { + let x = 654 + 24 + (view.turn - 1) * 53 + let y = 80 + 24 + ui.turn.style.left = x - 25 + "px" + ui.turn.style.top = y - 25 + "px" +} + +function layout_round_marker() { + let x = 709 + 24 + (view.round - 1) * 53 + let y = 142 + 24 + ui.round.style.left = x - 25 + "px" + ui.round.style.top = y - 25 + "px" + if (view.round_player === "Democrat") + // TODO: bit flag? + ui.round.className = "marker dem" + else + ui.round.className = "marker com" +} + +function layout_stability_marker() { + let x = 24 + 1381 + let y = 24 + 1081 + view.stability * 54 + ui.stability.style.left = x - 25 + "px" + ui.stability.style.top = y - 25 + "px" +} + +let TST_X = [ 0, 53, 53 + 69, 53 + 69 * 2, 53 + 69 * 3, 53 + 69 * 4, 53 + 69 * 5, 53 + 69 * 6, 556 ] +let TST_Y = [ 2128, 2257 ] + +function layout_tst_marker(e, v, top) { + let x = TST_X[v] + 24 + let y = TST_Y[top] + 24 + e.style.left = x - 25 + "px" + e.style.top = y - 25 + "px" +} + +function layout_vp_marker() { + let x, y + + if (view.vp > 21) { view.vp = 21 } + if (view.vp < -21) { view.vp = -21 } + if (view.vp === 0) { + y = 2425 + 25 + x = 843 + 28 + } else if (view.vp === -21) { + y = 2424 + 25 + x = 803 + 28 - 651 + } else if (view.vp === 21) { + y = 2424 + 25 + x = 883 + 28 + 651 + } else if (view.vp < 0) { + if (view.vp & 1) { + y = 2456 + 25 + x = 803 + 28 - ((-view.vp - 1) / 2) * 62 + } else { + y = 2395 + 25 + x = 772 + 28 - ((-view.vp - 2) / 2) * 62 + } + } else if (view.vp > 0) { + if (view.vp & 1) { + y = 2396 + 25 + x = 883 + 28 + ((view.vp - 1) / 2) * 62 + } else { + y = 2455 + 25 + x = 913 + 28 + ((view.vp - 2) / 2) * 62 + } + } + ui.vp.style.left = x - 25 + "px" + ui.vp.style.top = y - 25 + "px" +} + +function layout_country(id) { + for (let i = 0; i < 6; i++) { + // TODO: what number to display? + if (view.revolutions[id]) + ui.countries[id].className = "marker demInfl ctl v" + view.times_held[id] + else if (view.times_held[id] > 0) + ui.countries[id].className = "marker comInfl ctl v" + view.times_held[id] + else + ui.countries[id].className = "marker hide" + } +} + +function layout_inf_markers(cn, one, two, three, v, ctl) { + if (ctl) + cn += " ctl" + if (v > 16) { + one.className = cn + " v" + 8 + two.className = cn + " v" + 8 + three.className = cn + " v" + (v - 16) + } + else if (v > 8) { + one.className = cn + " v" + 8 + two.className = cn + " v" + (v - 8) + three.className = "hide" + } else if (v > 0) { + one.className = cn + " v" + v + two.className = "hide" + three.className = "hide" + } else { + one.className = "hide" + two.className = "hide" + three.className = "hide" + } +} + +function on_update() { + if (!ui.spaces) + create_ui() + + // UPDATE PLAYER INFO + + if (view.is_pwr_struggle) { + roles.Democrat.stat.textContent = `${view.democrat_power_hand} Power cards` + roles.Communist.stat.textContent = `${view.communist_power_hand} Power cards` + } else { + roles.Democrat.stat.textContent = `${view.democrat_hand} cards` + roles.Communist.stat.innerText = `${view.communist_hand} cards` + } + + ui.turn_info.innerText = `Strategy deck: ${view.strategy_deck} cards` + + // UPDATE TRACK MARKERS + + layout_turn_marker() + layout_round_marker() + layout_stability_marker() + layout_vp_marker() + layout_tst_marker(ui.dem_tst, view.dem_tst, 0) + layout_tst_marker(ui.com_tst, view.com_tst, 1) + + // UPDATE EVENT MARKERS ON THE BOARD + + if (view.persistent_events.includes(C_SOLIDARITY_LEGALIZED)) + ui.events[C_SOLIDARITY_LEGALIZED].style.display = "block" + else + ui.events[C_SOLIDARITY_LEGALIZED].style.display = "none" + + if (view.persistent_events.includes(C_THE_WALL)) + ui.events[C_THE_WALL].style.display = "block" + else + ui.events[C_THE_WALL].style.display = "none" + + if (view.persistent_events.includes(C_SYSTEMATIZATION)) { + ui.events[C_SYSTEMATIZATION].style.display = "block" + ui.events[C_SYSTEMATIZATION].style.left = ui.layout_xy[view.systematization][0] - 25 + "px" + ui.events[C_SYSTEMATIZATION].style.top = ui.layout_xy[view.systematization][1] - 25 + "px" + } else { + ui.events[C_SYSTEMATIZATION].style.display = "none" + } + + if (view.the_tyrant_is_gone) { + ui.events[C_THE_TYRANT_IS_GONE].style.display = "block" + ui.events[C_THE_TYRANT_IS_GONE].style.left = ui.layout_xy[view.the_tyrant_is_gone][0] - 25 + "px" + ui.events[C_THE_TYRANT_IS_GONE].style.top = ui.layout_xy[view.the_tyrant_is_gone][1] - 50 + "px" + } else { + ui.events[C_THE_TYRANT_IS_GONE].style.display = "none" + } + + // EVENT REMINDER LIST + + ui.event_reminder_list.replaceChildren() + for (let id of box_events) + if (view.persistent_events.includes(id)) + ui.event_reminder_list.appendChild(ui.events[id]) + + // UPDATE INFLUENCE VALUES + + for (let s = 0; s <= last_space; ++s) { + const demInfl = view.demInfl[s] + const comInfl = view.comInfl[s] + layout_inf_markers("marker demInfl", ui.dem_inf[s], ui.dem_inf2[s], ui.dem_inf3[s], demInfl, demInfl - comInfl >= spaces[s].stability) + layout_inf_markers("marker comInfl", ui.com_inf[s], ui.com_inf2[s], ui.com_inf3[s], comInfl, comInfl - demInfl >= spaces[s].stability) + } + + // UPDATE COUNTRY MARKERS + + for (let i = 0; i < 6; ++i) + layout_country(i) + + // UPDATE CARD DISPLAYS + + ui.samizdat_card.replaceChildren() + if (view.samizdat > 0) + ui.samizdat_card.appendChild(ui.cards[view.samizdat]) + + ui.hand.replaceChildren() + for (let c of view.hand) + ui.hand.appendChild(ui.cards[c]) + + ui.power_hand.replaceChildren() + if (view.power_hand) + for (let c of view.power_hand) + ui.power_hand.appendChild(ui.power_cards[c]) + + ui.power_discard.replaceChildren() + if (view.power_struggle_discard) + for (let c of view.power_struggle_discard) + ui.power_discard.appendChild(ui.power_cards[c]) + + ui.opp_hand.replaceChildren() + if (view.opp_hand) + for (let c of view.opp_hand) + ui.opp_hand.appendChild(ui.cards[c]) + + ui.securitate.replaceChildren() + if (view.opp_power_hand) + for (let c of view.opp_power_hand) + ui.securitate.appendChild(ui.power_cards[c]) + + ui.ceausescu_hand.replaceChildren() + if (view.ceausescu_cards) + for (let c of view.ceausescu_cards) + ui.ceausescu_hand.appendChild(ui.power_cards[c]) + + ui.discard.replaceChildren() + for (let c of view.strategy_discard) + ui.discard.appendChild(ui.cards[c]) + if (view.discard) + document.getElementById("discard_panel").classList.remove("hide") + else + document.getElementById("discard_panel").classList.add("hide") + + ui.removed.replaceChildren() + for (let c of view.strategy_removed) + ui.removed.appendChild(ui.cards[c]) + + ui.persistent.replaceChildren() + for (let c of view.persistent_events) + if (c < 111) + ui.persistent.appendChild(ui.cards[c]) + + ui.played_card.replaceChildren() + if (view.played_card > 0) + ui.played_card.appendChild(ui.cards[view.played_card]) + if (view.power_card_1 > 0) + ui.played_card.appendChild(ui.power_cards[view.power_card_1]) + if (view.power_card_2 > 0) + ui.played_card.appendChild(ui.power_cards[view.power_card_2]) + + for (let e of action_register) + e.classList.toggle("action", is_action(e.my_action, e.my_id)) + + for (let s = 0; s <= last_space; ++s) + ui.spaces[s].classList.toggle("selected", view.selected_space === s) + + action_button("yes", "Yes") + action_button("no", "No") + action_button("start", "Start") + action_button("check", "Check held cards") + action_button("tst_7", "Cancel opponent event") + action_button("tst_8", "Event and operations") + action_button("end", "End Game") + action_button("continue", "Continue playing") + action_button("east_germany", "East Germany") + action_button("poland", "Poland") + action_button("czechoslovakia", "Czechoslovakia") + action_button("hungary", "Hungary") + action_button("romania", "Romania") + action_button("bulgaria", "Bulgaria") + action_button("extra", "Take action round") + action_button("pass", "Pass") + action_button("remove", "Remove SPs") + action_button("add", "Add SPs") + action_button("ops", "Operations") + action_button("discard", "Discard") + action_button("strike", "Strike") + action_button("march", "March") + action_button("rally", "Rally in the Square") + action_button("petition", "Petition") + action_button("bonus", "Calculate VP bonus") + action_button("scoring", "Score country") + action_button("surrender", "Surrender Power") + action_button("retain", "Retain Power") + action_button("take", "Take Power") + action_button("concede", "Concede") + action_button("struggle", "Begin power struggle") + action_button("raise", "Raise the stakes") + action_button("draw", "Draw") + action_button("scoring", "Scoring") + action_button("event", "Event") + action_button("opp_event", "Resolve opponent event") + action_button("influence", "Place SPs") + action_button("support_check", "Support Checks") + action_button("tst", "Tiananmen Square Track") + action_button("roll", "Roll a die") + action_button("done", "Done") + action_button("end_round", "End Round") + action_button("undo", "Undo") +} + +// =========================== LOG FUNCTIONS ============================================== + +function sub_card_name(_match, p1) { + let x = p1 | 0 + return `<span class="card_name" onmouseenter="on_focus_card_tip(${x})" onmouseleave="on_blur_card_tip()">${cards[x].name.replace("*", "")}</span>` +} + +function sub_power_card_name(_match, p1) { + let x = p1 | 0 + return `<span class="card_name" onmouseenter="on_focus_power_card_tip(${x})" onmouseleave="on_blur_power_card_tip()">${power_cards[x].name}</span>` +} + +function sub_power_card_value(_match, p1) { + let x = p1 | 0 + return `<span class="card_name">${x}</span>` +} + +function sub_space_name(_match, p1) { + let id = p1 | 0 + let name = spaces[id].name_unique + return `<span class="space_tip" onmouseenter="on_focus_space_tip(${id})" onmouseleave="on_blur_space_tip(${id})" onclick="on_click_space_tip(${id})">${name}</span>` +} + +function sub_die(match) { + return die[match] || match +} + +const die = { + D1: '<span class="die white d1"></span>', + D2: '<span class="die white d2"></span>', + D3: '<span class="die white d3"></span>', + D4: '<span class="die white d4"></span>', + D5: '<span class="die white d5"></span>', + D6: '<span class="die white d6"></span>', +} + +function on_log(text) { + let p = document.createElement("div") + + if (text.match(/^>/)) { + text = text.substring(1) + p.className = "i" + } + + text = text.replace(/_/g, " ") + text = text.replace(/C(\d+)/g, sub_card_name) + text = text.replace(/P(\d+)/g, sub_power_card_name) + text = text.replace(/V(\d+)/g, sub_power_card_value) + text = text.replace(/%(\d+)/g, sub_space_name) + text = text.replace(/D[1-6]/g, sub_die) + + if (text.match(/^\.h1/)) { + text = text.substring(4) + p.className = "h1" + } else if (text.match(/^\.h2d/)) { + text = text.substring(5) + p.className = "h2 dem" + } else if (text.match(/^\.h2c/)) { + text = text.substring(5) + p.className = "h2 com" + } else if (text.match(/^\.h2/)) { + text = text.substring(4) + p.className = "h2" + } else if (text.match(/^\.h3/)) { + text = text.substring(4) + p.className = "h3" + } + + p.innerHTML = text + return p +} + +// =========================== VISUAL FUNCTIONS ==========================================# + +function on_focus_card_tip(card_number) { + document.getElementById("tooltip").className = "card event_" + card_number +} + +function on_blur_card_tip() { + document.getElementById("tooltip").classList = "card hide" +} + +function on_focus_power_card_tip(card_number) { + document.getElementById("tooltip").className = "card power_" + card_number +} + +function on_blur_power_card_tip() { + document.getElementById("tooltip").classList = "card hide" +} + +function on_focus_space_tip(id) { + ui.spaces[id].classList.add("tip") +} + +function on_blur_space_tip(id) { + ui.spaces[id].classList.remove("tip") +} + +function on_click_space_tip(id) { + scroll_into_view(ui.spaces[id]) +} + +function toggle_discard() { + document.getElementById("discard_panel").classList.toggle("hide") +} + +function toggle_removed() { + document.getElementById("removed_panel").classList.toggle("hide") +} |