From 69122f338270f015ef12fc5ab08858431248fcc9 Mon Sep 17 00:00:00 2001 From: iainp5 Date: Mon, 1 Jul 2024 22:03:07 +0100 Subject: Feat: actions working --- play.js | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 81 insertions(+), 17 deletions(-) (limited to 'play.js') diff --git a/play.js b/play.js index 6cdb209..42c5d40 100644 --- a/play.js +++ b/play.js @@ -3,6 +3,8 @@ const scenario = 'standard' const options = 'none' //const rules = require("./rules") +const dem_infl_markers = [] + const stability=0 const US_tiananmen=0 const USSR_tiananmen=0 @@ -12,7 +14,6 @@ const mapContainer = document.querySelector('.map') let handActive=0 let doInfl=0 let doSupportCheck=0 -let availableOps=0 let demTSTPos=0 let comTSTPos=0 let demTSTPrev=0 @@ -60,25 +61,23 @@ const spaceCharacteristicsElement = document.getElementById('space-characteristi }) -// Call game setup material - -// const game = rules.setup(seed, scenario, options) - // Create map areas dynamically based on coordinates -function createMap() { + function create_map() { spaces.forEach((space) => { if (space && space.box) { const { x, y, h, w } = space.box; const spaceArea = document.createElement('div'); spaceArea.classList.add('space-area', space.country) - spaceArea.id=space.name; + spaceArea.id=space.name_unique; spaceArea.style.left = x + 'px'; spaceArea.style.top = y + 'px'; spaceArea.style.width = w + 'px'; spaceArea.style.height = h + 'px'; - //spaceArea.addEventListener('click', changeInfl) + spaceArea.style.zIndex = 2; + spaceArea.my_space = space.name_unique; + spaceArea.addEventListener('mousedown', on_click_space); //spaceArea.addEventListener('click', finishSupportCheck) /*if (space.demInfl > 0 && space.demInfl - space.comInfl >= space.stability) { @@ -90,14 +89,18 @@ function createMap() { } else if (space.demInfl > 0) {*/ const dem_img = document.createElement('img') dem_img.classList.add('demInfl', space.country) - dem_img.id=space.name + dem_img.style.display = 'none' + dem_img.id=`${space.name_unique}_demInfl` dem_img.src = `images/USd_blank.gif` + dem_img.style.zIndex = 1 spaceArea.appendChild(dem_img) const demInflValue = document.createElement('p') demInflValue.className='demInflValue' - demInflValue.id=space.name + demInflValue.style.display = 'none' + demInflValue.id=`${space.name_unique}_demInflValue` demInflValue.innerText=space.demInfl + demInflValue.style.zIndex = 1 spaceArea.appendChild(demInflValue) //} @@ -110,14 +113,18 @@ function createMap() { } else if (space.comInfl > 0) {*/ const com_img = document.createElement('img') com_img.className='comInfl' - com_img.id=space.name + com_img.style.display='none' + com_img.id=`${space.name_unique}_comInfl` com_img.src = `images/SVd_blank.gif` + com_img.style.zIndex = 1 spaceArea.appendChild(com_img) const comInflValue = document.createElement('p') comInflValue.className='comInflValue' - comInflValue.id=space.name + comInflValue.style.display='none' + comInflValue.id=`${space.name_unique}_comInflValue` comInflValue.innerText=space.comInfl + comInflValue.style.zIndex = 1 spaceArea.appendChild(comInflValue) //} @@ -126,10 +133,36 @@ function createMap() { }); } + +create_map() + //setup() -createMap() + console.log('Hello') -console.log('game:',game) + +//function changeInfl() {} +//function finishSupportCheck() {} + +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 { + console.log('send_action failed for space:', space); + } + } + //hide_popup_menu(); +} + +function is_action(action) { + console.log('is_action called with: ', action) + if (view.actions && view.actions[action]) + return true + return false +} + let ui = { @@ -143,8 +176,39 @@ let ui = { hand_panel: document.getElementById("hand_panel"), } -console.log('strategy deck', game.strategy_deck) -//function changeInfl() {} -//function finishSupportCheck() {} +function on_update() { + console.log('on_update called') + console.log('view.actions: ', view.actions) + + //Check influence values + const pieces = view.pieces + pieces.forEach(piece => { + const dem_marker = document.getElementById(`${piece.name_unique}_demInfl`); + const dem_number = document.getElementById(`${piece.name_unique}_demInflValue`); + const com_marker = document.getElementById(`${piece.name_unique}_comInfl`); + const com_number = document.getElementById(`${piece.name_unique}_comInflValue`); + + dem_number.innerText=piece.demInfl + if (piece.demInfl > 0) { + dem_marker.style.display = 'block'; + dem_number.style.display = 'block'; + } else { + dem_marker.style.display = 'none'; + dem_number.style.display = 'none'; + } + com_number.innerText=piece.comInfl + if (piece.comInfl > 0) { + com_marker.style.display = 'block'; + com_number.style.display = 'block'; + } else { + com_marker.style.display = 'none'; + com_number.style.display = 'none'; + } + + }); + + action_button("done", "Done") + action_button("undo", "Undo") +} -- cgit v1.2.3