From 9ca8a214ab0bc45fb295a2da44dfb5deefe6300b Mon Sep 17 00:00:00 2001 From: iainp5 Date: Thu, 26 Sep 2024 15:24:14 +0100 Subject: Removed var from game.pieces --- play.js | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) (limited to 'play.js') diff --git a/play.js b/play.js index 647be0f..a5cd60a 100644 --- a/play.js +++ b/play.js @@ -200,20 +200,9 @@ function is_action(action) { function on_log(text) { // eslint-disable-line no-unused-vars + console.log('on_log called') let p = document.createElement("div") -//Check if adding influence the the same place as the previous influence - - //let last_log_entry = document.getElementById("log").lastElementChild - console.log('view.log', view.log) - let last_log_entry = document.querySelector(`#log div:nth-child(${view.log.length-1})`) - let last_log_entry_text - console.log('last_log_entry', last_log_entry) - if (last_log_entry) { - last_log_entry_text = last_log_entry.innerHTML - console.log('last_log_entry_text', last_log_entry_text) - } - /* let last_text = last_log_entry ? last_log_entry.split(' ') : [] @@ -259,12 +248,12 @@ function on_log(text) { // eslint-disable-line no-unused-vars } //console.log('view.log', view.log) - console.log('new text', text) + /*console.log('new text', text) if (last_log_entry_text) { console.log('log = text', last_log_entry_text === text) } - +*/ p.innerHTML = text return p } @@ -310,19 +299,22 @@ function on_update() { //Check influence values const pieces = view.pieces - pieces.forEach(piece => { + pieces.forEach((piece, index) => { if (!piece) return - 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`); + const space = spaces[index] + //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=piece.demInfl if (piece.demInfl > 0) { dem_marker.style.display = 'block'; dem_number.style.display = 'block'; - - if(piece.demCtrl === 1){ + console.log('piece', piece, 'space', space) + if(check_dem_control(piece, space)){ dem_marker.classList.add('controlled') dem_number.classList.add('outlined_text') dem_marker.classList.remove('uncontrolled') @@ -340,7 +332,7 @@ function on_update() { com_marker.style.display = 'block'; com_number.style.display = 'block'; - if(piece.comCtrl === 1){ + if(check_com_control(piece, space)){ com_marker.classList.add('controlled') com_number.classList.add('controlled') com_marker.classList.remove('uncontrolled') @@ -625,7 +617,6 @@ if (view.persistent_events['the_tyrant_is_gone'] > 0) { action_button("done", "Done") action_button("undo", "Undo") - //console.log('view.log', view.log) } @@ -696,5 +687,16 @@ function toggle_discard() { document.getElementById("discard_panel").classList.toggle("hide") } +function check_dem_control(piece, space) { + if ((piece.demInfl - piece.comInfl) >= space.stability) { + return true + } else{ false} +} + +function check_com_control(piece, space) { + if ((piece.comInfl - piece.demInfl) >= space.stability) { + return true + } else{ false} +} create_ui() -- cgit v1.2.3