summaryrefslogtreecommitdiff
path: root/play.js
diff options
context:
space:
mode:
authorFrans Bongers <fransbongers@franss-mbp.home>2024-11-28 22:36:10 +0100
committerFrans Bongers <fransbongers@franss-mbp.home>2024-11-28 22:36:10 +0100
commit629206f773d5fd4c9247db03e3a705c4dcdc77c4 (patch)
tree692b809c4bfc01a452b3ae110310a9103a720b44 /play.js
parent9414fe91218a00fe9e44b48fdf40e51de5cb4479 (diff)
downloadland-and-freedom-629206f773d5fd4c9247db03e3a705c4dcdc77c4.tar.gz
setup game engine
Diffstat (limited to 'play.js')
-rw-r--r--play.js71
1 files changed, 56 insertions, 15 deletions
diff --git a/play.js b/play.js
index af1eccb..9c1b6f2 100644
--- a/play.js
+++ b/play.js
@@ -46,30 +46,30 @@ const LAYOUT_TRACKS = [
spaces.appendChild(element);
const frontValueElement = (ui.frontValues[front.id] = document.createElement('span'));
frontValueElement.classList.add('value');
+ register_action(element, 'front', id);
element.appendChild(frontValueElement);
});
})();
console.log('ui', ui);
-// @ts-ignore
-function register_action(e, _action, _id) {
- // e.my_action = action
- // e.my_id = id
+function register_action(e, action, id) {
+ e.my_action = action;
+ e.my_id = id;
e.onmousedown = on_click_action;
action_register.push(e);
}
function on_click_action(evt) {
+ console.log('on_click_action', evt);
if (evt.button === 0)
if (send_action(evt.target.my_action, evt.target.my_id))
evt.stopPropagation();
}
-// function is_action(action, arg) {
-// if (arg === undefined) return !!(view.actions && view.actions[action] === 1);
-// return !!(
-// view.actions &&
-// view.actions[action] &&
-// view.actions[action].includes(arg)
-// );
-// }
+function is_action(action, arg) {
+ if (arg === undefined)
+ return !!(view.actions && view.actions[action] === 1);
+ return !!(view.actions &&
+ view.actions[action] &&
+ view.actions[action].includes(arg));
+}
let on_init_once = false;
function on_init() {
console.log('on_init');
@@ -97,6 +97,7 @@ function on_init() {
e.className = 'standee';
e.setAttribute('data-standee-id', '' + s);
register_action(e, 'standee', s);
+ ui.tracks.appendChild(ui.standees[s]);
}
console.log('standees', ui.standees);
// create card elements
@@ -106,6 +107,7 @@ function on_init() {
e.setAttribute('data-card-id', '' + data.cards[c].id);
register_action(e, 'card', c);
}
+ console.log('action_register', action_register[0]);
}
// @ts-ignore
function on_update() {
@@ -128,15 +130,54 @@ function on_update() {
for (let c of view.hand)
ui.hand.appendChild(ui.cards[c]);
for (let i = 0; i < view.tracks.length; i++) {
- ui.tracks.appendChild(ui.standees[i]);
+ // ui.tracks.appendChild(ui.standees[i]);
ui.standees[i].style.left = LAYOUT_TRACKS[i][view.tracks[i]][0] + 'px';
ui.standees[i].style.top = LAYOUT_TRACKS[i][view.tracks[i]][1] + 'px';
}
for (let frontId of Object.keys(view.fronts)) {
ui.frontValues[frontId].replaceChildren(view.fronts[frontId]);
}
- // for (let e of action_register)
- // e.classList.toggle('action', is_action(e.my_action, e.my_id));
+ for (let e of action_register)
+ e.classList.toggle('action', is_action(e.my_action, e.my_id));
action_button('next', 'Next');
action_button('undo', 'Undo');
+ action_button('add_glory', 'Add Glory');
+}
+// @ts-ignore
+function on_log(text) {
+ let p = document.createElement("div");
+ if (text.match(/^>/)) {
+ text = text.substring(1);
+ p.className = 'i';
+ }
+ text = text.replace(/&/g, "&amp;");
+ text = text.replace(/</g, "&lt;");
+ text = text.replace(/>/g, "&gt;");
+ // text = text.replace(/C(\d+)/g, sub_card_name)
+ // text = text.replace(/S(\d+)/g, sub_space_name)
+ // text = text.replace(/U(\d+)/g, sub_unit_name)
+ // TODO dice icons
+ // text = text.replace(/\bD\d\b/g, sub_icon)
+ if (text.match(/^\.h1/)) {
+ text = text.substring(4);
+ p.className = 'h1';
+ }
+ else if (text.match(/^\.h2/)) {
+ text = text.substring(4);
+ p.className = 'h2';
+ }
+ else if (text.match(/^\.h3\.allies/)) {
+ text = text.substring(10);
+ p.className = 'h3 allies';
+ }
+ else if (text.match(/^\.h3\.germans/)) {
+ text = text.substring(11);
+ p.className = 'h3 germans';
+ }
+ else if (text.match(/^\.h3/)) {
+ text = text.substring(4);
+ p.className = 'h3';
+ }
+ p.innerHTML = text;
+ return p;
}