@muvtacode/cli 0.1.9 → 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 +4 -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/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 +123 -6
- package/dist/templates/game/adapt-audio-01/meta.json +47 -34
- package/dist/templates/game/adapt-camera-rig-01/files/src/camera/rig.ts +226 -55
- package/dist/templates/game/adapt-camera-rig-01/meta.json +53 -38
- package/dist/templates/game/adapt-controle-teclado-01/files/src/controles/teclado.ts +175 -171
- package/dist/templates/game/adapt-controle-teclado-01/meta.json +36 -34
- package/dist/templates/game/adapt-controle-toque-01/files/src/controles/toque.ts +152 -36
- package/dist/templates/game/adapt-controle-toque-01/meta.json +43 -36
- package/dist/templates/game/adapt-dia-noite-01/files/src/world/dianoite.ts +274 -53
- package/dist/templates/game/adapt-dia-noite-01/meta.json +21 -9
- package/dist/templates/game/adapt-hud-01/files/src/hud/hud.ts +859 -263
- package/dist/templates/game/adapt-hud-01/meta.json +69 -36
- package/dist/templates/game/adapt-menu-01/files/src/ui/menu.ts +427 -273
- package/dist/templates/game/adapt-menu-01/meta.json +41 -36
- package/dist/templates/game/adapt-particulas-01/files/src/vfx/particulas.ts +107 -39
- package/dist/templates/game/adapt-particulas-01/meta.json +50 -38
- package/dist/templates/game/adapt-perf-mobile-01/files/src/engine/performance.ts +108 -33
- package/dist/templates/game/adapt-perf-mobile-01/meta.json +20 -6
- 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/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-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/engine.ts +22 -2
- package/dist/templates/game/game-engine-base-01/files/src/engine/index.ts +22 -2
- package/dist/templates/game/game-engine-base-01/files/src/engine/input.ts +430 -58
- 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 -13
- package/dist/templates/game/mundo-3d-01/files/src/world/mundo3d.ts +2953 -73
- package/dist/templates/game/mundo-3d-01/meta.json +125 -6
- 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-3d-01/files/src/models/personagem3d.ts +428 -107
- package/dist/templates/game/personagem-3d-01/meta.json +60 -6
- package/package.json +2 -1
|
@@ -1,273 +1,427 @@
|
|
|
1
|
-
// ---------------------------------------------------------------------------
|
|
2
|
-
// Menus navegáveis por teclado, gamepad E toque — com o mesmo código.
|
|
3
|
-
//
|
|
4
|
-
// O truque é não pensar em "clique" e sim em ÍNDICE SELECIONADO. Teclado e
|
|
5
|
-
// gamepad movem o índice; o toque/mouse move o índice para o item sob o dedo e
|
|
6
|
-
// confirma. Um caminho só, sem duplicar lógica por dispositivo.
|
|
7
|
-
//
|
|
8
|
-
// A pausa aqui é real: chama engine.pausar(), que congela a simulação. Só
|
|
9
|
-
// desenhar uma tela por cima deixaria o jogo rodando atrás — inimigo continua
|
|
10
|
-
// andando enquanto o jogador mexe nas opções.
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
redimensionar()
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
const
|
|
142
|
-
if (
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
1
|
+
// ---------------------------------------------------------------------------
|
|
2
|
+
// Menus navegáveis por teclado, gamepad E toque — com o mesmo código.
|
|
3
|
+
//
|
|
4
|
+
// O truque é não pensar em "clique" e sim em ÍNDICE SELECIONADO. Teclado e
|
|
5
|
+
// gamepad movem o índice; o toque/mouse move o índice para o item sob o dedo e
|
|
6
|
+
// confirma. Um caminho só, sem duplicar lógica por dispositivo.
|
|
7
|
+
//
|
|
8
|
+
// A pausa aqui é real: chama engine.pausar(), que congela a simulação. Só
|
|
9
|
+
// desenhar uma tela por cima deixaria o jogo rodando atrás — inimigo continua
|
|
10
|
+
// andando enquanto o jogador mexe nas opções.
|
|
11
|
+
//
|
|
12
|
+
// E por isso mesmo o menu tem LAÇO PRÓPRIO enquanto está aberto. A versão
|
|
13
|
+
// anterior dependia de a cena chamar menu.atualizar()/desenhar() — mas com o
|
|
14
|
+
// engine pausado a cena não roda, então o menu de pausa abria INVISÍVEL: o jogo
|
|
15
|
+
// congelava, o canvas transparente engolia os cliques e parecia travamento.
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
|
|
18
|
+
import type { Engine, Input } from '../engine';
|
|
19
|
+
import { getPalette, alpha, type as tipo, PALETTE_NAMES, setPalette, paletteAtual } from '../design/tokens';
|
|
20
|
+
|
|
21
|
+
export const tuning = {
|
|
22
|
+
larguraItem: 320,
|
|
23
|
+
alturaItem: 52,
|
|
24
|
+
espacamento: 10,
|
|
25
|
+
/** Repetição ao segurar a direção (segundos). */
|
|
26
|
+
atrasoRepeticao: 0.42,
|
|
27
|
+
intervaloRepeticao: 0.13
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export interface ItemMenu {
|
|
31
|
+
rotulo: string;
|
|
32
|
+
/** Ação ao confirmar. Ausente = item informativo. */
|
|
33
|
+
aoConfirmar?: () => void;
|
|
34
|
+
/** Se presente, o item vira um seletor ◄ valor ►. */
|
|
35
|
+
opcoes?: string[];
|
|
36
|
+
valorAtual?: () => string;
|
|
37
|
+
aoMudar?: (novo: string, indice: number) => void;
|
|
38
|
+
desabilitado?: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface Tela {
|
|
42
|
+
titulo: string;
|
|
43
|
+
itens: ItemMenu[];
|
|
44
|
+
/** Ao apertar voltar/Esc. Ausente = não dá para sair. */
|
|
45
|
+
aoVoltar?: () => void;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface Menu {
|
|
49
|
+
abrir(tela: Tela): void;
|
|
50
|
+
fechar(): void;
|
|
51
|
+
readonly aberto: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Mantido por compatibilidade: o menu agora se atualiza sozinho (laço próprio
|
|
54
|
+
* enquanto aberto). Chamar não faz mal — não faz nada.
|
|
55
|
+
*/
|
|
56
|
+
atualizar(passo: number): void;
|
|
57
|
+
/** Mantido por compatibilidade: o laço próprio já desenha a cada quadro. */
|
|
58
|
+
desenhar(): void;
|
|
59
|
+
dispose(): void;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function criarMenu(engine: Engine, input: Input): Menu {
|
|
63
|
+
const canvas = document.createElement('canvas');
|
|
64
|
+
canvas.style.cssText = 'position:fixed;inset:0;z-index:30;display:none;touch-action:none;';
|
|
65
|
+
document.body.appendChild(canvas);
|
|
66
|
+
const ctx = canvas.getContext('2d')!;
|
|
67
|
+
|
|
68
|
+
const redimensionar = () => {
|
|
69
|
+
const dpr = Math.min(devicePixelRatio || 1, 2);
|
|
70
|
+
canvas.width = Math.round(innerWidth * dpr);
|
|
71
|
+
canvas.height = Math.round(innerHeight * dpr);
|
|
72
|
+
canvas.style.width = `${innerWidth}px`;
|
|
73
|
+
canvas.style.height = `${innerHeight}px`;
|
|
74
|
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
75
|
+
};
|
|
76
|
+
redimensionar();
|
|
77
|
+
addEventListener('resize', redimensionar);
|
|
78
|
+
|
|
79
|
+
let tela: Tela | null = null;
|
|
80
|
+
let selecionado = 0;
|
|
81
|
+
let tempoRepeticao = 0;
|
|
82
|
+
let repetindo = false;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Altura de item e espaçamento que CABEM na tela. Celular deitado (o jeito
|
|
86
|
+
* de jogar FPS) tem ~380 px de altura: um menu de 6 itens de 52 px estourava
|
|
87
|
+
* para fora, com o título cortado em cima.
|
|
88
|
+
*/
|
|
89
|
+
const medidas = () => {
|
|
90
|
+
const n = tela!.itens.length;
|
|
91
|
+
const disponivel = innerHeight - tipo.titulo - 70;
|
|
92
|
+
const total = n * tuning.alturaItem + (n - 1) * tuning.espacamento;
|
|
93
|
+
if (total <= disponivel) return { alt: tuning.alturaItem, esp: tuning.espacamento };
|
|
94
|
+
const k = Math.max(0.55, disponivel / total);
|
|
95
|
+
return {
|
|
96
|
+
alt: Math.max(30, Math.floor(tuning.alturaItem * k)),
|
|
97
|
+
esp: Math.max(3, Math.floor(tuning.espacamento * k))
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
/** Retângulo de cada item — usado no desenho E no toque. Fonte única. */
|
|
102
|
+
const retangulo = (i: number) => {
|
|
103
|
+
const total = tela!.itens.length;
|
|
104
|
+
const { alt, esp } = medidas();
|
|
105
|
+
const alturaTotal = total * alt + (total - 1) * esp;
|
|
106
|
+
const y0 = Math.max(tipo.titulo + 40, innerHeight / 2 - alturaTotal / 2 + 30);
|
|
107
|
+
const largura = Math.min(tuning.larguraItem, innerWidth - 32);
|
|
108
|
+
return {
|
|
109
|
+
x: innerWidth / 2 - largura / 2,
|
|
110
|
+
y: y0 + i * (alt + esp),
|
|
111
|
+
l: largura,
|
|
112
|
+
a: alt
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const itemEm = (x: number, y: number): number => {
|
|
117
|
+
if (!tela) return -1;
|
|
118
|
+
for (let i = 0; i < tela.itens.length; i++) {
|
|
119
|
+
const r = retangulo(i);
|
|
120
|
+
if (x >= r.x && x <= r.x + r.l && y >= r.y && y <= r.y + r.a) return i;
|
|
121
|
+
}
|
|
122
|
+
return -1;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const proximoValido = (dir: number) => {
|
|
126
|
+
if (!tela) return;
|
|
127
|
+
const n = tela.itens.length;
|
|
128
|
+
for (let k = 1; k <= n; k++) {
|
|
129
|
+
const i = (selecionado + dir * k + n * k) % n;
|
|
130
|
+
if (!tela.itens[i]?.desabilitado) { selecionado = i; return; }
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const confirmar = () => {
|
|
135
|
+
const item = tela?.itens[selecionado];
|
|
136
|
+
if (!item || item.desabilitado) return;
|
|
137
|
+
item.aoConfirmar?.();
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const mudarValor = (dir: number) => {
|
|
141
|
+
const item = tela?.itens[selecionado];
|
|
142
|
+
if (!item?.opcoes?.length || !item.valorAtual || !item.aoMudar) return;
|
|
143
|
+
const atual = item.opcoes.indexOf(item.valorAtual());
|
|
144
|
+
const novo = (atual + dir + item.opcoes.length) % item.opcoes.length;
|
|
145
|
+
item.aoMudar(item.opcoes[novo]!, novo);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
// ------------------------------------------------------------- ponteiro
|
|
149
|
+
const aoTocar = (e: PointerEvent) => {
|
|
150
|
+
if (!tela) return;
|
|
151
|
+
const i = itemEm(e.clientX, e.clientY);
|
|
152
|
+
if (i < 0 || tela.itens[i]?.desabilitado) return;
|
|
153
|
+
selecionado = i;
|
|
154
|
+
|
|
155
|
+
// Seletor: metade esquerda diminui, direita aumenta.
|
|
156
|
+
const item = tela.itens[i]!;
|
|
157
|
+
if (item.opcoes?.length) {
|
|
158
|
+
const r = retangulo(i);
|
|
159
|
+
mudarValor(e.clientX < r.x + r.l / 2 ? -1 : 1);
|
|
160
|
+
} else {
|
|
161
|
+
confirmar();
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
canvas.addEventListener('pointerdown', aoTocar);
|
|
165
|
+
|
|
166
|
+
const aoMoverPonteiro = (e: PointerEvent) => {
|
|
167
|
+
if (!tela) return;
|
|
168
|
+
const i = itemEm(e.clientX, e.clientY);
|
|
169
|
+
if (i >= 0 && !tela.itens[i]?.desabilitado) selecionado = i;
|
|
170
|
+
};
|
|
171
|
+
canvas.addEventListener('pointermove', aoMoverPonteiro);
|
|
172
|
+
|
|
173
|
+
// -------------------------------------------------------------- teclado
|
|
174
|
+
const aoTeclar = (e: KeyboardEvent) => {
|
|
175
|
+
if (!tela) return;
|
|
176
|
+
e.preventDefault();
|
|
177
|
+
switch (e.code) {
|
|
178
|
+
case 'ArrowUp': case 'KeyW': proximoValido(-1); break;
|
|
179
|
+
case 'ArrowDown': case 'KeyS': proximoValido(1); break;
|
|
180
|
+
case 'ArrowLeft': case 'KeyA': mudarValor(-1); break;
|
|
181
|
+
case 'ArrowRight': case 'KeyD': mudarValor(1); break;
|
|
182
|
+
case 'Enter': case 'Space': confirmar(); break;
|
|
183
|
+
case 'Escape': tela.aoVoltar?.(); break;
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
// ------------------------------------------------------------- gamepad
|
|
188
|
+
// Lido DIRETO do navigator, não de input.eixo(): o eixo do Input soma o
|
|
189
|
+
// teclado, e o teclado já navega pelo keydown acima — a seta andaria dois itens.
|
|
190
|
+
const botoesAntes: boolean[] = [];
|
|
191
|
+
|
|
192
|
+
const gamepadAtual = (): Gamepad | null => {
|
|
193
|
+
if (typeof navigator === 'undefined' || !navigator.getGamepads) return null;
|
|
194
|
+
for (const gp of navigator.getGamepads()) if (gp) return gp;
|
|
195
|
+
return null;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Fotografa os botões no momento em que uma tela abre. Sem isto, o Start que
|
|
200
|
+
* ABRIU a pausa ainda está apertado no quadro seguinte e já a fecharia.
|
|
201
|
+
*/
|
|
202
|
+
const fotografarBotoes = (): void => {
|
|
203
|
+
botoesAntes.length = 0;
|
|
204
|
+
const gp = gamepadAtual();
|
|
205
|
+
gp?.buttons.forEach((b, i) => { botoesAntes[i] = b.pressed; });
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
const navegarPorGamepad = (passo: number): void => {
|
|
209
|
+
const gp = gamepadAtual();
|
|
210
|
+
if (!gp) { tempoRepeticao = 0; repetindo = false; return; }
|
|
211
|
+
|
|
212
|
+
const apertou = (i: number): boolean => {
|
|
213
|
+
const agora = gp.buttons[i]?.pressed ?? false;
|
|
214
|
+
const antes = botoesAntes[i] ?? false;
|
|
215
|
+
botoesAntes[i] = agora;
|
|
216
|
+
return agora && !antes;
|
|
217
|
+
};
|
|
218
|
+
// Lê TODAS as bordas antes de agir: confirmar pode trocar de tela.
|
|
219
|
+
const confirmou = apertou(0); // A
|
|
220
|
+
const voltou = apertou(1) || apertou(9); // B ou Start
|
|
221
|
+
const cima = gp.buttons[12]?.pressed, baixo = gp.buttons[13]?.pressed;
|
|
222
|
+
const esq = gp.buttons[14]?.pressed, dir = gp.buttons[15]?.pressed;
|
|
223
|
+
const ax = gp.axes[0] ?? 0, ay = gp.axes[1] ?? 0;
|
|
224
|
+
|
|
225
|
+
if (confirmou) { confirmar(); return; }
|
|
226
|
+
if (voltou) { tela?.aoVoltar?.(); return; }
|
|
227
|
+
|
|
228
|
+
// D-pad OU analógico, com repetição — senão um toque no analógico pularia
|
|
229
|
+
// a lista inteira.
|
|
230
|
+
const dirY = cima ? -1 : baixo ? 1 : Math.abs(ay) > 0.55 ? Math.sign(ay) : 0;
|
|
231
|
+
const dirX = esq ? -1 : dir ? 1 : Math.abs(ax) > 0.55 ? Math.sign(ax) : 0;
|
|
232
|
+
if (dirY === 0 && dirX === 0) {
|
|
233
|
+
tempoRepeticao = 0;
|
|
234
|
+
repetindo = false;
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
if (tempoRepeticao <= 0) {
|
|
238
|
+
if (dirY !== 0) proximoValido(dirY);
|
|
239
|
+
else mudarValor(dirX);
|
|
240
|
+
tempoRepeticao = repetindo ? tuning.intervaloRepeticao : tuning.atrasoRepeticao;
|
|
241
|
+
repetindo = true;
|
|
242
|
+
} else {
|
|
243
|
+
tempoRepeticao -= passo;
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
// ---------------------------------------------------------- laço próprio
|
|
248
|
+
// `geracao` impede dois laços ao mesmo tempo: confirmar um item pode fechar e
|
|
249
|
+
// reabrir o menu dentro do próprio quadro, e cada abrir() agenda um laço novo.
|
|
250
|
+
let rafMenu = 0;
|
|
251
|
+
let ultimoT = 0;
|
|
252
|
+
let geracao = 0;
|
|
253
|
+
const iniciarLaco = (): void => {
|
|
254
|
+
const minha = ++geracao;
|
|
255
|
+
ultimoT = 0;
|
|
256
|
+
const laco = (t: number): void => {
|
|
257
|
+
if (!tela || minha !== geracao) return;
|
|
258
|
+
const dt = ultimoT ? Math.min(0.1, (t - ultimoT) / 1000) : 0;
|
|
259
|
+
ultimoT = t;
|
|
260
|
+
navegarPorGamepad(dt);
|
|
261
|
+
desenhar();
|
|
262
|
+
if (tela && minha === geracao) rafMenu = requestAnimationFrame(laco);
|
|
263
|
+
};
|
|
264
|
+
rafMenu = requestAnimationFrame(laco);
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
// -------------------------------------------------------------- desenho
|
|
268
|
+
const desenhar = (): void => {
|
|
269
|
+
if (!tela) return;
|
|
270
|
+
const p = getPalette();
|
|
271
|
+
ctx.clearRect(0, 0, innerWidth, innerHeight);
|
|
272
|
+
|
|
273
|
+
ctx.fillStyle = alpha(p.fundo, 0.86);
|
|
274
|
+
ctx.fillRect(0, 0, innerWidth, innerHeight);
|
|
275
|
+
|
|
276
|
+
ctx.fillStyle = p.primaria;
|
|
277
|
+
ctx.font = `bold ${tipo.titulo}px ${tipo.familia}`;
|
|
278
|
+
ctx.textAlign = 'center';
|
|
279
|
+
ctx.textBaseline = 'middle';
|
|
280
|
+
// Título acima do 1º item, mas nunca cortado no topo da tela.
|
|
281
|
+
ctx.fillText(tela.titulo, innerWidth / 2, Math.max(tipo.titulo * 0.75, retangulo(0).y - 62));
|
|
282
|
+
|
|
283
|
+
tela.itens.forEach((item, i) => {
|
|
284
|
+
const r = retangulo(i);
|
|
285
|
+
const ativo = i === selecionado;
|
|
286
|
+
const cor = item.desabilitado ? p.textoFraco : ativo ? p.acento : p.texto;
|
|
287
|
+
|
|
288
|
+
ctx.fillStyle = alpha(ativo ? p.superficie : p.fundo, ativo ? 0.95 : 0.6);
|
|
289
|
+
ctx.beginPath();
|
|
290
|
+
ctx.roundRect(r.x, r.y, r.l, r.a, 8);
|
|
291
|
+
ctx.fill();
|
|
292
|
+
|
|
293
|
+
ctx.strokeStyle = ativo ? p.acento : alpha(p.contorno, 0.7);
|
|
294
|
+
ctx.lineWidth = ativo ? 2.5 : 1.5;
|
|
295
|
+
ctx.stroke();
|
|
296
|
+
|
|
297
|
+
ctx.fillStyle = cor;
|
|
298
|
+
ctx.font = `${ativo ? 'bold ' : ''}${tipo.base}px ${tipo.familia}`;
|
|
299
|
+
|
|
300
|
+
if (item.opcoes?.length && item.valorAtual) {
|
|
301
|
+
ctx.textAlign = 'left';
|
|
302
|
+
ctx.fillText(item.rotulo, r.x + 18, r.y + r.a / 2);
|
|
303
|
+
ctx.textAlign = 'right';
|
|
304
|
+
ctx.fillText(`◄ ${item.valorAtual()} ►`, r.x + r.l - 18, r.y + r.a / 2);
|
|
305
|
+
} else {
|
|
306
|
+
ctx.textAlign = 'center';
|
|
307
|
+
ctx.fillText(item.rotulo, r.x + r.l / 2, r.y + r.a / 2);
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
// ---------------------------------------------------------------- telas
|
|
313
|
+
const abrir = (t: Tela): void => {
|
|
314
|
+
const jaAberto = tela !== null;
|
|
315
|
+
tela = t;
|
|
316
|
+
selecionado = t.itens.findIndex((i) => !i.desabilitado);
|
|
317
|
+
if (selecionado < 0) selecionado = 0;
|
|
318
|
+
tempoRepeticao = 0;
|
|
319
|
+
repetindo = false;
|
|
320
|
+
fotografarBotoes();
|
|
321
|
+
canvas.style.display = 'block';
|
|
322
|
+
// Mouse travado (FPS) não tem cursor para clicar no menu: solta.
|
|
323
|
+
if (typeof document !== 'undefined' && document.pointerLockElement) document.exitPointerLock?.();
|
|
324
|
+
if (!jaAberto) {
|
|
325
|
+
addEventListener('keydown', aoTeclar);
|
|
326
|
+
engine.pausar();
|
|
327
|
+
iniciarLaco();
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
const fechar = (): void => {
|
|
332
|
+
if (!tela) return;
|
|
333
|
+
tela = null;
|
|
334
|
+
geracao++;
|
|
335
|
+
cancelAnimationFrame(rafMenu);
|
|
336
|
+
canvas.style.display = 'none';
|
|
337
|
+
removeEventListener('keydown', aoTeclar);
|
|
338
|
+
engine.retomar();
|
|
339
|
+
// Descarta as bordas que o Input anotou com o menu aberto: o Esc que fechou
|
|
340
|
+
// a pausa também é a tecla de 'pausar', e reabriria o menu no passo seguinte.
|
|
341
|
+
input.fimDePasso();
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
return {
|
|
345
|
+
abrir,
|
|
346
|
+
fechar,
|
|
347
|
+
get aberto() { return tela !== null; },
|
|
348
|
+
atualizar: () => { /* laço próprio — ver iniciarLaco() */ },
|
|
349
|
+
desenhar,
|
|
350
|
+
dispose() {
|
|
351
|
+
geracao++;
|
|
352
|
+
cancelAnimationFrame(rafMenu);
|
|
353
|
+
removeEventListener('keydown', aoTeclar);
|
|
354
|
+
removeEventListener('resize', redimensionar);
|
|
355
|
+
canvas.remove();
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Um seletor "◄ valor ►" genérico para injetar na tela de opções.
|
|
362
|
+
*
|
|
363
|
+
* É por aqui que entram gráficos, sensibilidade e inverter-Y sem que o menu
|
|
364
|
+
* precise importar o gerenciador de performance ou o rig de câmera — o menu
|
|
365
|
+
* ficaria acoplado a templates que talvez não estejam aplicados no projeto.
|
|
366
|
+
*/
|
|
367
|
+
export interface SeletorOpcao {
|
|
368
|
+
rotulo: string;
|
|
369
|
+
opcoes: string[];
|
|
370
|
+
valor(): string;
|
|
371
|
+
definir(novo: string, indice: number): void;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Tela de opções pronta — inclui o seletor das 12 paletas.
|
|
376
|
+
*
|
|
377
|
+
* Para adicionar o nível gráfico (adapt-perf-mobile-01):
|
|
378
|
+
*
|
|
379
|
+
* ```ts
|
|
380
|
+
* import { PRESETS, ROTULO_PRESET, type Preset } from '../engine/performance';
|
|
381
|
+
*
|
|
382
|
+
* menu.abrir(telaOpcoes(menu, voltar, [{
|
|
383
|
+
* rotulo: 'Gráficos',
|
|
384
|
+
* opcoes: PRESETS.map((p) => ROTULO_PRESET[p]),
|
|
385
|
+
* valor: () => ROTULO_PRESET[perf.preset],
|
|
386
|
+
* definir: (_, i) => perf.definirPreset(PRESETS[i]!)
|
|
387
|
+
* }]));
|
|
388
|
+
* ```
|
|
389
|
+
*
|
|
390
|
+
* E para inverter o eixo vertical da câmera (adapt-camera-rig-01):
|
|
391
|
+
*
|
|
392
|
+
* ```ts
|
|
393
|
+
* {
|
|
394
|
+
* rotulo: 'Inverter Y',
|
|
395
|
+
* opcoes: ['Não', 'Sim'],
|
|
396
|
+
* valor: () => (tuningCamera.inverterY ? 'Sim' : 'Não'),
|
|
397
|
+
* definir: (_, i) => { tuningCamera.inverterY = i === 1; }
|
|
398
|
+
* }
|
|
399
|
+
* ```
|
|
400
|
+
*/
|
|
401
|
+
export function telaOpcoes(
|
|
402
|
+
// Recebido para manter a assinatura das outras telas (e para telas futuras que
|
|
403
|
+
// precisem navegar a partir daqui); esta não usa.
|
|
404
|
+
_menu: Menu,
|
|
405
|
+
aoVoltar: () => void,
|
|
406
|
+
extras: SeletorOpcao[] = []
|
|
407
|
+
): Tela {
|
|
408
|
+
return {
|
|
409
|
+
titulo: 'Opções',
|
|
410
|
+
itens: [
|
|
411
|
+
{
|
|
412
|
+
rotulo: 'Tema',
|
|
413
|
+
opcoes: PALETTE_NAMES,
|
|
414
|
+
valorAtual: () => paletteAtual(),
|
|
415
|
+
aoMudar: (novo) => setPalette(novo)
|
|
416
|
+
},
|
|
417
|
+
...extras.map((s) => ({
|
|
418
|
+
rotulo: s.rotulo,
|
|
419
|
+
opcoes: s.opcoes,
|
|
420
|
+
valorAtual: () => s.valor(),
|
|
421
|
+
aoMudar: (novo: string, indice: number) => s.definir(novo, indice)
|
|
422
|
+
})),
|
|
423
|
+
{ rotulo: 'Voltar', aoConfirmar: aoVoltar }
|
|
424
|
+
],
|
|
425
|
+
aoVoltar
|
|
426
|
+
};
|
|
427
|
+
}
|