-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtile-fall.ts
36 lines (33 loc) · 1.43 KB
/
tile-fall.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { canvas_from_drag_mobile } from "./view-helpers";
import { getWidgetPoint } from "./widget-helpers";
import { compose, inverse } from '../util/se2';
import { Point } from "../util/types";
import { vm } from "../util/vutil";
import { resolveLandResult } from "../core/landing-resolve";
import { landMoveOnState } from "../core/landing-result";
import { CoreState, GameState } from "../core/state";
import { MouseState } from '../core/state-types';
import { get_hand_tiles } from "../core/tile-helpers";
import { pointFall, withCoreState, checkValid } from "../core/state-helpers";
export function tileFall(state: CoreState, ms: MouseState): Point {
return vm(compose(
inverse(state.canvas_from_world),
canvas_from_drag_mobile(state, ms)).translate,
Math.round);
}
export function dropTopHandTile(state: GameState): GameState {
const cs = state.coreState;
const handTiles = get_hand_tiles(cs);
if (handTiles.length == 0) {
return state;
}
const tile = handTiles[0];
if (state.mouseState.t == 'up' && getWidgetPoint(cs, state.mouseState.p_in_canvas).t == 'world') {
const p_in_world_int = pointFall(cs, state.mouseState.p_in_canvas);
const lr = landMoveOnState({ src: { t: 'tile', letter: tile.letter }, p_in_world_int }, cs);
if (lr.t != 'collision') {
return withCoreState(state, cs => checkValid(resolveLandResult(cs, lr, { p_in_world_int, src: { t: 'mobile', id: tile.id } })));
}
}
return state;
}