@hi-ashleyj/llama 0.12.5 → 0.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.
- package/README.md +273 -0
- package/dist/drawables/index.d.ts +1 -0
- package/dist/drawables/index.js +1 -0
- package/dist/index.d.ts +4 -15
- package/dist/index.js +4 -14
- package/dist/primitives/Area.svelte +25 -0
- package/dist/primitives/Area.svelte.d.ts +25 -0
- package/dist/primitives/Inset.svelte +29 -0
- package/dist/primitives/Inset.svelte.d.ts +21 -0
- package/dist/primitives/Node.svelte +22 -0
- package/dist/primitives/Node.svelte.d.ts +19 -0
- package/dist/primitives/Opacity.svelte +25 -0
- package/dist/primitives/Opacity.svelte.d.ts +18 -0
- package/dist/{extras → primitives}/Rotate.svelte +2 -2
- package/dist/{extras → primitives}/Rotate.svelte.d.ts +1 -1
- package/dist/primitives/Translate.svelte +22 -0
- package/dist/primitives/Translate.svelte.d.ts +19 -0
- package/dist/primitives.d.ts +7 -0
- package/dist/primitives.js +8 -0
- package/dist/resources.d.ts +7 -0
- package/dist/resources.js +8 -0
- package/dist/scenes.d.ts +3 -0
- package/dist/scenes.js +3 -0
- package/package.json +13 -1
- package/dist/GameObject.svelte +0 -38
- package/dist/GameObject.svelte.d.ts +0 -26
- /package/dist/{extras → primitives}/Empty.svelte +0 -0
- /package/dist/{extras → primitives}/Empty.svelte.d.ts +0 -0
- /package/dist/{extras → scenes}/SceneSwitcher.svelte +0 -0
- /package/dist/{extras → scenes}/SceneSwitcher.svelte.d.ts +0 -0
- /package/dist/{extras → scenes}/SceneTransition.svelte +0 -0
- /package/dist/{extras → scenes}/SceneTransition.svelte.d.ts +0 -0
- /package/dist/{extras → scenes}/scenes.d.ts +0 -0
- /package/dist/{extras → scenes}/scenes.js +0 -0
package/README.md
CHANGED
|
@@ -33,3 +33,276 @@ To get started:
|
|
|
33
33
|
</style>
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
+
## Asset Handling
|
|
37
|
+
Let's prepare some asset handling. I recommend doing this in it's own component. The following pattern preloads assets with the page:
|
|
38
|
+
|
|
39
|
+
```diff
|
|
40
|
+
/// +page.svelte
|
|
41
|
+
|
|
42
|
+
import { SensibleDefaultStyles, Game } from "@hi-ashleyj/llama";
|
|
43
|
+
+ import Assets from "./Assets.svelte";
|
|
44
|
+
|
|
45
|
+
...
|
|
46
|
+
|
|
47
|
+
<Game>
|
|
48
|
+
|
|
49
|
+
+ <Assets />
|
|
50
|
+
|
|
51
|
+
</Game>
|
|
52
|
+
```
|
|
53
|
+
```html
|
|
54
|
+
/// Assets.svelte
|
|
55
|
+
|
|
56
|
+
<script lang="ts">
|
|
57
|
+
|
|
58
|
+
import { AssetPool, ImageAsset, AudioBufferedAsset, AudioMediaAsset } from "@hi-ashleyj/llama/resources";
|
|
59
|
+
|
|
60
|
+
// ... use standard Vite imports here
|
|
61
|
+
|
|
62
|
+
</script>
|
|
63
|
+
|
|
64
|
+
<AssetPool>
|
|
65
|
+
|
|
66
|
+
<ImageAsset url={...} />
|
|
67
|
+
...
|
|
68
|
+
|
|
69
|
+
</AssetPool>
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Layer Setup
|
|
74
|
+
A Llama game is made of multiple 2D Layers. I highly recommend creating a folder for all layers, then having an additional folder per layer.
|
|
75
|
+
We'll create an additional layers.ts file in order to glob import the layer components, as Vite only supports globbing in TS files.
|
|
76
|
+
|
|
77
|
+
```diff
|
|
78
|
+
/src/routes
|
|
79
|
+
+ ├── layers
|
|
80
|
+
+ │ ├── background
|
|
81
|
+
+ │ ├── ui
|
|
82
|
+
+ │ └── layers.ts
|
|
83
|
+
├── +page.svelte
|
|
84
|
+
└── Assets.svelte
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
// layers/layers.ts
|
|
89
|
+
import type { SvelteComponent } from "svelte";
|
|
90
|
+
|
|
91
|
+
const imports = import.meta.glob<{default: SvelteComponent}>("./**/_Layer.svelte", {eager: true});
|
|
92
|
+
export const layers: SvelteComponent[] = Object.keys(imports).map((it) => imports[it].default);
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
```diff
|
|
96
|
+
/// +page.svelte
|
|
97
|
+
|
|
98
|
+
import Assets from "./Assets.svelte";
|
|
99
|
+
+ import { layers } from "./layers/layers.js";
|
|
100
|
+
|
|
101
|
+
...
|
|
102
|
+
|
|
103
|
+
<Game>
|
|
104
|
+
|
|
105
|
+
+ {#each layers as layer}
|
|
106
|
+
+ <svelte:component this={layer}>
|
|
107
|
+
+ {/each}
|
|
108
|
+
|
|
109
|
+
</Game>
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Layers and Scenes
|
|
113
|
+
Let's get started with actually creating some Layers now.
|
|
114
|
+
You'll probably find it faster to also setup Scenes now as well.
|
|
115
|
+
Let's start by making a file to store potential scenes in.
|
|
116
|
+
|
|
117
|
+
```diff
|
|
118
|
+
/src/lib
|
|
119
|
+
+ └── constants.ts
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
/// src/lib/constants.ts
|
|
124
|
+
|
|
125
|
+
export const SCENES = {
|
|
126
|
+
// examples
|
|
127
|
+
MENU: "default", // Scene "default" will be shown on load.
|
|
128
|
+
GAME: "game"
|
|
129
|
+
...
|
|
130
|
+
} as const;
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
And now, let's create a layer, and add the scene switcher to it.
|
|
134
|
+
|
|
135
|
+
```diff
|
|
136
|
+
/src/routes
|
|
137
|
+
├── layers
|
|
138
|
+
│ ├── background
|
|
139
|
+
+ │ │ └── _Layer.svelte
|
|
140
|
+
│ └── ...
|
|
141
|
+
└── ...
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
```html
|
|
145
|
+
/// layers/background/_Layer.svelte
|
|
146
|
+
|
|
147
|
+
<script lang="ts">
|
|
148
|
+
|
|
149
|
+
import { Layer } from "@hi-ashleyj/llama";
|
|
150
|
+
import { SceneSwitcher } from "@hi-ashleyj/llama/scenes";
|
|
151
|
+
import { SCENES } from "$lib/constants.js";
|
|
152
|
+
|
|
153
|
+
// ... import individual scene components here
|
|
154
|
+
|
|
155
|
+
</script>
|
|
156
|
+
|
|
157
|
+
<Layer name="background" zIndex={0}>
|
|
158
|
+
<SceneSwitcher scenes={{
|
|
159
|
+
...
|
|
160
|
+
}}/>
|
|
161
|
+
</Layer>
|
|
162
|
+
|
|
163
|
+
```
|
|
164
|
+
And that's all we need to create a layer. We should also probably setup a scene.
|
|
165
|
+
Here's an example for how to add the Menu and Game scenes we hinted earlier:
|
|
166
|
+
|
|
167
|
+
```diff
|
|
168
|
+
/src/routes
|
|
169
|
+
├── layers
|
|
170
|
+
│ ├── background
|
|
171
|
+
│ │ ├── _Layer.svelte
|
|
172
|
+
+ │ │ ├── Game.svelte
|
|
173
|
+
+ │ │ └── Menu.svelte
|
|
174
|
+
│ └── ...
|
|
175
|
+
└── ...
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
```diff
|
|
179
|
+
/// layers/background/_Layer.svelte
|
|
180
|
+
|
|
181
|
+
import { SCENES } from "$lib/constants.js";
|
|
182
|
+
|
|
183
|
+
// ... import individual scene components here
|
|
184
|
+
+ import Menu from "./Menu.svelte"
|
|
185
|
+
+ import Game from "./Game.svelte"
|
|
186
|
+
|
|
187
|
+
...
|
|
188
|
+
|
|
189
|
+
<SceneSwitcher scenes={{
|
|
190
|
+
+ [ SCENES.MENU ]: Menu,
|
|
191
|
+
+ [ SCENES.GAME ]: Game
|
|
192
|
+
}}/>
|
|
193
|
+
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Note that both Menu and Game are empty, as an empty .svelte file is still a valid Svelte component.
|
|
197
|
+
|
|
198
|
+
## Scene Transition / Changing Scene
|
|
199
|
+
One thing left to do before scenes can be changed is to consume the SceneTransition component somewhere.
|
|
200
|
+
I like to do this in a layer above all others. Here's a basic fade animation as the scene changes.
|
|
201
|
+
|
|
202
|
+
```diff
|
|
203
|
+
/src/routes
|
|
204
|
+
├── layers
|
|
205
|
+
+ │ ├── transition
|
|
206
|
+
+ │ │ └── _Layer.svelte
|
|
207
|
+
│ └── ...
|
|
208
|
+
└── ...
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
```html
|
|
212
|
+
/// layers/transition/_Layer.svelte
|
|
213
|
+
|
|
214
|
+
<script lang="ts">
|
|
215
|
+
|
|
216
|
+
import { Layer } from "@hi-ashleyj/llama";
|
|
217
|
+
import { SceneSwitcher } from "@hi-ashleyj/llama/scenes";
|
|
218
|
+
import { Node, Area, Opacity } from "@hi-ashleyj/llama/primitives";
|
|
219
|
+
import { Rectangle } from "@hi-ashleyj/llama/drawables";
|
|
220
|
+
|
|
221
|
+
</script>
|
|
222
|
+
|
|
223
|
+
<Layer name="transition" zIndex={99}>
|
|
224
|
+
<SceneTransition let:normalized duration={800}>
|
|
225
|
+
<Node x={0} y={0}>
|
|
226
|
+
<Area w={0} h={0}>
|
|
227
|
+
<Opacity opacity={normalized}>
|
|
228
|
+
<Rectangle fill="black" />
|
|
229
|
+
</Opacity>
|
|
230
|
+
</Area>
|
|
231
|
+
</Node>
|
|
232
|
+
</SceneTransition>
|
|
233
|
+
</Layer>
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
Note that due to the glob-based importing, this should be sucked into the project automagically.
|
|
237
|
+
|
|
238
|
+
## Primitives (@hi-ashleyj/llama/primitives)
|
|
239
|
+
These are the basic building blocks for displaying anything.
|
|
240
|
+
Thing of these as points, and bounding boxes.
|
|
241
|
+
|
|
242
|
+
## Empty
|
|
243
|
+
Component that literally does nothing. Use for wrapping multiple similar items together.
|
|
244
|
+
|
|
245
|
+
### Node
|
|
246
|
+
Base entry point. Wrapper around a single item in the game (think GameObject in unity or Empty in Blender).
|
|
247
|
+
|
|
248
|
+
```ts
|
|
249
|
+
type Props = {
|
|
250
|
+
x: number;
|
|
251
|
+
y: number;
|
|
252
|
+
}
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### Area
|
|
256
|
+
Use within a `Node`. Specifies a bounding box for a drawable.
|
|
257
|
+
Position of the parent is considered the top-left corner of the area.
|
|
258
|
+
If `center` is true, it will consider parent position to be the center of the area.
|
|
259
|
+
```ts
|
|
260
|
+
type Props = {
|
|
261
|
+
w: number;
|
|
262
|
+
h: number;
|
|
263
|
+
center: boolean = false;
|
|
264
|
+
x?: number; // Optional offset
|
|
265
|
+
y?: number; // Optional offset
|
|
266
|
+
}
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
### Translate
|
|
270
|
+
Use within a `Node`. Offsets the position of the node for all children.
|
|
271
|
+
```ts
|
|
272
|
+
type Props = {
|
|
273
|
+
x: number;
|
|
274
|
+
y: number;
|
|
275
|
+
}
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### Inset
|
|
279
|
+
Use within an `Area`. Works similar to CSS `inset` prop. Use to move the bounding box of an `Area` towards the middle (use negative to extend).
|
|
280
|
+
```ts
|
|
281
|
+
type Props = {
|
|
282
|
+
top: number = 0;
|
|
283
|
+
left: number = 0;
|
|
284
|
+
right: number = 0;
|
|
285
|
+
bottom: number = 0;
|
|
286
|
+
}
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### Opacity
|
|
290
|
+
Adjusts the opacity for all drawn children. This is set absolutely, so nesting 0.5 with another 0.5 does not make a 0.25 opaque child.
|
|
291
|
+
If opacity is 0 or less, drawing of children (including other opacity nodes) is skipped.
|
|
292
|
+
Opacity will be clamped to 1.
|
|
293
|
+
```ts
|
|
294
|
+
type Props = {
|
|
295
|
+
opacity: number; // Between 0 and 1.
|
|
296
|
+
}
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
### Rotate
|
|
300
|
+
Rotates the element by some number of degrees.
|
|
301
|
+
Rotates around the top left corner of the element, unless `centered` is specified.
|
|
302
|
+
```ts
|
|
303
|
+
type Props = {
|
|
304
|
+
centered: boolean = false;
|
|
305
|
+
degrees: number;
|
|
306
|
+
}
|
|
307
|
+
```
|
|
308
|
+
|
|
@@ -6,3 +6,4 @@ export { default as Text } from "./Text.svelte";
|
|
|
6
6
|
export { default as MultiLineText } from "./MultiLineText.svelte";
|
|
7
7
|
export { default as RoundedRectangle } from "./RoundedRectangle.svelte";
|
|
8
8
|
export { default as Tiled } from "./Tiled.svelte";
|
|
9
|
+
export { setupDrawable, type DrawableContext, type DrawFunction, type DrawableObject } from "../drawable.js";
|
package/dist/drawables/index.js
CHANGED
|
@@ -6,3 +6,4 @@ export { default as Text } from "./Text.svelte";
|
|
|
6
6
|
export { default as MultiLineText } from "./MultiLineText.svelte";
|
|
7
7
|
export { default as RoundedRectangle } from "./RoundedRectangle.svelte";
|
|
8
8
|
export { default as Tiled } from "./Tiled.svelte";
|
|
9
|
+
export { setupDrawable } from "../drawable.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,35 +1,24 @@
|
|
|
1
1
|
export { default as Game } from "./Game.svelte";
|
|
2
2
|
export { default as Layer } from "./Layer.svelte";
|
|
3
|
-
export { default as GameObject } from "./GameObject.svelte";
|
|
4
3
|
export { getGame, getLayer, getTriggerLayerRender } from "./core-contexts.js";
|
|
5
4
|
export type { GameContext, LayerContext, LayerDrawable } from "./core-contexts.js";
|
|
6
5
|
export { default as MouseClickable } from "./controllers/MouseClickable.svelte";
|
|
7
6
|
export { default as MouseEventArea } from "./controllers/MouseEventArea.svelte";
|
|
8
7
|
export { MOUSE_ACTION } from "./controllers/mouse.js";
|
|
9
8
|
export { KEYBOARD_ACTION } from "./controllers/keyboard.js";
|
|
10
|
-
export { setupDrawable, type DrawableContext, type DrawFunction, type DrawableObject } from "./drawable.js";
|
|
11
9
|
export * as Drawables from "./drawables/index.js";
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export { resolveBuffer as resolveAudioBuffer } from "./resources/audio.js";
|
|
15
|
-
export { default as AssetPool } from "./resources/AssetPool.svelte";
|
|
16
|
-
export { default as AudioBufferedAsset } from "./resources/AudioBufferedAsset.svelte";
|
|
17
|
-
export { default as AudioMediaAsset } from "./resources/AudioMediaAsset.svelte";
|
|
18
|
-
export { default as ImageAsset } from "./resources/ImageAsset.svelte";
|
|
10
|
+
export * as Resource from "./resources.js";
|
|
11
|
+
export * as Primitives from "./primitives.js";
|
|
19
12
|
export { default as SensibleDefaultStyles } from "./extras/SensibleDefaultStyles.svelte";
|
|
20
|
-
export { default as Empty } from "./extras/Empty.svelte";
|
|
21
13
|
export { default as LayerPortal } from "./extras/LayerPortal.svelte";
|
|
22
|
-
export { changeScene } from "./extras/scenes.js";
|
|
23
|
-
export { default as SceneSwitcher } from "./extras/SceneSwitcher.svelte";
|
|
24
|
-
export { default as SceneTransition } from "./extras/SceneTransition.svelte";
|
|
25
|
-
export { default as Rotate } from "./extras/Rotate.svelte";
|
|
26
14
|
export { default as Tweened } from "./extras/Tweened.svelte";
|
|
27
15
|
export { default as DefaultFontFace } from "./extras/DefaultFontFace.svelte";
|
|
28
16
|
export { default as FullScreenEventHandler } from "./extras/FullScreenEventHandler.svelte";
|
|
29
|
-
export { getAudioContext, getConnector as getAudioConnector } from "./audio/context.js";
|
|
17
|
+
export { getAudioContext, getConnector as getAudioConnector, type AudioSvelteContext as LlamaAudioContext } from "./audio/context.js";
|
|
30
18
|
export { default as AudioListenerPosition } from "./audio/AudioListenerPosition.svelte";
|
|
31
19
|
export { default as BufferedAudioSource } from "./audio/BufferedAudioSource.svelte";
|
|
32
20
|
export { default as MediaAudioSource } from "./audio/MediaAudioSource.svelte";
|
|
33
21
|
export { default as AudioGain } from "./audio/AudioGain.svelte";
|
|
34
22
|
export { default as AudioPanner } from "./audio/AudioPanner.svelte";
|
|
35
23
|
export { default as AudioCompressor } from "./audio/AudioCompressor.svelte";
|
|
24
|
+
export * as Scenes from "./scenes.js";
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// CORE
|
|
2
2
|
export { default as Game } from "./Game.svelte";
|
|
3
3
|
export { default as Layer } from "./Layer.svelte";
|
|
4
|
-
export { default as GameObject } from "./GameObject.svelte";
|
|
5
4
|
export { getGame, getLayer, getTriggerLayerRender } from "./core-contexts.js";
|
|
6
5
|
// CONTROLLERS
|
|
7
6
|
export { default as MouseClickable } from "./controllers/MouseClickable.svelte";
|
|
@@ -9,24 +8,14 @@ export { default as MouseEventArea } from "./controllers/MouseEventArea.svelte";
|
|
|
9
8
|
export { MOUSE_ACTION } from "./controllers/mouse.js";
|
|
10
9
|
export { KEYBOARD_ACTION } from "./controllers/keyboard.js";
|
|
11
10
|
// DRAWABLES
|
|
12
|
-
export { setupDrawable } from "./drawable.js";
|
|
13
11
|
export * as Drawables from "./drawables/index.js";
|
|
14
12
|
// RESOURCES
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
export
|
|
18
|
-
export { default as AssetPool } from "./resources/AssetPool.svelte";
|
|
19
|
-
export { default as AudioBufferedAsset } from "./resources/AudioBufferedAsset.svelte";
|
|
20
|
-
export { default as AudioMediaAsset } from "./resources/AudioMediaAsset.svelte";
|
|
21
|
-
export { default as ImageAsset } from "./resources/ImageAsset.svelte";
|
|
13
|
+
export * as Resource from "./resources.js";
|
|
14
|
+
// PRIMITIVES
|
|
15
|
+
export * as Primitives from "./primitives.js";
|
|
22
16
|
// EXTRAS
|
|
23
17
|
export { default as SensibleDefaultStyles } from "./extras/SensibleDefaultStyles.svelte";
|
|
24
|
-
export { default as Empty } from "./extras/Empty.svelte";
|
|
25
18
|
export { default as LayerPortal } from "./extras/LayerPortal.svelte";
|
|
26
|
-
export { changeScene } from "./extras/scenes.js";
|
|
27
|
-
export { default as SceneSwitcher } from "./extras/SceneSwitcher.svelte";
|
|
28
|
-
export { default as SceneTransition } from "./extras/SceneTransition.svelte";
|
|
29
|
-
export { default as Rotate } from "./extras/Rotate.svelte";
|
|
30
19
|
export { default as Tweened } from "./extras/Tweened.svelte";
|
|
31
20
|
export { default as DefaultFontFace } from "./extras/DefaultFontFace.svelte";
|
|
32
21
|
export { default as FullScreenEventHandler } from "./extras/FullScreenEventHandler.svelte";
|
|
@@ -38,3 +27,4 @@ export { default as MediaAudioSource } from "./audio/MediaAudioSource.svelte";
|
|
|
38
27
|
export { default as AudioGain } from "./audio/AudioGain.svelte";
|
|
39
28
|
export { default as AudioPanner } from "./audio/AudioPanner.svelte";
|
|
40
29
|
export { default as AudioCompressor } from "./audio/AudioCompressor.svelte";
|
|
30
|
+
export * as Scenes from "./scenes.js";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<script>import { setupDrawable } from "../drawable.js";
|
|
2
|
+
import { onMount } from "svelte";
|
|
3
|
+
export let x = 0;
|
|
4
|
+
export let y = 0;
|
|
5
|
+
export let w;
|
|
6
|
+
export let h;
|
|
7
|
+
export let center = false;
|
|
8
|
+
const targets = /* @__PURE__ */ new Set();
|
|
9
|
+
const draw = function({ width, height, ctx }, offset) {
|
|
10
|
+
targets.forEach((f) => f.draw({ width, height, ctx }, { x: offset.x + x - (center ? w / 2 : 0), y: offset.y + y - (center ? h / 2 : 0), w, h }));
|
|
11
|
+
};
|
|
12
|
+
let register = setupDrawable({
|
|
13
|
+
assign: (ctx) => {
|
|
14
|
+
targets.add(ctx);
|
|
15
|
+
return () => {
|
|
16
|
+
targets.delete(ctx);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
onMount(() => {
|
|
21
|
+
return register({ draw });
|
|
22
|
+
});
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<slot/>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: {
|
|
4
|
+
x?: number | undefined;
|
|
5
|
+
y?: number | undefined;
|
|
6
|
+
w: number;
|
|
7
|
+
h: number;
|
|
8
|
+
/**
|
|
9
|
+
* TRUE = ALIGN CENTER
|
|
10
|
+
* FALSE (default) = ALIGN TOP LEFT
|
|
11
|
+
*/ center?: boolean | undefined;
|
|
12
|
+
};
|
|
13
|
+
events: {
|
|
14
|
+
[evt: string]: CustomEvent<any>;
|
|
15
|
+
};
|
|
16
|
+
slots: {
|
|
17
|
+
default: {};
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export type AreaProps = typeof __propDef.props;
|
|
21
|
+
export type AreaEvents = typeof __propDef.events;
|
|
22
|
+
export type AreaSlots = typeof __propDef.slots;
|
|
23
|
+
export default class Area extends SvelteComponent<AreaProps, AreaEvents, AreaSlots> {
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<script>import { setupDrawable } from "../drawable.js";
|
|
2
|
+
import { onMount } from "svelte";
|
|
3
|
+
export let left = 0;
|
|
4
|
+
export let right = 0;
|
|
5
|
+
export let top = 0;
|
|
6
|
+
export let bottom = 0;
|
|
7
|
+
const targets = /* @__PURE__ */ new Set();
|
|
8
|
+
const draw = function({ width, height, ctx }, o) {
|
|
9
|
+
targets.forEach((f) => f.draw({ width, height, ctx }, {
|
|
10
|
+
x: o.x + left,
|
|
11
|
+
y: o.y + top,
|
|
12
|
+
w: o.x - left - right,
|
|
13
|
+
h: o.y - top - bottom
|
|
14
|
+
}));
|
|
15
|
+
};
|
|
16
|
+
let register = setupDrawable({
|
|
17
|
+
assign: (ctx) => {
|
|
18
|
+
targets.add(ctx);
|
|
19
|
+
return () => {
|
|
20
|
+
targets.delete(ctx);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
onMount(() => {
|
|
25
|
+
return register({ draw });
|
|
26
|
+
});
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<slot/>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: {
|
|
4
|
+
left?: number | undefined;
|
|
5
|
+
right?: number | undefined;
|
|
6
|
+
top?: number | undefined;
|
|
7
|
+
bottom?: number | undefined;
|
|
8
|
+
};
|
|
9
|
+
events: {
|
|
10
|
+
[evt: string]: CustomEvent<any>;
|
|
11
|
+
};
|
|
12
|
+
slots: {
|
|
13
|
+
default: {};
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export type InsetProps = typeof __propDef.props;
|
|
17
|
+
export type InsetEvents = typeof __propDef.events;
|
|
18
|
+
export type InsetSlots = typeof __propDef.slots;
|
|
19
|
+
export default class Inset extends SvelteComponent<InsetProps, InsetEvents, InsetSlots> {
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<script>import { setupDrawable } from "../drawable.js";
|
|
2
|
+
import { onMount } from "svelte";
|
|
3
|
+
export let x;
|
|
4
|
+
export let y;
|
|
5
|
+
const targets = /* @__PURE__ */ new Set();
|
|
6
|
+
const draw = function({ width, height, ctx }) {
|
|
7
|
+
targets.forEach((f) => f.draw({ width, height, ctx }, { x, y }));
|
|
8
|
+
};
|
|
9
|
+
let register = setupDrawable({
|
|
10
|
+
assign: (ctx) => {
|
|
11
|
+
targets.add(ctx);
|
|
12
|
+
return () => {
|
|
13
|
+
targets.delete(ctx);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
onMount(() => {
|
|
18
|
+
return register({ draw });
|
|
19
|
+
});
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<slot/>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
};
|
|
7
|
+
events: {
|
|
8
|
+
[evt: string]: CustomEvent<any>;
|
|
9
|
+
};
|
|
10
|
+
slots: {
|
|
11
|
+
default: {};
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export type NodeProps = typeof __propDef.props;
|
|
15
|
+
export type NodeEvents = typeof __propDef.events;
|
|
16
|
+
export type NodeSlots = typeof __propDef.slots;
|
|
17
|
+
export default class Node extends SvelteComponent<NodeProps, NodeEvents, NodeSlots> {
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<script>import { setupDrawable } from "../drawable.js";
|
|
2
|
+
import { onMount } from "svelte";
|
|
3
|
+
export let opacity;
|
|
4
|
+
const targets = /* @__PURE__ */ new Set();
|
|
5
|
+
const draw = function({ width, height, ctx }, offset) {
|
|
6
|
+
if (opacity <= 0)
|
|
7
|
+
return;
|
|
8
|
+
ctx.globalAlpha = Math.min(opacity, 1);
|
|
9
|
+
targets.forEach((f) => f.draw({ width, height, ctx }, offset));
|
|
10
|
+
ctx.globalAlpha = 1;
|
|
11
|
+
};
|
|
12
|
+
let register = setupDrawable({
|
|
13
|
+
assign: (ctx) => {
|
|
14
|
+
targets.add(ctx);
|
|
15
|
+
return () => {
|
|
16
|
+
targets.delete(ctx);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
onMount(() => {
|
|
21
|
+
return register({ draw });
|
|
22
|
+
});
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<slot/>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: {
|
|
4
|
+
opacity: number;
|
|
5
|
+
};
|
|
6
|
+
events: {
|
|
7
|
+
[evt: string]: CustomEvent<any>;
|
|
8
|
+
};
|
|
9
|
+
slots: {
|
|
10
|
+
default: {};
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export type OpacityProps = typeof __propDef.props;
|
|
14
|
+
export type OpacityEvents = typeof __propDef.events;
|
|
15
|
+
export type OpacitySlots = typeof __propDef.slots;
|
|
16
|
+
export default class Opacity extends SvelteComponent<OpacityProps, OpacityEvents, OpacitySlots> {
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
<script>import { setupDrawable } from "../drawable";
|
|
1
|
+
<script>import { setupDrawable } from "../drawable.js";
|
|
2
2
|
import { onMount } from "svelte";
|
|
3
3
|
export let centered = false;
|
|
4
|
-
export let degrees
|
|
4
|
+
export let degrees;
|
|
5
5
|
const targets = /* @__PURE__ */ new Set();
|
|
6
6
|
const draw = function({ width, height, ctx }, { x, y, w, h }) {
|
|
7
7
|
ctx.translate(x, y);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<script>import { setupDrawable } from "../drawable.js";
|
|
2
|
+
import { onMount } from "svelte";
|
|
3
|
+
export let x;
|
|
4
|
+
export let y;
|
|
5
|
+
const targets = /* @__PURE__ */ new Set();
|
|
6
|
+
const draw = function({ width, height, ctx }, offset) {
|
|
7
|
+
targets.forEach((f) => f.draw({ width, height, ctx }, { x: offset.x + x, y: offset.y + y }));
|
|
8
|
+
};
|
|
9
|
+
let register = setupDrawable({
|
|
10
|
+
assign: (ctx) => {
|
|
11
|
+
targets.add(ctx);
|
|
12
|
+
return () => {
|
|
13
|
+
targets.delete(ctx);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
onMount(() => {
|
|
18
|
+
return register({ draw });
|
|
19
|
+
});
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<slot/>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
};
|
|
7
|
+
events: {
|
|
8
|
+
[evt: string]: CustomEvent<any>;
|
|
9
|
+
};
|
|
10
|
+
slots: {
|
|
11
|
+
default: {};
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export type TranslateProps = typeof __propDef.props;
|
|
15
|
+
export type TranslateEvents = typeof __propDef.events;
|
|
16
|
+
export type TranslateSlots = typeof __propDef.slots;
|
|
17
|
+
export default class Translate extends SvelteComponent<TranslateProps, TranslateEvents, TranslateSlots> {
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { default as Empty } from "./primitives/Empty.svelte";
|
|
2
|
+
export { default as Node } from "./primitives/Node.svelte";
|
|
3
|
+
export { default as Area } from "./primitives/Area.svelte";
|
|
4
|
+
export { default as Translate } from "./primitives/Translate.svelte";
|
|
5
|
+
export { default as Inset } from "./primitives/Inset.svelte";
|
|
6
|
+
export { default as Opacity } from "./primitives/Opacity.svelte";
|
|
7
|
+
export { default as Rotate } from "./primitives/Rotate.svelte";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// BASE
|
|
2
|
+
export { default as Empty } from "./primitives/Empty.svelte";
|
|
3
|
+
export { default as Node } from "./primitives/Node.svelte";
|
|
4
|
+
export { default as Area } from "./primitives/Area.svelte";
|
|
5
|
+
export { default as Translate } from "./primitives/Translate.svelte";
|
|
6
|
+
export { default as Inset } from "./primitives/Inset.svelte";
|
|
7
|
+
export { default as Opacity } from "./primitives/Opacity.svelte";
|
|
8
|
+
export { default as Rotate } from "./primitives/Rotate.svelte";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { resolve as resolveImage } from "./resources/images.js";
|
|
2
|
+
export { useTileSet, getTile, type TileSet } from "./resources/tileset.js";
|
|
3
|
+
export { resolveBuffer as resolveAudioBuffer } from "./resources/audio.js";
|
|
4
|
+
export { default as AssetPool } from "./resources/AssetPool.svelte";
|
|
5
|
+
export { default as AudioBufferedAsset } from "./resources/AudioBufferedAsset.svelte";
|
|
6
|
+
export { default as AudioMediaAsset } from "./resources/AudioMediaAsset.svelte";
|
|
7
|
+
export { default as ImageAsset } from "./resources/ImageAsset.svelte";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// RESOURCES
|
|
2
|
+
export { resolve as resolveImage } from "./resources/images.js";
|
|
3
|
+
export { useTileSet, getTile } from "./resources/tileset.js";
|
|
4
|
+
export { resolveBuffer as resolveAudioBuffer } from "./resources/audio.js";
|
|
5
|
+
export { default as AssetPool } from "./resources/AssetPool.svelte";
|
|
6
|
+
export { default as AudioBufferedAsset } from "./resources/AudioBufferedAsset.svelte";
|
|
7
|
+
export { default as AudioMediaAsset } from "./resources/AudioMediaAsset.svelte";
|
|
8
|
+
export { default as ImageAsset } from "./resources/ImageAsset.svelte";
|
package/dist/scenes.d.ts
ADDED
package/dist/scenes.js
ADDED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hi-ashleyj/llama",
|
|
3
3
|
"description": "A (Very Incomplete) 2D Canvas Game Engine powered by Svelte",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.13.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "vite dev",
|
|
@@ -45,6 +45,18 @@
|
|
|
45
45
|
"./drawables": {
|
|
46
46
|
"types": "./dist/drawables/index.d.ts",
|
|
47
47
|
"svelte": "./dist/drawables/index.js"
|
|
48
|
+
},
|
|
49
|
+
"./primitives": {
|
|
50
|
+
"types": "./dist/primitives/index.d.ts",
|
|
51
|
+
"svelte": "./dist/primitives/index.js"
|
|
52
|
+
},
|
|
53
|
+
"./scenes": {
|
|
54
|
+
"types": "./dist/scenes.d.ts",
|
|
55
|
+
"svelte": "./dist/scenes.js"
|
|
56
|
+
},
|
|
57
|
+
"./resources": {
|
|
58
|
+
"types": "./dist/resources.d.ts",
|
|
59
|
+
"svelte": "./dist/resources.js"
|
|
48
60
|
}
|
|
49
61
|
},
|
|
50
62
|
"types": "./dist/index.d.ts"
|
package/dist/GameObject.svelte
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
<script>import { setupDrawable } from "./drawable.js";
|
|
2
|
-
import { onMount } from "svelte";
|
|
3
|
-
export let x = 0;
|
|
4
|
-
export let y = 0;
|
|
5
|
-
export let w = 0;
|
|
6
|
-
export let h = 0;
|
|
7
|
-
export let centered = false;
|
|
8
|
-
export let opacity = 1;
|
|
9
|
-
$:
|
|
10
|
-
ax = centered ? x - w / 2 : x;
|
|
11
|
-
$:
|
|
12
|
-
ay = centered ? y - h / 2 : y;
|
|
13
|
-
const targets = /* @__PURE__ */ new Set();
|
|
14
|
-
const draw = function({ width, height, ctx }) {
|
|
15
|
-
if (opacity <= 0)
|
|
16
|
-
return;
|
|
17
|
-
if (opacity < 1) {
|
|
18
|
-
ctx.globalAlpha = opacity;
|
|
19
|
-
}
|
|
20
|
-
targets.forEach((f) => f.draw({ width, height, ctx }, { x: ax, y: ay, w, h }));
|
|
21
|
-
if (opacity < 1) {
|
|
22
|
-
ctx.globalAlpha = 1;
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
let register = setupDrawable({
|
|
26
|
-
assign: (ctx) => {
|
|
27
|
-
targets.add(ctx);
|
|
28
|
-
return () => {
|
|
29
|
-
targets.delete(ctx);
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
onMount(() => {
|
|
34
|
-
return register({ draw });
|
|
35
|
-
});
|
|
36
|
-
</script>
|
|
37
|
-
|
|
38
|
-
<slot/>
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { SvelteComponent } from "svelte";
|
|
2
|
-
declare const __propDef: {
|
|
3
|
-
props: {
|
|
4
|
-
x?: number | undefined;
|
|
5
|
-
y?: number | undefined;
|
|
6
|
-
w?: number | undefined;
|
|
7
|
-
h?: number | undefined;
|
|
8
|
-
/**
|
|
9
|
-
* FALSE = ANCHOR TOP LEFT
|
|
10
|
-
* TRUE = ANCHOR CENTER
|
|
11
|
-
*/ centered?: boolean | undefined;
|
|
12
|
-
opacity?: number | undefined;
|
|
13
|
-
};
|
|
14
|
-
events: {
|
|
15
|
-
[evt: string]: CustomEvent<any>;
|
|
16
|
-
};
|
|
17
|
-
slots: {
|
|
18
|
-
default: {};
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
export type GameObjectProps = typeof __propDef.props;
|
|
22
|
-
export type GameObjectEvents = typeof __propDef.events;
|
|
23
|
-
export type GameObjectSlots = typeof __propDef.slots;
|
|
24
|
-
export default class GameObject extends SvelteComponent<GameObjectProps, GameObjectEvents, GameObjectSlots> {
|
|
25
|
-
}
|
|
26
|
-
export {};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|