@bornengine/engine 0.4.16
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/LICENSE +21 -0
- package/README.md +231 -0
- package/native/android/Cargo.lock +1848 -0
- package/native/android/Cargo.toml +24 -0
- package/native/android/src/lib.rs +702 -0
- package/native/ios/Cargo.lock +1690 -0
- package/native/ios/Cargo.toml +32 -0
- package/native/ios/src/lib.rs +1267 -0
- package/native/linux/Cargo.lock +3279 -0
- package/native/linux/Cargo.toml +29 -0
- package/native/linux/src/lib.rs +1331 -0
- package/native/macos/Cargo.lock +3310 -0
- package/native/macos/Cargo.toml +46 -0
- package/native/macos/src/lib.rs +1302 -0
- package/native/shared/Cargo.lock +1899 -0
- package/native/shared/Cargo.toml +62 -0
- package/native/shared/assets/default_font.ttf +0 -0
- package/native/shared/build.rs +270 -0
- package/native/shared/shaders/common/clouds.wgsl +122 -0
- package/native/shared/shaders/common/fog.wgsl +16 -0
- package/native/shared/shaders/common/foliage_wind.wgsl +98 -0
- package/native/shared/shaders/common/imposter.wgsl +112 -0
- package/native/shared/shaders/common/pbr.wgsl +186 -0
- package/native/shared/shaders/common/shadows.wgsl +186 -0
- package/native/shared/shaders/common/sky.wgsl +8 -0
- package/native/shared/shaders/common/tonemap.wgsl +25 -0
- package/native/shared/shaders/impulse_field.wgsl +57 -0
- package/native/shared/shaders/material_abi.wgsl +383 -0
- package/native/shared/shaders/materials/test_minimal.wgsl +42 -0
- package/native/shared/src/anim_mixer.rs +61 -0
- package/native/shared/src/attach.rs +263 -0
- package/native/shared/src/audio/decode.rs +123 -0
- package/native/shared/src/audio/mod.rs +863 -0
- package/native/shared/src/audio/render.rs +892 -0
- package/native/shared/src/audio/spsc.rs +156 -0
- package/native/shared/src/audio/stream.rs +226 -0
- package/native/shared/src/custom_shaders.rs +104 -0
- package/native/shared/src/decals.rs +245 -0
- package/native/shared/src/drs.rs +211 -0
- package/native/shared/src/engine.rs +261 -0
- package/native/shared/src/ffi.rs +116 -0
- package/native/shared/src/ffi_core/assets.rs +388 -0
- package/native/shared/src/ffi_core/audio_ffi.rs +184 -0
- package/native/shared/src/ffi_core/draw.rs +334 -0
- package/native/shared/src/ffi_core/game_loop.rs +577 -0
- package/native/shared/src/ffi_core/input.rs +234 -0
- package/native/shared/src/ffi_core/mod.rs +127 -0
- package/native/shared/src/ffi_core/models.rs +1154 -0
- package/native/shared/src/ffi_core/ragdoll_ffi.rs +261 -0
- package/native/shared/src/ffi_core/scene.rs +626 -0
- package/native/shared/src/ffi_core/vfx.rs +212 -0
- package/native/shared/src/ffi_core/visual.rs +691 -0
- package/native/shared/src/frame_callbacks.rs +122 -0
- package/native/shared/src/geometry.rs +236 -0
- package/native/shared/src/handles.rs +182 -0
- package/native/shared/src/input.rs +448 -0
- package/native/shared/src/jolt_sys.rs +822 -0
- package/native/shared/src/lib.rs +55 -0
- package/native/shared/src/models.rs +1093 -0
- package/native/shared/src/models_gltf.rs +1280 -0
- package/native/shared/src/particles.rs +391 -0
- package/native/shared/src/physics_jolt.rs +1908 -0
- package/native/shared/src/picking.rs +298 -0
- package/native/shared/src/postfx.rs +345 -0
- package/native/shared/src/profiler.rs +492 -0
- package/native/shared/src/ragdoll.rs +474 -0
- package/native/shared/src/renderer/atmosphere_lut.rs +573 -0
- package/native/shared/src/renderer/brdf_lut.rs +154 -0
- package/native/shared/src/renderer/draw2d.rs +143 -0
- package/native/shared/src/renderer/formats.rs +822 -0
- package/native/shared/src/renderer/froxel.rs +421 -0
- package/native/shared/src/renderer/gi_bake.rs +653 -0
- package/native/shared/src/renderer/graph.rs +462 -0
- package/native/shared/src/renderer/hiz.rs +269 -0
- package/native/shared/src/renderer/hot_reload.rs +390 -0
- package/native/shared/src/renderer/impulse_field.rs +456 -0
- package/native/shared/src/renderer/lighting.rs +154 -0
- package/native/shared/src/renderer/material_instancing.rs +171 -0
- package/native/shared/src/renderer/material_pipeline.rs +700 -0
- package/native/shared/src/renderer/material_system.rs +1996 -0
- package/native/shared/src/renderer/material_system_tests.rs +601 -0
- package/native/shared/src/renderer/material_system_wasm.rs +41 -0
- package/native/shared/src/renderer/mod.rs +12556 -0
- package/native/shared/src/renderer/model_draw.rs +641 -0
- package/native/shared/src/renderer/occlusion.rs +429 -0
- package/native/shared/src/renderer/planar_pass.rs +593 -0
- package/native/shared/src/renderer/planar_reflection.rs +499 -0
- package/native/shared/src/renderer/post_pass.rs +249 -0
- package/native/shared/src/renderer/postfx_chain.rs +728 -0
- package/native/shared/src/renderer/pt_pass.rs +577 -0
- package/native/shared/src/renderer/scene_pass.rs +607 -0
- package/native/shared/src/renderer/shader_include.rs +205 -0
- package/native/shared/src/renderer/shader_library.rs +135 -0
- package/native/shared/src/renderer/shaders/ao.rs +570 -0
- package/native/shared/src/renderer/shaders/core.rs +1243 -0
- package/native/shared/src/renderer/shaders/env.rs +907 -0
- package/native/shared/src/renderer/shaders/gi.rs +810 -0
- package/native/shared/src/renderer/shaders/mod.rs +19 -0
- package/native/shared/src/renderer/shaders/post.rs +1558 -0
- package/native/shared/src/renderer/shaders/pt.rs +1859 -0
- package/native/shared/src/renderer/shaders/ssgi.rs +1586 -0
- package/native/shared/src/renderer/shadow_pass.rs +731 -0
- package/native/shared/src/renderer/ssgi_pass.rs +392 -0
- package/native/shared/src/renderer/ssr_pass.rs +188 -0
- package/native/shared/src/renderer/texture_store.rs +473 -0
- package/native/shared/src/renderer/transient.rs +591 -0
- package/native/shared/src/renderer/types.rs +941 -0
- package/native/shared/src/renderer/util.rs +152 -0
- package/native/shared/src/scene.rs +1362 -0
- package/native/shared/src/sdf_cache.rs +274 -0
- package/native/shared/src/shadows.rs +1036 -0
- package/native/shared/src/staging.rs +102 -0
- package/native/shared/src/string_header.rs +266 -0
- package/native/shared/src/text_renderer.rs +502 -0
- package/native/shared/src/textures.rs +197 -0
- package/native/tvos/Cargo.lock +1693 -0
- package/native/tvos/Cargo.toml +36 -0
- package/native/tvos/metal-patched/Cargo.toml +178 -0
- package/native/tvos/metal-patched/LICENSE-APACHE +201 -0
- package/native/tvos/metal-patched/LICENSE-MIT +25 -0
- package/native/tvos/metal-patched/src/acceleration_structure.rs +667 -0
- package/native/tvos/metal-patched/src/acceleration_structure_pass.rs +108 -0
- package/native/tvos/metal-patched/src/argument.rs +366 -0
- package/native/tvos/metal-patched/src/blitpass.rs +102 -0
- package/native/tvos/metal-patched/src/buffer.rs +71 -0
- package/native/tvos/metal-patched/src/capturedescriptor.rs +76 -0
- package/native/tvos/metal-patched/src/capturemanager.rs +113 -0
- package/native/tvos/metal-patched/src/commandbuffer.rs +192 -0
- package/native/tvos/metal-patched/src/commandqueue.rs +44 -0
- package/native/tvos/metal-patched/src/computepass.rs +107 -0
- package/native/tvos/metal-patched/src/constants.rs +152 -0
- package/native/tvos/metal-patched/src/counters.rs +119 -0
- package/native/tvos/metal-patched/src/depthstencil.rs +190 -0
- package/native/tvos/metal-patched/src/device.rs +2134 -0
- package/native/tvos/metal-patched/src/drawable.rs +39 -0
- package/native/tvos/metal-patched/src/encoder.rs +2041 -0
- package/native/tvos/metal-patched/src/heap.rs +281 -0
- package/native/tvos/metal-patched/src/indirect_encoder.rs +344 -0
- package/native/tvos/metal-patched/src/lib.rs +657 -0
- package/native/tvos/metal-patched/src/library.rs +902 -0
- package/native/tvos/metal-patched/src/mps.rs +575 -0
- package/native/tvos/metal-patched/src/pipeline/compute.rs +475 -0
- package/native/tvos/metal-patched/src/pipeline/mod.rs +71 -0
- package/native/tvos/metal-patched/src/pipeline/render.rs +762 -0
- package/native/tvos/metal-patched/src/renderpass.rs +443 -0
- package/native/tvos/metal-patched/src/resource.rs +182 -0
- package/native/tvos/metal-patched/src/sampler.rs +165 -0
- package/native/tvos/metal-patched/src/sync.rs +178 -0
- package/native/tvos/metal-patched/src/texture.rs +352 -0
- package/native/tvos/metal-patched/src/types.rs +90 -0
- package/native/tvos/metal-patched/src/vertexdescriptor.rs +250 -0
- package/native/tvos/src/audio_backend.rs +197 -0
- package/native/tvos/src/lib.rs +1891 -0
- package/native/visionos/Cargo.lock +1693 -0
- package/native/visionos/Cargo.toml +40 -0
- package/native/visionos/src/audio_backend.rs +197 -0
- package/native/visionos/src/lib.rs +1887 -0
- package/native/watchos/Cargo.lock +16 -0
- package/native/watchos/Cargo.toml +19 -0
- package/native/watchos/shaders/bloom_postfx.metal +99 -0
- package/native/watchos/src/BloomWatchApp.swift +1267 -0
- package/native/watchos/src/BloomWatchAudio.swift +179 -0
- package/native/watchos/src/audio.rs +55 -0
- package/native/watchos/src/draw_list.rs +229 -0
- package/native/watchos/src/ffi_stubs.rs +915 -0
- package/native/watchos/src/ffi_stubs_manual.rs +35 -0
- package/native/watchos/src/lib.rs +1124 -0
- package/native/watchos/src/models.rs +746 -0
- package/native/watchos/src/postfx.rs +95 -0
- package/native/watchos/src/scene.rs +534 -0
- package/native/watchos/src/textures.rs +184 -0
- package/native/web/Cargo.lock +1657 -0
- package/native/web/Cargo.toml +43 -0
- package/native/web/bloom_glue.js +695 -0
- package/native/web/build.sh +131 -0
- package/native/web/index.html +35 -0
- package/native/web/jolt_bridge.js +1519 -0
- package/native/web/src/input_ffi.rs +286 -0
- package/native/web/src/lib.rs +1796 -0
- package/native/web/src/material_ffi.rs +710 -0
- package/native/web/src/parity_ffi.rs +343 -0
- package/native/web/src/physics_ffi.rs +643 -0
- package/native/web/src/ragdoll_ffi.rs +250 -0
- package/native/web/src/render_settings.rs +98 -0
- package/native/windows/Cargo.lock +1815 -0
- package/native/windows/Cargo.toml +68 -0
- package/native/windows/src/lib.rs +1486 -0
- package/package.json +4279 -0
- package/src/audio/index.ts +315 -0
- package/src/core/colors.ts +63 -0
- package/src/core/index.ts +1206 -0
- package/src/core/keys.ts +63 -0
- package/src/core/types.ts +104 -0
- package/src/index.ts +171 -0
- package/src/math/index.ts +516 -0
- package/src/mobile/index.ts +294 -0
- package/src/models/index.ts +1258 -0
- package/src/physics/index.ts +1134 -0
- package/src/scene/index.ts +698 -0
- package/src/shapes/index.ts +120 -0
- package/src/text/index.ts +48 -0
- package/src/textures/index.ts +187 -0
- package/src/vfx/index.ts +191 -0
- package/src/world/index.ts +24 -0
- package/src/world/loader.ts +423 -0
- package/src/world/prefab.ts +217 -0
- package/src/world/render.ts +172 -0
- package/src/world/saver.ts +108 -0
- package/src/world/serialize.ts +301 -0
- package/src/world/terrain.ts +355 -0
- package/src/world/types.ts +160 -0
- package/src/world/validate.ts +319 -0
- package/src/world/version.ts +114 -0
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import { Color } from '../core/types';
|
|
2
|
+
import {
|
|
3
|
+
injectKeyDown, injectKeyUp,
|
|
4
|
+
injectGamepadAxis, injectGamepadButtonDown, injectGamepadButtonUp,
|
|
5
|
+
getTouchX, getTouchY, getTouchCount,
|
|
6
|
+
getScreenWidth, getScreenHeight,
|
|
7
|
+
isKeyDown,
|
|
8
|
+
getGamepadAxis,
|
|
9
|
+
} from '../core/index';
|
|
10
|
+
import { drawCircle, drawCircleLines } from '../shapes/index';
|
|
11
|
+
import { drawText, measureText } from '../text/index';
|
|
12
|
+
import { Key } from '../core/keys';
|
|
13
|
+
|
|
14
|
+
// ============================================================
|
|
15
|
+
// Types
|
|
16
|
+
// ============================================================
|
|
17
|
+
|
|
18
|
+
export interface VirtualJoystick {
|
|
19
|
+
zone: 'left' | 'right';
|
|
20
|
+
radius: number;
|
|
21
|
+
deadzone: number;
|
|
22
|
+
axisX: number;
|
|
23
|
+
axisY: number;
|
|
24
|
+
// Runtime state
|
|
25
|
+
active: boolean;
|
|
26
|
+
touchIndex: number;
|
|
27
|
+
originX: number;
|
|
28
|
+
originY: number;
|
|
29
|
+
handleX: number;
|
|
30
|
+
handleY: number;
|
|
31
|
+
valueX: number;
|
|
32
|
+
valueY: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface VirtualButton {
|
|
36
|
+
x: number;
|
|
37
|
+
y: number;
|
|
38
|
+
radius: number;
|
|
39
|
+
label: string;
|
|
40
|
+
key: number | null;
|
|
41
|
+
gamepadButton: number | null;
|
|
42
|
+
// Runtime state
|
|
43
|
+
active: boolean;
|
|
44
|
+
touchIndex: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// ============================================================
|
|
48
|
+
// Touch claim system
|
|
49
|
+
// ============================================================
|
|
50
|
+
|
|
51
|
+
const claimedTouches = new Set<number>();
|
|
52
|
+
|
|
53
|
+
export function resetTouchClaims(): void {
|
|
54
|
+
claimedTouches.clear();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// ============================================================
|
|
58
|
+
// Virtual Joystick
|
|
59
|
+
// ============================================================
|
|
60
|
+
|
|
61
|
+
export function createVirtualJoystick(opts?: {
|
|
62
|
+
zone?: 'left' | 'right';
|
|
63
|
+
radius?: number;
|
|
64
|
+
deadzone?: number;
|
|
65
|
+
axisX?: number;
|
|
66
|
+
axisY?: number;
|
|
67
|
+
}): VirtualJoystick {
|
|
68
|
+
return {
|
|
69
|
+
zone: opts?.zone ?? 'left',
|
|
70
|
+
radius: opts?.radius ?? 60,
|
|
71
|
+
deadzone: opts?.deadzone ?? 0.15,
|
|
72
|
+
axisX: opts?.axisX ?? 0,
|
|
73
|
+
axisY: opts?.axisY ?? 1,
|
|
74
|
+
active: false,
|
|
75
|
+
touchIndex: -1,
|
|
76
|
+
originX: 0,
|
|
77
|
+
originY: 0,
|
|
78
|
+
handleX: 0,
|
|
79
|
+
handleY: 0,
|
|
80
|
+
valueX: 0,
|
|
81
|
+
valueY: 0,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function updateVirtualJoystick(js: VirtualJoystick): void {
|
|
86
|
+
const screenW = getScreenWidth();
|
|
87
|
+
const touchCount = getTouchCount();
|
|
88
|
+
|
|
89
|
+
// If already active, check if our finger is still down
|
|
90
|
+
if (js.active) {
|
|
91
|
+
let stillActive = false;
|
|
92
|
+
for (let i = 0; i < touchCount; i++) {
|
|
93
|
+
const tx = getTouchX(i);
|
|
94
|
+
const ty = getTouchY(i);
|
|
95
|
+
if (i === js.touchIndex && tx !== 0 && ty !== 0) {
|
|
96
|
+
stillActive = true;
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
// Also check that the touch index is still within count
|
|
101
|
+
if (js.touchIndex >= touchCount) {
|
|
102
|
+
stillActive = false;
|
|
103
|
+
}
|
|
104
|
+
if (!stillActive) {
|
|
105
|
+
js.active = false;
|
|
106
|
+
js.touchIndex = -1;
|
|
107
|
+
js.valueX = 0;
|
|
108
|
+
js.valueY = 0;
|
|
109
|
+
injectGamepadAxis(js.axisX, 0);
|
|
110
|
+
injectGamepadAxis(js.axisY, 0);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Look for a new touch if not active
|
|
116
|
+
if (!js.active) {
|
|
117
|
+
for (let i = 0; i < touchCount; i++) {
|
|
118
|
+
if (claimedTouches.has(i)) continue;
|
|
119
|
+
const tx = getTouchX(i);
|
|
120
|
+
const ty = getTouchY(i);
|
|
121
|
+
if (tx === 0 && ty === 0) continue;
|
|
122
|
+
|
|
123
|
+
// Check if touch is in the correct zone
|
|
124
|
+
const inZone = js.zone === 'left' ? tx < screenW / 2 : tx >= screenW / 2;
|
|
125
|
+
if (!inZone) continue;
|
|
126
|
+
|
|
127
|
+
// PUBG-style: joystick origin appears at touch position
|
|
128
|
+
js.active = true;
|
|
129
|
+
js.touchIndex = i;
|
|
130
|
+
js.originX = tx;
|
|
131
|
+
js.originY = ty;
|
|
132
|
+
js.handleX = tx;
|
|
133
|
+
js.handleY = ty;
|
|
134
|
+
claimedTouches.add(i);
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (!js.active) return;
|
|
140
|
+
|
|
141
|
+
claimedTouches.add(js.touchIndex);
|
|
142
|
+
|
|
143
|
+
// Read current touch position
|
|
144
|
+
const tx = getTouchX(js.touchIndex);
|
|
145
|
+
const ty = getTouchY(js.touchIndex);
|
|
146
|
+
|
|
147
|
+
const dx = tx - js.originX;
|
|
148
|
+
const dy = ty - js.originY;
|
|
149
|
+
const dist = Math.sqrt(dx * dx + dy * dy);
|
|
150
|
+
|
|
151
|
+
if (dist < js.deadzone * js.radius) {
|
|
152
|
+
js.handleX = tx;
|
|
153
|
+
js.handleY = ty;
|
|
154
|
+
js.valueX = 0;
|
|
155
|
+
js.valueY = 0;
|
|
156
|
+
} else {
|
|
157
|
+
const clamped = Math.min(dist, js.radius);
|
|
158
|
+
const norm = clamped / dist;
|
|
159
|
+
js.handleX = js.originX + dx * norm;
|
|
160
|
+
js.handleY = js.originY + dy * norm;
|
|
161
|
+
js.valueX = (dx * norm) / js.radius;
|
|
162
|
+
js.valueY = (dy * norm) / js.radius;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
injectGamepadAxis(js.axisX, js.valueX);
|
|
166
|
+
injectGamepadAxis(js.axisY, js.valueY);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export function drawVirtualJoystick(js: VirtualJoystick): void {
|
|
170
|
+
if (!js.active) return;
|
|
171
|
+
|
|
172
|
+
const bgColor: Color = { r: 255, g: 255, b: 255, a: 60 };
|
|
173
|
+
const handleColor: Color = { r: 255, g: 255, b: 255, a: 140 };
|
|
174
|
+
|
|
175
|
+
drawCircleLines(js.originX, js.originY, js.radius, bgColor);
|
|
176
|
+
drawCircle(js.handleX, js.handleY, js.radius * 0.4, handleColor);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// ============================================================
|
|
180
|
+
// Virtual Button
|
|
181
|
+
// ============================================================
|
|
182
|
+
|
|
183
|
+
export function createVirtualButton(x: number, y: number, opts?: {
|
|
184
|
+
radius?: number;
|
|
185
|
+
label?: string;
|
|
186
|
+
key?: number | null;
|
|
187
|
+
gamepadButton?: number | null;
|
|
188
|
+
}): VirtualButton {
|
|
189
|
+
return {
|
|
190
|
+
x,
|
|
191
|
+
y,
|
|
192
|
+
radius: opts?.radius ?? 30,
|
|
193
|
+
label: opts?.label ?? '',
|
|
194
|
+
key: opts?.key ?? null,
|
|
195
|
+
gamepadButton: opts?.gamepadButton ?? null,
|
|
196
|
+
active: false,
|
|
197
|
+
touchIndex: -1,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export function updateVirtualButton(btn: VirtualButton): void {
|
|
202
|
+
const touchCount = getTouchCount();
|
|
203
|
+
const wasActive = btn.active;
|
|
204
|
+
|
|
205
|
+
// Check if any unclaimed touch is inside the button
|
|
206
|
+
let nowActive = false;
|
|
207
|
+
let activeIndex = -1;
|
|
208
|
+
|
|
209
|
+
for (let i = 0; i < touchCount; i++) {
|
|
210
|
+
if (claimedTouches.has(i)) continue;
|
|
211
|
+
const tx = getTouchX(i);
|
|
212
|
+
const ty = getTouchY(i);
|
|
213
|
+
if (tx === 0 && ty === 0) continue;
|
|
214
|
+
|
|
215
|
+
const dx = tx - btn.x;
|
|
216
|
+
const dy = ty - btn.y;
|
|
217
|
+
if (dx * dx + dy * dy <= btn.radius * btn.radius) {
|
|
218
|
+
nowActive = true;
|
|
219
|
+
activeIndex = i;
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (nowActive) {
|
|
225
|
+
claimedTouches.add(activeIndex);
|
|
226
|
+
btn.touchIndex = activeIndex;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (nowActive && !wasActive) {
|
|
230
|
+
// Just pressed
|
|
231
|
+
btn.active = true;
|
|
232
|
+
if (btn.key !== null) injectKeyDown(btn.key);
|
|
233
|
+
if (btn.gamepadButton !== null) injectGamepadButtonDown(btn.gamepadButton);
|
|
234
|
+
} else if (!nowActive && wasActive) {
|
|
235
|
+
// Just released
|
|
236
|
+
btn.active = false;
|
|
237
|
+
btn.touchIndex = -1;
|
|
238
|
+
if (btn.key !== null) injectKeyUp(btn.key);
|
|
239
|
+
if (btn.gamepadButton !== null) injectGamepadButtonUp(btn.gamepadButton);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export function drawVirtualButton(btn: VirtualButton): void {
|
|
244
|
+
const bgColor: Color = btn.active
|
|
245
|
+
? { r: 255, g: 255, b: 255, a: 120 }
|
|
246
|
+
: { r: 255, g: 255, b: 255, a: 60 };
|
|
247
|
+
|
|
248
|
+
drawCircle(btn.x, btn.y, btn.radius, bgColor);
|
|
249
|
+
|
|
250
|
+
if (btn.label) {
|
|
251
|
+
const fontSize = btn.radius * 0.8;
|
|
252
|
+
const textWidth = measureText(btn.label, fontSize);
|
|
253
|
+
const labelColor: Color = { r: 255, g: 255, b: 255, a: 200 };
|
|
254
|
+
drawText(btn.label, btn.x - textWidth / 2, btn.y - fontSize / 2, fontSize, labelColor);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// ============================================================
|
|
259
|
+
// Convenience: unified movement input
|
|
260
|
+
// ============================================================
|
|
261
|
+
|
|
262
|
+
export function getMovementInput(): { x: number; y: number } {
|
|
263
|
+
let x = 0;
|
|
264
|
+
let y = 0;
|
|
265
|
+
|
|
266
|
+
// WASD
|
|
267
|
+
if (isKeyDown(Key.D)) x += 1;
|
|
268
|
+
if (isKeyDown(Key.A)) x -= 1;
|
|
269
|
+
if (isKeyDown(Key.S)) y += 1;
|
|
270
|
+
if (isKeyDown(Key.W)) y -= 1;
|
|
271
|
+
|
|
272
|
+
// Arrow keys
|
|
273
|
+
if (isKeyDown(Key.RIGHT)) x += 1;
|
|
274
|
+
if (isKeyDown(Key.LEFT)) x -= 1;
|
|
275
|
+
if (isKeyDown(Key.DOWN)) y += 1;
|
|
276
|
+
if (isKeyDown(Key.UP)) y -= 1;
|
|
277
|
+
|
|
278
|
+
// Gamepad axes (overrides if non-zero)
|
|
279
|
+
const gx = getGamepadAxis(0);
|
|
280
|
+
const gy = getGamepadAxis(1);
|
|
281
|
+
if (Math.abs(gx) > 0.1 || Math.abs(gy) > 0.1) {
|
|
282
|
+
x = gx;
|
|
283
|
+
y = gy;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// Clamp
|
|
287
|
+
const len = Math.sqrt(x * x + y * y);
|
|
288
|
+
if (len > 1) {
|
|
289
|
+
x /= len;
|
|
290
|
+
y /= len;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
return { x, y };
|
|
294
|
+
}
|