mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-09-17 11:11:47 +08:00
refactor: TextContentParser & TextContentTyper
This commit is contained in:
parent
24d9c63de3
commit
b74c61b8ba
@ -1,7 +1,7 @@
|
|||||||
import { DefaultProps, ElementLocator, Font } from '@motajs/render';
|
import { DefaultProps, ElementLocator, Font } from '@motajs/render';
|
||||||
import { computed, defineComponent, reactive, ref } from 'vue';
|
import { computed, defineComponent, reactive, ref } from 'vue';
|
||||||
import { Background, Selection } from './misc';
|
import { Background, Selection } from './misc';
|
||||||
import { TextContent, TextContentExpose, TextContentProps } from './textbox';
|
import { TextContent, TextContentProps } from './textbox';
|
||||||
import { TextAlign } from './textboxTyper';
|
import { TextAlign } from './textboxTyper';
|
||||||
import { Page, PageExpose } from './page';
|
import { Page, PageExpose } from './page';
|
||||||
import { GameUI, IUIMountable, SetupComponentOptions } from '@motajs/system-ui';
|
import { GameUI, IUIMountable, SetupComponentOptions } from '@motajs/system-ui';
|
||||||
@ -83,7 +83,6 @@ export const ConfirmBox = defineComponent<
|
|||||||
ConfirmBoxEmits,
|
ConfirmBoxEmits,
|
||||||
keyof ConfirmBoxEmits
|
keyof ConfirmBoxEmits
|
||||||
>((props, { emit, attrs }) => {
|
>((props, { emit, attrs }) => {
|
||||||
const content = ref<TextContentExpose>();
|
|
||||||
const height = ref(200);
|
const height = ref(200);
|
||||||
const selected = ref(props.defaultYes ? true : false);
|
const selected = ref(props.defaultYes ? true : false);
|
||||||
const yesSize = ref<[number, number]>([0, 0]);
|
const yesSize = ref<[number, number]>([0, 0]);
|
||||||
@ -151,7 +150,6 @@ export const ConfirmBox = defineComponent<
|
|||||||
/>
|
/>
|
||||||
<TextContent
|
<TextContent
|
||||||
{...attrs}
|
{...attrs}
|
||||||
ref={content}
|
|
||||||
loc={contentLoc.value}
|
loc={contentLoc.value}
|
||||||
text={props.text}
|
text={props.text}
|
||||||
width={props.width - pad.value * 2}
|
width={props.width - pad.value * 2}
|
||||||
|
@ -173,25 +173,26 @@ export const TextContent = defineComponent<
|
|||||||
const renderContent = (canvas: MotaOffscreenCanvas2D) => {
|
const renderContent = (canvas: MotaOffscreenCanvas2D) => {
|
||||||
const ctx = canvas.ctx;
|
const ctx = canvas.ctx;
|
||||||
ctx.textBaseline = 'top';
|
ctx.textBaseline = 'top';
|
||||||
renderable.forEach(v => {
|
for (const data of renderable) {
|
||||||
switch (v.type) {
|
if (data.cut) break;
|
||||||
|
switch (data.type) {
|
||||||
case TextContentType.Text: {
|
case TextContentType.Text: {
|
||||||
if (v.text.length === 0) return;
|
if (data.text.length === 0) continue;
|
||||||
ctx.fillStyle = v.fillStyle;
|
ctx.fillStyle = data.fillStyle;
|
||||||
ctx.strokeStyle = v.strokeStyle;
|
ctx.strokeStyle = data.strokeStyle;
|
||||||
ctx.font = v.font;
|
ctx.font = data.font;
|
||||||
const text = v.text.slice(0, v.pointer);
|
const text = data.text.slice(0, data.pointer);
|
||||||
|
|
||||||
if (props.fill ?? true) {
|
if (props.fill ?? true) {
|
||||||
ctx.fillText(text, v.x, v.y);
|
ctx.fillText(text, data.x, data.y);
|
||||||
}
|
}
|
||||||
if (props.stroke) {
|
if (props.stroke) {
|
||||||
ctx.strokeText(text, v.x, v.y);
|
ctx.strokeText(text, data.x, data.y);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TextContentType.Icon: {
|
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 render = r.render;
|
||||||
const [x, y, w, h] = render[0];
|
const [x, y, w, h] = render[0];
|
||||||
const icon = r.autotile ? r.image[0] : r.image;
|
const icon = r.autotile ? r.image[0] : r.image;
|
||||||
@ -199,7 +200,7 @@ export const TextContent = defineComponent<
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderFunc = (data: TyperRenderable[]) => {
|
const renderFunc = (data: TyperRenderable[]) => {
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -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.",
|
"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'.",
|
"62": "Recursive fallback fonts in '$1'.",
|
||||||
"63": "Uncaught promise error in waiting box component. Error reason: $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.",
|
"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."
|
"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."
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user