@hi-ashleyj/llama 0.3.5 → 0.5.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/components/GameObject.svelte +9 -0
- package/components/GameObject.svelte.d.ts +1 -0
- package/components/drawables/MultiLineText.svelte +43 -0
- package/components/drawables/MultiLineText.svelte.d.ts +24 -0
- package/components/drawables/index.d.ts +1 -0
- package/components/drawables/index.js +1 -0
- package/package.json +2 -1
|
@@ -9,11 +9,20 @@ export let h = 0;
|
|
|
9
9
|
* TRUE = ANCHOR CENTER
|
|
10
10
|
*/
|
|
11
11
|
export let centered = false;
|
|
12
|
+
export let opacity = 1;
|
|
12
13
|
$: ax = (centered) ? x - (w / 2) : x;
|
|
13
14
|
$: ay = (centered) ? y - (h / 2) : y;
|
|
14
15
|
const targets = new Set();
|
|
15
16
|
const draw = function ({ width, height, ctx }) {
|
|
17
|
+
if (opacity <= 0)
|
|
18
|
+
return;
|
|
19
|
+
if (opacity < 1) {
|
|
20
|
+
ctx.globalAlpha = opacity;
|
|
21
|
+
}
|
|
16
22
|
targets.forEach(f => f.draw({ width, height, ctx }, { x: ax, y: ay, w, h }));
|
|
23
|
+
if (opacity < 1) {
|
|
24
|
+
ctx.globalAlpha = 1;
|
|
25
|
+
}
|
|
17
26
|
};
|
|
18
27
|
let register = setupDrawable({
|
|
19
28
|
assign: (ctx) => {
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
<script>import { setupDrawable } from "../../setup";
|
|
2
|
+
import { onMount } from "svelte";
|
|
3
|
+
export let text;
|
|
4
|
+
export let size;
|
|
5
|
+
export let spacing = 1.4;
|
|
6
|
+
export let font;
|
|
7
|
+
export let style = undefined;
|
|
8
|
+
export let fill = undefined;
|
|
9
|
+
export let stroke = undefined;
|
|
10
|
+
export let alignH = "left";
|
|
11
|
+
export let alignV = "top";
|
|
12
|
+
$: computedFont = (style ? style + " " : "") + size + "px " + font;
|
|
13
|
+
$: splits = text?.split("\n") || [];
|
|
14
|
+
$: offset =
|
|
15
|
+
alignV === "bottom"
|
|
16
|
+
? ((splits?.length || 1) - 1) * size * spacing
|
|
17
|
+
: alignV === "middle"
|
|
18
|
+
? ((splits?.length || 1) - 1) * size * spacing * 0.5
|
|
19
|
+
: 0;
|
|
20
|
+
const draw = function ({ ctx }, { x, y }) {
|
|
21
|
+
if (!splits)
|
|
22
|
+
return;
|
|
23
|
+
for (let i = 0; i < splits.length; i++) {
|
|
24
|
+
const line = splits[i];
|
|
25
|
+
ctx.beginPath();
|
|
26
|
+
ctx.textAlign = alignH;
|
|
27
|
+
ctx.textBaseline = alignV;
|
|
28
|
+
ctx.font = computedFont;
|
|
29
|
+
if (fill) {
|
|
30
|
+
ctx.fillStyle = fill;
|
|
31
|
+
ctx.fillText(line, x, y + size * spacing * i - offset);
|
|
32
|
+
}
|
|
33
|
+
if (stroke) {
|
|
34
|
+
ctx.strokeStyle = stroke;
|
|
35
|
+
ctx.strokeText(line, x, y + size * spacing * i - offset);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
let register = setupDrawable({});
|
|
40
|
+
onMount(() => {
|
|
41
|
+
return register({ draw });
|
|
42
|
+
});
|
|
43
|
+
</script>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { SvelteComponentTyped } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: {
|
|
4
|
+
text: string;
|
|
5
|
+
size: number;
|
|
6
|
+
spacing?: number | undefined;
|
|
7
|
+
font: string;
|
|
8
|
+
style?: string | undefined;
|
|
9
|
+
fill?: string | undefined;
|
|
10
|
+
stroke?: string | undefined;
|
|
11
|
+
alignH?: "left" | "center" | "right" | undefined;
|
|
12
|
+
alignV?: "top" | "middle" | "bottom" | "alphabetic" | undefined;
|
|
13
|
+
};
|
|
14
|
+
events: {
|
|
15
|
+
[evt: string]: CustomEvent<any>;
|
|
16
|
+
};
|
|
17
|
+
slots: {};
|
|
18
|
+
};
|
|
19
|
+
export declare type MultiLineTextProps = typeof __propDef.props;
|
|
20
|
+
export declare type MultiLineTextEvents = typeof __propDef.events;
|
|
21
|
+
export declare type MultiLineTextSlots = typeof __propDef.slots;
|
|
22
|
+
export default class MultiLineText extends SvelteComponentTyped<MultiLineTextProps, MultiLineTextEvents, MultiLineTextSlots> {
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -3,3 +3,4 @@ export { default as Circle } from "./Circle.svelte";
|
|
|
3
3
|
export { default as Arc } from "./Arc.svelte";
|
|
4
4
|
export { default as DisplayImage } from "./DisplayImage.svelte";
|
|
5
5
|
export { default as Text } from "./Text.svelte";
|
|
6
|
+
export { default as MultiLineText } from "./MultiLineText.svelte";
|
|
@@ -3,3 +3,4 @@ export { default as Circle } from "./Circle.svelte";
|
|
|
3
3
|
export { default as Arc } from "./Arc.svelte";
|
|
4
4
|
export { default as DisplayImage } from "./DisplayImage.svelte";
|
|
5
5
|
export { default as Text } from "./Text.svelte";
|
|
6
|
+
export { default as MultiLineText } from "./MultiLineText.svelte";
|
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.5.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"./components/drawables/Arc.svelte": "./components/drawables/Arc.svelte",
|
|
33
33
|
"./components/drawables/Circle.svelte": "./components/drawables/Circle.svelte",
|
|
34
34
|
"./components/drawables/DisplayImage.svelte": "./components/drawables/DisplayImage.svelte",
|
|
35
|
+
"./components/drawables/MultiLineText.svelte": "./components/drawables/MultiLineText.svelte",
|
|
35
36
|
"./components/drawables/Rectangle.svelte": "./components/drawables/Rectangle.svelte",
|
|
36
37
|
"./components/drawables/Text.svelte": "./components/drawables/Text.svelte",
|
|
37
38
|
"./components/drawables": "./components/drawables/index.js",
|