@muvtacode/cli 0.1.8 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/loop.js +10 -1
- package/dist/agent/loop.js.map +1 -1
- package/dist/agent/prompt.js +101 -0
- package/dist/agent/prompt.js.map +1 -1
- package/dist/cli.js +102 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/index.js +28 -0
- package/dist/commands/index.js.map +1 -1
- package/dist/i18n/en.js +4 -0
- package/dist/i18n/en.js.map +1 -1
- package/dist/i18n/pt.js +4 -0
- package/dist/i18n/pt.js.map +1 -1
- package/dist/remote/claudeSessions.js +82 -0
- package/dist/remote/claudeSessions.js.map +1 -0
- package/dist/remote/host.js +530 -0
- package/dist/remote/host.js.map +1 -0
- package/dist/remote/passagem.js +545 -0
- package/dist/remote/passagem.js.map +1 -0
- package/dist/repl.js +94 -22
- package/dist/repl.js.map +1 -1
- package/dist/state/templates.js +43 -10
- package/dist/state/templates.js.map +1 -1
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/AssaultRifle_1.mtl +42 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/AssaultRifle_1.obj +1472 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Grip.mtl +12 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Grip.obj +890 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/LICENCA.txt +25 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Pistol_1.mtl +52 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Pistol_1.obj +1444 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Pistol_4.mtl +32 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Pistol_4.obj +1789 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Revolver_1.mtl +32 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Revolver_1.obj +1273 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Scope_1.mtl +32 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Scope_1.obj +485 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Shotgun_1.mtl +42 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Shotgun_1.obj +1589 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Silencer_1.mtl +12 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/Silencer_1.obj +309 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/SniperRifle_1.mtl +52 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/SniperRifle_1.obj +1681 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/SubmachineGun_1.mtl +42 -0
- package/dist/templates/game/adapt-assets-3d-01/files/public/models/armas/SubmachineGun_1.obj +1275 -0
- package/dist/templates/game/adapt-assets-3d-01/files/src/assets/modelos.ts +270 -0
- package/dist/templates/game/adapt-assets-3d-01/meta.json +30 -0
- package/dist/templates/game/adapt-audio-01/files/src/audio/audio.ts +309 -0
- package/dist/templates/game/adapt-audio-01/meta.json +47 -0
- package/dist/templates/game/adapt-camera-rig-01/files/src/camera/rig.ts +364 -0
- package/dist/templates/game/adapt-camera-rig-01/meta.json +53 -0
- package/dist/templates/game/adapt-controle-teclado-01/files/src/controles/teclado.ts +175 -0
- package/dist/templates/game/adapt-controle-teclado-01/meta.json +36 -0
- package/dist/templates/game/adapt-controle-toque-01/files/src/controles/toque.ts +407 -0
- package/dist/templates/game/adapt-controle-toque-01/meta.json +43 -0
- package/dist/templates/game/adapt-dia-noite-01/files/src/world/dianoite.ts +378 -0
- package/dist/templates/game/adapt-dia-noite-01/meta.json +50 -0
- package/dist/templates/game/adapt-hud-01/files/src/hud/hud.ts +859 -0
- package/dist/templates/game/adapt-hud-01/meta.json +69 -0
- package/dist/templates/game/adapt-menu-01/files/src/ui/menu.ts +427 -0
- package/dist/templates/game/adapt-menu-01/meta.json +41 -0
- package/dist/templates/game/adapt-particulas-01/files/src/vfx/particulas.ts +280 -0
- package/dist/templates/game/adapt-particulas-01/meta.json +50 -0
- package/dist/templates/game/adapt-perf-mobile-01/files/src/engine/performance.ts +220 -0
- package/dist/templates/game/adapt-perf-mobile-01/meta.json +49 -0
- package/dist/templates/game/adapt-primeira-pessoa-01/files/src/camera/primeirapessoa.ts +595 -0
- package/dist/templates/game/adapt-primeira-pessoa-01/meta.json +63 -0
- package/dist/templates/game/adapt-save-01/files/src/save/save.ts +188 -0
- package/dist/templates/game/adapt-save-01/meta.json +34 -0
- package/dist/templates/game/carro-2d-01/files/src/models/carro2d.ts +253 -0
- package/dist/templates/game/carro-2d-01/meta.json +38 -0
- package/dist/templates/game/carro-3d-01/files/src/models/carro3d.ts +266 -0
- package/dist/templates/game/carro-3d-01/meta.json +13 -0
- package/dist/templates/game/estruturas-3d-01/files/src/world/estruturas.ts +490 -0
- package/dist/templates/game/estruturas-3d-01/meta.json +13 -0
- package/dist/templates/game/fps-3d-01/files/src/fps/arena.ts +324 -0
- package/dist/templates/game/fps-3d-01/files/src/fps/armas.ts +398 -0
- package/dist/templates/game/fps-3d-01/files/src/fps/cena.ts +801 -0
- package/dist/templates/game/fps-3d-01/files/src/fps/coletaveis.ts +129 -0
- package/dist/templates/game/fps-3d-01/files/src/fps/fisica.ts +257 -0
- package/dist/templates/game/fps-3d-01/files/src/fps/inimigos.ts +608 -0
- package/dist/templates/game/fps-3d-01/files/src/fps/jogador.ts +224 -0
- package/dist/templates/game/fps-3d-01/files/src/main.ts +21 -0
- package/dist/templates/game/fps-3d-01/meta.json +48 -0
- package/dist/templates/game/game-design-tokens-01/files/src/design/tokens.ts +274 -0
- package/dist/templates/game/game-design-tokens-01/meta.json +13 -0
- package/dist/templates/game/game-engine-base-01/files/index.html +37 -0
- package/dist/templates/game/game-engine-base-01/files/package.json +19 -0
- package/dist/templates/game/game-engine-base-01/files/src/engine/device.ts +57 -0
- package/dist/templates/game/game-engine-base-01/files/src/engine/engine.ts +221 -0
- package/dist/templates/game/game-engine-base-01/files/src/engine/index.ts +68 -0
- package/dist/templates/game/game-engine-base-01/files/src/engine/input.ts +578 -0
- package/dist/templates/game/game-engine-base-01/files/src/engine/layout.ts +192 -0
- package/dist/templates/game/game-engine-base-01/files/tsconfig.json +14 -0
- package/dist/templates/game/game-engine-base-01/files/vite.config.ts +10 -0
- package/dist/templates/game/game-engine-base-01/meta.json +70 -0
- package/dist/templates/game/mundo-25d-01/files/src/world/mundo25d.ts +252 -0
- package/dist/templates/game/mundo-25d-01/meta.json +39 -0
- package/dist/templates/game/mundo-2d-01/files/src/world/mundo2d.ts +273 -0
- package/dist/templates/game/mundo-2d-01/meta.json +38 -0
- package/dist/templates/game/mundo-3d-01/files/src/world/mundo3d.ts +3130 -0
- package/dist/templates/game/mundo-3d-01/meta.json +132 -0
- package/dist/templates/game/npc-3d-01/files/src/ai/npc3d.ts +658 -0
- package/dist/templates/game/npc-3d-01/meta.json +13 -0
- package/dist/templates/game/personagem-2d-01/files/src/models/personagem2d.ts +341 -0
- package/dist/templates/game/personagem-2d-01/meta.json +41 -0
- package/dist/templates/game/personagem-3d-01/files/src/models/personagem3d.ts +614 -0
- package/dist/templates/game/personagem-3d-01/meta.json +67 -0
- package/package.json +2 -1
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Detecção de dispositivo — a decisão que muda controle, HUD e performance.
|
|
2
|
+
//
|
|
3
|
+
// Não usamos user-agent sniffing como fonte primária: ele mente (iPad se diz
|
|
4
|
+
// Mac, navegador desktop com modo responsivo se diz celular). O sinal confiável
|
|
5
|
+
// é a CAPACIDADE: ponteiro grosso (dedo) x fino (mouse), e existência de toque.
|
|
6
|
+
|
|
7
|
+
export type Alvo = 'desktop' | 'mobile';
|
|
8
|
+
|
|
9
|
+
export interface Dispositivo {
|
|
10
|
+
alvo: Alvo;
|
|
11
|
+
temToque: boolean;
|
|
12
|
+
temPonteiroFino: boolean;
|
|
13
|
+
temTeclado: boolean;
|
|
14
|
+
/** Núcleos lógicos. Usado pelo adapt-perf-mobile para escolher o nível gráfico. */
|
|
15
|
+
nucleos: number;
|
|
16
|
+
/** GB de RAM, quando o navegador informa (Chrome). 0 = desconhecido. */
|
|
17
|
+
memoriaGb: number;
|
|
18
|
+
/** devicePixelRatio real, antes do clamp. */
|
|
19
|
+
dpr: number;
|
|
20
|
+
/** true quando o usuário pediu menos animação no sistema. Respeite. */
|
|
21
|
+
preferMenosMovimento: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function consultar(query: string): boolean {
|
|
25
|
+
return typeof matchMedia === 'function' && matchMedia(query).matches;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function detectarDispositivo(): Dispositivo {
|
|
29
|
+
const temToque =
|
|
30
|
+
typeof navigator !== 'undefined' &&
|
|
31
|
+
(navigator.maxTouchPoints > 0 || 'ontouchstart' in globalThis);
|
|
32
|
+
|
|
33
|
+
// 'pointer: fine' = mouse/trackpad/caneta. 'pointer: coarse' = dedo.
|
|
34
|
+
const temPonteiroFino = consultar('(pointer: fine)');
|
|
35
|
+
const temHoverReal = consultar('(hover: hover)');
|
|
36
|
+
|
|
37
|
+
// Um híbrido (notebook com tela sensível) tem os dois. Nesse caso vale o
|
|
38
|
+
// ponteiro fino: quem tem mouse espera controle de desktop.
|
|
39
|
+
const alvo: Alvo = temPonteiroFino && temHoverReal ? 'desktop' : temToque ? 'mobile' : 'desktop';
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
alvo,
|
|
43
|
+
temToque,
|
|
44
|
+
temPonteiroFino,
|
|
45
|
+
temTeclado: alvo === 'desktop',
|
|
46
|
+
nucleos: (typeof navigator !== 'undefined' && navigator.hardwareConcurrency) || 4,
|
|
47
|
+
memoriaGb: (typeof navigator !== 'undefined' && (navigator as never as { deviceMemory?: number }).deviceMemory) || 0,
|
|
48
|
+
dpr: typeof devicePixelRatio === 'number' ? devicePixelRatio : 1,
|
|
49
|
+
preferMenosMovimento: consultar('(prefers-reduced-motion: reduce)')
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Instância única — detectar é barato, mas o resultado não muda durante a partida. */
|
|
54
|
+
export const dispositivo: Dispositivo = detectarDispositivo();
|
|
55
|
+
|
|
56
|
+
/** Orientação atual. Jogo mobile costuma exigir uma delas. */
|
|
57
|
+
export const ehRetrato = (): boolean => innerHeight >= innerWidth;
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Laço principal com PASSO FIXO.
|
|
3
|
+
//
|
|
4
|
+
// Por que não `requestAnimationFrame` puro com delta variável:
|
|
5
|
+
// num monitor de 144Hz o delta é ~7ms, num celular fraco pode ser 50ms. Física
|
|
6
|
+
// integrada com delta variável muda de comportamento com o hardware — o pulo
|
|
7
|
+
// fica mais alto no PC bom, a colisão atravessa a parede no celular ruim.
|
|
8
|
+
//
|
|
9
|
+
// Aqui a simulação anda em fatias fixas (padrão 1/60s) e o desenho interpola
|
|
10
|
+
// entre a fatia anterior e a atual. Resultado: mesmo comportamento em qualquer
|
|
11
|
+
// máquina, e movimento suave mesmo quando a taxa de desenho não bate com a de
|
|
12
|
+
// simulação. É o "fix your timestep" clássico do Glenn Fiedler.
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
|
|
15
|
+
import { Input } from './input';
|
|
16
|
+
import { dispositivo } from './device';
|
|
17
|
+
|
|
18
|
+
export interface Cena {
|
|
19
|
+
nome: string;
|
|
20
|
+
/** Chamado uma vez ao entrar. Carregue e monte aqui. */
|
|
21
|
+
entrar?(ctx: ContextoEngine): void | Promise<void>;
|
|
22
|
+
/** Simulação. `passo` é SEMPRE o mesmo valor (padrão 1/60). */
|
|
23
|
+
atualizar(passo: number, ctx: ContextoEngine): void;
|
|
24
|
+
/**
|
|
25
|
+
* Desenho. `alpha` (0..1) é o quanto interpolar entre o estado anterior e o
|
|
26
|
+
* atual — use para posicionar visuais e o movimento fica suave.
|
|
27
|
+
*/
|
|
28
|
+
desenhar(alpha: number, ctx: ContextoEngine): void;
|
|
29
|
+
/** Chamado ao sair. Libere geometrias, listeners, áudio. */
|
|
30
|
+
sair?(): void;
|
|
31
|
+
/** Chamado no resize. */
|
|
32
|
+
redimensionar?(largura: number, altura: number): void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface ContextoEngine {
|
|
36
|
+
engine: Engine;
|
|
37
|
+
input: Input;
|
|
38
|
+
canvas: HTMLCanvasElement;
|
|
39
|
+
/** Largura/altura em pixels CSS (não físicos). Use para lógica e layout. */
|
|
40
|
+
largura: number;
|
|
41
|
+
altura: number;
|
|
42
|
+
dispositivo: typeof dispositivo;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface EngineOpts {
|
|
46
|
+
canvas: HTMLCanvasElement;
|
|
47
|
+
/** Passos de simulação por segundo. 60 serve para quase tudo. */
|
|
48
|
+
hz?: number;
|
|
49
|
+
/**
|
|
50
|
+
* Teto de devicePixelRatio. Celular moderno tem DPR 3-4: renderizar nisso
|
|
51
|
+
* custa 9-16x mais pixels e derruba o FPS sem ganho visual real num jogo.
|
|
52
|
+
*/
|
|
53
|
+
dprMaximo?: number;
|
|
54
|
+
/** Pausa quando a aba perde o foco. Economiza bateria e evita "pulo no tempo". */
|
|
55
|
+
pausarSemFoco?: boolean;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export class Engine {
|
|
59
|
+
readonly canvas: HTMLCanvasElement;
|
|
60
|
+
readonly input: Input;
|
|
61
|
+
readonly hz: number;
|
|
62
|
+
private readonly passo: number;
|
|
63
|
+
private dprMaximo: number;
|
|
64
|
+
|
|
65
|
+
private cena: Cena | null = null;
|
|
66
|
+
private rodando = false;
|
|
67
|
+
private pausado = false;
|
|
68
|
+
private acumulador = 0;
|
|
69
|
+
private ultimoTempo = 0;
|
|
70
|
+
private rafId = 0;
|
|
71
|
+
|
|
72
|
+
/** Estatísticas para o HUD de debug. */
|
|
73
|
+
readonly stats = { fps: 0, passosPorQuadro: 0, msQuadro: 0 };
|
|
74
|
+
private amostrasFps: number[] = [];
|
|
75
|
+
|
|
76
|
+
constructor(opts: EngineOpts) {
|
|
77
|
+
this.canvas = opts.canvas;
|
|
78
|
+
this.hz = opts.hz ?? 60;
|
|
79
|
+
this.passo = 1 / this.hz;
|
|
80
|
+
this.dprMaximo = opts.dprMaximo ?? (dispositivo.alvo === 'mobile' ? 2 : 2.5);
|
|
81
|
+
this.input = new Input(this.canvas);
|
|
82
|
+
|
|
83
|
+
addEventListener('resize', this.aoRedimensionar);
|
|
84
|
+
this.aoRedimensionar();
|
|
85
|
+
|
|
86
|
+
if (opts.pausarSemFoco ?? true) {
|
|
87
|
+
document.addEventListener('visibilitychange', () => {
|
|
88
|
+
if (document.hidden) this.pausar();
|
|
89
|
+
else this.retomar();
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
private get contexto(): ContextoEngine {
|
|
95
|
+
return {
|
|
96
|
+
engine: this,
|
|
97
|
+
input: this.input,
|
|
98
|
+
canvas: this.canvas,
|
|
99
|
+
largura: this.canvas.clientWidth,
|
|
100
|
+
altura: this.canvas.clientHeight,
|
|
101
|
+
dispositivo
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
private aoRedimensionar = (): void => {
|
|
106
|
+
const dpr = Math.min(devicePixelRatio || 1, this.dprMaximo);
|
|
107
|
+
const l = this.canvas.clientWidth || innerWidth;
|
|
108
|
+
const a = this.canvas.clientHeight || innerHeight;
|
|
109
|
+
// Só mexe no buffer se mudou de verdade: atribuir width/height limpa o
|
|
110
|
+
// canvas e recria a textura da GPU, então fazer isso todo quadro custa caro.
|
|
111
|
+
const lp = Math.round(l * dpr);
|
|
112
|
+
const ap = Math.round(a * dpr);
|
|
113
|
+
if (this.canvas.width !== lp || this.canvas.height !== ap) {
|
|
114
|
+
this.canvas.width = lp;
|
|
115
|
+
this.canvas.height = ap;
|
|
116
|
+
}
|
|
117
|
+
this.cena?.redimensionar?.(l, a);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Teto de devicePixelRatio. O gerenciador de performance chama isto ao trocar
|
|
122
|
+
* o nível gráfico — é de longe o ajuste com maior efeito no FPS, porque o
|
|
123
|
+
* custo é quadrático no número de pixels.
|
|
124
|
+
*/
|
|
125
|
+
definirDprMaximo(valor: number): void {
|
|
126
|
+
const novo = Math.max(0.5, Math.min(4, valor));
|
|
127
|
+
if (novo === this.dprMaximo) return;
|
|
128
|
+
this.dprMaximo = novo;
|
|
129
|
+
this.aoRedimensionar();
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
get dprEfetivo(): number {
|
|
133
|
+
return Math.min(devicePixelRatio || 1, this.dprMaximo);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Troca a cena, chamando sair() da antiga e entrar() da nova. */
|
|
137
|
+
async trocarCena(nova: Cena): Promise<void> {
|
|
138
|
+
this.cena?.sair?.();
|
|
139
|
+
this.cena = nova;
|
|
140
|
+
await nova.entrar?.(this.contexto);
|
|
141
|
+
nova.redimensionar?.(this.canvas.clientWidth, this.canvas.clientHeight);
|
|
142
|
+
// Zera o acumulador: o tempo gasto carregando a cena não é tempo de jogo.
|
|
143
|
+
this.acumulador = 0;
|
|
144
|
+
this.ultimoTempo = performance.now();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
iniciar(): void {
|
|
148
|
+
if (this.rodando) return;
|
|
149
|
+
this.rodando = true;
|
|
150
|
+
this.ultimoTempo = performance.now();
|
|
151
|
+
this.rafId = requestAnimationFrame(this.quadro);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
pausar(): void { this.pausado = true; }
|
|
155
|
+
|
|
156
|
+
retomar(): void {
|
|
157
|
+
if (!this.pausado) return;
|
|
158
|
+
this.pausado = false;
|
|
159
|
+
// Sem isto, o tempo parado vira um delta gigante e a física explode.
|
|
160
|
+
this.ultimoTempo = performance.now();
|
|
161
|
+
this.acumulador = 0;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
parar(): void {
|
|
165
|
+
this.rodando = false;
|
|
166
|
+
cancelAnimationFrame(this.rafId);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
private quadro = (agora: number): void => {
|
|
170
|
+
if (!this.rodando) return;
|
|
171
|
+
this.rafId = requestAnimationFrame(this.quadro);
|
|
172
|
+
if (this.pausado || !this.cena) return;
|
|
173
|
+
|
|
174
|
+
const inicio = performance.now();
|
|
175
|
+
let delta = (agora - this.ultimoTempo) / 1000;
|
|
176
|
+
this.ultimoTempo = agora;
|
|
177
|
+
|
|
178
|
+
// Teto do delta: se a aba ficou 10s congelada, NÃO simule 600 passos de
|
|
179
|
+
// uma vez (travaria por segundos e ainda por cima com física errada).
|
|
180
|
+
// Perder tempo de simulação é melhor do que travar — é a "espiral da morte".
|
|
181
|
+
if (delta > 0.25) delta = 0.25;
|
|
182
|
+
|
|
183
|
+
this.acumulador += delta;
|
|
184
|
+
this.input.inicioDeQuadro();
|
|
185
|
+
|
|
186
|
+
let passos = 0;
|
|
187
|
+
const ctx = this.contexto;
|
|
188
|
+
while (this.acumulador >= this.passo) {
|
|
189
|
+
this.cena.atualizar(this.passo, ctx);
|
|
190
|
+
// Fecha o passo DENTRO do laço: as bordas (`pressionou`) valem para um
|
|
191
|
+
// passo, não para o quadro. Fechar só no fim transformava um toque no
|
|
192
|
+
// espaço em até 5 pulos num quadro pesado.
|
|
193
|
+
this.input.fimDePasso();
|
|
194
|
+
this.acumulador -= this.passo;
|
|
195
|
+
if (++passos >= 5) { this.acumulador = 0; break; } // trava de segurança
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
this.cena.desenhar(this.acumulador / this.passo, ctx);
|
|
199
|
+
this.input.fimDeQuadro();
|
|
200
|
+
|
|
201
|
+
this.stats.passosPorQuadro = passos;
|
|
202
|
+
this.stats.msQuadro = performance.now() - inicio;
|
|
203
|
+
this.medirFps(delta);
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
/** FPS suavizado em 30 amostras — o instantâneo pisca demais para ser lido. */
|
|
207
|
+
private medirFps(delta: number): void {
|
|
208
|
+
if (delta <= 0) return;
|
|
209
|
+
this.amostrasFps.push(1 / delta);
|
|
210
|
+
if (this.amostrasFps.length > 30) this.amostrasFps.shift();
|
|
211
|
+
const soma = this.amostrasFps.reduce((a, b) => a + b, 0);
|
|
212
|
+
this.stats.fps = Math.round(soma / this.amostrasFps.length);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
dispose(): void {
|
|
216
|
+
this.parar();
|
|
217
|
+
this.cena?.sair?.();
|
|
218
|
+
this.input.dispose();
|
|
219
|
+
removeEventListener('resize', this.aoRedimensionar);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Ponto de entrada do engine. Importe daqui, não dos arquivos internos.
|
|
2
|
+
export { Engine } from './engine';
|
|
3
|
+
export type { Cena, ContextoEngine, EngineOpts } from './engine';
|
|
4
|
+
export { Input, MAPA_TECLADO, ACOES, tuningInput } from './input';
|
|
5
|
+
export type { Acao, EstadoPonteiro, EstadoOlhar } from './input';
|
|
6
|
+
export { dispositivo, detectarDispositivo, ehRetrato } from './device';
|
|
7
|
+
export type { Dispositivo, Alvo } from './device';
|
|
8
|
+
export {
|
|
9
|
+
safeArea,
|
|
10
|
+
margemDe,
|
|
11
|
+
registrarZonas,
|
|
12
|
+
removerZonas,
|
|
13
|
+
zonasOcupadas,
|
|
14
|
+
zonaNoCanto,
|
|
15
|
+
cantoLivre,
|
|
16
|
+
invalidarLayout
|
|
17
|
+
} from './layout';
|
|
18
|
+
export type { Insets, Zona, Canto } from './layout';
|
|
19
|
+
|
|
20
|
+
import { Engine } from './engine';
|
|
21
|
+
import { dispositivo } from './device';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Sobe o jogo em 3 linhas.
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* const engine = bootstrap();
|
|
28
|
+
* await engine.trocarCena(minhaCena);
|
|
29
|
+
* engine.iniciar();
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* Cria o canvas se ele não existir, aplica o CSS mínimo (tela cheia, sem
|
|
33
|
+
* scroll, sem highlight azul de toque no celular) e devolve o engine pronto.
|
|
34
|
+
*/
|
|
35
|
+
export function bootstrap(seletor = '#jogo'): Engine {
|
|
36
|
+
let canvas = document.querySelector<HTMLCanvasElement>(seletor);
|
|
37
|
+
if (!canvas) {
|
|
38
|
+
canvas = document.createElement('canvas');
|
|
39
|
+
canvas.id = seletor.replace('#', '');
|
|
40
|
+
document.body.appendChild(canvas);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const estilo = document.createElement('style');
|
|
44
|
+
estilo.textContent = `
|
|
45
|
+
:root {
|
|
46
|
+
/* Publicadas para quem preferir posicionar em CSS. Quem posiciona em
|
|
47
|
+
canvas deve usar safeArea() do layout.ts — custom property com env()
|
|
48
|
+
não é lida de volta de forma confiável por getComputedStyle. */
|
|
49
|
+
--sat: env(safe-area-inset-top, 0px);
|
|
50
|
+
--sab: env(safe-area-inset-bottom, 0px);
|
|
51
|
+
--sal: env(safe-area-inset-left, 0px);
|
|
52
|
+
--sar: env(safe-area-inset-right, 0px);
|
|
53
|
+
}
|
|
54
|
+
html, body { margin: 0; height: 100%; overflow: hidden; background: #000; }
|
|
55
|
+
${seletor} {
|
|
56
|
+
display: block; width: 100vw; height: 100dvh;
|
|
57
|
+
touch-action: none; /* sem scroll/zoom acidental no jogo */
|
|
58
|
+
-webkit-tap-highlight-color: transparent;
|
|
59
|
+
user-select: none;
|
|
60
|
+
}
|
|
61
|
+
`;
|
|
62
|
+
document.head.appendChild(estilo);
|
|
63
|
+
|
|
64
|
+
// Menu de contexto atrapalha o "segurar para atirar" no celular.
|
|
65
|
+
canvas.addEventListener('contextmenu', (e) => e.preventDefault());
|
|
66
|
+
|
|
67
|
+
return new Engine({ canvas, pausarSemFoco: true, dprMaximo: dispositivo.alvo === 'mobile' ? 2 : 2.5 });
|
|
68
|
+
}
|