Repository navigation
feat(guns): explain the special guns when they come online #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| import { SPECIAL_GUN_CHARGE } from '../../config/shipSystems'; | ||
| import { h, mountUiLayer } from '../../ui/dom'; | ||
|
|
||
| export interface SpecialGunIntroCard { | ||
| destroy: () => void; | ||
| } | ||
|
|
||
| /** The card belongs to the refit bay right before the first sector that flies Lance, and to no other. */ | ||
| export function isSpecialGunIntroDue(clearedLevel: number): boolean { | ||
| return clearedLevel === SPECIAL_GUN_CHARGE.fromLevel - 1; | ||
| } | ||
|
|
||
| /** The card's lines; touch names the on-screen swap key instead of Q. */ | ||
| export function describeSpecialGunIntro(touch: boolean): readonly string[] { | ||
| return [ | ||
| 'Your main gun is now the LANCE: slower shots that pierce every ship in a line.', | ||
| `${touch ? 'Tap the swap key' : 'Press Q'} to switch to SCATTER or SEEKERS.`, | ||
| 'Special guns run on a charge. When it is empty you drop back to the Lance, which refills it.', | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * A short explanation of the special guns, shown over the refit bay before the shop opens. Nothing to | ||
| * choose: CONTINUE (or Enter, Space, Escape) closes it, and focus never leaves it while it is open. | ||
| */ | ||
| export function createSpecialGunIntroCard(touch: boolean, onContinue: () => void): SpecialGunIntroCard { | ||
| const done = h('button', { type: 'button', className: 'ui-btn ui-btn--primary menu-sheet__done' }, 'CONTINUE'); | ||
| done.addEventListener('click', onContinue); | ||
| const sheet = h( | ||
| 'section', | ||
| { | ||
| className: 'ui-panel menu-sheet gun-intro', | ||
| role: 'dialog', | ||
| 'aria-modal': 'true', | ||
| 'aria-labelledby': 'gun-intro-title', | ||
| 'aria-describedby': 'gun-intro-lines', | ||
| tabIndex: -1, | ||
| }, | ||
| h('div', { className: 'ui-frame', 'aria-hidden': 'true' }), | ||
| h('p', { className: 'ui-caption' }, 'REFIT BAY · NEW HARDWARE'), | ||
| h('h2', { className: 'ui-heading', id: 'gun-intro-title' }, 'SPECIAL GUNS ONLINE'), | ||
| h( | ||
| 'div', | ||
| { className: 'gun-intro__lines', id: 'gun-intro-lines' }, | ||
| ...describeSpecialGunIntro(touch).map((line) => h('p', {}, line)) | ||
| ), | ||
| done | ||
| ); | ||
| const modal = h('div', { className: 'ui-modal' }, sheet); | ||
| modal.addEventListener('keydown', (event) => { | ||
| if (event.code === 'Escape') { | ||
| // Handled here: the bay behind must not also read Escape as "carry on". | ||
| event.preventDefault(); | ||
| event.stopPropagation(); | ||
| onContinue(); | ||
| } else if (event.code === 'Tab' || event.code.startsWith('Arrow')) { | ||
| // One control: Tab and the arrows keep focus on it. | ||
| event.preventDefault(); | ||
| } | ||
| }); | ||
| // A press on the card itself must not pull focus off CONTINUE, or Enter would stop working. | ||
| modal.addEventListener('mousedown', (event) => { | ||
| if (event.target !== done) event.preventDefault(); | ||
| }); | ||
|
|
||
| // Its own layer above the refit bay; the scene makes the bay inert meanwhile. | ||
| const layer = mountUiLayer(); | ||
| layer.append(modal); | ||
| done.focus({ preventScroll: true }); | ||
| return { destroy: () => layer.remove() }; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Closing the dialog with Enter allows Phaser's queued Enter keydown event to trigger
handleUnfocusedKey('Enter'), accidentally purchasing the first purchasable upgrade card.Severity: MEDIUM
Suggested Fix
Call
stopPropagation()or prevent the default action on the Enter key event within the dialog continue handler, or defer un-inerting the upgrade bay view until the next frame/tick so the queued Enter event is consumed safely.Prompt for AI Agent
Did we get this right? 👍 / 👎 to inform future reviews.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a bug: the Enter keydown never reaches Phaser. Every UI layer stops propagation of Enter/Space pressed on a focused button (
keepNativeKeysinsrc/ui/dom.ts:42), so the scene's keydown handler does not see the key that closed the card. The e2e test closes the card with Enter on desktop and the bay afterwards still shows 8000 credits and Hull Armor at 0/5.