-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
138 additions
and
55 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,27 +1,32 @@ | ||
import { ViewData } from '../app'; | ||
import { ViewData } from '../ui/ui-helpers'; | ||
import { Point } from '../util/types'; | ||
import { SceneState } from './state'; | ||
|
||
// There are UiActions, which might have different behavior depending | ||
// on view state, and other GameActions, which should be treated | ||
// uniformly. | ||
|
||
export type GameAction = { t: 'none'; } | | ||
UiAction; | ||
// I think I want to migrate some of these up to GameAction | ||
export type GameAction = | ||
| { t: 'none' } | ||
| UiAction; | ||
|
||
export type UiAction = { t: 'key'; code: string; } | | ||
{ t: 'mouseDown'; button: number; p: Point; } | | ||
{ t: 'mouseUp'; p: Point; } | | ||
{ t: 'mouseMove'; p: Point; } | | ||
{ t: 'wheel'; p: Point; delta: number; } | | ||
{ t: 'repaint'; }; | ||
// I think I want to migrate some of these up to GameAction | ||
export type UiAction = | ||
| { t: 'key', code: string } | ||
| { t: 'mouseDown', button: number, p: Point } | ||
| { t: 'mouseUp', p: Point } | ||
| { t: 'mouseMove', p: Point } | ||
| { t: 'wheel', p: Point, delta: number } | ||
| { t: 'repaint' } | ||
; | ||
|
||
export type Action = { t: 'resize'; vd: ViewData; } | | ||
{ t: 'newGame'; } | | ||
{ t: 'setSceneState'; state: SceneState; } | | ||
GameAction; | ||
export type Action = | ||
| { t: 'resize', vd: ViewData } | ||
| { t: 'newGame' } | ||
| { t: 'setSceneState', state: SceneState } | ||
| GameAction | ||
; | ||
|
||
export type Effect = { t: 'none'; }; | ||
export type Effect = { t: 'none' }; | ||
|
||
export type Dispatch = (action: Action) => void; |
This file contains 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 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 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,31 @@ | ||
import { canvas_bds_in_canvas } from '../ui/widget-helpers'; | ||
import { Point } from '../util/types'; | ||
import { vint } from '../util/vutil'; | ||
|
||
export type ViewData = { | ||
wsize: Point, | ||
}; | ||
|
||
export function resizeView(c: HTMLCanvasElement): ViewData { | ||
const ratio = devicePixelRatio; | ||
|
||
const parent = c.parentElement?.getBoundingClientRect(); | ||
const w = canvas_bds_in_canvas.sz.x; | ||
const h = canvas_bds_in_canvas.sz.y; | ||
|
||
c.width = w; | ||
c.height = h; | ||
|
||
const ow = w; | ||
const oh = h; | ||
|
||
c.width = ow * ratio; | ||
c.height = oh * ratio; | ||
|
||
c.style.width = ow + 'px'; | ||
c.style.height = oh + 'px'; | ||
|
||
const wsize = vint({ x: c.width / ratio, y: c.height / ratio }); | ||
|
||
return { wsize }; | ||
} |