summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--play.js213
1 files changed, 153 insertions, 60 deletions
diff --git a/play.js b/play.js
index c21d880..7ecdbd2 100644
--- a/play.js
+++ b/play.js
@@ -1,43 +1,17 @@
+
const seed = 'none'
const scenario = 'standard'
const options = 'none'
//const rules = require("./rules")
const last_card = 110
+const last_power_card = 52
-const stability=0
-const US_tiananmen=0
-const USSR_tiananmen=0
const toolbar = document.getElementById('toolbar')
const vpMarker = document.getElementById('vp')
const mapContainer = document.querySelector('.map')
-let handActive=0
-let doInfl=0
-let doSupportCheck=0
-let demTSTPos=0
-let comTSTPos=0
-let demTSTPrev=0
-let comTSTPrev=0
-let turn=1
-let actionRound=1
-let supportCheckTargetName=''
-let supportCheckTargetCountry=0
-let vp = 0
-let germanyRevolution=0
-let polandRevolution=0
-let czechRevolution=0
-let hungaryRevolution=0
-let romaniaRevolution=0
-let buglariaRevolution=0
-let germanyHeld=0
-let polandHeld=0
-let czechHeld=0
-let hungaryHeld=0
-let romaniaHeld=0
-let bulgariaHeld=0
-
-
-const countryNames= [
+
+const countries= [
null,
"East Germany",
"Poland",
@@ -72,7 +46,7 @@ const spaceCharacteristicsElement = document.getElementById('space-characteristi
const { x, y, h, w } = space.box;
const spaceArea = document.createElement('div');
spaceArea.classList.add('space-area', space.country)
- spaceArea.id=space.name_unique;
+ spaceArea.id=`space_${space.space_id}`;
spaceArea.style.left = x + 'px';
spaceArea.style.top = y + 'px';
spaceArea.style.width = w + 'px';
@@ -94,6 +68,8 @@ const spaceCharacteristicsElement = document.getElementById('space-characteristi
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)
const demInflValue = document.createElement('p')
@@ -102,6 +78,8 @@ const spaceCharacteristicsElement = document.getElementById('space-characteristi
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)
//}
@@ -117,6 +95,8 @@ const spaceCharacteristicsElement = document.getElementById('space-characteristi
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)
const comInflValue = document.createElement('p')
@@ -125,6 +105,8 @@ const spaceCharacteristicsElement = document.getElementById('space-characteristi
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)
//}
@@ -137,44 +119,58 @@ const spaceCharacteristicsElement = document.getElementById('space-characteristi
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('mousedown', on_click_card);
- ui.cards.push(hand_card);
+ 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('mousedown', on_click_card);
+ ui.cards.push(hand_card);
+ }
+ //for (let card of power_cards)
+ 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);
}
-
}
function on_click_space(evt) {
if (evt.button === 0) {
const space = evt.target.my_space;
- console.log('on_click_space_called with space:', space);
+ //console.log('on_click_space_called with space:', space);
if (send_action('infl', space)) {
- evt.stopPropagation();
- } else {
- console.log('send_action failed for space:', 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) {
+ //console.log('on_click_card')
if (evt.button === 0) {
const card = evt.target.my_card;
- console.log('on_click_card_called with card:', card);
+ // console.log('on_click_card_called with card:', card);
if (send_action('card', card)) {
evt.stopPropagation();
} else {
- console.log('send_action failed for card:', card);
+ // console.log('send_action failed for card:', card);
}
}
}
function is_action(action) {
- console.log('is_action called with: ', action)
+ //console.log('is_action called with: ', action)
if (view.actions && view.actions[action])
return true
return false
@@ -221,6 +217,9 @@ let ui = {
document.getElementById("role_Communist"),
],
cards: [ null ],
+ power_cards: [],
+ dem_hand_count: document.getElementById("role_stat_dem"),
+ com_hand_count: document.getElementById("role_stat_com"),
played_card: 0,
events_panel: document.getElementById("events_panel"),
hand_panel: document.getElementById("hand_panel"),
@@ -235,10 +234,20 @@ let ui = {
}
function on_update() {
- console.log('on_update called')
- console.log('view.valid_spaces: ', view.valid_spaces)
- console.log('ui.spaces: ', ui.spaces)
+ //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
const pieces = view.pieces
@@ -283,13 +292,32 @@ function on_update() {
});
+// UPDATE COUNTRY MARKERS
+ for (let i = 1; i < countries.length; i++) {
+ const country = countries[i];
+ const marker = document.getElementById(country);
+
+ if (view.revolutions[country]) {
+ marker.classList.add('revolution')
+ marker.style.display = 'block'
+ } else if (view.times_held[country] > 0 ) {
+ marker.classList.add('held')
+ marker.style.display = 'block'
+ }
+ else {marker.style.display = 'none'}
+ }
+
+// UPDATE ASIDE
+
+ ui.dem_hand_count.innerText = `${view.democrat_hand} cards in hand`
+ ui.com_hand_count.innerText = `${view.communist_hand} cards in hand`
// UPDATE HAND
document.getElementById("hand").replaceChildren()
document.getElementById("events").replaceChildren()
-
- if (view.hand.length) {
+
+ if (view.hand.length && view.is_pwr_struggle === false) {
document.getElementById("hand_panel").classList.remove("hide")
for (let c of view.hand) {
//const cardElement = ui.cards[c];
@@ -311,26 +339,91 @@ function on_update() {
document.getElementById("events_panel").classList.add("hide")
}
-// UPDATE BOARD MARKERS
- ui.turn.className = `t${view.turn}`
- ui.round.className = `dem-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}`
- ui.vp.className = `vp${view.vp}`
+// POWER STRUGGLE HAND
+ document.getElementById("power_hand").replaceChildren()
+ if (view.is_pwr_struggle) {
+ document.getElementById("power_panel").classList.remove("hide")
+ //console.log('ui.power_cards: ', ui.power_cards)
+ //console.log('ui.cards: ', ui.cards)
+const power_hand = document.getElementById("power_hand");
+if (!power_hand) {
+ console.error("Element with id 'power_hand' not found.");
+} else {
+ //console.log('view.power_hand: ', view.power_hand)
+ //console.log('view.hand:', view.hand)
+ //console.log('view.valid_cards: ', view.valid_cards)
+ for (let card_number of view.power_hand) {
+ const power_card = ui.power_cards.find(card => card.my_card === card_number);
+ if (power_card instanceof Node) {
+ //console.log(`Checking card number: ${card_number}`)
+ //console.log(`Is card number ${card_number} valid? ${view.valid_cards.includes(card_number)}`);
+ const cardInfo = power_cards.find(card => card.number === card_number);
- action_button("done", "Done")
- action_button("undo", "Undo")
+ if (cardInfo) {
+ //console.log(`Card info for number ${card_number}:`, cardInfo);
+ // console.log(`Socio value for card ${card_number}: ${cardInfo.socio}`);
+ }
+ if (view.valid_cards.includes(card_number)) {
+ power_card.classList.add('selected');
+ }
+ power_hand.appendChild(power_card);
+ } else {
+ // console.error(`ui.power_cards[${index-1}] is not a valid DOM node.`);
+ }
+ }
+}
+ } else {
+ //console.log('document.getElementById("power_panel"): ', document.getElementById("power_panel"))
+ document.getElementById("power_panel").classList.add("hide")
+ }
+
+// UPDATE BOARD MARKERS
+ ui.turn.className = `t${view.turn}`
+ //console.log('view.round_player: ', view.round_player)
+ if (view.round_player === 'Democrat') {
+ //console.log('in democrat')
+ ui.round.className = `dem-action-round-tracker r${view.round}`
+ } else {
+ //console.log('in communist')
+ ui.round.className = `com-action-round-tracker r${view.round}`
+ }
+ ui.stability.className = `s${view.stability}`
+ ui.dem_TST.className = `tst${view.dem_tst}`
+ //console.log('view.com_tst: ', view.com_tst)
+ ui.com_TST.className = `tst${view.com_tst}`
+ ui.vp.className = `vp${view.vp}`
+
+console.log('strategy discard: ', view.strategy_discard)
+console.log('valid spaces: ', view.valid_spaces)
+
+//console.log('view.pieces: ', view.pieces)
+
+
+ action_button("strike", "Strike")
+ action_button("march", "March")
+ action_button("rally", "Rally in the Square")
+ action_button("petition", "Petition")
+ 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 cards")
+ action_button("scoring", "Scoring")
action_button("event", "Event")
action_button("influence", "Influence")
action_button("tst", "Tiananmen Square Track")
action_button("support_check", "Support Check")
-
+ action_button("roll", "Roll a die")
+ action_button("done", "Done")
+ action_button("undo", "Undo")
}