diff options
Diffstat (limited to 'play.js')
-rw-r--r-- | play.js | 71 |
1 files changed, 56 insertions, 15 deletions
@@ -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, "&"); + 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; } |