@hi-ashleyj/llama 0.3.2 → 0.3.4
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/components/Game.svelte +4 -4
- package/components/GameObject.svelte +11 -8
- package/components/Layer.svelte +5 -5
- package/components/drawables/Arc.svelte +1 -1
- package/components/drawables/Circle.svelte +1 -1
- package/components/drawables/DisplayImage.svelte +1 -1
- package/components/drawables/Rectangle.svelte +1 -1
- package/components/drawables/Text.svelte +1 -1
- package/components/resources/images.d.ts +1 -1
- package/components/resources/images.js +1 -1
- package/package.json +1 -1
- package/setup.d.ts +6 -2
- package/setup.js +4 -4
- package/types/contexts.d.ts +5 -6
package/components/Game.svelte
CHANGED
|
@@ -24,12 +24,12 @@ $: {
|
|
|
24
24
|
const layers = new Set();
|
|
25
25
|
const draw = function (delta, time) {
|
|
26
26
|
for (let layer of layers) {
|
|
27
|
-
layer(delta, time);
|
|
27
|
+
layer.draw(delta, time);
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
|
-
const assign = function (
|
|
31
|
-
layers.add(
|
|
32
|
-
return () => layers.delete(
|
|
30
|
+
const assign = function (ctx) {
|
|
31
|
+
layers.add(ctx);
|
|
32
|
+
return () => layers.delete(ctx);
|
|
33
33
|
};
|
|
34
34
|
const timing = new Timing();
|
|
35
35
|
const controller = new Controller();
|
|
@@ -12,17 +12,20 @@ export let centered = false;
|
|
|
12
12
|
$: ax = (centered) ? x - (w / 2) : x;
|
|
13
13
|
$: ay = (centered) ? y - (h / 2) : y;
|
|
14
14
|
const targets = new Set();
|
|
15
|
-
const assign = function (callable) {
|
|
16
|
-
targets.add(callable);
|
|
17
|
-
return () => { targets.delete(callable); };
|
|
18
|
-
};
|
|
19
15
|
const draw = function ({ width, height, ctx }) {
|
|
20
|
-
targets.forEach(f => f({ width, height, ctx }, { x: ax, y: ay, w, h }));
|
|
16
|
+
targets.forEach(f => f.draw({ width, height, ctx }, { x: ax, y: ay, w, h }));
|
|
21
17
|
};
|
|
22
|
-
let register = setupDrawable({
|
|
18
|
+
let register = setupDrawable({
|
|
19
|
+
assign: (ctx) => {
|
|
20
|
+
targets.add(ctx);
|
|
21
|
+
return () => {
|
|
22
|
+
targets.delete(ctx);
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
});
|
|
23
26
|
onMount(() => {
|
|
24
|
-
return register(draw);
|
|
27
|
+
return register({ draw });
|
|
25
28
|
});
|
|
26
29
|
</script>
|
|
27
30
|
|
|
28
|
-
<slot
|
|
31
|
+
<slot/>
|
package/components/Layer.svelte
CHANGED
|
@@ -8,17 +8,17 @@ const draw = () => {
|
|
|
8
8
|
if (ctx === null)
|
|
9
9
|
return;
|
|
10
10
|
ctx.clearRect(0, 0, $width, $height);
|
|
11
|
-
targets.forEach(f => f({ width: $width, height: $height, ctx }));
|
|
11
|
+
targets.forEach(f => f.draw({ width: $width, height: $height, ctx }));
|
|
12
12
|
};
|
|
13
13
|
let { width, height } = getGame();
|
|
14
14
|
let register = setupLayer({
|
|
15
|
-
assign: (
|
|
16
|
-
targets.add(
|
|
17
|
-
return () => { targets.delete(
|
|
15
|
+
assign: (ctx) => {
|
|
16
|
+
targets.add(ctx);
|
|
17
|
+
return () => { targets.delete(ctx); };
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
20
|
onMount(() => {
|
|
21
|
-
return register(draw);
|
|
21
|
+
return register({ draw });
|
|
22
22
|
});
|
|
23
23
|
</script>
|
|
24
24
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const resolve: (src:
|
|
1
|
+
export declare const resolve: (src: string) => HTMLImageElement;
|
package/package.json
CHANGED
package/setup.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type { GameContext, LayerContext, DrawableContext, DrawableFunction } from "./types";
|
|
2
2
|
export declare const setupGame: (context: GameContext) => void;
|
|
3
|
-
export declare const setupLayer: (context: LayerContext) => (draw:
|
|
4
|
-
|
|
3
|
+
export declare const setupLayer: (context: LayerContext) => ({ draw }: {
|
|
4
|
+
draw: () => any;
|
|
5
|
+
}) => () => any;
|
|
6
|
+
export declare const setupDrawable: ({ assign }: Partial<DrawableContext>) => ({ draw }: {
|
|
7
|
+
draw: () => DrawableFunction;
|
|
8
|
+
}) => () => any;
|
|
5
9
|
export declare const getGame: () => GameContext;
|
package/setup.js
CHANGED
|
@@ -17,8 +17,8 @@ export const setupLayer = function (context) {
|
|
|
17
17
|
throw new Error("Layers must be inside a Game");
|
|
18
18
|
setContext(LAYER, context);
|
|
19
19
|
setupDrawable({ assign: context.assign });
|
|
20
|
-
return (
|
|
21
|
-
return game.assign(
|
|
20
|
+
return (ctx) => {
|
|
21
|
+
return game.assign(ctx);
|
|
22
22
|
};
|
|
23
23
|
};
|
|
24
24
|
export const setupDrawable = function ({ assign }) {
|
|
@@ -26,10 +26,10 @@ export const setupDrawable = function ({ assign }) {
|
|
|
26
26
|
if (assign) {
|
|
27
27
|
setContext(DRAWABLE, { assign });
|
|
28
28
|
}
|
|
29
|
-
return (
|
|
29
|
+
return (ctx) => {
|
|
30
30
|
if (!parent)
|
|
31
31
|
return () => { };
|
|
32
|
-
return parent.assign(
|
|
32
|
+
return parent.assign(ctx);
|
|
33
33
|
};
|
|
34
34
|
};
|
|
35
35
|
export const getGame = function () {
|
package/types/contexts.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { Timing } from "../components/motions";
|
|
|
3
3
|
import { Controller } from "../components/controller";
|
|
4
4
|
|
|
5
5
|
export type GameContext = {
|
|
6
|
-
assign: (draw: Function) => () => any,
|
|
6
|
+
assign: (context: { draw: Function }) => () => any,
|
|
7
7
|
width: Writable<number>,
|
|
8
8
|
height: Writable<number>,
|
|
9
9
|
background: Writable<string>,
|
|
@@ -17,13 +17,12 @@ export type GameContext = {
|
|
|
17
17
|
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
export type LayerContext = {
|
|
21
|
-
assign: (draw: Function) => () => any
|
|
20
|
+
export type LayerContext = {
|
|
21
|
+
assign: (context: { draw: Function }) => () => any
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
export type DrawableFunction = ({}: { width: number, height: number, ctx: CanvasRenderingContext2D }, ...more: any[] ) => any;
|
|
25
25
|
|
|
26
|
-
export type DrawableContext = {
|
|
27
|
-
assign: (draw: Function) => () => any
|
|
28
|
-
draw: DrawableFunction
|
|
26
|
+
export type DrawableContext = {
|
|
27
|
+
assign: (context: { draw: Function }) => () => any
|
|
29
28
|
}
|