mirror of
https://github.com/motajs/template.git
synced 2026-11-25 23:44:37 +08:00
refactor: 组件中的 ITextureManager 和 IMapRenderer 从 inject 中获取默认值
This commit is contained in:
1 parent
65b6b24b1f
commit
ba90ce6dac
16 files changed
+153
-83
No files matched your search
@@ -17,12 +17,12 @@ export interface BackgroundProps extends DefaultProps {
|
||||
border?: CanvasStyle;
|
||||
/** 非 `winskin` 模式下,圆角矩形的参数,默认为 [4] */
|
||||
circle?: RectRCircleParams;
|
||||
/** 使用的贴图管理器 */
|
||||
manager?: ITextureManager;
|
||||
/** 使用的贴图管理器,默认会使用主对象上的贴图管理器 */
|
||||
materials?: ITextureManager;
|
||||
}
|
||||
|
||||
const backgroundProps = {
|
||||
props: ['winskin', 'borderWidth', 'color', 'border', 'manager', 'circle']
|
||||
props: ['winskin', 'borderWidth', 'color', 'border', 'materials', 'circle']
|
||||
} satisfies SetupComponentOptions<BackgroundProps>;
|
||||
|
||||
/**
|
||||
@@ -41,7 +41,7 @@ export const Background = defineComponent<BackgroundProps>(props => {
|
||||
isWinskin.value ? (
|
||||
<Winskin
|
||||
winskin={props.winskin}
|
||||
manager={props.manager}
|
||||
materials={props.materials}
|
||||
borderSize={props.borderWidth}
|
||||
noanti
|
||||
/>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { DefaultProps } from '@motajs/render-vue';
|
||||
import { SetupComponentOptions } from '@motajs/system';
|
||||
import { computed, defineComponent, markRaw } from 'vue';
|
||||
import { computed, defineComponent, inject, markRaw } from 'vue';
|
||||
import { IMaterialFramedData, ITextureManager } from '../material';
|
||||
import { isNil } from 'lodash-es';
|
||||
import { ITexture, TextureRowAnimater } from '@motajs/render';
|
||||
@@ -8,8 +8,8 @@ import { ITexture, TextureRowAnimater } from '@motajs/render';
|
||||
export interface IIconProps extends DefaultProps {
|
||||
/** 当前显示的图标 */
|
||||
icon?: number | string;
|
||||
/** 贴图管理器 */
|
||||
manager?: ITextureManager;
|
||||
/** 贴图管理器,默认会使用主对象上的贴图管理器 */
|
||||
materials?: ITextureManager;
|
||||
/** 是否播放图块动画 */
|
||||
animate?: boolean;
|
||||
/** 展示图块指定帧数的动画,传入时会忽略 `animate` 的动画 */
|
||||
@@ -17,20 +17,23 @@ export interface IIconProps extends DefaultProps {
|
||||
}
|
||||
|
||||
const iconProps = {
|
||||
props: ['icon', 'manager', 'animate', 'frame']
|
||||
props: ['icon', 'materials', 'animate', 'frame']
|
||||
} satisfies SetupComponentOptions<IIconProps>;
|
||||
|
||||
export const Icon = defineComponent<IIconProps>(props => {
|
||||
const animater = markRaw(new TextureRowAnimater());
|
||||
const defaultMaterials = inject<ITextureManager>('@default/materials');
|
||||
|
||||
/** 贴图管理器 */
|
||||
const materials = computed(() => props.materials ?? defaultMaterials);
|
||||
/** 图块的渲染数据 */
|
||||
const data = computed<IMaterialFramedData | null>(() => {
|
||||
if (!props.manager) return null;
|
||||
if (!materials.value) return null;
|
||||
const icon = props.icon ?? 0;
|
||||
if (typeof icon === 'number') {
|
||||
return props.manager.getTile(icon);
|
||||
return materials.value.getTile(icon);
|
||||
} else {
|
||||
return props.manager.getTileByAlias(icon);
|
||||
return materials.value.getTileByAlias(icon);
|
||||
}
|
||||
});
|
||||
/** 图块的完整贴图 */
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import {
|
||||
ElementLocator,
|
||||
CustomRenderItem,
|
||||
MotaOffscreenCanvas2D,
|
||||
CanvasStyle,
|
||||
RectRCircleParams
|
||||
@@ -12,7 +11,7 @@ import {
|
||||
onExcitedFunc,
|
||||
PathProps
|
||||
} from '@motajs/render-vue';
|
||||
import { computed, defineComponent, ref, watch } from 'vue';
|
||||
import { computed, defineComponent, inject, ref, watch } from 'vue';
|
||||
import { TextContent, TextContentProps } from './textbox';
|
||||
import { Scroll, ScrollExpose, ScrollProps } from './scroll';
|
||||
import { SetupComponentOptions } from '@motajs/system';
|
||||
@@ -21,10 +20,8 @@ import { cosh, CurveMode } from '@motajs/animate';
|
||||
import { ITextureManager } from '../material';
|
||||
|
||||
interface ProgressProps extends DefaultProps {
|
||||
/** 进度条的位置 */
|
||||
loc: ElementLocator;
|
||||
/** 进度条的进度,1表示完成,0表示未完成 */
|
||||
progress: number;
|
||||
progress?: number;
|
||||
/** 已完成部分的样式,默认为绿色(green) */
|
||||
success?: CanvasStyle;
|
||||
/** 未完成部分的样式,默认为灰色(gray) */
|
||||
@@ -48,36 +45,47 @@ const progressProps = {
|
||||
* ```
|
||||
*/
|
||||
export const Progress = defineComponent<ProgressProps>(props => {
|
||||
const element = ref<CustomRenderItem>();
|
||||
/** 当前的进度条值 */
|
||||
const progress = computed(() => props.progress ?? 0);
|
||||
/** 进度条线宽 */
|
||||
const lineWidth = computed(() => props.lineWidth ?? 2);
|
||||
/** 未完成部分的颜色 */
|
||||
const background = computed(() => props.background ?? 'gray');
|
||||
/** 已完成部分的颜色 */
|
||||
const success = computed(() => props.success ?? 'green');
|
||||
|
||||
const render = (canvas: MotaOffscreenCanvas2D) => {
|
||||
const { ctx, width, height } = canvas;
|
||||
const lw = lineWidth.value;
|
||||
ctx.lineCap = 'round';
|
||||
const lineWidth = props.lineWidth ?? 2;
|
||||
ctx.lineWidth = lineWidth;
|
||||
ctx.strokeStyle = props.background ?? 'gray';
|
||||
ctx.lineWidth = lw;
|
||||
ctx.strokeStyle = background.value;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(lineWidth, height / 2);
|
||||
ctx.lineTo(width - lineWidth, height / 2);
|
||||
ctx.moveTo(lw, height / 2);
|
||||
ctx.lineTo(width - lw, height / 2);
|
||||
ctx.stroke();
|
||||
const progress = clamp(props.progress, 0, 1);
|
||||
if (!isNaN(progress)) {
|
||||
ctx.strokeStyle = props.success ?? 'green';
|
||||
const p = lineWidth + (width - lineWidth * 2) * progress;
|
||||
const p = clamp(progress.value, 0, 1);
|
||||
if (!isNaN(p)) {
|
||||
ctx.strokeStyle = success.value;
|
||||
const px = lw + (width - lw * 2) * p;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(lineWidth, height / 2);
|
||||
ctx.lineTo(p, height / 2);
|
||||
ctx.moveTo(lw, height / 2);
|
||||
ctx.lineTo(px, height / 2);
|
||||
ctx.stroke();
|
||||
}
|
||||
};
|
||||
|
||||
watch(props, () => {
|
||||
element.value?.update();
|
||||
});
|
||||
|
||||
return () => {
|
||||
return <custom ref={element} render={render}></custom>;
|
||||
};
|
||||
return () => (
|
||||
<custom
|
||||
render={render}
|
||||
bindings={[
|
||||
progress.value,
|
||||
lineWidth.value,
|
||||
background.value,
|
||||
success.value
|
||||
]}
|
||||
></custom>
|
||||
);
|
||||
}, progressProps);
|
||||
|
||||
export interface ArrowProps extends PathProps {
|
||||
@@ -264,6 +272,8 @@ export const ScrollText = defineComponent<
|
||||
lastFixedPos = 0;
|
||||
};
|
||||
|
||||
watch(() => props.speed, setSpeed);
|
||||
|
||||
expose<ScrollTextExpose>({ pause, resume, setSpeed, rescroll });
|
||||
|
||||
return () => (
|
||||
@@ -294,8 +304,8 @@ export interface SelectionProps extends DefaultProps {
|
||||
winskin?: string;
|
||||
/** 边框宽度,默认为 2 */
|
||||
borderSize?: number;
|
||||
/** winskin 使用的贴图管理器 */
|
||||
manager?: ITextureManager;
|
||||
/** winskin 使用的贴图管理器,默认会使用主对象上的贴图管理器 */
|
||||
materials?: ITextureManager;
|
||||
/** 选择图标的不透明度范围 */
|
||||
alphaRange?: [number, number];
|
||||
}
|
||||
@@ -307,7 +317,7 @@ const selectionProps = {
|
||||
'circle',
|
||||
'winskin',
|
||||
'borderSize',
|
||||
'manager',
|
||||
'materials',
|
||||
'alphaRange'
|
||||
]
|
||||
} satisfies SetupComponentOptions<SelectionProps>;
|
||||
@@ -322,7 +332,9 @@ const selectionProps = {
|
||||
* ```
|
||||
*/
|
||||
export const Selection = defineComponent<SelectionProps>(props => {
|
||||
/** 最小不透明度值 */
|
||||
const minAlpha = computed(() => props.alphaRange?.[0] ?? 0.25);
|
||||
/** 最大不透明度值 */
|
||||
const maxAlpha = computed(() => props.alphaRange?.[1] ?? 0.55);
|
||||
const alpha = cycledTransition(
|
||||
minAlpha.value,
|
||||
@@ -330,13 +342,18 @@ export const Selection = defineComponent<SelectionProps>(props => {
|
||||
2000,
|
||||
cosh(2, CurveMode.EaseInOut)
|
||||
)!;
|
||||
const defaultMaterials = inject<ITextureManager>('@default/materials');
|
||||
|
||||
/** 使用的贴图管理器 */
|
||||
const materials = computed(() => props.materials ?? defaultMaterials);
|
||||
/** 当前是否使用 winskin */
|
||||
const isWinskin = computed(() => !isNil(props.winskin));
|
||||
/** 当前的 winskin 贴图 */
|
||||
const winskin = computed(() => {
|
||||
if (isNil(props.winskin) || !props.manager) {
|
||||
if (isNil(props.winskin) || !materials.value) {
|
||||
return null;
|
||||
} else {
|
||||
return props.manager.getImageByAlias(props.winskin);
|
||||
return materials.value.getImageByAlias(props.winskin);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import { ElementLocator, Font, MotaOffscreenCanvas2D } from '@motajs/render';
|
||||
import {
|
||||
computed,
|
||||
defineComponent,
|
||||
inject,
|
||||
onMounted,
|
||||
ref,
|
||||
shallowRef,
|
||||
@@ -35,7 +36,7 @@ export interface TextContentProps extends DefaultProps {
|
||||
autoHeight?: boolean;
|
||||
/** 打字机对象,如果需要自定义配置,那么需要传入,如果不需要自定义配置,不传入也可以 */
|
||||
typer?: TextContentTyper;
|
||||
/** 素材管理器,用于显示图标 */
|
||||
/** 素材管理器,用于显示图标,默认使用主对象上的贴图管理器 */
|
||||
materials?: ITextureManager;
|
||||
}
|
||||
|
||||
@@ -99,6 +100,10 @@ export const TextContent = defineComponent<
|
||||
TextContentEmits,
|
||||
keyof TextContentEmits
|
||||
>((props, { emit, expose }) => {
|
||||
const defaultMaterials = inject<ITextureManager>('@default/materials');
|
||||
/** 使用的贴图管理器 */
|
||||
const materials = computed(() => props.materials ?? defaultMaterials);
|
||||
|
||||
const [x, y, width, height] = xywh(props);
|
||||
/** 正文高度 */
|
||||
const contentHeight = ref(height.value);
|
||||
@@ -112,7 +117,7 @@ export const TextContent = defineComponent<
|
||||
const root = useRendererRoot();
|
||||
const typer = computed(
|
||||
() =>
|
||||
props.typer ?? new TextContentTyper({ materials: props.materials })
|
||||
props.typer ?? new TextContentTyper({ materials: materials.value })
|
||||
);
|
||||
const renderable = shallowRef<TyperRenderable[]>([]);
|
||||
let needUpdate = false;
|
||||
@@ -142,7 +147,14 @@ export const TextContent = defineComponent<
|
||||
needUpdate = true;
|
||||
renderable.value = [];
|
||||
|
||||
typer.value.setConfig({ width: width.value });
|
||||
if (materials.value) {
|
||||
typer.value.setConfig({
|
||||
width: width.value,
|
||||
materials: materials.value
|
||||
});
|
||||
} else {
|
||||
typer.value.setConfig({ width: width.value });
|
||||
}
|
||||
typer.value.setText(props.text ?? '');
|
||||
typer.value.type();
|
||||
needUpdate = false;
|
||||
@@ -410,7 +422,7 @@ export const Textbox = defineComponent<
|
||||
color={props.backColor}
|
||||
border={props.strokeColor}
|
||||
circle={[0]}
|
||||
manager={props.materials}
|
||||
materials={props.materials}
|
||||
loc={[0, 0, tw.value, th.value]}
|
||||
/>
|
||||
<text
|
||||
@@ -429,7 +441,7 @@ export const Textbox = defineComponent<
|
||||
color={props.backColor}
|
||||
border={props.strokeColor}
|
||||
circle={[0]}
|
||||
manager={props.materials}
|
||||
materials={props.materials}
|
||||
loc={[0, contentY.value, width.value, backHeight.value]}
|
||||
/>
|
||||
|
||||
@@ -437,7 +449,7 @@ export const Textbox = defineComponent<
|
||||
hidden={!!iconData.value}
|
||||
icon={props.icon}
|
||||
loc={iconLoc.value}
|
||||
manager={props.materials}
|
||||
materials={props.materials}
|
||||
animate
|
||||
/>
|
||||
<g-rect
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
Transform
|
||||
} from '@motajs/render';
|
||||
import { DefaultProps, xywh } from '@motajs/render-vue';
|
||||
import { computed, defineComponent, watch } from 'vue';
|
||||
import { computed, defineComponent, inject, watch } from 'vue';
|
||||
import { SetupComponentOptions } from '@motajs/system';
|
||||
import { IMapRenderer } from '../map';
|
||||
import { IMapState } from '@user/data-base';
|
||||
@@ -17,7 +17,7 @@ export interface IThumbnailCellProps extends DefaultProps {
|
||||
floorId?: string;
|
||||
/** 楼层存储对象 */
|
||||
maps?: IMapState;
|
||||
/** 地图渲染器,注意如果你不知道地图渲染的细节,一定永远传入 `expandMapRenderer`! */
|
||||
/** 地图渲染器,默认会使用主对象上的辅助地图渲染器,如果不知道传什么就不要传 */
|
||||
renderer?: IMapRenderer;
|
||||
/** 显示尺寸,1 表示与原始尺寸一致,默认为 1 */
|
||||
size?: number;
|
||||
@@ -72,6 +72,10 @@ export const ThumbnailCell = defineComponent<
|
||||
ThumbnailCellEmits,
|
||||
keyof ThumbnailCellEmits
|
||||
>((props, { emit }) => {
|
||||
const defaultRenderer = inject<IMapRenderer>('@default/expandMapRenderer');
|
||||
/** 使用的地图渲染器 */
|
||||
const mapRenderer = computed(() => props.renderer ?? defaultRenderer);
|
||||
|
||||
const [x, y, width, height] = xywh(props);
|
||||
|
||||
/** 渲染缩放尺寸 */
|
||||
@@ -90,7 +94,7 @@ export const ThumbnailCell = defineComponent<
|
||||
|
||||
/** 渲染区域大小 */
|
||||
const chunkSize = computed<[number, number]>(() => {
|
||||
const renderer = props.renderer;
|
||||
const renderer = mapRenderer.value;
|
||||
if (!renderer || !props.origin || !map.value) return [0, 0];
|
||||
const [ox, oy] = props.origin;
|
||||
const { chunkWidth, chunkHeight } = renderer.vertex.block;
|
||||
@@ -107,7 +111,7 @@ export const ThumbnailCell = defineComponent<
|
||||
|
||||
/** 真实的渲染尺寸 */
|
||||
const renderSize = computed<[number, number]>(() => {
|
||||
const renderer = props.renderer;
|
||||
const renderer = mapRenderer.value;
|
||||
if (!renderer) return [1, 1];
|
||||
const [cw, ch] = chunkSize.value;
|
||||
if (cw === 0 || ch === 0) return [1, 1];
|
||||
@@ -134,7 +138,7 @@ export const ThumbnailCell = defineComponent<
|
||||
const render = (canvas: MotaOffscreenCanvas2D) => {
|
||||
const [cw, ch] = chunkSize.value;
|
||||
const ctx = canvas.ctx;
|
||||
if (!props.renderer || !map.value || cw === 0 || ch === 0) {
|
||||
if (!mapRenderer.value || !map.value || cw === 0 || ch === 0) {
|
||||
ctx.fillStyle = 'black';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
ctx.fillStyle = 'white';
|
||||
@@ -145,7 +149,7 @@ export const ThumbnailCell = defineComponent<
|
||||
ctx.fillText('未绑定渲染器或楼层对象', hw, hh);
|
||||
return;
|
||||
}
|
||||
const renderer = props.renderer;
|
||||
const renderer = mapRenderer.value;
|
||||
// 重置激励时间戳,保证显示内容的一致性,不会因为动画导致显示内容变化
|
||||
renderer.excited(0);
|
||||
renderer.setGameMap(map.value);
|
||||
@@ -307,6 +311,9 @@ const thumbnailProps = {
|
||||
} satisfies SetupComponentOptions<ThumbnailProps>;
|
||||
|
||||
export const Thumbnail = defineComponent<ThumbnailProps>(props => {
|
||||
const defaultRenderer = inject<IMapRenderer>('@default/expandMapRenderer');
|
||||
/** 使用的地图渲染器 */
|
||||
const mapRenderer = computed(() => props.renderer ?? defaultRenderer);
|
||||
/** 空白区域填充样式 */
|
||||
const padStyle = computed(() => props.padStyle ?? 'black');
|
||||
/** 渲染尺寸比例 */
|
||||
@@ -335,7 +342,7 @@ export const Thumbnail = defineComponent<ThumbnailProps>(props => {
|
||||
|
||||
/** 渲染尺寸 */
|
||||
const renderSize = computed(() => {
|
||||
const renderer = props.renderer;
|
||||
const renderer = mapRenderer.value;
|
||||
if (!renderer || !props.area) return [1, 1];
|
||||
const [, , w, h] = props.area;
|
||||
const { cellWidth, cellHeight } = renderer;
|
||||
@@ -354,7 +361,7 @@ export const Thumbnail = defineComponent<ThumbnailProps>(props => {
|
||||
|
||||
/** ThumbnailCell 的分块信息 */
|
||||
const chunks = computed<IThumbnailChunkData>(() => {
|
||||
const renderer = props.renderer;
|
||||
const renderer = mapRenderer.value;
|
||||
if (!renderer || !props.area) {
|
||||
return {
|
||||
chunks: [],
|
||||
@@ -413,7 +420,7 @@ export const Thumbnail = defineComponent<ThumbnailProps>(props => {
|
||||
<ThumbnailCell
|
||||
loc={chunk.loc}
|
||||
origin={chunk.origin}
|
||||
renderer={props.renderer}
|
||||
renderer={mapRenderer.value}
|
||||
maps={props.maps}
|
||||
floorId={props.floorId}
|
||||
size={size.value}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ElementLocator, Font } from '@motajs/render';
|
||||
import { computed, defineComponent, ref } from 'vue';
|
||||
import { computed, defineComponent, inject, ref } from 'vue';
|
||||
import { cosh } from '@motajs/animate';
|
||||
import { debounce } from 'lodash-es';
|
||||
import { SetupComponentOptions } from '@motajs/system';
|
||||
@@ -8,8 +8,6 @@ import { Icon } from './icon';
|
||||
import { ITextureManager } from '../material';
|
||||
|
||||
export interface TipProps extends DefaultProps {
|
||||
/** 显示的位置 */
|
||||
loc: ElementLocator;
|
||||
/** 边距 */
|
||||
pad?: [number, number];
|
||||
/** 圆角 */
|
||||
@@ -32,10 +30,25 @@ export interface TipExpose {
|
||||
}
|
||||
|
||||
const tipProps = {
|
||||
props: ['loc', 'x', 'y', 'width', 'height', 'pad', 'corner', 'id']
|
||||
props: [
|
||||
'loc',
|
||||
'x',
|
||||
'y',
|
||||
'width',
|
||||
'height',
|
||||
'pad',
|
||||
'corner',
|
||||
'id',
|
||||
'materials',
|
||||
'font'
|
||||
]
|
||||
} satisfies SetupComponentOptions<TipProps>;
|
||||
|
||||
export const Tip = defineComponent<TipProps>((props, { expose }) => {
|
||||
const defaultMaterials = inject<ITextureManager>('@default/materials');
|
||||
|
||||
/** 贴图管理器 */
|
||||
const materials = computed(() => props.materials ?? defaultMaterials);
|
||||
/** 图标 id 或数字 */
|
||||
const icon = ref<number | string>(0);
|
||||
/** 显示的文字 */
|
||||
@@ -69,7 +82,7 @@ export const Tip = defineComponent<TipProps>((props, { expose }) => {
|
||||
const showIcon = computed(() => icon.value !== 0);
|
||||
/** 图标的原始尺寸 */
|
||||
const iconSize = computed<[number, number]>(() => {
|
||||
const manager = props.materials;
|
||||
const manager = materials.value;
|
||||
if (!manager) return [0, 0];
|
||||
const data = manager.tile(icon.value);
|
||||
if (!data) return [0, 0];
|
||||
@@ -136,7 +149,7 @@ export const Tip = defineComponent<TipProps>((props, { expose }) => {
|
||||
/>
|
||||
<Icon
|
||||
icon={icon.value}
|
||||
manager={props.materials}
|
||||
materials={materials.value}
|
||||
hidden={!showIcon.value}
|
||||
loc={iconLoc.value}
|
||||
/>
|
||||
|
||||
@@ -2,14 +2,14 @@ import { DefaultProps } from '@motajs/render-vue';
|
||||
import { ITextureManager } from '../material';
|
||||
import { SetupComponentOptions } from '@motajs/system';
|
||||
import { ITexture, MotaOffscreenCanvas2D } from '@motajs/render';
|
||||
import { computed, defineComponent } from 'vue';
|
||||
import { computed, defineComponent, inject } from 'vue';
|
||||
import { isNil } from 'lodash-es';
|
||||
|
||||
export interface IWinskinProps extends DefaultProps {
|
||||
/** winskin 图片的名称,带后缀 */
|
||||
winskin?: string;
|
||||
/** 使用的贴图素材管理器 */
|
||||
manager?: ITextureManager;
|
||||
/** 使用的贴图素材管理器,默认会使用主对象上的贴图管理器 */
|
||||
materials?: ITextureManager;
|
||||
/** 手动传入贴图对象,如果传入,会忽略 `winskin` 和 `manager` */
|
||||
texture?: ITexture;
|
||||
/** 边框的宽度,默认为 32 */
|
||||
@@ -17,7 +17,7 @@ export interface IWinskinProps extends DefaultProps {
|
||||
}
|
||||
|
||||
const winskinProps = {
|
||||
props: ['winskin', 'manager', 'texture', 'borderSize']
|
||||
props: ['winskin', 'materials', 'texture', 'borderSize']
|
||||
} satisfies SetupComponentOptions<IWinskinProps>;
|
||||
|
||||
/** winskin 最小单元宽度 */
|
||||
@@ -26,13 +26,17 @@ const CW = 16 / 192;
|
||||
const CH = 16 / 128;
|
||||
|
||||
export const Winskin = defineComponent<IWinskinProps>(props => {
|
||||
const defaultMaterials = inject<ITextureManager>('@default/materials');
|
||||
|
||||
/** 使用的贴图管理器 */
|
||||
const materials = computed(() => props.materials ?? defaultMaterials);
|
||||
/** 边框宽度 */
|
||||
const border = computed(() => props.borderSize ?? 32);
|
||||
/** 贴图对象 */
|
||||
const texture = computed<ITexture | null>(() => {
|
||||
if (props.texture) return props.texture;
|
||||
if (isNil(props.winskin) || !props.manager) return null;
|
||||
return props.manager.getImageByAlias(props.winskin);
|
||||
if (isNil(props.winskin) || !materials.value) return null;
|
||||
return materials.value.getImageByAlias(props.winskin);
|
||||
});
|
||||
|
||||
const render = (canvas: MotaOffscreenCanvas2D) => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { IExcitation, IExcitationDivider } from '@motajs/animate';
|
||||
import { IRenderTreeRoot } from '@motajs/render';
|
||||
import { IRenderItem, IRenderTreeRoot } from '@motajs/render';
|
||||
import {
|
||||
IUIController,
|
||||
IUIDefaultPropsBase,
|
||||
@@ -11,6 +11,7 @@ import { ISaveSystem } from './save';
|
||||
import { ITextureManager } from './material';
|
||||
import { IMapRenderer } from './map';
|
||||
import { IClientHotkey } from './hotkey';
|
||||
import { App } from 'vue';
|
||||
|
||||
export interface IGameUIPropsBase<
|
||||
T extends UIComponent = UIComponent
|
||||
@@ -45,6 +46,8 @@ export interface IClientBase extends ICoreState {
|
||||
readonly mainUIController: IUIController<IGameUIPropsBase>;
|
||||
/** 渲染端主按键系统 */
|
||||
readonly hotkey: IClientHotkey;
|
||||
/** 当前渲染端主对象使用的 vue app */
|
||||
readonly vueApp: App<IRenderItem>;
|
||||
}
|
||||
|
||||
export interface IClientBaseExtended {
|
||||
|
||||
@@ -19,7 +19,7 @@ import {
|
||||
SoundPlayer,
|
||||
BGMPlayer
|
||||
} from '@motajs/audio';
|
||||
import { IRenderTreeRoot, MotaRenderer } from '@motajs/render';
|
||||
import { IRenderItem, IRenderTreeRoot, MotaRenderer } from '@motajs/render';
|
||||
import {
|
||||
ITextureManager,
|
||||
TextureManager,
|
||||
@@ -40,7 +40,8 @@ import {
|
||||
} from '@motajs/animate';
|
||||
import { IUIController, UIController } from '@motajs/system';
|
||||
import { createUIPropsBase } from './ui/func';
|
||||
import { markRaw } from 'vue';
|
||||
import { App, markRaw } from 'vue';
|
||||
import { createRendererFor } from '@motajs/render-vue';
|
||||
|
||||
export class ClientCore extends CoreState implements IClientCore {
|
||||
// Layer 4 渲染基础层
|
||||
@@ -57,6 +58,7 @@ export class ClientCore extends CoreState implements IClientCore {
|
||||
readonly sceneController: IUIController<IGameUIPropsBase>;
|
||||
readonly mainUIController: IUIController<IGameUIPropsBase>;
|
||||
readonly hotkey: IClientHotkey;
|
||||
readonly vueApp: App<IRenderItem>;
|
||||
|
||||
// Layer 5 渲染顶层 - 目前没东西
|
||||
|
||||
@@ -112,6 +114,13 @@ export class ClientCore extends CoreState implements IClientCore {
|
||||
|
||||
this.renderer.registerElement('map-render', () => new MapRenderItem());
|
||||
|
||||
// 初始化 vue app
|
||||
const { createApp } = createRendererFor(this.renderer);
|
||||
this.vueApp = createApp(config.createInitialComponent(this));
|
||||
this.vueApp.mount(this.renderer);
|
||||
|
||||
this.vueApp.provide('@defulat/materials', this.materials);
|
||||
|
||||
this.loader.addCoreConfig('client', config.clientURL);
|
||||
|
||||
// 渲染端插件注册表
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
IPluginDefine,
|
||||
IPluginBase
|
||||
} from '@user/data-state';
|
||||
import { DefineComponent, DefineSetupFnComponent } from 'vue';
|
||||
|
||||
//#region 插件系统
|
||||
|
||||
@@ -87,6 +88,10 @@ export interface IClientCoreConfig extends ICoreStateConfig {
|
||||
readonly mapCellWidth: number;
|
||||
/** 地图的初始图块像素高度,后续还可以通过接口调整 */
|
||||
readonly mapCellHeight: number;
|
||||
/** vue app 的初始根组件 */
|
||||
readonly createInitialComponent: (
|
||||
state: IClientCore
|
||||
) => DefineComponent | DefineSetupFnComponent<{}>;
|
||||
}
|
||||
|
||||
export interface IClientCore extends IClientBase {
|
||||
|
||||
@@ -2,8 +2,6 @@ import { WebLoadStarter } from '@motajs/loader';
|
||||
import { createClientCore } from './client/entry';
|
||||
import { IClientCore } from '@user/client-modules';
|
||||
import { LoadSceneUI } from './client/ui/load';
|
||||
import { createRendererFor } from '@motajs/render-vue';
|
||||
import { createRendererScene } from './client/ui/scene';
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
@@ -13,9 +11,6 @@ declare global {
|
||||
|
||||
const client = createClientCore(new WebLoadStarter());
|
||||
|
||||
const { createApp } = createRendererFor(client.renderer);
|
||||
createApp(createRendererScene(client)).mount(client.renderer);
|
||||
|
||||
// 游戏副作用启动
|
||||
window.mainClient = client;
|
||||
client.sceneController.open(LoadSceneUI, {});
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
MAP_HEIGHT,
|
||||
MAP_WIDTH
|
||||
} from './uiConstant';
|
||||
import { createRendererScene } from './ui/scene';
|
||||
|
||||
/**
|
||||
* 创建渲染端配置对象
|
||||
@@ -44,6 +45,7 @@ export function createClientCoreConfig(
|
||||
mapBlockHeight: MAP_BLOCK_HEIGHT,
|
||||
expandMapRendererWidth: MAP_WIDTH,
|
||||
expandMapRendererHeight: MAP_HEIGHT,
|
||||
createInitialComponent: createRendererScene,
|
||||
clientPlugins: [new MainClientPlugin(), ...clientPlugins],
|
||||
|
||||
...createCoreStateConfig(starter)
|
||||
|
||||
@@ -276,7 +276,7 @@ export const Shop = defineComponent<IShopProps>(props => {
|
||||
/>
|
||||
<Icon
|
||||
icon={item.num}
|
||||
manager={props.state.materials}
|
||||
materials={props.state.materials}
|
||||
loc={[10, 6, ROW_ICON_SIZE, ROW_ICON_SIZE]}
|
||||
/>
|
||||
<text
|
||||
|
||||
@@ -276,7 +276,7 @@ export const EnemyOne = defineComponent<IEnemyOneProps>(props => {
|
||||
/>
|
||||
<Icon
|
||||
icon={enemy.value?.code ?? 0}
|
||||
manager={props.materials}
|
||||
materials={props.materials}
|
||||
loc={[ICON_CENTER, height.value / 2, ICON_SIZE, ICON_SIZE]}
|
||||
anc={[0.5, 0.5]}
|
||||
noevent
|
||||
|
||||
@@ -474,7 +474,7 @@ export const EquipBox = defineComponent<EquipBoxProps>(props => {
|
||||
// 拖动起手仍只在图标上,整格只负责悬停判定
|
||||
<Icon
|
||||
icon={slotEquip ? slotEquip.item.num : 0}
|
||||
manager={props.state.materials}
|
||||
materials={props.state.materials}
|
||||
loc={slotIconLoc}
|
||||
cursor="pointer"
|
||||
onEnter={getSlotEnter(i)}
|
||||
@@ -533,7 +533,7 @@ export const EquipBox = defineComponent<EquipBoxProps>(props => {
|
||||
/>,
|
||||
<Icon
|
||||
icon={item.item.num}
|
||||
manager={props.state.materials}
|
||||
materials={props.state.materials}
|
||||
loc={ownedIconLoc}
|
||||
noevent
|
||||
/>,
|
||||
@@ -563,7 +563,7 @@ export const EquipBox = defineComponent<EquipBoxProps>(props => {
|
||||
{/* 拖拽浮层 */}
|
||||
<Icon
|
||||
icon={dragNum.value > 0 ? dragNum.value : 0}
|
||||
manager={props.state.materials}
|
||||
materials={props.state.materials}
|
||||
loc={dragLoc}
|
||||
noevent
|
||||
zIndex={100}
|
||||
|
||||
@@ -254,7 +254,7 @@ export const ToolBox = defineComponent<ToolBoxProps>(props => {
|
||||
/>,
|
||||
<Icon
|
||||
icon={item.num}
|
||||
manager={props.state.materials}
|
||||
materials={props.state.materials}
|
||||
loc={[10, y + 7, ROW_ICON_SIZE, ROW_ICON_SIZE]}
|
||||
noevent
|
||||
/>,
|
||||
@@ -307,7 +307,7 @@ export const ToolBox = defineComponent<ToolBoxProps>(props => {
|
||||
/>,
|
||||
<Icon
|
||||
icon={item.num}
|
||||
manager={props.state.materials}
|
||||
materials={props.state.materials}
|
||||
loc={[10, y + 7, ROW_ICON_SIZE, ROW_ICON_SIZE]}
|
||||
noevent
|
||||
/>,
|
||||
@@ -333,7 +333,7 @@ export const ToolBox = defineComponent<ToolBoxProps>(props => {
|
||||
{/* 详情图标、名称与类型 */}
|
||||
<Icon
|
||||
icon={current ? current.num : 0}
|
||||
manager={props.state.materials}
|
||||
materials={props.state.materials}
|
||||
loc={[INFO_LEFT + 8, 8, DETAIL_ICON_SIZE, DETAIL_ICON_SIZE]}
|
||||
noevent
|
||||
hidden={!current}
|
||||
|
||||
Reference in new issue
Block a user