Skip to content

Commit

Permalink
key events for ubg
Browse files Browse the repository at this point in the history
SQUASHED: AUTO-COMMIT-src-components-widgets-ubg-card.js,AUTO-COMMIT-src-components-widgets-ubg-cards-editor.html,AUTO-COMMIT-src-components-widgets-ubg-cards-editor.js,AUTO-COMMIT-src-components-widgets-ubg-cards-editor.js.l4a,AUTO-COMMIT-src-components-widgets-ubg-cards-entry.js,AUTO-COMMIT-src-components-widgets-ubg-cards.html,AUTO-COMMIT-src-components-widgets-ubg-cards.js,
  • Loading branch information
onsetsu committed Oct 11, 2024
1 parent 2b871df commit c365807
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 28 deletions.
24 changes: 17 additions & 7 deletions src/components/widgets/ubg-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,11 @@ ${SVG.elementSymbol(others[2], lively.pt(12.5, 8.5), 1.5)}`, lively.rect(0, 0, 1
},

cycling: (cost, who) => {
if (['acard', 'one', 'all'].includes(cost)) {
who = cost
cost = undefined
}

let whoToPrint = 'this'
if (who === 'acard') {
whoToPrint = 'a card'
Expand All @@ -821,9 +826,9 @@ ${SVG.elementSymbol(others[2], lively.pt(12.5, 8.5), 1.5)}`, lively.rect(0, 0, 1
}

if (cost) {
return `gear Pay (${cost}) and trash ${whoToPrint} to play a card of equal or lower cost.`
return `gear Pay (${cost}) and sacrifice ${whoToPrint} to play a card of equal or lower cost.`
}
return `gear Trash ${whoToPrint} to play a card of equal or lower cost.`
return `gear Sacrifice ${whoToPrint} to play a card of equal or lower cost.`
},

dash: (cost, who) => {
Expand Down Expand Up @@ -885,25 +890,29 @@ ${SVG.elementSymbol(others[2], lively.pt(12.5, 8.5), 1.5)}`, lively.rect(0, 0, 1
if (who === 'one') {
subject = 'the card';
}
return `gear Trash ${subject} to exec its blitz effects.`
return `gear Sacrifice ${subject} to exec its blitz effects.`
},

impulse: () => {
return `To impulse a card, set it aside. You may buy it this turn as gear. If you don't: Trash it at end of turn.`
},

instant: () => {
return 'You may buy this as a free action.'
return 'gear Buy this.'
},

invoke: () => {
return 'You may trash this from hand or field to exec the effect.'
return 'gear Discard or sacrifice this to exec the effect.'
},

manaburst: () => {
return 'Only activate manaburst abilities if x is 4+.'
},

magnetic: () => {
return 'gear Pay this card\'s cost to meld it from hand to a card on field. The melded card has all abilities and combined stats ((), vp, element, type) of its parts.'
},

meld: () => {
return 'The melded card has all abilities and combined stats ((), vp, element, type) of its parts.'
},
Expand All @@ -913,7 +922,7 @@ ${SVG.elementSymbol(others[2], lively.pt(12.5, 8.5), 1.5)}`, lively.rect(0, 0, 1
},

potion: (...args) => {
return `Trash this from hand or field to exec the effect.`
return `Discard or sacrifice this to exec the effect.`
},

quest: () => {
Expand Down Expand Up @@ -997,7 +1006,7 @@ ${SVG.elementSymbol(others[2], lively.pt(12.5, 8.5), 1.5)}`, lively.rect(0, 0, 1
whoText = 'a card'
}

return `gear 1/turn Trash ${whoText} from hand to draw a card.`
return `gear 1/turn Discard ${whoText} to draw a card.`
},

upgrade: (diff, who) => {
Expand Down Expand Up @@ -1076,6 +1085,7 @@ ${SVG.elementSymbol(others[2], lively.pt(12.5, 8.5), 1.5)}`, lively.rect(0, 0, 1
//'#3FDAA5' some turquise
highlightKeyword(/trad(ed?|ing)\b/gmi, '#2E9F78', SVG.inlineSVG(tradeSVG.innerHTML, lively.rect(0, 0, 36, 36), 'x="10%" y="10%" width="80%" height="80%"', ''));
highlightKeyword(/upgraded?\b/gmi, C_ORANGE, SVG.inlineSVG(upgradeSVG.innerHTML, lively.rect(0, 0, 36, 36), 'x="10%" y="10%" width="80%" height="80%"', ''));
highlightKeyword(/magnetic\b/gmi, C_RED_LIGHT, '<i class="fa-solid fa-magnet"></i> ');

return printedRules
}
Expand Down
2 changes: 2 additions & 0 deletions src/components/widgets/ubg-cards-editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@
<label for="choiceNeedsRevision">needs revision</label>
<input type="radio" id="choiceRemove" name="rating" value="remove" />
<label for="choiceRemove">remove</label>
<input type="radio" id="choiceTestNext" name="rating" value="test next" />
<label for="choiceTestNext">test next</label>
<input type="radio" id="choiceToTest" name="rating" value="to test" />
<label for="choiceToTest">to test</label>
<input type="radio" id="choiceUnset" name="rating" value="unset" />
Expand Down
42 changes: 23 additions & 19 deletions src/components/widgets/ubg-cards-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,32 @@ export default class UBGCardsEditor extends Morph {
}
});
rating.addEventListener('keydown', evt => {
const key = evt.key;
lively.notify(key)
if (key >= '1' && key <= '9') {
const index = parseInt(key, 10) - 1;
lively.notify('key', index)
const radioButtonName = 'rating';
const radioButtons = rating.querySelectorAll(`input[type="radio"][name="${radioButtonName}"]`);

if (index < radioButtons.length) { // Check if the index is within the range of your radio buttons
const button = radioButtons[index]
button.checked = true;
button.focus()
const changeEvent = new Event('change', {
'bubbles': true, // Allows the event to bubble up through the DOM
'cancelable': false // Indicates the event cannot be canceled
});
radioButtons[index].dispatchEvent(changeEvent);
}
}
this.setRatingFromKeyEvent(evt)
});
}

setRatingFromKeyEvent(evt) {
// lively.notify(evt.key)
const key = evt.key;
if (key >= '1' && key <= '9') {
const index = parseInt(key, 10) - 1;
// lively.notify('key', index)
const radioButtonName = 'rating';
const radioButtons = this.getAllSubmorphs(`input[type="radio"][name="${radioButtonName}"]`);

if (index < radioButtons.length) { // Check if the index is within the range of your radio buttons
const button = radioButtons[index]
button.checked = true;
button.focus()
const changeEvent = new Event('change', {
'bubbles': true, // Allows the event to bubble up through the DOM
'cancelable': false // Indicates the event cannot be canceled
});
radioButtons[index].dispatchEvent(changeEvent);
}
}
}

get ubg() {
return lively.allParents(this, undefined, true).find(ele => ele.tagName === 'UBG-CARDS' || ele.tagName === 'JSPDF-EXAMPLE');
}
Expand Down
Loading

0 comments on commit c365807

Please sign in to comment.