From 1f47dc63b4aaf7f52334d702ae2de8dc69fcf2ee Mon Sep 17 00:00:00 2001 From: iainp5 Date: Sun, 29 Sep 2024 13:38:09 +0100 Subject: Carry changes to play.js --- play.js | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'play.js') diff --git a/play.js b/play.js index e2a5dc8..3c0e71d 100644 --- a/play.js +++ b/play.js @@ -299,10 +299,13 @@ function on_update() { }); //Check influence values - const pieces = view.pieces - pieces.forEach((piece, index) => { - if (!piece) return - const space = spaces[index] + //const pieces = view.pieces + + for (let i = 1; 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`); @@ -311,11 +314,11 @@ function on_update() { const com_number = document.getElementById(`${space.name_unique}_comInflValue`); dem_number.innerText=piece.demInfl - if (piece.demInfl > 0) { + if (demInfl > 0) { dem_marker.style.display = 'block'; dem_number.style.display = 'block'; - if(check_dem_control(piece, space)){ + if(check_dem_control(demInfl, comInfl, space)){ dem_marker.classList.add('controlled') dem_number.classList.add('outlined_text') dem_marker.classList.remove('uncontrolled') @@ -329,11 +332,11 @@ function on_update() { dem_number.style.display = 'none'; } com_number.innerText=piece.comInfl - if (piece.comInfl > 0) { + if (comInfl > 0) { com_marker.style.display = 'block'; com_number.style.display = 'block'; - if(check_com_control(piece, space)){ + if(check_com_control(demInfl, comInfl, space)){ com_marker.classList.add('controlled') com_number.classList.add('controlled') com_marker.classList.remove('uncontrolled') @@ -349,7 +352,7 @@ function on_update() { com_number.style.display = 'none'; } - }); + } // UPDATE COUNTRY MARKERS for (let i = 1; i < countries.length; i++) { @@ -688,14 +691,14 @@ function toggle_discard() { document.getElementById("discard_panel").classList.toggle("hide") } -function check_dem_control(piece, space) { - if ((piece.demInfl - piece.comInfl) >= space.stability) { +function check_dem_control(demInfl, comInfl, space) { + if ((demInfl - comInfl) >= space.stability) { return true } else{ false} } -function check_com_control(piece, space) { - if ((piece.comInfl - piece.demInfl) >= space.stability) { +function check_com_control(demInfl, comInfl, space) { + if ((comInfl - demInfl) >= space.stability) { return true } else{ false} } -- cgit v1.2.3