like2d 2.12.1 → 2.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,58 +0,0 @@
1
- import { type Scene } from '../scene';
2
- import { Like } from '..';
3
- /**
4
- * ## Why
5
- *
6
- * 1. Because the LIKE logo looks awesome.
7
- * 2. Autoplay restriction, doesn't let you play audio until the page is clicked.
8
- * 3. You have to click on the game in order to send inputs, anyway.
9
- * 4. It's polite.
10
- *
11
- * ## Usage
12
- *
13
- * ```typescript
14
- * import { createLike, StartScreen } from 'like';
15
- * import { GameScene } from './game';
16
- *
17
- * const container = document.getElementById("myGame");
18
- * const like = createLike(container);
19
- *
20
- * // these callbacks will be ignored until the scene is clicked
21
- * like.update = function () { ... }
22
- * like.draw = function () { ... }
23
- *
24
- * // Set up the start screen
25
- * like.pushScene(new StartScreen())
26
- * like.start();
27
- * ```
28
- *
29
- * Alternatively, copy-paste this code into your own project and modify it freely.
30
- * Update imports:
31
- *
32
- * ```ts
33
- * import { type Scene } from 'like/scene';
34
- * import type { ImageHandle } from 'like/graphics';
35
- * import { Vec2 } from 'like/math';
36
- * import { Like } from 'like';
37
- * ```
38
- *
39
- * ## Custom Rendering
40
- *
41
- * Pass a custom draw function to replace the default logo:
42
- *
43
- * ```typescript
44
- * const startup = new StartupScene(gameScene, (like) => {
45
- * like.gfx.clear([0, 0, 0, 1]);
46
- * like.gfx.print([1, 1, 1], 'Click to Start', [100, 100]);
47
- * });
48
- * ```
49
- */
50
- export declare class StartScreen implements Scene {
51
- private onDraw?;
52
- private logo;
53
- constructor(onDraw?: ((like: Like) => void) | undefined);
54
- load(like: Like): void;
55
- draw(like: Like): void;
56
- mousepressed(like: Like): void;
57
- }
58
- //# sourceMappingURL=startScreen.d.ts.map
package/dist/scene.d.ts DELETED
@@ -1,145 +0,0 @@
1
- import type { LikeEvent, EventMap } from './events';
2
- import type { Like } from './like';
3
- /**
4
- * An interface for creating scenes.
5
- *
6
- * ## Why Scenes?
7
- *
8
- * For any game with more than one scene, we have to either:
9
- * - switch-case on game state in every single callback
10
- * - rebind all of the callbacks ourselves
11
- * - wrap handleEvent (hint: that's what this does)
12
- *
13
- * Also, no need to pass around a `like` object.
14
- * Here, `like` instead piggybacks on a closure that follows around
15
- * your running scene and shows up as an additional first argument
16
- * to every callback.
17
- *
18
- * ## The scene stack
19
- *
20
- * There is a stack of scenes for state management and/or overlays.
21
- *
22
- * Use {@link LikeBase.pushScene | pushScene} and {@link LikeBase.popScene | Like.popScene} to manage the stack.
23
- *
24
- * {@link LikeBase.setScene | setScene} Sets the top of the stack only, replacing the current scene if any.
25
- *
26
- * ## Quick Start
27
- *
28
- * Have a scene handle all the callbacks, disabling global
29
- * callbacks.
30
- * ```typescript
31
- * // set up a scene
32
- * class MagicalGrowingRectangle implements Scene {
33
- * rectangleSize = 10;
34
- * constructor() {}
35
- *
36
- * keypressed(_like: Like) {
37
- * this.rectangleSize += 10;
38
- * }
39
- *
40
- * draw(like: Like) {
41
- * like.gfx.rectangle('fill', 'green',
42
- * [10, 10, this.rectangleSize, this.rectangleSize])
43
- * }
44
- * }
45
- *
46
- * like.pushScene(new MagicalGrowingRectangle(), false);
47
- * ```
48
- *
49
- * To get back to global callbacks, just use {@link Like.popScene | like.popScene}
50
- *
51
- * ## Scene Lifecycle
52
- *
53
- * Works a lot like global callbacks.
54
- *
55
- * 1. `like.setScene(scene)` or `like.pushScene(scene)` is called
56
- * 2. Scene's `load` callback fires immediately
57
- * 3. `update` and `draw` begin on next frame
58
- * 4. Scene receives input events as they occur
59
- *
60
- * ## Composing scenes
61
- *
62
- * Thought you'd never ask.
63
- * Just like the `like` object, scenes have handleEvent on them.
64
- * So, you could layer them like this, for example:
65
- *
66
- * ```typescript
67
- * class UI implements Scene {
68
- * constructor(public game: Scene) {}
69
- *
70
- * handleEvent(like: Like, event: LikeEvent) {
71
- * // Block mouse events in order to create a top bar.
72
- * const mouseY = like.mouse.getPosition()[1];
73
- * if (!event.type.startsWith('mouse') || mouseY > 100) {
74
- * sceneDispatch(this.game, like, event);
75
- * }
76
- *
77
- * // Then, call my own callbacks.
78
- * // By calling it here, the UI draws on top.
79
- * callSceneHandlers(this, like, event);
80
- * }
81
- * ...
82
- * }
83
- *
84
- * class Game implements Scene {
85
- * ...
86
- * }
87
- *
88
- * like.pushScene(new UI(new Game()), false)
89
- * ```
90
- *
91
- * Composing scenes lets you filter events, layer game elements,
92
- * and more. Don't sleep on it.
93
- *
94
- * The main advance of composing scenes versus the stack-overlay
95
- * technique is that the parent scene knows about its child.
96
- * Because there's a **known interface**, the two scenes
97
- * can communicate.
98
- *
99
- * This makes it perfect for reusable UI,
100
- * level editors, debug viewers, and more.
101
- *
102
- * ## Overlay scenes
103
- *
104
- * You might assume that the purpose of a scene stack is
105
- * visual: first push the BG, then the FG, etc.
106
- *
107
- * Actually, composing scenes (above) is a
108
- * better pattern for that, since it's both explicit
109
- * _and_ the parent can have a known interface on its child.
110
- * Here, the **upper** scene only knows that the
111
- * **lower** scene _is_ a scene.
112
- *
113
- * That's the tradeoff. Overlay scenes are good for things
114
- * like pause screens or gamepad overlays. Anything where
115
- * the upper doesn't care _what_ the lower is, and where
116
- * the upper scene should be easily addable/removable.
117
- *
118
- * Using `like.getScene(-2)`, the overlay scene can see
119
- * the lower scene and choose how to propagate events.
120
- *
121
- * The only technical difference between overlay and
122
- * opaque is whether or not the scene we've pushed
123
- * on top of stays loaded.
124
- *
125
- * @interface
126
- *
127
- */
128
- export type Scene = {
129
- [K in keyof EventMap]?: (like: Like, ...args: EventMap[K]) => void;
130
- } & {
131
- handleEvent?(like: Like, event: LikeEvent): void;
132
- };
133
- /**
134
- * Used to call a scene's own handlers like `update` or `draw`,
135
- * typically at the end of handleEvent
136
- * after modifying the event stream or composing sub-scenes.
137
- */
138
- export declare const callSceneHandlers: (scene: Scene, like: Like, event: LikeEvent) => void;
139
- /**
140
- * Used to call sub scenes while respecting potential `handleEvent` within them.
141
- * The main scene is similar to a sub-scene of the root (like) object in this
142
- * regard.
143
- */
144
- export declare const sceneDispatch: (scene: Scene, like: Like, event: LikeEvent) => void;
145
- //# sourceMappingURL=scene.d.ts.map
package/dist/scene.js DELETED
@@ -1,23 +0,0 @@
1
- /**
2
- * Used to call a scene's own handlers like `update` or `draw`,
3
- * typically at the end of handleEvent
4
- * after modifying the event stream or composing sub-scenes.
5
- */
6
- export const callSceneHandlers = (scene, like, event) => {
7
- if (event.type in scene) {
8
- scene[event.type](like, ...event.args);
9
- }
10
- };
11
- /**
12
- * Used to call sub scenes while respecting potential `handleEvent` within them.
13
- * The main scene is similar to a sub-scene of the root (like) object in this
14
- * regard.
15
- */
16
- export const sceneDispatch = (scene, like, event) => {
17
- if (scene.handleEvent) {
18
- scene.handleEvent(like, event);
19
- }
20
- else {
21
- callSceneHandlers(scene, like, event);
22
- }
23
- };