diff options
author | Frans Bongers <fransbongers@franss-mbp.home> | 2024-11-28 22:36:10 +0100 |
---|---|---|
committer | Frans Bongers <fransbongers@franss-mbp.home> | 2024-11-28 22:36:10 +0100 |
commit | 629206f773d5fd4c9247db03e3a705c4dcdc77c4 (patch) | |
tree | 692b809c4bfc01a452b3ae110310a9103a720b44 /play.ts | |
parent | 9414fe91218a00fe9e44b48fdf40e51de5cb4479 (diff) | |
download | land-and-freedom-629206f773d5fd4c9247db03e3a705c4dcdc77c4.tar.gz |
setup game engine
Diffstat (limited to 'play.ts')
-rw-r--r-- | play.ts | 84 |
1 files changed, 67 insertions, 17 deletions
@@ -63,38 +63,40 @@ 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: HTMLElement, - _action: string, - _id: string | number + e: HTMLElement & {my_action?: string; my_id?: string | number}, + action: string, + id: string | number ) { - // e.my_action = action - // e.my_id = 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; @@ -128,6 +130,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); @@ -139,6 +142,8 @@ 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 @@ -165,7 +170,7 @@ 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'; } @@ -174,9 +179,54 @@ function on_update() { 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, "&") + text = text.replace(/</g, "<") + text = text.replace(/>/g, ">") + // 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 +}
\ No newline at end of file |