summaryrefslogtreecommitdiff
path: root/play.js
diff options
context:
space:
mode:
authoriainp5 <iain.pearce.ip@gmail.com>2024-09-26 15:24:14 +0100
committeriainp5 <iain.pearce.ip@gmail.com>2024-09-26 15:24:14 +0100
commit9ca8a214ab0bc45fb295a2da44dfb5deefe6300b (patch)
treefbe581f8f41ca2ead010b44cb91b7ec4095dfdca /play.js
parentc0b373f5e05dbc64c81c1be9be86d167207a5366 (diff)
download1989-dawn-of-freedom-9ca8a214ab0bc45fb295a2da44dfb5deefe6300b.tar.gz
Removed var from game.pieces
Diffstat (limited to 'play.js')
-rw-r--r--play.js48
1 files changed, 25 insertions, 23 deletions
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()