@hi-ashleyj/llama 0.7.0 → 0.8.1
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 +2 -0
- package/components/Layer.svelte +12 -2
- package/components/Layer.svelte.d.ts +1 -0
- package/components/mouse/MouseClickable.svelte +0 -1
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/setup.d.ts +4 -1
- package/setup.js +10 -0
- package/types/contexts.d.ts +2 -1
package/components/Game.svelte
CHANGED
package/components/Layer.svelte
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
<script>import { setupLayer, getGame } from "../setup";
|
|
2
2
|
import { onMount } from "svelte";
|
|
3
3
|
export let zIndex = 0;
|
|
4
|
+
export let staticMode = false;
|
|
5
|
+
let shouldRenderNextFrame = true;
|
|
4
6
|
let canvas;
|
|
5
7
|
$: ctx = (typeof canvas !== "undefined") ? canvas.getContext("2d") : null;
|
|
6
8
|
let targets = new Set();
|
|
@@ -15,10 +17,18 @@ let register = setupLayer({
|
|
|
15
17
|
assign: (ctx) => {
|
|
16
18
|
targets.add(ctx);
|
|
17
19
|
return () => { targets.delete(ctx); };
|
|
20
|
+
},
|
|
21
|
+
requestFrame: () => {
|
|
22
|
+
if (!staticMode)
|
|
23
|
+
return;
|
|
24
|
+
shouldRenderNextFrame = true;
|
|
18
25
|
}
|
|
19
26
|
});
|
|
20
27
|
onMount(() => {
|
|
21
|
-
return register({ draw
|
|
28
|
+
return register({ draw, isStatic: () => { if (shouldRenderNextFrame) {
|
|
29
|
+
shouldRenderNextFrame = false;
|
|
30
|
+
draw();
|
|
31
|
+
} return staticMode; } });
|
|
22
32
|
});
|
|
23
33
|
</script>
|
|
24
34
|
|
|
@@ -34,4 +44,4 @@ onMount(() => {
|
|
|
34
44
|
height: 100%;
|
|
35
45
|
object-fit: contain;
|
|
36
46
|
}
|
|
37
|
-
</style>
|
|
47
|
+
</style>
|
package/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { default as MouseLeftClick } from "./components/mouse/MouseLeftClick.sve
|
|
|
5
5
|
export { default as MouseClickable } from "./components/mouse/MouseClickable.svelte";
|
|
6
6
|
export { default as MouseEventArea } from "./components/mouse/MouseEventArea.svelte";
|
|
7
7
|
export * as drawables from "./components/drawables/index";
|
|
8
|
-
export { setupDrawable, getGame } from "./setup";
|
|
8
|
+
export { setupDrawable, getGame, getLayer, getTriggerLayerRender } from "./setup";
|
|
9
9
|
export { resolve as resolveImage } from "./components/resources/images";
|
|
10
10
|
export { CONTROLLER_ACTION } from "./components/controller";
|
|
11
11
|
export { MOUSE_ACTION } from "./components/mouse";
|
package/index.js
CHANGED
|
@@ -5,7 +5,7 @@ export { default as MouseLeftClick } from "./components/mouse/MouseLeftClick.sve
|
|
|
5
5
|
export { default as MouseClickable } from "./components/mouse/MouseClickable.svelte";
|
|
6
6
|
export { default as MouseEventArea } from "./components/mouse/MouseEventArea.svelte";
|
|
7
7
|
export * as drawables from "./components/drawables/index";
|
|
8
|
-
export { setupDrawable, getGame } from "./setup";
|
|
8
|
+
export { setupDrawable, getGame, getLayer, getTriggerLayerRender } from "./setup";
|
|
9
9
|
export { resolve as resolveImage } from "./components/resources/images";
|
|
10
10
|
export { CONTROLLER_ACTION } from "./components/controller";
|
|
11
11
|
export { MOUSE_ACTION } from "./components/mouse";
|
package/package.json
CHANGED
package/setup.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
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 }: {
|
|
3
|
+
export declare const setupLayer: (context: LayerContext) => ({ draw, isStatic }: {
|
|
4
4
|
draw: () => any;
|
|
5
|
+
isStatic: () => boolean;
|
|
5
6
|
}) => () => any;
|
|
7
|
+
export declare const getLayer: () => LayerContext;
|
|
8
|
+
export declare const getTriggerLayerRender: () => () => any;
|
|
6
9
|
export declare const setupDrawable: ({ assign }: Partial<DrawableContext>) => ({ draw }: {
|
|
7
10
|
draw: () => DrawableFunction;
|
|
8
11
|
}) => () => any;
|
package/setup.js
CHANGED
|
@@ -22,6 +22,16 @@ export const setupLayer = function (context) {
|
|
|
22
22
|
return game.assign(ctx);
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
|
+
export const getLayer = function () {
|
|
26
|
+
let layer = getContext(LAYER);
|
|
27
|
+
if (!layer)
|
|
28
|
+
throw new Error("Layer context does not exist!");
|
|
29
|
+
return layer;
|
|
30
|
+
};
|
|
31
|
+
export const getTriggerLayerRender = function () {
|
|
32
|
+
let layer = getLayer();
|
|
33
|
+
return layer.requestFrame;
|
|
34
|
+
};
|
|
25
35
|
export const setupDrawable = function ({ assign }) {
|
|
26
36
|
let parent = getContext(DRAWABLE);
|
|
27
37
|
if (assign) {
|
package/types/contexts.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { Controller } from "../components/controller";
|
|
|
4
4
|
import { Mouse } from "../components/mouse";
|
|
5
5
|
|
|
6
6
|
export type GameContext = {
|
|
7
|
-
assign: (context: { draw: Function }) => () => any,
|
|
7
|
+
assign: (context: { draw: Function, isStatic: () => boolean }) => () => any,
|
|
8
8
|
width: Writable<number>,
|
|
9
9
|
height: Writable<number>,
|
|
10
10
|
background: Writable<string>,
|
|
@@ -25,6 +25,7 @@ export type GameContext = {
|
|
|
25
25
|
|
|
26
26
|
export type LayerContext = {
|
|
27
27
|
assign: (context: { draw: Function }) => () => any
|
|
28
|
+
requestFrame: () => any;
|
|
28
29
|
};
|
|
29
30
|
|
|
30
31
|
export type DrawableFunction = ({}: { width: number, height: number, ctx: CanvasRenderingContext2D }, ...more: any[] ) => any;
|