chore: 地图与素材配置等改为样板内容

This commit is contained in:
AncTe committed 2025-09-29 20:15:54 +08:00
1 parent 5de5153441
commit 6ace764dc9
219 files changed
+402 -24733

No files matched your search

@@ -1,6 +1,6 @@
import { KeyCode } from '@motajs/client-base';
import { gameKey, HotkeyJSON } from '@motajs/system-action';
import { hovered, mainUi, tip, openDanmakuPoster } from '@motajs/legacy-ui';
import { hovered, mainUi, openDanmakuPoster } from '@motajs/legacy-ui';
import { GameStorage } from '@motajs/legacy-system';
export const mainScope = Symbol.for('@key_main');
@@ -220,23 +220,6 @@ gameKey
defaults: KeyCode.Digit0,
alt: true
})
//#region 技能按键
.group('skill', '技能按键')
.register({
id: 'skill1',
name: '断灭之刃',
defaults: KeyCode.Digit1
})
.register({
id: 'skill2',
name: '跳跃',
defaults: KeyCode.Digit2
})
.register({
id: 'skill3',
name: '铸剑为盾',
defaults: KeyCode.Digit3
})
//#region 系统按键
.group('system', '系统按键')
.register({
@@ -590,45 +573,6 @@ gameKey
.realize('comment', () => {
core.actions._clickGameInfo_openComments();
})
.realize('skill1', () => {
const HeroSkill = Mota.require('@user/data-state').HeroSkill;
if (!HeroSkill.learnedSkill(HeroSkill.Blade)) return;
if (HeroSkill.getAutoSkill()) {
tip('error', '已开启自动切换技能!');
return;
}
core.playSound('光标移动');
HeroSkill.toggleSkill(HeroSkill.Blade);
core.status.route.push('useSkill:Blade');
core.updateStatusBar();
})
.realize('skill2', () => {
const HeroSkill = Mota.require('@user/data-state').HeroSkill;
if (
!flags.onChase &&
!core.status.floorId.startsWith('tower') &&
HeroSkill.learnedSkill(HeroSkill.Jump)
) {
Mota.require('@user/legacy-plugin-data').jumpSkill();
core.status.route.push('useSkill:Jump');
} else {
if (core.hasItem('pickaxe')) {
core.useItem('pickaxe');
}
}
})
.realize('skill3', () => {
const HeroSkill = Mota.require('@user/data-state').HeroSkill;
if (!HeroSkill.learnedSkill(HeroSkill.Shield)) return;
if (HeroSkill.getAutoSkill()) {
tip('error', '已开启自动切换技能!');
return;
}
core.playSound('光标移动');
HeroSkill.toggleSkill(HeroSkill.Shield);
core.status.route.push('useSkill:Shield');
core.updateStatusBar();
})
.realize('debug', () => {
core.debug();
});
@@ -2,12 +2,10 @@ import { createApp, Font } from '@motajs/render';
import { defineComponent } from 'vue';
import { DEFAULT_FONT, MAIN_HEIGHT, MAIN_WIDTH } from './shared';
import { hook, loading } from '@user/data-base';
import { createLoopMap } from './loopMap';
import { createElements } from './elements';
import { mainRenderer } from './renderer';
import { createUI } from './ui';
import { createAction } from './action';
import { createLegacy } from './legacy';
import { sceneController } from './scene';
import { GameTitleUI } from './ui/title';
import { createWeather } from './weather';
@@ -29,10 +27,8 @@ export function createGameRenderer() {
export function createRender() {
createElements();
createLegacy();
createUI();
createAction();
createLoopMap();
createWeather();
loading.on('loaded', () => {
@@ -51,7 +47,6 @@ export function createRender() {
export * from './components';
export * from './elements';
export * from './fx';
export * from './legacy';
export * from './ui';
export * from './utils';
export * from './weather';
@@ -1,64 +0,0 @@
import { logger } from '@motajs/common';
import { loading } from '@user/data-base';
import {
ILayerGroupRenderExtends,
LayerGroup,
LayerGroupFloorBinder
} from '../elements';
const filterMap: [FloorIds[], string][] = [];
function getCanvasFilterByFloorId(floorId: FloorIds = core.status.floorId) {
return filterMap.find(v => v[0].includes(floorId))?.[1] ?? '';
}
export function createGameCanvas() {
loading.once('coreInit', () => {
filterMap.push(
[['MT50', 'MT60', 'MT61'], 'contrast(120%)'], // 童心佬的滤镜(
[
core.floorIds
.slice(61, 70)
.concat(core.floorIds.slice(72, 107)),
'contrast(120%)'
] // 童心佬的滤镜(
);
});
}
export class LayerGroupFilter implements ILayerGroupRenderExtends {
id: string = 'filter';
group!: LayerGroup;
binder!: LayerGroupFloorBinder;
setFilter(floorId: FloorIds) {
const filter = getCanvasFilterByFloorId(floorId);
this.group.setFilter(filter);
// console.log(filter);
}
private onFloorChange = (floor: FloorIds) => {
this.setFilter(floor);
};
private listen() {
this.binder.on('floorChange', this.onFloorChange);
}
awake(group: LayerGroup): void {
this.group = group;
const ex = group.getExtends('floor-binder');
if (ex instanceof LayerGroupFloorBinder) {
this.binder = ex;
this.listen();
} else {
logger.error(1201);
group.removeExtends('floor-damage');
}
}
onDestroy(_group: LayerGroup): void {
this.binder?.off('floorChange', this.onFloorChange);
}
}
@@ -1,9 +0,0 @@
import { createGameCanvas } from './gameCanvas';
import { createShadow } from './shadow';
export function createLegacy() {
createGameCanvas();
createShadow();
}
export * from './shadow';
@@ -1,103 +0,0 @@
import {
wrapInstancedComponent,
RenderItem,
RenderItemPosition,
Transform,
MotaOffscreenCanvas2D
} from '@motajs/render';
import { TimingFn } from 'mutate-animate';
interface PopData {
cx: number;
cy: number;
path: TimingFn<2>;
text: string;
time: number;
start: number;
color: CanvasStyle;
}
function parabola(input: number): [number, number] {
const x = input * 100;
return [x, x ** 2 / 20 - 3 * x];
}
export class Pop extends RenderItem {
private popList: Set<PopData> = new Set();
private delegation: number = 0;
constructor(type: RenderItemPosition) {
super(type, false);
this.delegation = this.delegateTicker(() => {
if (this.popList.size > 0) this.update();
});
}
/**
* 添加一个弹出文字
* @param text 要显示的文字
* @param time 持续时长
* @param cx 中心点,也就是从哪弹出的
* @param cy 中心点,也就是从哪弹出的
* @param path 自定义路径,不填表示默认的抛物线路径
*/
addPop(
text: string,
time: number,
cx: number,
cy: number,
color: CanvasStyle,
path?: TimingFn<2>
) {
this.popList.add({
text,
time,
cx,
cy,
color,
path: path ?? parabola,
start: Date.now()
});
this.update();
}
protected render(
canvas: MotaOffscreenCanvas2D,
_transform: Transform
): void {
const ctx = canvas.ctx;
const toDelete = new Set<PopData>();
const now = Date.now();
ctx.strokeStyle = '#000';
ctx.font = '22px Verdana';
ctx.lineWidth = 3;
this.popList.forEach(v => {
const { cx, cy, path, text, color, time, start } = v;
const dt = now - start;
const progress = dt / time;
if (progress >= 1) {
toDelete.add(v);
return;
}
const [x, y] = path(progress);
const dx = cx + x;
const dy = cy + y;
ctx.globalAlpha = Math.min(1, 2 - progress * 2);
ctx.fillStyle = color;
ctx.strokeText(text, dx, dy);
ctx.fillText(text, dx, dy);
});
toDelete.forEach(v => {
this.popList.delete(v);
});
}
destroy(): void {
super.destroy();
this.removeTicker(this.delegation);
}
}
export const PopText = wrapInstancedComponent(() => new Pop('static'));
@@ -1,296 +0,0 @@
import { logger } from '@motajs/common';
import { MotaOffscreenCanvas2D } from '@motajs/render';
import { mainSetting, MotaSettingItem } from '@motajs/legacy-ui';
import { Sprite } from '@motajs/render';
import { BluePalace } from '@user/data-state';
import {
ILayerGroupRenderExtends,
LayerGroup,
LayerGroupFloorBinder
} from '../elements';
/** 最大粒子数 */
const MAX_PARTICLES = 10;
/** 粒子持续时长 */
const PARTICLE_LAST = 2000;
/** 粒子产生间隔 */
const PARTICLE_INTERVAL = PARTICLE_LAST / MAX_PARTICLES;
export class LayerGroupPortal implements ILayerGroupRenderExtends {
id: string = 'portal';
group!: LayerGroup;
binder!: LayerGroupFloorBinder;
portal!: Portal;
private onFloorChange = (floor: FloorIds) => {
const data = BluePalace.portals;
this.portal.cellSize = this.group.cellSize;
this.portal.setData(data[floor] ?? []);
};
private listen() {
this.binder.on('floorChange', this.onFloorChange);
}
awake(group: LayerGroup): void {
this.group = group;
const ex = group.getExtends('floor-binder');
if (ex instanceof LayerGroupFloorBinder) {
this.binder = ex;
this.portal = new Portal();
this.portal.setHD(true);
this.portal.size(group.width, group.height);
group.appendChild(this.portal);
this.listen();
} else {
logger.error(1301);
group.removeExtends('portal');
}
}
onDestroy(_group: LayerGroup): void {
this.binder.off('floorChange', this.onFloorChange);
}
}
interface DrawingPortal {
color: string;
x: number;
y: number;
particles: Set<PortalParticle>;
/** v表示竖向,h表示横向 */
type: 'v' | 'h';
/** 上一次新增粒子的时间 */
lastParticle: number;
}
interface PortalParticle {
fx: number;
fy: number;
totalTime: number;
time: number;
tx: number;
ty: number;
r: number;
}
export class Portal extends Sprite {
static colors: string[] = ['#0f0', '#ff0', '#0ff', '#fff', '#f0f'];
cellSize: number = 32;
/** 当前的渲染数据 */
private renderData: BluePalace.Portal[] = [];
/** 渲染内容 */
private renderable: Set<DrawingPortal> = new Set();
/** 粒子开关设置 */
private particleSetting: MotaSettingItem;
/** 上一帧时刻 */
private lastTime: number = 0;
private delegation: number;
constructor() {
super('static', false, true);
this.particleSetting = mainSetting.getSetting('fx.portalParticle')!;
this.delegation = this.delegateTicker(() => {
if (this.particleSetting.value && this.renderable.size > 0) {
this.update(this);
}
});
this.setZIndex(35);
this.setRenderFn((canvas, _transform) => {
this.renderPortal(canvas);
});
}
/**
* 设置渲染内容
*/
setData(data: BluePalace.Portal[]) {
this.renderData = data;
this.generateRenderable();
this.update(this);
}
private generateRenderable() {
this.renderable.clear();
if (this.renderData.length === 0) return;
const colorLength = Portal.colors.length;
const cell = this.cellSize;
this.renderData.forEach((v, i) => {
const c = Portal.colors[i % colorLength];
const { fx, fy, tx, ty, dir, toDir } = v;
let x1 = fx * cell;
let y1 = fy * cell;
let x2 = tx * cell;
let y2 = ty * cell;
if (dir === 'down') y1 += cell;
else if (dir === 'right') x1 += cell;
if (toDir === 'down') y2 += cell;
else if (toDir === 'right') x2 += cell;
this.renderable.add({
x: x1,
y: y1,
type: dir === 'left' || dir === 'right' ? 'v' : 'h',
color: c,
particles: new Set(),
lastParticle: Date.now()
});
this.renderable.add({
x: x2,
y: y2,
type: toDir === 'left' || toDir === 'right' ? 'v' : 'h',
color: c,
particles: new Set(),
lastParticle: Date.now()
});
});
}
private renderPortal(canvas: MotaOffscreenCanvas2D) {
if (this.renderable.size === 0) return;
const { ctx } = canvas;
const p = this.particleSetting.value;
ctx.lineCap = 'round';
ctx.lineWidth = 3;
ctx.shadowOffsetX = 0;
ctx.shadowOffsetY = 0;
if (p) {
ctx.shadowBlur = 8;
} else {
ctx.shadowBlur = 0;
}
const time = Date.now();
const dt = time - this.lastTime;
this.lastTime = time;
this.renderable.forEach(v => {
const { color, x, y, type, lastParticle, particles } = v;
ctx.strokeStyle = color;
ctx.fillStyle = color;
ctx.globalAlpha = 1;
ctx.shadowColor = color;
if (type === 'v') {
ctx.beginPath();
ctx.moveTo(x, y - 14);
ctx.lineTo(x, y + 30);
ctx.stroke();
} else {
ctx.beginPath();
ctx.moveTo(x + 2, y);
ctx.lineTo(x + 30, y);
ctx.stroke();
}
if (!p) return;
const needDelete = new Set<PortalParticle>();
particles.forEach(v => {
const { fx, fy, tx, ty, time: t, totalTime, r } = v;
const progress = t / totalTime;
const nx = (tx - fx) * progress + fx;
const ny = (ty - fy) * progress + fy;
v.time += dt;
if (progress > 1) {
needDelete.add(v);
return;
} else if (progress > 0.75) {
ctx.globalAlpha = (1 - progress) * 4;
} else if (progress < 0.25) {
ctx.globalAlpha = progress * 4;
} else {
ctx.globalAlpha = 1;
}
ctx.beginPath();
ctx.arc(nx, ny, r, 0, Math.PI * 2);
ctx.closePath();
ctx.fill();
});
needDelete.forEach(v => {
particles.delete(v);
});
if (
time - lastParticle >= PARTICLE_INTERVAL &&
particles.size < MAX_PARTICLES
) {
// 添加新粒子
const direction = Math.random();
const k = Math.random() / 2 - 0.3;
const verticle = Math.floor(Math.random() * 8 + 8);
const r = Math.random() * 2;
v.lastParticle = time;
if (direction > 0.5) {
// 左边 | 上边
if (type === 'h') {
const fx = Math.floor(Math.random() * 24 + x + 4);
particles.add({
fx: fx,
fy: y - 1,
tx: verticle * k + fx + 4,
ty: -verticle + y - 1,
r: r,
time: 0,
totalTime: PARTICLE_LAST
});
} else {
const fy = Math.floor(Math.random() * 44 + y - 14);
particles.add({
fy: fy,
fx: x - 1,
ty: verticle * k + fy + 4,
tx: -verticle + x - 1,
r: r,
time: 0,
totalTime: PARTICLE_LAST
});
}
} else {
// 右边 | 下边
if (type === 'h') {
const fx = Math.floor(Math.random() * 24 + x + 4);
particles.add({
fx: fx,
fy: y + 1,
tx: verticle * k + fx + 4,
ty: verticle + y - 1,
r: r,
time: 0,
totalTime: PARTICLE_LAST
});
} else {
const fy = Math.floor(Math.random() * 44 + y - 14);
particles.add({
fy: fy,
fx: x + 1,
ty: verticle * k + fy + 4,
tx: verticle + x + 1,
r: r,
time: 0,
totalTime: PARTICLE_LAST
});
}
}
}
});
}
destroy(): void {
super.destroy();
this.removeTicker(this.delegation);
}
}
File diff suppressed because it is too large. Load diff
@@ -1,108 +0,0 @@
import { Container, MotaRenderer } from '@motajs/render';
import { hook } from '@user/data-base';
import { MiscData } from '@user/data-state';
import { FloorDamageExtends } from './elements/damage';
import { FloorItemDetail } from './elements/itemDetail';
import {
LayerGroup,
FloorLayer,
LayerGroupFloorBinder,
FloorViewport
} from './elements';
import { MAP_WIDTH } from './shared';
const loopMaps = MiscData.loopMaps;
let loopLayer: LayerGroup;
let show: boolean = false;
/** 循环式地图中,更新视角的委托ticker */
let delegation: number = -1;
export function createLoopMap() {
hook.on('changingFloor', (floorId, _heroLoc) => {
enableLoopMapElement(floorId);
});
}
function createLayer() {
const group = new LayerGroup();
['bg', 'bg2', 'event', 'fg', 'fg2'].forEach(v => {
group.addLayer(v as FloorLayer);
});
const damage = new FloorDamageExtends();
const detail = new FloorItemDetail();
group.id = 'layer-loop';
group.extends(damage);
group.extends(detail);
loopLayer = group;
group.setZIndex(20);
}
function enableLoopMapElement(floorId: FloorIds) {
if (!loopMaps.has(floorId)) {
disableLoopMapElement();
return;
}
if (!loopLayer) createLayer();
const render = MotaRenderer.get('render-main');
const draw = render?.getElementById('map-draw') as Container;
const group = render?.getElementById('layer-main') as LayerGroup;
if (!draw || !group) return;
const ex = loopLayer.getExtends('floor-binder') as LayerGroupFloorBinder;
const viewport = group.getExtends('viewport') as FloorViewport;
if (!ex || !viewport) return;
ex.bindFloor(floorId);
draw.appendChild(loopLayer);
show = true;
const floor = core.status.maps[floorId];
viewport.setAutoBound(false);
const transform = group.camera;
const width = floor.width;
const testPos = width * loopLayer.cellSize;
loopLayer.removeTicker(delegation);
delegation = loopLayer.delegateTicker(() => {
const [x1] = transform.transformed(0, 0);
const camera = loopLayer.camera;
if (x1 > 0) {
// 这个是计算循环地图应该显示在哪
const [, y2] = transform.transformed(x1 - testPos, 0);
camera.reset();
camera.translate(MAP_WIDTH - testPos, y2);
loopLayer.pos(transform.x - MAP_WIDTH, 0);
loopLayer.show();
loopLayer.update(loopLayer);
} else {
const [x2, y2] = transform.transformed(testPos, 0);
if (x2 < MAP_WIDTH) {
// 这个不用做其他运算,可以直接显示
camera.reset();
camera.translate(0, y2);
loopLayer.pos(x2, 0);
loopLayer.show();
loopLayer.update(loopLayer);
} else {
loopLayer.hide();
}
}
});
}
function disableLoopMapElement() {
if (!show) return;
show = false;
loopLayer.remove();
const render = MotaRenderer.get('render-main');
const group = render?.getElementById('layer-main') as LayerGroup;
if (!group) return;
const viewport = group.getExtends('viewport') as FloorViewport;
if (!viewport) return;
viewport.setAutoBound(true);
loopLayer.removeTicker(delegation);
}
@@ -62,7 +62,7 @@ export const CENTER_LOC: ElementLocator = [
/** 弹框的宽度,使用在内置 UI 与组件中,包括确认框、选择框、等待框等 */
export const POP_BOX_WIDTH = MAP_WIDTH / 2;
/** 默认字体 */
export const DEFAULT_FONT = new Font('normal', 18);
export const DEFAULT_FONT = new Font('Verdana', 16);
//#region 存档界面
@@ -1,4 +1,3 @@
import { LayerShadowExtends } from '../legacy/shadow';
import {
Props,
Font,
@@ -39,11 +38,8 @@ import { ReplayingStatus } from './toolbar';
import { getHeroStatusOn } from '@user/data-state';
import { hook } from '@user/data-base';
import { FloorDamageExtends, FloorItemDetail } from '../elements';
import { LayerGroupPortal } from '../legacy/portal';
import { LayerGroupFilter } from '../legacy/gameCanvas';
import { LayerGroupHalo } from '../legacy/halo';
import { FloorChange } from '../legacy/fallback';
import { PopText } from '../legacy/pop';
import { mainUIController } from './controller';
import {
ILayerGroupRenderExtends,
@@ -61,16 +57,13 @@ const MainScene = defineComponent(() => {
const layerGroupExtends: ILayerGroupRenderExtends[] = [
new FloorDamageExtends(),
new FloorItemDetail(),
new LayerGroupFilter(),
new LayerGroupPortal(),
new LayerGroupHalo(),
new LayerGroupAnimate(),
new FloorViewport()
];
const eventExtends: ILayerRenderExtends[] = [
new HeroRenderer(),
new LayerDoorAnimate(),
new LayerShadowExtends()
new LayerDoorAnimate()
];
const mainTextboxProps: Props<typeof Textbox> = {
text: '',
@@ -81,7 +74,7 @@ const MainScene = defineComponent(() => {
titleFill: 'gold',
font: new Font('normal'),
titleFont: new Font('normal', 20, 'px', 700),
winskin: 'winskin2.png',
winskin: 'winskin.png',
interval: 30,
lineHeight: 4,
width: MAP_WIDTH
@@ -283,7 +276,6 @@ const MainScene = defineComponent(() => {
<layer layer="event" zIndex={30} ex={eventExtends}></layer>
<layer layer="fg" zIndex={40}></layer>
<layer layer="fg2" zIndex={50}></layer>
<PopText id="pop-main" zIndex={80}></PopText>
</layer-group>
<Textbox id="main-textbox" {...mainTextboxProps}></Textbox>
<FloorChange id="floor-change" zIndex={50}></FloorChange>
@@ -69,8 +69,8 @@ const saveBtnProps = {
} satisfies SetupComponentOptions<SaveItemProps>;
export const SaveItem = defineComponent<SaveItemProps>(props => {
const font = Font.defaults({ size: 18 });
const statusFont = Font.defaults({ size: 14 });
const font = Font.defaults({ size: 16 });
const statusFont = Font.defaults({ size: 12 });
const w = computed(() => props.loc[2] ?? 200);
const h = computed(() => props.loc[3] ?? 200);
@@ -267,7 +267,7 @@ export const Save = defineComponent<SaveProps, SaveEmits, keyof SaveEmits>(
`确认要删除存档 ${index + 1}?`,
[HALF_WIDTH, HALF_HEIGHT, void 0, void 0, 0.5, 0.5],
POP_BOX_WIDTH,
{ winskin: 'winskin2.png' }
{ winskin: 'winskin.png' }
);
if (confirm) {
emit('delete', index, exist(posIndex));
@@ -246,6 +246,7 @@ export const ReplaySettings = defineComponent<MainSettingsProps>(props => {
onChoose={choose}
interval={8}
scope={scope}
maxHeight={MAIN_HEIGHT - 32}
/>
);
}, mainSettingsProps);
@@ -72,7 +72,7 @@ const gameTitleProps = {
} satisfies SetupComponentOptions<GameTitleProps>;
export const GameTitle = defineComponent<GameTitleProps>(props => {
const bg = core.material.images.images['bg.webp'];
const bg = core.material.images.images['bg.jpg'];
//#region 计算背景图
const [width, height] = adjustCover(
@@ -437,7 +437,6 @@ export const GameTitle = defineComponent<GameTitleProps>(props => {
image={bg}
loc={[HALF_WIDTH, HALF_HEIGHT, width, height]}
anc={[0.5, 0.5]}
filter="brightness(120%)contrast(110%)"
zIndex={0}
/>
<shader
@@ -32,7 +32,6 @@ import {
LayerGroupFloorBinder
} from '../elements';
import { LayerGroupHalo } from '../legacy/halo';
import { LayerGroupPortal } from '../legacy/portal';
import { Font } from '@motajs/render-style';
import { clamp, mean } from 'lodash-es';
import { calculateStatisticsOne, StatisticsDataOneFloor } from './statistics';
@@ -66,7 +65,6 @@ export const ViewMap = defineComponent<ViewMapProps>(props => {
const layerGroupExtends: ILayerGroupRenderExtends[] = [
new FloorDamageExtends(),
new FloorItemDetail(),
new LayerGroupPortal(),
new LayerGroupHalo(),
new LayerGroupAnimate()
];