@rpgjs/client 5.0.0-beta.7 → 5.0.0-beta.8
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/CHANGELOG.md +14 -0
- package/dist/Game/Map.js +2 -1
- package/dist/Game/Map.js.map +1 -1
- package/dist/Game/Object.d.ts +17 -9
- package/dist/Game/Object.js +1 -12
- package/dist/Game/Object.js.map +1 -1
- package/dist/Gui/Gui.d.ts +17 -4
- package/dist/Gui/Gui.js +63 -33
- package/dist/Gui/Gui.js.map +1 -1
- package/dist/Gui/Gui.spec.d.ts +1 -0
- package/dist/Resource.js +1 -1
- package/dist/Resource.js.map +1 -1
- package/dist/RpgClient.d.ts +35 -2
- package/dist/RpgClientEngine.d.ts +41 -5
- package/dist/RpgClientEngine.js +43 -3
- package/dist/RpgClientEngine.js.map +1 -1
- package/dist/components/character.ce.js +225 -2
- package/dist/components/character.ce.js.map +1 -1
- package/dist/components/dynamics/bar.ce.js +96 -0
- package/dist/components/dynamics/bar.ce.js.map +1 -0
- package/dist/components/dynamics/image.ce.js +23 -0
- package/dist/components/dynamics/image.ce.js.map +1 -0
- package/dist/components/dynamics/parse-value.d.ts +3 -0
- package/dist/components/dynamics/parse-value.js +51 -35
- package/dist/components/dynamics/parse-value.js.map +1 -1
- package/dist/components/dynamics/parse-value.spec.d.ts +1 -0
- package/dist/components/dynamics/shape-utils.d.ts +16 -0
- package/dist/components/dynamics/shape-utils.js +73 -0
- package/dist/components/dynamics/shape-utils.js.map +1 -0
- package/dist/components/dynamics/shape-utils.spec.d.ts +1 -0
- package/dist/components/dynamics/shape.ce.js +83 -0
- package/dist/components/dynamics/shape.ce.js.map +1 -0
- package/dist/components/dynamics/text.ce.js +28 -41
- package/dist/components/dynamics/text.ce.js.map +1 -1
- package/dist/components/player-components-utils.d.ts +67 -0
- package/dist/components/player-components-utils.js +162 -0
- package/dist/components/player-components-utils.js.map +1 -0
- package/dist/components/player-components-utils.spec.d.ts +1 -0
- package/dist/components/player-components.ce.js +188 -0
- package/dist/components/player-components.ce.js.map +1 -0
- package/dist/core/setup.js.map +1 -1
- package/dist/module.js +3 -0
- package/dist/module.js.map +1 -1
- package/dist/node_modules/.pnpm/@signe_reactive@2.10.0/node_modules/@signe/reactive/dist/index.js +197 -3
- package/dist/node_modules/.pnpm/@signe_reactive@2.10.0/node_modules/@signe/reactive/dist/index.js.map +1 -1
- package/dist/node_modules/.pnpm/@signe_room@2.10.0/node_modules/@signe/room/dist/index.js +1 -1
- package/dist/services/loadMap.d.ts +6 -0
- package/dist/services/loadMap.js.map +1 -1
- package/package.json +4 -4
- package/src/Game/Map.ts +12 -2
- package/src/Game/Object.ts +22 -35
- package/src/Gui/Gui.spec.ts +273 -0
- package/src/Gui/Gui.ts +105 -50
- package/src/Resource.ts +1 -2
- package/src/RpgClient.ts +36 -2
- package/src/RpgClientEngine.ts +64 -10
- package/src/components/character.ce +281 -1
- package/src/components/dynamics/bar.ce +87 -0
- package/src/components/dynamics/image.ce +20 -0
- package/src/components/dynamics/parse-value.spec.ts +41 -0
- package/src/components/dynamics/parse-value.ts +102 -37
- package/src/components/dynamics/shape-utils.spec.ts +46 -0
- package/src/components/dynamics/shape-utils.ts +61 -0
- package/src/components/dynamics/shape.ce +89 -0
- package/src/components/dynamics/text.ce +34 -149
- package/src/components/player-components-utils.spec.ts +109 -0
- package/src/components/player-components-utils.ts +205 -0
- package/src/components/player-components.ce +221 -0
- package/src/core/setup.ts +2 -2
- package/src/module.ts +5 -1
- package/src/services/loadMap.ts +2 -0
- package/dist/node_modules/.pnpm/@signe_reactive@2.9.2/node_modules/@signe/reactive/dist/index.js +0 -227
- package/dist/node_modules/.pnpm/@signe_reactive@2.9.2/node_modules/@signe/reactive/dist/index.js.map +0 -1
|
@@ -1,44 +1,60 @@
|
|
|
1
1
|
import { computed } from "canvasengine";
|
|
2
2
|
//#region src/components/dynamics/parse-value.ts
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (
|
|
14
|
-
return
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
break;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
if (typeof currentValue === "function") currentValue = currentValue();
|
|
32
|
-
propertyValue = currentValue != null ? String(currentValue) : "";
|
|
33
|
-
} catch (error) {
|
|
34
|
-
propertyValue = "";
|
|
3
|
+
var readSignal = (value) => typeof value === "function" ? value() : value;
|
|
4
|
+
var DYNAMIC_VALUE_PATTERN = /\{([^}]+)\}/g;
|
|
5
|
+
var hasDynamicValue = (value) => {
|
|
6
|
+
value = readSignal(value);
|
|
7
|
+
if (typeof value !== "string") return false;
|
|
8
|
+
DYNAMIC_VALUE_PATTERN.lastIndex = 0;
|
|
9
|
+
return DYNAMIC_VALUE_PATTERN.test(value);
|
|
10
|
+
};
|
|
11
|
+
var resolveDynamicSnapshot = (value, object) => {
|
|
12
|
+
value = readSignal(value);
|
|
13
|
+
if (Array.isArray(value)) return value.map((entry) => resolveDynamicSnapshot(entry, object));
|
|
14
|
+
if (value && typeof value === "object") return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, resolveDynamicSnapshot(entry, object)]));
|
|
15
|
+
return resolveDynamicValue(value, object);
|
|
16
|
+
};
|
|
17
|
+
var getDynamicValue = (property, object) => {
|
|
18
|
+
try {
|
|
19
|
+
const propertyPath = property.split(".");
|
|
20
|
+
let currentValue = object;
|
|
21
|
+
for (let j = 0; j < propertyPath.length; j++) {
|
|
22
|
+
let prop = propertyPath[j];
|
|
23
|
+
currentValue = readSignal(currentValue);
|
|
24
|
+
if (j === 0) {
|
|
25
|
+
if (prop === "hp") prop = "hpSignal";
|
|
26
|
+
if (prop === "sp") prop = "spSignal";
|
|
27
|
+
if (prop === "param") prop = "_param";
|
|
35
28
|
}
|
|
36
|
-
|
|
29
|
+
if (currentValue && typeof currentValue === "object" && prop in currentValue) currentValue = currentValue[prop];
|
|
30
|
+
else return;
|
|
37
31
|
}
|
|
38
|
-
return
|
|
32
|
+
return readSignal(currentValue);
|
|
33
|
+
} catch (error) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var resolveDynamicValue = (value, object) => {
|
|
38
|
+
value = readSignal(value);
|
|
39
|
+
if (typeof value !== "string") return value;
|
|
40
|
+
return value.replace(DYNAMIC_VALUE_PATTERN, (fullMatch, property) => {
|
|
41
|
+
const propertyValue = getDynamicValue(property, object);
|
|
42
|
+
if (propertyValue == null && property.startsWith("$")) return fullMatch;
|
|
43
|
+
return propertyValue != null ? String(propertyValue) : "";
|
|
39
44
|
});
|
|
40
45
|
};
|
|
46
|
+
var resolveDynamicProp = (value, object) => {
|
|
47
|
+
if (Array.isArray(value) || value && typeof value === "object" && typeof value !== "function") return computed(() => resolveDynamicSnapshot(value, object));
|
|
48
|
+
if (typeof value === "function" || hasDynamicValue(value)) return computed(() => resolveDynamicValue(value, object));
|
|
49
|
+
return value;
|
|
50
|
+
};
|
|
51
|
+
var resolveDynamicProps = (props, object) => {
|
|
52
|
+
props = readSignal(props);
|
|
53
|
+
if (Array.isArray(props)) return computed(() => resolveDynamicSnapshot(props, object));
|
|
54
|
+
if (props && typeof props === "object") return Object.fromEntries(Object.entries(props).map(([key, value]) => [key, resolveDynamicProp(value, object)]));
|
|
55
|
+
return resolveDynamicProp(props, object);
|
|
56
|
+
};
|
|
41
57
|
//#endregion
|
|
42
|
-
export {
|
|
58
|
+
export { resolveDynamicProps, resolveDynamicValue };
|
|
43
59
|
|
|
44
60
|
//# sourceMappingURL=parse-value.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-value.js","names":[],"sources":["../../../src/components/dynamics/parse-value.ts"],"sourcesContent":["import { computed } from \"canvasengine\";\n\ninterface MatchResult {\n property: string;\n fullMatch: string;\n index: number;\n}\n\
|
|
1
|
+
{"version":3,"file":"parse-value.js","names":[],"sources":["../../../src/components/dynamics/parse-value.ts"],"sourcesContent":["import { computed } from \"canvasengine\";\n\ninterface MatchResult {\n property: string;\n fullMatch: string;\n index: number;\n}\n\nconst readSignal = (value: any) => typeof value === 'function' ? value() : value;\nconst DYNAMIC_VALUE_PATTERN = /\\{([^}]+)\\}/g;\n\nconst hasDynamicValue = (value: any) => {\n value = readSignal(value);\n if (typeof value !== 'string') return false;\n DYNAMIC_VALUE_PATTERN.lastIndex = 0;\n return DYNAMIC_VALUE_PATTERN.test(value);\n};\n\nconst resolveDynamicSnapshot = (value: any, object?: any): any => {\n value = readSignal(value);\n\n if (Array.isArray(value)) {\n return value.map((entry) => resolveDynamicSnapshot(entry, object));\n }\n\n if (value && typeof value === 'object') {\n return Object.fromEntries(\n Object.entries(value).map(([key, entry]) => [key, resolveDynamicSnapshot(entry, object)])\n );\n }\n\n return resolveDynamicValue(value, object);\n};\n\nexport const getDynamicValue = (property: string, object?: any) => {\n try {\n const propertyPath = property.split('.');\n let currentValue = object;\n\n for (let j = 0; j < propertyPath.length; j++) {\n let prop = propertyPath[j];\n\n currentValue = readSignal(currentValue);\n\n if (j === 0) {\n if (prop === 'hp') prop = 'hpSignal';\n if (prop === 'sp') prop = 'spSignal';\n if (prop === 'param') prop = '_param';\n }\n\n if (currentValue && typeof currentValue === 'object' && prop in currentValue) {\n currentValue = currentValue[prop];\n } else {\n return undefined;\n }\n }\n\n return readSignal(currentValue);\n } catch (error) {\n return undefined;\n }\n};\n\nexport const resolveDynamicValue = (value: any, object?: any): any => {\n value = readSignal(value);\n\n if (typeof value !== 'string') {\n return value;\n }\n\n return value.replace(DYNAMIC_VALUE_PATTERN, (fullMatch, property) => {\n const propertyValue = getDynamicValue(property, object);\n if (propertyValue == null && property.startsWith('$')) return fullMatch;\n return propertyValue != null ? String(propertyValue) : '';\n });\n};\n\nconst resolveDynamicProp = (value: any, object?: any): any => {\n if (Array.isArray(value) || (value && typeof value === 'object' && typeof value !== 'function')) {\n return computed(() => resolveDynamicSnapshot(value, object));\n }\n\n if (typeof value === 'function' || hasDynamicValue(value)) {\n return computed(() => resolveDynamicValue(value, object));\n }\n\n return value;\n};\n\nexport const resolveDynamicProps = (props: any, object?: any): any => {\n props = readSignal(props);\n\n if (Array.isArray(props)) {\n return computed(() => resolveDynamicSnapshot(props, object));\n }\n\n if (props && typeof props === 'object') {\n return Object.fromEntries(\n Object.entries(props).map(([key, value]) => [key, resolveDynamicProp(value, object)])\n );\n }\n\n return resolveDynamicProp(props, object);\n};\n\nexport const parseDynamicValue = (value: any, object?: any) => {\n if (typeof value !== 'string') {\n return computed(() => String(value ?? ''));\n }\n\n // Find all dynamic references like {propertyName}\n const matches: MatchResult[] = [];\n let match;\n\n DYNAMIC_VALUE_PATTERN.lastIndex = 0;\n while ((match = DYNAMIC_VALUE_PATTERN.exec(value)) !== null) {\n matches.push({\n property: match[1],\n fullMatch: match[0],\n index: match.index!\n });\n }\n\n // If no dynamic references found, return simple computed\n if (matches.length === 0) {\n return computed(() => value);\n }\n\n // Create computed that tracks all referenced signals\n return computed(() => {\n let result = value;\n \n // Replace from end to start to preserve indices\n for (let i = matches.length - 1; i >= 0; i--) {\n const { property, fullMatch } = matches[i];\n \n const currentValue = getDynamicValue(property, object);\n const propertyValue = currentValue != null ? String(currentValue) : property.startsWith('$') ? fullMatch : '';\n \n result = result.replace(fullMatch, propertyValue);\n }\n \n return result;\n });\n};\n"],"mappings":";;AAQA,IAAM,cAAc,UAAe,OAAO,UAAU,aAAa,OAAO,GAAG;AAC3E,IAAM,wBAAwB;AAE9B,IAAM,mBAAmB,UAAe;CACpC,QAAQ,WAAW,MAAM;CACzB,IAAI,OAAO,UAAU,UAAU,OAAO;CACtC,sBAAsB,YAAY;CAClC,OAAO,sBAAsB,KAAK,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AAO,CAAC;CAGhE,IAAI,OAAO,UAAU,cAAc,gBAAgB,MAAM,EACrD,OAAO,eAAe,oBAAoB,OAAO,OAAO,CAAC;CAG7D,OAAO;;AAGX,IAAa,uBAAuB,OAAY,WAAsB;CAClE,QAAQ,WAAW,MAAM;CAEzB,IAAI,MAAM,QAAQ,MAAM,EACpB,OAAO,eAAe,uBAAuB,OAAO,OAAO,CAAC;CAGhE,IAAI,SAAS,OAAO,UAAU,UAC1B,OAAO,OAAO,YACV,OAAO,QAAQ,MAAM,CAAC,KAAK,CAAC,KAAK,WAAW,CAAC,KAAK,mBAAmB,OAAO,OAAO,CAAC,CAAC,CACxF;CAGL,OAAO,mBAAmB,OAAO,OAAO"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare function getShapePointBounds(points?: any[], toNumber?: (value: any, fallback?: number) => number): {
|
|
2
|
+
minX: number;
|
|
3
|
+
minY: number;
|
|
4
|
+
maxX: number;
|
|
5
|
+
maxY: number;
|
|
6
|
+
};
|
|
7
|
+
export declare function getShapeBox(cfg: any, toNumber?: (value: any, fallback?: number) => number): {
|
|
8
|
+
width: any;
|
|
9
|
+
height: any;
|
|
10
|
+
offsetX: number;
|
|
11
|
+
offsetY: number;
|
|
12
|
+
};
|
|
13
|
+
export declare function translatePolygonPoints(points: any[] | undefined, box: {
|
|
14
|
+
offsetX: number;
|
|
15
|
+
offsetY: number;
|
|
16
|
+
}, toNumber?: (value: any, fallback?: number) => number): number[];
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
//#region src/components/dynamics/shape-utils.ts
|
|
2
|
+
var defaultToNumber = (value, fallback = 0) => {
|
|
3
|
+
const num = typeof value === "number" ? value : parseFloat(value);
|
|
4
|
+
return Number.isFinite(num) ? num : fallback;
|
|
5
|
+
};
|
|
6
|
+
function getShapePointBounds(points = [], toNumber = defaultToNumber) {
|
|
7
|
+
if (!Array.isArray(points) || points.length < 2) return {
|
|
8
|
+
minX: 0,
|
|
9
|
+
minY: 0,
|
|
10
|
+
maxX: 1,
|
|
11
|
+
maxY: 1
|
|
12
|
+
};
|
|
13
|
+
let minX = Infinity;
|
|
14
|
+
let minY = Infinity;
|
|
15
|
+
let maxX = -Infinity;
|
|
16
|
+
let maxY = -Infinity;
|
|
17
|
+
for (let i = 0; i < points.length; i += 2) {
|
|
18
|
+
const x = toNumber(points[i], 0);
|
|
19
|
+
const y = toNumber(points[i + 1], 0);
|
|
20
|
+
minX = Math.min(minX, x);
|
|
21
|
+
minY = Math.min(minY, y);
|
|
22
|
+
maxX = Math.max(maxX, x);
|
|
23
|
+
maxY = Math.max(maxY, y);
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
minX,
|
|
27
|
+
minY,
|
|
28
|
+
maxX,
|
|
29
|
+
maxY
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function getShapeBox(cfg, toNumber = defaultToNumber) {
|
|
33
|
+
if (cfg.type === "circle") return {
|
|
34
|
+
width: cfg.radius * 2,
|
|
35
|
+
height: cfg.radius * 2,
|
|
36
|
+
offsetX: 0,
|
|
37
|
+
offsetY: 0
|
|
38
|
+
};
|
|
39
|
+
if (cfg.type === "line") {
|
|
40
|
+
const minX = Math.min(cfg.x1, cfg.x2);
|
|
41
|
+
const minY = Math.min(cfg.y1, cfg.y2);
|
|
42
|
+
const maxX = Math.max(cfg.x1, cfg.x2);
|
|
43
|
+
const maxY = Math.max(cfg.y1, cfg.y2);
|
|
44
|
+
return {
|
|
45
|
+
width: Math.max(1, maxX - minX),
|
|
46
|
+
height: Math.max(1, maxY - minY),
|
|
47
|
+
offsetX: -minX,
|
|
48
|
+
offsetY: -minY
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
if (cfg.type === "polygon") {
|
|
52
|
+
const bounds = getShapePointBounds(cfg.points, toNumber);
|
|
53
|
+
return {
|
|
54
|
+
width: Math.max(1, bounds.maxX - bounds.minX),
|
|
55
|
+
height: Math.max(1, bounds.maxY - bounds.minY),
|
|
56
|
+
offsetX: -bounds.minX,
|
|
57
|
+
offsetY: -bounds.minY
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
width: cfg.width,
|
|
62
|
+
height: cfg.height,
|
|
63
|
+
offsetX: 0,
|
|
64
|
+
offsetY: 0
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function translatePolygonPoints(points = [], box, toNumber = defaultToNumber) {
|
|
68
|
+
return points.map((point, index) => toNumber(point, 0) + (index % 2 === 0 ? box.offsetX : box.offsetY));
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
export { getShapeBox, translatePolygonPoints };
|
|
72
|
+
|
|
73
|
+
//# sourceMappingURL=shape-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shape-utils.js","names":[],"sources":["../../../src/components/dynamics/shape-utils.ts"],"sourcesContent":["const defaultToNumber = (value: any, fallback = 0) => {\n const num = typeof value === 'number' ? value : parseFloat(value);\n return Number.isFinite(num) ? num : fallback;\n};\n\nexport function getShapePointBounds(points: any[] = [], toNumber = defaultToNumber) {\n if (!Array.isArray(points) || points.length < 2) {\n return { minX: 0, minY: 0, maxX: 1, maxY: 1 };\n }\n\n let minX = Infinity;\n let minY = Infinity;\n let maxX = -Infinity;\n let maxY = -Infinity;\n\n for (let i = 0; i < points.length; i += 2) {\n const x = toNumber(points[i], 0);\n const y = toNumber(points[i + 1], 0);\n minX = Math.min(minX, x);\n minY = Math.min(minY, y);\n maxX = Math.max(maxX, x);\n maxY = Math.max(maxY, y);\n }\n\n return { minX, minY, maxX, maxY };\n}\n\nexport function getShapeBox(cfg: any, toNumber = defaultToNumber) {\n if (cfg.type === 'circle') {\n return { width: cfg.radius * 2, height: cfg.radius * 2, offsetX: 0, offsetY: 0 };\n }\n\n if (cfg.type === 'line') {\n const minX = Math.min(cfg.x1, cfg.x2);\n const minY = Math.min(cfg.y1, cfg.y2);\n const maxX = Math.max(cfg.x1, cfg.x2);\n const maxY = Math.max(cfg.y1, cfg.y2);\n return {\n width: Math.max(1, maxX - minX),\n height: Math.max(1, maxY - minY),\n offsetX: -minX,\n offsetY: -minY\n };\n }\n\n if (cfg.type === 'polygon') {\n const bounds = getShapePointBounds(cfg.points, toNumber);\n return {\n width: Math.max(1, bounds.maxX - bounds.minX),\n height: Math.max(1, bounds.maxY - bounds.minY),\n offsetX: -bounds.minX,\n offsetY: -bounds.minY\n };\n }\n\n return { width: cfg.width, height: cfg.height, offsetX: 0, offsetY: 0 };\n}\n\nexport function translatePolygonPoints(points: any[] = [], box: { offsetX: number; offsetY: number }, toNumber = defaultToNumber) {\n return points.map((point, index) => toNumber(point, 0) + (index % 2 === 0 ? box.offsetX : box.offsetY));\n}\n"],"mappings":";AAAA,IAAM,mBAAmB,OAAY,WAAW,MAAM;CACpD,MAAM,MAAM,OAAO,UAAU,WAAW,QAAQ,WAAW,MAAM;CACjE,OAAO,OAAO,SAAS,IAAI,GAAG,MAAM;;AAGtC,SAAgB,oBAAoB,SAAgB,EAAE,EAAE,WAAW,iBAAiB;CAClF,IAAI,CAAC,MAAM,QAAQ,OAAO,IAAI,OAAO,SAAS,GAC5C,OAAO;EAAE,MAAM;EAAG,MAAM;EAAG,MAAM;EAAG,MAAM;EAAG;CAG/C,IAAI,OAAO;CACX,IAAI,OAAO;CACX,IAAI,OAAO;CACX,IAAI,OAAO;CAEX,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK,GAAG;EACzC,MAAM,IAAI,SAAS,OAAO,IAAI,EAAE;EAChC,MAAM,IAAI,SAAS,OAAO,IAAI,IAAI,EAAE;EACpC,OAAO,KAAK,IAAI,MAAM,EAAE;EACxB,OAAO,KAAK,IAAI,MAAM,EAAE;EACxB,OAAO,KAAK,IAAI,MAAM,EAAE;EACxB,OAAO,KAAK,IAAI,MAAM,EAAE;;CAG1B,OAAO;EAAE;EAAM;EAAM;EAAM;EAAM;;AAGnC,SAAgB,YAAY,KAAU,WAAW,iBAAiB;CAChE,IAAI,IAAI,SAAS,UACf,OAAO;EAAE,OAAO,IAAI,SAAS;EAAG,QAAQ,IAAI,SAAS;EAAG,SAAS;EAAG,SAAS;EAAG;CAGlF,IAAI,IAAI,SAAS,QAAQ;EACvB,MAAM,OAAO,KAAK,IAAI,IAAI,IAAI,IAAI,GAAG;EACrC,MAAM,OAAO,KAAK,IAAI,IAAI,IAAI,IAAI,GAAG;EACrC,MAAM,OAAO,KAAK,IAAI,IAAI,IAAI,IAAI,GAAG;EACrC,MAAM,OAAO,KAAK,IAAI,IAAI,IAAI,IAAI,GAAG;EACrC,OAAO;GACL,OAAO,KAAK,IAAI,GAAG,OAAO,KAAK;GAC/B,QAAQ,KAAK,IAAI,GAAG,OAAO,KAAK;GAChC,SAAS,CAAC;GACV,SAAS,CAAC;GACX;;CAGH,IAAI,IAAI,SAAS,WAAW;EAC1B,MAAM,SAAS,oBAAoB,IAAI,QAAQ,SAAS;EACxD,OAAO;GACL,OAAO,KAAK,IAAI,GAAG,OAAO,OAAO,OAAO,KAAK;GAC7C,QAAQ,KAAK,IAAI,GAAG,OAAO,OAAO,OAAO,KAAK;GAC9C,SAAS,CAAC,OAAO;GACjB,SAAS,CAAC,OAAO;GAClB;;CAGH,OAAO;EAAE,OAAO,IAAI;EAAO,QAAQ,IAAI;EAAQ,SAAS;EAAG,SAAS;EAAG;;AAGzE,SAAgB,uBAAuB,SAAgB,EAAE,EAAE,KAA2C,WAAW,iBAAiB;CAChI,OAAO,OAAO,KAAK,OAAO,UAAU,SAAS,OAAO,EAAE,IAAI,QAAQ,MAAM,IAAI,IAAI,UAAU,IAAI,SAAS"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { resolveDynamicValue } from "./parse-value.js";
|
|
2
|
+
import { getShapeBox, translatePolygonPoints } from "./shape-utils.js";
|
|
3
|
+
import { Container, Graphics, computed, h, useDefineProps, useProps } from "canvasengine";
|
|
4
|
+
//#region src/components/dynamics/shape.ce
|
|
5
|
+
function component($$props) {
|
|
6
|
+
useProps($$props);
|
|
7
|
+
const props = useDefineProps($$props)();
|
|
8
|
+
const { object } = props;
|
|
9
|
+
const read = (prop, fallback) => prop ? prop() : fallback;
|
|
10
|
+
const toNumber = (value, fallback = 0) => {
|
|
11
|
+
const resolved = resolveDynamicValue(value, object);
|
|
12
|
+
const num = typeof resolved === "number" ? resolved : parseFloat(resolved);
|
|
13
|
+
return Number.isFinite(num) ? num : fallback;
|
|
14
|
+
};
|
|
15
|
+
const toColor = (value, fallback) => {
|
|
16
|
+
const resolved = resolveDynamicValue(value, object);
|
|
17
|
+
if (typeof resolved === "number") return resolved;
|
|
18
|
+
if (typeof resolved === "string" && resolved.startsWith("#")) return parseInt(resolved.slice(1), 16);
|
|
19
|
+
return resolved ?? fallback;
|
|
20
|
+
};
|
|
21
|
+
const config = computed(() => ({
|
|
22
|
+
type: read(props.type, "rectangle"),
|
|
23
|
+
fill: toColor(read(props.fill, "#ffffff"), 16777215),
|
|
24
|
+
radius: toNumber(read(props.radius, 8), 8),
|
|
25
|
+
width: toNumber(read(props.width, 16), 16),
|
|
26
|
+
height: toNumber(read(props.height, 16), 16),
|
|
27
|
+
x1: toNumber(read(props.x1, 0), 0),
|
|
28
|
+
y1: toNumber(read(props.y1, 0), 0),
|
|
29
|
+
x2: toNumber(read(props.x2, 16), 16),
|
|
30
|
+
y2: toNumber(read(props.y2, 0), 0),
|
|
31
|
+
opacity: Math.max(0, Math.min(1, toNumber(read(props.opacity, 1), 1))),
|
|
32
|
+
points: read(props.points, []),
|
|
33
|
+
line: read(props.line, null)
|
|
34
|
+
}));
|
|
35
|
+
const shapeBox = computed(() => getShapeBox(config(), toNumber));
|
|
36
|
+
const shapeWidth = computed(() => shapeBox().width);
|
|
37
|
+
const shapeHeight = computed(() => shapeBox().height);
|
|
38
|
+
const drawShape = (g) => {
|
|
39
|
+
const cfg = config();
|
|
40
|
+
const box = shapeBox();
|
|
41
|
+
if (cfg.type === "circle") g.circle(cfg.radius, cfg.radius, cfg.radius);
|
|
42
|
+
else if (cfg.type === "ellipse") g.ellipse(box.width / 2, box.height / 2, box.width / 2, box.height / 2);
|
|
43
|
+
else if (cfg.type === "line") {
|
|
44
|
+
g.moveTo(cfg.x1 + box.offsetX, cfg.y1 + box.offsetY);
|
|
45
|
+
g.lineTo(cfg.x2 + box.offsetX, cfg.y2 + box.offsetY);
|
|
46
|
+
} else if (cfg.type === "polygon" && Array.isArray(cfg.points)) g.poly(translatePolygonPoints(cfg.points, box, toNumber));
|
|
47
|
+
else if (cfg.type === "rounded-rectangle") g.roundRect(0, 0, box.width, box.height, toNumber(read(props.radius, 4), 4));
|
|
48
|
+
else g.rect(0, 0, box.width, box.height);
|
|
49
|
+
if (cfg.type === "line") {
|
|
50
|
+
const line = cfg.line ?? {};
|
|
51
|
+
g.stroke({
|
|
52
|
+
color: toColor(line.color, cfg.fill),
|
|
53
|
+
width: toNumber(line.width, 1),
|
|
54
|
+
alpha: toNumber(line.alpha, cfg.opacity)
|
|
55
|
+
});
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
g.fill({
|
|
59
|
+
color: cfg.fill,
|
|
60
|
+
alpha: cfg.opacity
|
|
61
|
+
});
|
|
62
|
+
if (cfg.line) g.stroke({
|
|
63
|
+
color: toColor(cfg.line.color, cfg.fill),
|
|
64
|
+
width: toNumber(cfg.line.width, 1),
|
|
65
|
+
alpha: toNumber(cfg.line.alpha, cfg.opacity)
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
return h(Container, {
|
|
69
|
+
width: shapeWidth,
|
|
70
|
+
height: shapeHeight,
|
|
71
|
+
minWidth: shapeWidth,
|
|
72
|
+
minHeight: shapeHeight
|
|
73
|
+
}, h(Graphics, {
|
|
74
|
+
width: shapeWidth,
|
|
75
|
+
height: shapeHeight,
|
|
76
|
+
draw: drawShape
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
var __ce_component = component;
|
|
80
|
+
//#endregion
|
|
81
|
+
export { __ce_component as default };
|
|
82
|
+
|
|
83
|
+
//# sourceMappingURL=shape.ce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shape.ce.js","names":[],"sources":["../../../src/components/dynamics/shape.ce"],"sourcesContent":["<Container width={shapeWidth} height={shapeHeight} minWidth={shapeWidth} minHeight={shapeHeight}>\n <Graphics width={shapeWidth} height={shapeHeight} draw={drawShape} />\n</Container>\n\n<script>\nimport { computed } from \"canvasengine\";\nimport { resolveDynamicValue } from \"./parse-value\";\nimport { getShapeBox, translatePolygonPoints } from \"./shape-utils\";\n\nconst props = defineProps();\nconst { object } = props;\n\nconst read = (prop, fallback) => prop ? prop() : fallback;\n\nconst toNumber = (value, fallback = 0) => {\n const resolved = resolveDynamicValue(value, object);\n const num = typeof resolved === 'number' ? resolved : parseFloat(resolved);\n return Number.isFinite(num) ? num : fallback;\n};\n\nconst toColor = (value, fallback) => {\n const resolved = resolveDynamicValue(value, object);\n if (typeof resolved === 'number') return resolved;\n if (typeof resolved === 'string' && resolved.startsWith('#')) {\n return parseInt(resolved.slice(1), 16);\n }\n return resolved ?? fallback;\n};\n\nconst config = computed(() => ({\n type: read(props.type, 'rectangle'),\n fill: toColor(read(props.fill, '#ffffff'), 0xffffff),\n radius: toNumber(read(props.radius, 8), 8),\n width: toNumber(read(props.width, 16), 16),\n height: toNumber(read(props.height, 16), 16),\n x1: toNumber(read(props.x1, 0), 0),\n y1: toNumber(read(props.y1, 0), 0),\n x2: toNumber(read(props.x2, 16), 16),\n y2: toNumber(read(props.y2, 0), 0),\n opacity: Math.max(0, Math.min(1, toNumber(read(props.opacity, 1), 1))),\n points: read(props.points, []),\n line: read(props.line, null)\n}));\n\nconst shapeBox = computed(() => getShapeBox(config(), toNumber));\n\nconst shapeWidth = computed(() => shapeBox().width);\nconst shapeHeight = computed(() => shapeBox().height);\n\nconst drawShape = (g) => {\n const cfg = config();\n const box = shapeBox();\n\n if (cfg.type === 'circle') {\n g.circle(cfg.radius, cfg.radius, cfg.radius);\n } else if (cfg.type === 'ellipse') {\n g.ellipse(box.width / 2, box.height / 2, box.width / 2, box.height / 2);\n } else if (cfg.type === 'line') {\n g.moveTo(cfg.x1 + box.offsetX, cfg.y1 + box.offsetY);\n g.lineTo(cfg.x2 + box.offsetX, cfg.y2 + box.offsetY);\n } else if (cfg.type === 'polygon' && Array.isArray(cfg.points)) {\n g.poly(translatePolygonPoints(cfg.points, box, toNumber));\n } else if (cfg.type === 'rounded-rectangle') {\n g.roundRect(0, 0, box.width, box.height, toNumber(read(props.radius, 4), 4));\n } else {\n g.rect(0, 0, box.width, box.height);\n }\n\n if (cfg.type === 'line') {\n const line = cfg.line ?? {};\n g.stroke({\n color: toColor(line.color, cfg.fill),\n width: toNumber(line.width, 1),\n alpha: toNumber(line.alpha, cfg.opacity)\n });\n return;\n }\n\n g.fill({ color: cfg.fill, alpha: cfg.opacity });\n\n if (cfg.line) {\n g.stroke({\n color: toColor(cfg.line.color, cfg.fill),\n width: toNumber(cfg.line.width, 1),\n alpha: toNumber(cfg.line.alpha, cfg.opacity)\n });\n }\n};\n</script>\n"],"mappings":";;;;AASM,SAAQ,UAAW,SAAE;CACR,SAAK,QAAA;CAElB,MAAQ,QAAA,eAAA,QAAmB,EAAA;;CAEjC,MAAM,QAAQ,MAAI,aAAe,OAAO,MAAE,GAAA;CAC1C,MAAE,YAAgB,OAAC,WAAA,MAAoB;EACrC,MAAM,WAAa,oBAAoB,OAAI,OAAU;EACrD,MAAO,MAAO,OAAA,aAAoB,WAAU,WAAA,WAAA,SAAA;EAC7C,OAAA,OAAA,SAAA,IAAA,GAAA,MAAA;;CAED,MAAM,WAAW,OAAO,aAAa;EACnC,MAAM,WAAW,oBAAoB,OAAO,OAAO;EACjD,IAAE,OAAO,aAAc,UACrB,OAAO;EACT,IAAA,OAAO,aAAiB,YAAW,SAAG,WAAA,IA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AS,aAAa,MAAK,QAAI,IAAQ,OAAA,EAChD,EAAC,KAAI,uBAAyB,IAAC,QAAM,KAAQ,SAAW,CAAC;OAExD,IAAI,IAAI,SAAS,qBACpB,EAAA,UAAc,GAAE,GAAI,IAAA,OAAW,IAAA,QAAQ,SAAa,KAAC,MAAM,QAAY,EAAE,EAAC,EAAA,CAAA;OAG9E,EAAA,KAAA,GAAA,GAAA,IAAA,OAAA,IAAA,OAAA;EAEE,IAAE,IAAI,SAAU,QAAO;GACvB,MAAU,OAAO,IAAI,QAAM,EAAA;GACzB,EAAA,OAAO;IACD,OAAC,QAAa,KAAM,OAAK,IAAK,KAAA;IAC9B,OAAC,SAAc,KAAM,OAAG,EAAA;IACxB,OAAC,SAAc,KAAM,OAAK,IAAA,QAAO;IACvC,CAAA;GACF;;;;;;EAGA,IAAI,IAAG,MAAA,EAAA,OAAA;GAED,OAAM,QAAA,IAAA,KAAA,OAAA,IAAA,KAAA;GACJ,OAAC,SAAA,IAAA,KAAA,OAAA,EAAA;GACD,OAAC,SAAY,IAAK,KAAO,OAAI,IAAK,QAAA;GACxC,CAAA;;CAIL,OADC,EAAA,WAAA;EAAA,OAAA;EAAA,QAAA;EAAA,UAAA;EAAA,WAAA;EAAA,EAAA,EAAA,UAAA;EAAA,OAAA;EAAA,QAAA;EAAA,MAAA;EAAA,CAAA,CACD"}
|
|
@@ -1,59 +1,46 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { resolveDynamicValue } from "./parse-value.js";
|
|
2
2
|
import { Text, computed, h, useDefineProps, useProps } from "canvasengine";
|
|
3
3
|
//#region src/components/dynamics/text.ce
|
|
4
4
|
function component($$props) {
|
|
5
5
|
useProps($$props);
|
|
6
|
-
const { object } = useDefineProps($$props)();
|
|
7
|
-
const
|
|
6
|
+
const { object, value, style } = useDefineProps($$props)();
|
|
7
|
+
const read = (prop, fallback) => prop ? prop() : fallback;
|
|
8
8
|
const parseNumericStyleValue = (value, object) => {
|
|
9
|
-
|
|
9
|
+
value = resolveDynamicValue(value, object);
|
|
10
|
+
if (value === void 0 || value === null) return void 0;
|
|
10
11
|
if (typeof value === "number") return value;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
return computed(() => {
|
|
14
|
-
const str = parsed();
|
|
15
|
-
const num = parseFloat(str);
|
|
16
|
-
return isNaN(num) ? 0 : num;
|
|
17
|
-
});
|
|
18
|
-
} else {
|
|
19
|
-
const num = parseFloat(value);
|
|
20
|
-
return isNaN(num) ? void 0 : num;
|
|
21
|
-
}
|
|
22
|
-
return value;
|
|
12
|
+
const num = parseFloat(value);
|
|
13
|
+
return isNaN(num) ? void 0 : num;
|
|
23
14
|
};
|
|
24
|
-
const
|
|
25
|
-
if (!
|
|
26
|
-
const style = component.style;
|
|
27
|
-
const result = {};
|
|
28
|
-
if (style.fill !== void 0) if (typeof style.fill === "string" && style.fill.includes("{")) result.color = parseDynamicValue(style.fill, object);
|
|
29
|
-
else result.color = style.fill;
|
|
30
|
-
if (style.fontSize !== void 0) {
|
|
31
|
-
const fontSizeValue = parseNumericStyleValue(style.fontSize, object);
|
|
32
|
-
if (fontSizeValue !== void 0) result.size = fontSizeValue;
|
|
33
|
-
}
|
|
34
|
-
if (style.fontFamily !== void 0) if (typeof style.fontFamily === "string" && style.fontFamily.includes("{")) result.fontFamily = parseDynamicValue(style.fontFamily, object);
|
|
35
|
-
else result.fontFamily = style.fontFamily;
|
|
15
|
+
const getTextStyle = (style) => {
|
|
16
|
+
if (!style) return {};
|
|
36
17
|
const textStyle = {};
|
|
37
|
-
if (style.fontStyle !== void 0)
|
|
38
|
-
|
|
39
|
-
if (style.
|
|
40
|
-
else if (typeof style.fontWeight === "number") textStyle.fontWeight = style.fontWeight;
|
|
41
|
-
else textStyle.fontWeight = style.fontWeight;
|
|
42
|
-
if (style.stroke !== void 0) if (typeof style.stroke === "string" && style.stroke.includes("{")) textStyle.stroke = parseDynamicValue(style.stroke, object);
|
|
43
|
-
else textStyle.stroke = style.stroke;
|
|
18
|
+
if (style.fontStyle !== void 0) textStyle.fontStyle = resolveDynamicValue(style.fontStyle, object);
|
|
19
|
+
if (style.fontWeight !== void 0) textStyle.fontWeight = resolveDynamicValue(style.fontWeight, object);
|
|
20
|
+
if (style.stroke !== void 0) textStyle.stroke = resolveDynamicValue(style.stroke, object);
|
|
44
21
|
if (style.opacity !== void 0) {
|
|
45
22
|
const opacityValue = parseNumericStyleValue(style.opacity, object);
|
|
46
23
|
if (opacityValue !== void 0) textStyle.opacity = opacityValue;
|
|
47
24
|
}
|
|
48
25
|
if (style.wordWrap !== void 0) textStyle.wordWrap = style.wordWrap;
|
|
49
|
-
if (style.align !== void 0)
|
|
50
|
-
|
|
51
|
-
if (Object.keys(textStyle).length > 0) result.style = textStyle;
|
|
52
|
-
return result;
|
|
26
|
+
if (style.align !== void 0) textStyle.align = resolveDynamicValue(style.align, object);
|
|
27
|
+
return textStyle;
|
|
53
28
|
};
|
|
54
29
|
return h(Text, {
|
|
55
|
-
text: computed(() =>
|
|
56
|
-
|
|
30
|
+
text: computed(() => String(resolveDynamicValue(read(value, ""), object) ?? "")),
|
|
31
|
+
color: computed(() => {
|
|
32
|
+
const currentStyle = read(style, {});
|
|
33
|
+
return currentStyle.fill !== void 0 ? resolveDynamicValue(currentStyle.fill, object) : void 0;
|
|
34
|
+
}),
|
|
35
|
+
size: computed(() => {
|
|
36
|
+
const currentStyle = read(style, {});
|
|
37
|
+
return currentStyle.fontSize !== void 0 ? parseNumericStyleValue(currentStyle.fontSize, object) : void 0;
|
|
38
|
+
}),
|
|
39
|
+
fontFamily: computed(() => {
|
|
40
|
+
const currentStyle = read(style, {});
|
|
41
|
+
return currentStyle.fontFamily !== void 0 ? resolveDynamicValue(currentStyle.fontFamily, object) : void 0;
|
|
42
|
+
}),
|
|
43
|
+
style: computed(() => getTextStyle(read(style, {})))
|
|
57
44
|
});
|
|
58
45
|
}
|
|
59
46
|
var __ce_component = component;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.ce.js","names":[],"sources":["../../../src/components/dynamics/text.ce"],"sourcesContent":["<Text text={
|
|
1
|
+
{"version":3,"file":"text.ce.js","names":[],"sources":["../../../src/components/dynamics/text.ce"],"sourcesContent":["<Text text={textValue} color={textColor} size={textSize} fontFamily={textFontFamily} style={textStyle} />\n\n<script>\nimport { computed } from \"canvasengine\";\nimport { resolveDynamicValue } from \"./parse-value\";\n\nconst { object, value, style } = defineProps();\n\nconst read = (prop, fallback) => prop ? prop() : fallback;\n\nconst parseNumericStyleValue = (value, object) => {\n value = resolveDynamicValue(value, object);\n if (value === undefined || value === null) return undefined;\n if (typeof value === 'number') return value;\n\n const num = parseFloat(value);\n return isNaN(num) ? undefined : num;\n};\n\nconst getTextStyle = (style) => {\n if (!style) return {};\n const textStyle = {};\n\n if (style.fontStyle !== undefined) {\n textStyle.fontStyle = resolveDynamicValue(style.fontStyle, object);\n }\n\n if (style.fontWeight !== undefined) {\n textStyle.fontWeight = resolveDynamicValue(style.fontWeight, object);\n }\n\n if (style.stroke !== undefined) {\n textStyle.stroke = resolveDynamicValue(style.stroke, object);\n }\n\n if (style.opacity !== undefined) {\n const opacityValue = parseNumericStyleValue(style.opacity, object);\n if (opacityValue !== undefined) {\n textStyle.opacity = opacityValue;\n }\n }\n\n if (style.wordWrap !== undefined) {\n textStyle.wordWrap = style.wordWrap;\n }\n\n if (style.align !== undefined) {\n textStyle.align = resolveDynamicValue(style.align, object);\n }\n\n return textStyle;\n};\n\nconst textValue = computed(() => String(resolveDynamicValue(read(value, ''), object) ?? ''));\nconst textColor = computed(() => {\n const currentStyle = read(style, {});\n return currentStyle.fill !== undefined ? resolveDynamicValue(currentStyle.fill, object) : undefined;\n});\nconst textSize = computed(() => {\n const currentStyle = read(style, {});\n return currentStyle.fontSize !== undefined ? parseNumericStyleValue(currentStyle.fontSize, object) : undefined;\n});\nconst textFontFamily = computed(() => {\n const currentStyle = read(style, {});\n return currentStyle.fontFamily !== undefined ? resolveDynamicValue(currentStyle.fontFamily, object) : und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uBAAA,aAAA,UAAA,OAAA,GAAA,KAAA;IAOF;EAAA,YALpC,eAAA;GACF,MAAM,eAAmB,KAAK,OAAE,EAAA,CAAA;GAC5B,OAAM,aAAc,eAAe,KAAA,IAAC,oBAAA,aAAA,YAAA,OAAA,GAAA,KAAA;IAGF;EAAA,OADpC,eAAA,aAAA,KAAA,OAAA,EAAA,CAAA,CAAA,CACoC;EAAA,CAC5B;;AAGJ,IAAA,iBAAA"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export declare const DEFAULT_HP_BAR_STYLE: {
|
|
2
|
+
fillColor: string;
|
|
3
|
+
};
|
|
4
|
+
export declare const DEFAULT_SP_BAR_STYLE: {
|
|
5
|
+
fillColor: string;
|
|
6
|
+
};
|
|
7
|
+
type NumberResolver = (value: any, fallback?: number) => number;
|
|
8
|
+
export declare function getPointBounds(points?: any[], toNumber?: NumberResolver): {
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
};
|
|
12
|
+
export declare function getComponentId(definition: any): any;
|
|
13
|
+
export declare function getComponentProps(definition: any): any;
|
|
14
|
+
export declare function estimateComponentSize(definition: any, { toNumber, estimateTextWidth }?: {
|
|
15
|
+
toNumber?: NumberResolver;
|
|
16
|
+
estimateTextWidth?: (value: any, style?: any) => number;
|
|
17
|
+
}): {
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
};
|
|
21
|
+
export declare function computeBlockSize({ position, layout, rowMetrics, gap, graphic, hitbox }: {
|
|
22
|
+
position: string;
|
|
23
|
+
layout?: any;
|
|
24
|
+
rowMetrics: Array<{
|
|
25
|
+
width: number;
|
|
26
|
+
height: number;
|
|
27
|
+
cells: any[];
|
|
28
|
+
}>;
|
|
29
|
+
gap?: {
|
|
30
|
+
row: number;
|
|
31
|
+
column: number;
|
|
32
|
+
};
|
|
33
|
+
graphic: {
|
|
34
|
+
width: number;
|
|
35
|
+
height: number;
|
|
36
|
+
};
|
|
37
|
+
hitbox: {
|
|
38
|
+
w: number;
|
|
39
|
+
h: number;
|
|
40
|
+
};
|
|
41
|
+
}): {
|
|
42
|
+
width: any;
|
|
43
|
+
height: any;
|
|
44
|
+
};
|
|
45
|
+
export declare function computeBlockPosition({ position, size, layout, graphic, hitbox }: {
|
|
46
|
+
position: string;
|
|
47
|
+
size: {
|
|
48
|
+
width: number;
|
|
49
|
+
height: number;
|
|
50
|
+
};
|
|
51
|
+
layout?: any;
|
|
52
|
+
graphic: {
|
|
53
|
+
left: number;
|
|
54
|
+
top: number;
|
|
55
|
+
right: number;
|
|
56
|
+
centerX: number;
|
|
57
|
+
centerY: number;
|
|
58
|
+
};
|
|
59
|
+
hitbox: {
|
|
60
|
+
w: number;
|
|
61
|
+
h: number;
|
|
62
|
+
};
|
|
63
|
+
}): {
|
|
64
|
+
x: number;
|
|
65
|
+
y: number;
|
|
66
|
+
};
|
|
67
|
+
export {};
|