feat: 标题界面换用新渲染系统

This commit is contained in:
AncTe committed 2025-06-22 17:01:59 +08:00
1 parent 58d2b5eb36
commit f832d75f50
19 files changed
+849 -91

No files matched your search

+2 -3
View File
@@ -31,7 +31,6 @@ import {
loadDefaultResource,
LoadTask
} from '@motajs/legacy-common';
import { GameUi } from '../controller';
import { formatSize } from '../utils';
import { logger } from '@motajs/common';
import { sleep } from 'mutate-animate';
@@ -70,10 +69,10 @@ onMounted(async () => {
core._afterLoadResources(props.callback);
logger.log(`Resource load end.`);
loadDiv.style.opacity = '0';
await sleep(500);
Mota.require('@user/data-base').loading.emit('loaded');
await sleep(1000);
await sleep(500);
props.controller.close(props.num);
props.controller.open('start');
});
loadDiv = document.getElementById('load') as HTMLDivElement;
});
+7 -3
View File
@@ -419,7 +419,8 @@ onUnmounted(() => {
);
background-clip: text;
-webkit-background-clip: text;
text-shadow: 1px 1px 4px rgba(0, 0, 0, 0.5),
text-shadow:
1px 1px 4px rgba(0, 0, 0, 0.5),
-1px -1px 3px rgba(255, 255, 255, 0.3),
5px 5px 5px rgba(0, 0, 0, 0.4);
filter: brightness(1.8);
@@ -442,14 +443,17 @@ onUnmounted(() => {
position: absolute;
opacity: 0;
animation: cursor 2.5s linear 0s infinite normal running;
transition: left 0.4s ease-out, top 0.4s ease-out,
transition:
left 0.4s ease-out,
top 0.4s ease-out,
opacity 1.5s ease-out;
}
.start-button {
position: relative;
font: bold 1.5em 'normal';
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.4),
text-shadow:
1px 1px 2px rgba(0, 0, 0, 0.4),
0px 0px 1px rgba(255, 255, 255, 0.3);
background-clip: text;
-webkit-background-clip: text;
+12 -24
View File
@@ -167,7 +167,7 @@ export abstract class GL2<E extends EGL2Event = EGL2Event> extends RenderItem<
protected framebufferMap: Map<string, WebGLFramebuffer> = new Map();
constructor(type: RenderItemPosition = 'static') {
super(type, !GL2.support);
super(type, false);
this.canvas = document.createElement('canvas');
this.gl = this.canvas.getContext('webgl2')!;
@@ -216,17 +216,16 @@ export abstract class GL2<E extends EGL2Event = EGL2Event> extends RenderItem<
this.gl.useProgram(this.program.program);
}
if (this.cacheDirty) {
// 清空画布
const gl = this.gl;
gl.viewport(0, 0, this.canvas.width, this.canvas.height);
gl.clearColor(0, 0, 0, 0);
gl.clearDepth(1);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
this.drawScene(canvas, gl, this.program, transform);
this.cacheDirty = false;
}
// 清空画布
const gl = this.gl;
gl.viewport(0, 0, this.canvas.width, this.canvas.height);
gl.clearColor(0, 0, 0, 0);
gl.clearDepth(1);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
this.program.ready();
this.drawScene(canvas, gl, this.program, transform);
canvas.clear();
canvas.ctx.drawImage(this.canvas, 0, 0, this.width, this.height);
}
@@ -1189,8 +1188,6 @@ export class GL2Program extends EventEmitter<ShaderProgramEvent> {
private shader: CompiledShader | null = null;
/** 当前的webgl程序 */
program: WebGLProgram | null = null;
/** 准备函数 */
private readyFn?: () => boolean;
/** 当前正在使用的顶点索引数组 */
usingIndices: IShaderIndices | null = null;
@@ -1219,18 +1216,10 @@ export class GL2Program extends EventEmitter<ShaderProgramEvent> {
}
/**
* 使用这个着色器程序时,在渲染之前执行的准备函数
* @param fn 准备函数,返回 false 时将不执行绘制
*/
setReady(fn: () => boolean) {
this.readyFn = fn;
}
/**
* 执行准备函数
* 渲染前准备
*/
ready(): boolean {
return this.readyFn?.() ?? true;
return true;
}
/**
@@ -1255,7 +1244,6 @@ export class GL2Program extends EventEmitter<ShaderProgramEvent> {
case RenderMode.ElementsInstanced:
return this.elementsInstancedParams as DrawParamsMap[T];
}
return null;
}
/**
+7 -3
View File
@@ -1,4 +1,4 @@
import { isNil } from 'lodash-es';
import { isEqual, isNil } from 'lodash-es';
import { EventEmitter } from 'eventemitter3';
import { MotaOffscreenCanvas2D } from './canvas2d';
import { Ticker, TickerFn } from 'mutate-animate';
@@ -445,9 +445,9 @@ export abstract class RenderItem<E extends ERenderItemEvent = ERenderItemEvent>
canvas.ctx.drawImage(this.cache.canvas, ax, ay, width, height);
} else {
this.cacheDirty = false;
canvas.ctx.translate(ax, ay);
this.render(canvas, tran);
this.cacheDirty = false;
}
ctx.restore();
this.emit('afterRender', transform);
@@ -505,6 +505,7 @@ export abstract class RenderItem<E extends ERenderItemEvent = ERenderItemEvent>
* 修改这个对象的大小
*/
size(width: number, height: number): void {
if (width === this.width && height === this.height) return;
this.width = width;
this.height = height;
if (this.enableCache) {
@@ -1186,7 +1187,7 @@ export abstract class RenderItem<E extends ERenderItemEvent = ERenderItemEvent>
}
case 'filter': {
if (!this.assertType(nextValue, 'string', key)) return;
this.setFilter(this.filter);
this.setFilter(nextValue);
return;
}
case 'hd': {
@@ -1238,6 +1239,7 @@ export abstract class RenderItem<E extends ERenderItemEvent = ERenderItemEvent>
return;
}
case 'loc': {
if (isEqual(nextValue, prevValue)) return;
if (!this.assertType(nextValue, Array, key)) return;
if (!isNil(nextValue[0]) && !isNil(nextValue[1])) {
this.pos(nextValue[0] as number, nextValue[1] as number);
@@ -1254,6 +1256,7 @@ export abstract class RenderItem<E extends ERenderItemEvent = ERenderItemEvent>
return;
}
case 'anc': {
if (isEqual(nextValue, prevValue)) return;
if (!this.assertType(nextValue, Array, key)) return;
this.setAnchor(nextValue[0] as number, nextValue[1] as number);
return;
@@ -1264,6 +1267,7 @@ export abstract class RenderItem<E extends ERenderItemEvent = ERenderItemEvent>
return;
}
case 'scale': {
if (isEqual(nextValue, prevValue)) return;
if (!this.assertType(nextValue, Array, key)) return;
this._transform.setScale(
nextValue[0] as number,
+11 -3
View File
@@ -26,8 +26,10 @@ void main() {
}
`;
const DEFAULT_FS = /* glsl */ `
out vec4 color;
void main() {
gl_FragColor = texture2D(u_sampler, v_texCoord);
color = texture(u_sampler, v_texCoord);
}
`;
@@ -55,7 +57,7 @@ export class Shader<E extends EShaderEvent = EShaderEvent> extends GL2<
}
export class ShaderProgram extends GL2Program {
protected override readonly prefix: IGL2ProgramPrefix = SHADER_PREFIX;
protected readonly prefix: IGL2ProgramPrefix = SHADER_PREFIX;
constructor(gl2: GL2, vs?: string, fs?: string) {
super(gl2, vs, fs);
@@ -66,6 +68,11 @@ export class ShaderProgram extends GL2Program {
}
}
ready(): boolean {
this.useIndices('defaultIndices');
return true;
}
protected override compile() {
const success = super.compile();
if (!success) return false;
@@ -76,7 +83,7 @@ export class ShaderProgram extends GL2Program {
const tex = this.defineAttribArray('a_texCoord');
const position = this.defineAttribArray('a_position');
const sampler = this.defineTexture('u_sampler', 0);
const indices = this.defineIndices('defalutIndices');
const indices = this.defineIndices('defaultIndices');
if (!tex || !position || !sampler || !indices) {
return true;
}
@@ -91,6 +98,7 @@ export class ShaderProgram extends GL2Program {
tex.enable();
indices.buffer(new Uint16Array([0, 1, 2, 2, 3, 1]), gl.STATIC_DRAW);
this.useIndices(indices);
this.mode(this.element.DRAW_ELEMENTS);
this.paramElements(gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0);
return true;
+6 -1
View File
@@ -5,7 +5,7 @@ import {
MotaOffscreenCanvas2D
} from '@motajs/render-core';
import { logger } from '@motajs/common';
import { clamp, isNil } from 'lodash-es';
import { clamp, isEqual, isNil } from 'lodash-es';
import { CanvasStyle } from './types';
export type CircleParams = [
@@ -442,6 +442,7 @@ export class Circle extends GraphicItemBase {
this.setAngle(this.start, nextValue);
return true;
case 'circle': {
if (isEqual(nextValue, prevValue)) return true;
const value = nextValue as CircleParams;
if (!this.assertType(value, Array, key)) return false;
const [cx, cy, radius, start, end] = value;
@@ -531,6 +532,7 @@ export class Ellipse extends GraphicItemBase {
this.setAngle(this.start, nextValue);
return true;
case 'ellipse': {
if (isEqual(nextValue, prevValue)) return true;
const value = nextValue as EllipseParams;
if (!this.assertType(value, Array, key)) return false;
const [cx, cy, radiusX, radiusY, start, end] = value;
@@ -619,6 +621,7 @@ export class Line extends GraphicItemBase {
this.setPoint2(this.x2, nextValue);
return true;
case 'line':
if (isEqual(nextValue, prevValue)) return true;
if (!this.assertType(nextValue as number[], Array, key)) {
return false;
}
@@ -750,6 +753,7 @@ export class BezierCurve extends GraphicItemBase {
this.setEnd(this.ex, nextValue);
return true;
case 'curve':
if (isEqual(nextValue, prevValue)) return true;
if (!this.assertType(nextValue as number[], Array, key)) {
return false;
}
@@ -873,6 +877,7 @@ export class QuadraticCurve extends GraphicItemBase {
this.setEnd(this.ex, nextValue);
return true;
case 'curve':
if (isEqual(nextValue, prevValue)) return true;
if (!this.assertType(nextValue as number[], Array, key)) {
return false;
}
+8 -1
View File
@@ -98,6 +98,8 @@ export class Hotkey extends EventEmitter<HotkeyEvent> {
/** 当前正在按下的按键 */
private pressed: Set<KeyCode> = new Set();
/** 有哪些单次按下的按键已经触发 */
private downEmitted: Set<KeyCode> = new Set();
/** 按键按下时的时间 */
private pressTime: Map<KeyCode, number> = new Map();
/** 按键节流时间 */
@@ -262,6 +264,10 @@ export class Hotkey extends EventEmitter<HotkeyEvent> {
});
this.emit('emit', key, assist, type);
if (type === 'down') {
this.downEmitted.add(key);
}
return emitted;
}
@@ -284,6 +290,7 @@ export class Hotkey extends EventEmitter<HotkeyEvent> {
if (!this.pressed.has(keyCode)) return;
this.pressed.delete(keyCode);
this.pressTime.delete(keyCode);
this.downEmitted.delete(keyCode);
this.emit('release', keyCode);
}
@@ -306,7 +313,7 @@ export class Hotkey extends EventEmitter<HotkeyEvent> {
}
if (!config) return false;
// 按下单次触发
if (config.type === 'down') return !this.pressed.has(keyCode);
if (config.type === 'down') return !this.downEmitted.has(keyCode);
// 按下重复触发
if (config.type === 'down-repeat') return true;
if (config.type === 'down-timeout') {