refactor: TextContentParser & TextContentTyper

This commit is contained in:
unanmed 2025-09-11 23:02:39 +08:00
parent 24d9c63de3
commit b74c61b8ba
4 changed files with 669 additions and 585 deletions

View File

@ -1,7 +1,7 @@
import { DefaultProps, ElementLocator, Font } from '@motajs/render';
import { computed, defineComponent, reactive, ref } from 'vue';
import { Background, Selection } from './misc';
import { TextContent, TextContentExpose, TextContentProps } from './textbox';
import { TextContent, TextContentProps } from './textbox';
import { TextAlign } from './textboxTyper';
import { Page, PageExpose } from './page';
import { GameUI, IUIMountable, SetupComponentOptions } from '@motajs/system-ui';
@ -83,7 +83,6 @@ export const ConfirmBox = defineComponent<
ConfirmBoxEmits,
keyof ConfirmBoxEmits
>((props, { emit, attrs }) => {
const content = ref<TextContentExpose>();
const height = ref(200);
const selected = ref(props.defaultYes ? true : false);
const yesSize = ref<[number, number]>([0, 0]);
@ -151,7 +150,6 @@ export const ConfirmBox = defineComponent<
/>
<TextContent
{...attrs}
ref={content}
loc={contentLoc.value}
text={props.text}
width={props.width - pad.value * 2}

View File

@ -173,25 +173,26 @@ export const TextContent = defineComponent<
const renderContent = (canvas: MotaOffscreenCanvas2D) => {
const ctx = canvas.ctx;
ctx.textBaseline = 'top';
renderable.forEach(v => {
switch (v.type) {
for (const data of renderable) {
if (data.cut) break;
switch (data.type) {
case TextContentType.Text: {
if (v.text.length === 0) return;
ctx.fillStyle = v.fillStyle;
ctx.strokeStyle = v.strokeStyle;
ctx.font = v.font;
const text = v.text.slice(0, v.pointer);
if (data.text.length === 0) continue;
ctx.fillStyle = data.fillStyle;
ctx.strokeStyle = data.strokeStyle;
ctx.font = data.font;
const text = data.text.slice(0, data.pointer);
if (props.fill ?? true) {
ctx.fillText(text, v.x, v.y);
ctx.fillText(text, data.x, data.y);
}
if (props.stroke) {
ctx.strokeText(text, v.x, v.y);
ctx.strokeText(text, data.x, data.y);
}
break;
}
case TextContentType.Icon: {
const { renderable: r, x: dx, y: dy, width, height } = v;
const { renderable: r, x: dx, y: dy, width, height } = data;
const render = r.render;
const [x, y, w, h] = render[0];
const icon = r.autotile ? r.image[0] : r.image;
@ -199,7 +200,7 @@ export const TextContent = defineComponent<
break;
}
}
});
}
};
const renderFunc = (data: TyperRenderable[]) => {

View File

@ -95,6 +95,7 @@
"61": "Unexpected recursive call of $1.update?$2 in render function. Please ensure you have to do this, if you do, ignore this warn.",
"62": "Recursive fallback fonts in '$1'.",
"63": "Uncaught promise error in waiting box component. Error reason: $1",
"64": "Text node type and block type mismatch: '$1' vs '$2'",
"1001": "Item-detail extension needs 'floor-binder' and 'floor-damage' extension as dependency.",
"1101": "Cannot add new effect to point effect instance, for there's no more reserve space for it. Please increase the max count of the instance."
}