@utsp/types 0.4.0-nightly.20251201222332.2d9d7a5 → 0.4.0
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/index.d.ts +366 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1045,10 +1045,11 @@ type MessageType = AnyNetworkMessage['type'];
|
|
|
1045
1045
|
interface IApplication<TCore = any, TUser = any, TRuntime = unknown> {
|
|
1046
1046
|
/**
|
|
1047
1047
|
* Initialize application (called once at startup, before users)
|
|
1048
|
+
* Can be async if you need to load resources.
|
|
1048
1049
|
* @param core - Core instance
|
|
1049
1050
|
* @param runtime - Runtime instance (optional)
|
|
1050
1051
|
*/
|
|
1051
|
-
init(core: TCore, runtime?: TRuntime): void
|
|
1052
|
+
init(core: TCore, runtime?: TRuntime): void | Promise<void>;
|
|
1052
1053
|
/**
|
|
1053
1054
|
* Update global logic (called every frame, runs once)
|
|
1054
1055
|
* @param core - Core instance
|
|
@@ -1120,5 +1121,368 @@ interface UserMetadata {
|
|
|
1120
1121
|
[key: string]: unknown;
|
|
1121
1122
|
}
|
|
1122
1123
|
|
|
1124
|
+
/**
|
|
1125
|
+
* Audio types for UTSP
|
|
1126
|
+
* @packageDocumentation
|
|
1127
|
+
*/
|
|
1128
|
+
/**
|
|
1129
|
+
* Supported audio file formats
|
|
1130
|
+
*/
|
|
1131
|
+
type SoundFormat = 'mp3' | 'wav' | 'ogg' | 'webm' | 'aac';
|
|
1132
|
+
/**
|
|
1133
|
+
* Sound loading type
|
|
1134
|
+
*/
|
|
1135
|
+
type SoundLoadType = 'file' | 'external';
|
|
1136
|
+
/**
|
|
1137
|
+
* A single sound to load via File mode (embedded data)
|
|
1138
|
+
*/
|
|
1139
|
+
interface SoundFileEntry {
|
|
1140
|
+
/** Unique sound identifier (0-255) */
|
|
1141
|
+
soundId: number;
|
|
1142
|
+
/** Human-readable name for playback (e.g., 'coin', 'explosion') */
|
|
1143
|
+
name: string;
|
|
1144
|
+
/** Audio format */
|
|
1145
|
+
format: SoundFormat;
|
|
1146
|
+
/** Raw audio data */
|
|
1147
|
+
data: Uint8Array;
|
|
1148
|
+
}
|
|
1149
|
+
/**
|
|
1150
|
+
* A single sound to load via External mode (URL reference)
|
|
1151
|
+
*/
|
|
1152
|
+
interface SoundExternalEntry {
|
|
1153
|
+
/** Unique sound identifier (0-255) */
|
|
1154
|
+
soundId: number;
|
|
1155
|
+
/** Human-readable name for playback */
|
|
1156
|
+
name: string;
|
|
1157
|
+
/** Audio format */
|
|
1158
|
+
format: SoundFormat;
|
|
1159
|
+
/** URL to fetch the audio from (CDN, external server, etc.) */
|
|
1160
|
+
url: string;
|
|
1161
|
+
/** Expected file size in bytes (optional, for progress tracking) */
|
|
1162
|
+
size?: number;
|
|
1163
|
+
/** Checksum for validation (optional) */
|
|
1164
|
+
checksum?: string;
|
|
1165
|
+
}
|
|
1166
|
+
/**
|
|
1167
|
+
* Sound Load packet - File mode
|
|
1168
|
+
* Audio data is embedded in the packet and sent via UTSP
|
|
1169
|
+
*/
|
|
1170
|
+
interface SoundLoadPacket {
|
|
1171
|
+
type: 'sound';
|
|
1172
|
+
mode: 'file';
|
|
1173
|
+
sounds: SoundFileEntry[];
|
|
1174
|
+
}
|
|
1175
|
+
/**
|
|
1176
|
+
* Sound External Load packet - External mode
|
|
1177
|
+
* Only URLs are sent, client downloads from external sources
|
|
1178
|
+
*/
|
|
1179
|
+
interface SoundExternalLoadPacket {
|
|
1180
|
+
type: 'sound';
|
|
1181
|
+
mode: 'external';
|
|
1182
|
+
sounds: SoundExternalEntry[];
|
|
1183
|
+
}
|
|
1184
|
+
/**
|
|
1185
|
+
* Union of all sound load packet types
|
|
1186
|
+
*/
|
|
1187
|
+
type AnySoundLoadPacket = SoundLoadPacket | SoundExternalLoadPacket;
|
|
1188
|
+
/**
|
|
1189
|
+
* Client acknowledgment that an external sound was loaded
|
|
1190
|
+
* Sent after successfully downloading and decoding an external sound
|
|
1191
|
+
*/
|
|
1192
|
+
interface SoundLoadedAck {
|
|
1193
|
+
/** Sound ID that was loaded */
|
|
1194
|
+
soundId: number;
|
|
1195
|
+
/** Loading status */
|
|
1196
|
+
status: 'loaded' | 'error';
|
|
1197
|
+
/** Error message if status is 'error' */
|
|
1198
|
+
error?: string;
|
|
1199
|
+
}
|
|
1200
|
+
/**
|
|
1201
|
+
* Unique identifier for a playing sound instance
|
|
1202
|
+
* Allows multiple instances of the same sound to play simultaneously
|
|
1203
|
+
* and be controlled independently
|
|
1204
|
+
*/
|
|
1205
|
+
type SoundInstanceId = number;
|
|
1206
|
+
/**
|
|
1207
|
+
* Command to play a sound on the client
|
|
1208
|
+
* Sent from server to trigger sound playback
|
|
1209
|
+
*/
|
|
1210
|
+
interface PlaySoundCommand {
|
|
1211
|
+
/** Sound ID or name to play */
|
|
1212
|
+
sound: number | string;
|
|
1213
|
+
/** Unique instance ID for this playback (allows stopping specific instances) */
|
|
1214
|
+
instanceId?: SoundInstanceId;
|
|
1215
|
+
/** Volume multiplier (0.0 to 1.0) */
|
|
1216
|
+
volume?: number;
|
|
1217
|
+
/** Pitch/playback rate (0.5 = octave down, 2.0 = octave up) */
|
|
1218
|
+
pitch?: number;
|
|
1219
|
+
/** Loop the sound */
|
|
1220
|
+
loop?: boolean;
|
|
1221
|
+
/** Fade in duration in seconds (0 = no fade, default: 0) */
|
|
1222
|
+
fadeIn?: number;
|
|
1223
|
+
/** Spatial position (if set, enables 2D positional audio) */
|
|
1224
|
+
position?: {
|
|
1225
|
+
/** X position (0-65535, 16-bit) */
|
|
1226
|
+
x: number;
|
|
1227
|
+
/** Y position (0-65535, 16-bit) */
|
|
1228
|
+
y: number;
|
|
1229
|
+
};
|
|
1230
|
+
}
|
|
1231
|
+
/**
|
|
1232
|
+
* Command to stop a sound on the client
|
|
1233
|
+
*/
|
|
1234
|
+
interface StopSoundCommand {
|
|
1235
|
+
/**
|
|
1236
|
+
* What to stop:
|
|
1237
|
+
* - SoundInstanceId (number > 0): Stop specific instance
|
|
1238
|
+
* - Sound name (string): Stop all instances of that sound
|
|
1239
|
+
* - 'all': Stop all sounds
|
|
1240
|
+
*/
|
|
1241
|
+
sound: SoundInstanceId | string | 'all';
|
|
1242
|
+
}
|
|
1243
|
+
/**
|
|
1244
|
+
* Command to fade out a sound on the client
|
|
1245
|
+
*/
|
|
1246
|
+
interface FadeOutSoundCommand {
|
|
1247
|
+
/** Marker to identify this as a fade-out command */
|
|
1248
|
+
fadeOut: true;
|
|
1249
|
+
/**
|
|
1250
|
+
* What to fade out:
|
|
1251
|
+
* - SoundInstanceId (number > 0): Fade out specific instance
|
|
1252
|
+
* - Sound name (string): Fade out all instances of that sound
|
|
1253
|
+
* - 'all': Fade out all sounds
|
|
1254
|
+
*/
|
|
1255
|
+
sound: SoundInstanceId | string | 'all';
|
|
1256
|
+
/** Fade out duration in seconds */
|
|
1257
|
+
duration: number;
|
|
1258
|
+
}
|
|
1259
|
+
/**
|
|
1260
|
+
* Command to pause a sound on the client
|
|
1261
|
+
*/
|
|
1262
|
+
interface PauseSoundCommand {
|
|
1263
|
+
/** Marker to identify this as a pause command */
|
|
1264
|
+
pause: true;
|
|
1265
|
+
/**
|
|
1266
|
+
* What to pause:
|
|
1267
|
+
* - SoundInstanceId (number > 0): Pause specific instance
|
|
1268
|
+
* - Sound name (string): Pause all instances of that sound
|
|
1269
|
+
* - 'all': Pause all sounds
|
|
1270
|
+
*/
|
|
1271
|
+
sound: SoundInstanceId | string | 'all';
|
|
1272
|
+
}
|
|
1273
|
+
/**
|
|
1274
|
+
* Command to resume a paused sound on the client
|
|
1275
|
+
*/
|
|
1276
|
+
interface ResumeSoundCommand {
|
|
1277
|
+
/** Marker to identify this as a resume command */
|
|
1278
|
+
resume: true;
|
|
1279
|
+
/**
|
|
1280
|
+
* What to resume:
|
|
1281
|
+
* - SoundInstanceId (number > 0): Resume specific instance
|
|
1282
|
+
* - Sound name (string): Resume all instances of that sound
|
|
1283
|
+
* - 'all': Resume all paused sounds
|
|
1284
|
+
*/
|
|
1285
|
+
sound: SoundInstanceId | string | 'all';
|
|
1286
|
+
}
|
|
1287
|
+
/**
|
|
1288
|
+
* Command to set the listener position for spatial audio
|
|
1289
|
+
*/
|
|
1290
|
+
interface SetListenerPositionCommand {
|
|
1291
|
+
type: 'set-listener-position';
|
|
1292
|
+
/** X position (0-65535) */
|
|
1293
|
+
x: number;
|
|
1294
|
+
/** Y position (0-65535) */
|
|
1295
|
+
y: number;
|
|
1296
|
+
}
|
|
1297
|
+
/**
|
|
1298
|
+
* Command to configure spatial audio parameters
|
|
1299
|
+
*/
|
|
1300
|
+
interface ConfigureSpatialCommand {
|
|
1301
|
+
type: 'configure-spatial';
|
|
1302
|
+
/** Maximum audible distance */
|
|
1303
|
+
maxDistance?: number;
|
|
1304
|
+
/** Reference distance (full volume) */
|
|
1305
|
+
referenceDistance?: number;
|
|
1306
|
+
/** Rolloff factor */
|
|
1307
|
+
rolloffFactor?: number;
|
|
1308
|
+
/** Pan spread (0-1) */
|
|
1309
|
+
panSpread?: number;
|
|
1310
|
+
}
|
|
1311
|
+
/**
|
|
1312
|
+
* Union of all audio configuration commands
|
|
1313
|
+
*/
|
|
1314
|
+
type AudioConfigCommand = SetListenerPositionCommand | ConfigureSpatialCommand;
|
|
1315
|
+
/**
|
|
1316
|
+
* Configuration for 2D spatial audio (listener position)
|
|
1317
|
+
*/
|
|
1318
|
+
interface SpatialAudioConfig {
|
|
1319
|
+
/** Listener X position (0-65535) - where the "ear" is */
|
|
1320
|
+
listenerX: number;
|
|
1321
|
+
/** Listener Y position (0-65535) - where the "ear" is */
|
|
1322
|
+
listenerY: number;
|
|
1323
|
+
/** Maximum audible distance (beyond this, volume = 0) */
|
|
1324
|
+
maxDistance: number;
|
|
1325
|
+
/** Reference distance (volume = 1.0 at this distance) */
|
|
1326
|
+
referenceDistance: number;
|
|
1327
|
+
/** Rolloff factor for distance attenuation (higher = faster falloff) */
|
|
1328
|
+
rolloffFactor: number;
|
|
1329
|
+
/** Pan spread factor (how much X offset affects stereo pan, 0-1) */
|
|
1330
|
+
panSpread: number;
|
|
1331
|
+
}
|
|
1332
|
+
/**
|
|
1333
|
+
* Options for playing a sound via IAudioProcessor
|
|
1334
|
+
*/
|
|
1335
|
+
interface AudioPlayOptions {
|
|
1336
|
+
/** Volume multiplier (0.0 to 1.0, default: 1.0) */
|
|
1337
|
+
volume?: number;
|
|
1338
|
+
/** Playback rate / pitch (0.5 = octave down, 2.0 = octave up, default: 1.0) */
|
|
1339
|
+
pitch?: number;
|
|
1340
|
+
/** Loop the sound (default: false) */
|
|
1341
|
+
loop?: boolean;
|
|
1342
|
+
/** Fade in duration in seconds (0 = no fade, default: 0) */
|
|
1343
|
+
fadeIn?: number;
|
|
1344
|
+
/** Spatial position for 2D positional audio */
|
|
1345
|
+
position?: {
|
|
1346
|
+
x: number;
|
|
1347
|
+
y: number;
|
|
1348
|
+
};
|
|
1349
|
+
/** Instance ID (provided by server in connected mode, auto-generated otherwise) */
|
|
1350
|
+
instanceId?: number;
|
|
1351
|
+
}
|
|
1352
|
+
/**
|
|
1353
|
+
* Result of playing a sound
|
|
1354
|
+
*/
|
|
1355
|
+
interface AudioPlayResult {
|
|
1356
|
+
/** Unique instance ID for this playback */
|
|
1357
|
+
instanceId: number;
|
|
1358
|
+
}
|
|
1359
|
+
/**
|
|
1360
|
+
* Spatial audio configuration options
|
|
1361
|
+
*/
|
|
1362
|
+
interface AudioSpatialOptions {
|
|
1363
|
+
/** Maximum audible distance */
|
|
1364
|
+
maxDistance?: number;
|
|
1365
|
+
/** Reference distance (full volume) */
|
|
1366
|
+
referenceDistance?: number;
|
|
1367
|
+
/** Rolloff factor */
|
|
1368
|
+
rolloffFactor?: number;
|
|
1369
|
+
/** Pan spread (0-1) */
|
|
1370
|
+
panSpread?: number;
|
|
1371
|
+
}
|
|
1372
|
+
/**
|
|
1373
|
+
* Interface for audio playback processing
|
|
1374
|
+
*
|
|
1375
|
+
* Implemented by AudioManager in @utsp/audio.
|
|
1376
|
+
* Used by User in @utsp/core to play sounds without direct dependency on AudioManager.
|
|
1377
|
+
*
|
|
1378
|
+
* This abstraction allows:
|
|
1379
|
+
* - Standalone mode: ClientRuntime injects AudioManager
|
|
1380
|
+
* - Connected mode: NetworkSync uses the same interface via User
|
|
1381
|
+
* - No circular dependency: Core → Types ← Audio
|
|
1382
|
+
*
|
|
1383
|
+
* @example
|
|
1384
|
+
* ```typescript
|
|
1385
|
+
* // In ClientRuntime
|
|
1386
|
+
* user.setAudioProcessor(audioManager);
|
|
1387
|
+
*
|
|
1388
|
+
* // In User.applyAudioCommands()
|
|
1389
|
+
* this.audioProcessor?.play('coin', { volume: 0.8 });
|
|
1390
|
+
* ```
|
|
1391
|
+
*/
|
|
1392
|
+
interface IAudioProcessor {
|
|
1393
|
+
/**
|
|
1394
|
+
* Play a sound by name or ID
|
|
1395
|
+
* @param sound - Sound name (string) or ID (number)
|
|
1396
|
+
* @param options - Playback options
|
|
1397
|
+
* @returns Play result with instanceId, or null if sound not found
|
|
1398
|
+
*/
|
|
1399
|
+
play(sound: string | number, options?: AudioPlayOptions): AudioPlayResult | null;
|
|
1400
|
+
/**
|
|
1401
|
+
* Stop sound(s) immediately
|
|
1402
|
+
* @param target - Instance ID (number) to stop specific instance,
|
|
1403
|
+
* or sound name (string) to stop all instances of that sound
|
|
1404
|
+
* @returns Number of instances stopped
|
|
1405
|
+
*/
|
|
1406
|
+
stop(target: number | string): number;
|
|
1407
|
+
/**
|
|
1408
|
+
* Fade out and stop sound(s)
|
|
1409
|
+
* @param target - Instance ID (number) to fade specific instance,
|
|
1410
|
+
* or sound name (string) to fade all instances of that sound,
|
|
1411
|
+
* or 'all' to fade all sounds
|
|
1412
|
+
* @param duration - Fade duration in seconds
|
|
1413
|
+
* @returns Number of instances being faded
|
|
1414
|
+
*/
|
|
1415
|
+
fadeOut(target: number | string | 'all', duration: number): number;
|
|
1416
|
+
/**
|
|
1417
|
+
* Stop all playing sounds immediately
|
|
1418
|
+
* @returns Number of instances stopped
|
|
1419
|
+
*/
|
|
1420
|
+
stopAll(): number;
|
|
1421
|
+
/**
|
|
1422
|
+
* Pause sound(s)
|
|
1423
|
+
* @param target - Instance ID (number) to pause specific instance,
|
|
1424
|
+
* or sound name (string) to pause all instances of that sound,
|
|
1425
|
+
* or 'all' to pause all sounds
|
|
1426
|
+
* @returns Number of instances paused
|
|
1427
|
+
*/
|
|
1428
|
+
pause(target: number | string | 'all'): number;
|
|
1429
|
+
/**
|
|
1430
|
+
* Resume paused sound(s)
|
|
1431
|
+
* @param target - Instance ID (number) to resume specific instance,
|
|
1432
|
+
* or sound name (string) to resume all instances of that sound,
|
|
1433
|
+
* or 'all' to resume all paused sounds
|
|
1434
|
+
* @returns Number of instances resumed
|
|
1435
|
+
*/
|
|
1436
|
+
resume(target: number | string | 'all'): number;
|
|
1437
|
+
/**
|
|
1438
|
+
* Set the listener position for spatial audio
|
|
1439
|
+
* @param x - X position (0-65535)
|
|
1440
|
+
* @param y - Y position (0-65535)
|
|
1441
|
+
*/
|
|
1442
|
+
setListenerPosition(x: number, y: number): void;
|
|
1443
|
+
/**
|
|
1444
|
+
* Configure spatial audio parameters
|
|
1445
|
+
* @param config - Spatial audio options
|
|
1446
|
+
*/
|
|
1447
|
+
configureSpatial(config: AudioSpatialOptions): void;
|
|
1448
|
+
}
|
|
1449
|
+
/**
|
|
1450
|
+
* Interface for loading sounds into the audio system
|
|
1451
|
+
*
|
|
1452
|
+
* Implemented by SoundBank in @utsp/audio.
|
|
1453
|
+
* Abstracts the difference between Browser (Web Audio API) and Node.js environments.
|
|
1454
|
+
*
|
|
1455
|
+
* @example
|
|
1456
|
+
* ```typescript
|
|
1457
|
+
* // File mode - embedded data
|
|
1458
|
+
* await soundLoader.loadFromData(0, 'coin', audioData);
|
|
1459
|
+
*
|
|
1460
|
+
* // External mode - URL
|
|
1461
|
+
* await soundLoader.loadFromUrl(1, 'music', 'https://cdn.example.com/music.mp3');
|
|
1462
|
+
* ```
|
|
1463
|
+
*/
|
|
1464
|
+
interface ISoundLoader {
|
|
1465
|
+
/**
|
|
1466
|
+
* Load a sound from binary data (File mode)
|
|
1467
|
+
* @param soundId - Unique sound identifier (0-255)
|
|
1468
|
+
* @param name - Human-readable name for playback
|
|
1469
|
+
* @param data - Raw audio data (mp3, wav, ogg, etc.)
|
|
1470
|
+
*/
|
|
1471
|
+
loadFromData(soundId: number, name: string, data: Uint8Array): Promise<void>;
|
|
1472
|
+
/**
|
|
1473
|
+
* Load a sound from a URL (External mode)
|
|
1474
|
+
* @param soundId - Unique sound identifier (0-255)
|
|
1475
|
+
* @param name - Human-readable name for playback
|
|
1476
|
+
* @param url - URL to fetch the audio from
|
|
1477
|
+
*/
|
|
1478
|
+
loadFromUrl(soundId: number, name: string, url: string): Promise<void>;
|
|
1479
|
+
/**
|
|
1480
|
+
* Check if a sound is loaded
|
|
1481
|
+
* @param nameOrId - Sound name or ID
|
|
1482
|
+
* @returns true if sound is loaded and ready to play
|
|
1483
|
+
*/
|
|
1484
|
+
has(nameOrId: string | number): boolean;
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1123
1487
|
export { GamepadInput, InputDeviceType, KeyboardInput, MouseInput, NetworkState, TVRemoteInput, TouchInput, Vector2, Vector3, createInputDescriptor, deserializeInputDescriptor, gamepadAxisIndexToInput, gamepadButtonIndexToInput, getTouchXAxis, getTouchYAxis, inputDescriptorToString, isAxis, isButton, isGamepadAxis, isGamepadButton, isMouseAxis, isMouseButton, isTVRemoteAxis, isTVRemoteButton, isTouchButton, isTouchGesture, isTouchPosition, keyCodeToKeyboardInput, keyboardInputToKeyCode, parseInputDescriptor, serializeInputDescriptor };
|
|
1124
|
-
export type { AnyNetworkMessage, AxisBinding, AxisSource, ButtonBinding, ButtonSource, ChatMessage, ClientInfo, ConnectionHandler, DisconnectionHandler, ErrorMessage, GamepadInputDescriptor, IApplication, IColorPalette, IInputSystem, INetworkClient, INetworkServer, IRenderer, InputBindingLoadPacket, InputDescriptor, InputEnum, InputMessage, JoinMessage, JoinResponseMessage, KeyboardInputDescriptor, LeaveMessage, LoadMessage, MessageType, MouseInputDescriptor, NetworkClientOptions, NetworkEventHandler, NetworkMessage, NetworkServerOptions, PingMessage, PongMessage, RGBColor, RenderState, RenderedCell, ServerEventHandler, TVRemoteInputDescriptor, TouchInputDescriptor, TypedInputDescriptor, UpdateMessage, UserMetadata, UserRenderState };
|
|
1488
|
+
export type { AnyNetworkMessage, AnySoundLoadPacket, AudioConfigCommand, AudioPlayOptions, AudioPlayResult, AudioSpatialOptions, AxisBinding, AxisSource, ButtonBinding, ButtonSource, ChatMessage, ClientInfo, ConfigureSpatialCommand, ConnectionHandler, DisconnectionHandler, ErrorMessage, FadeOutSoundCommand, GamepadInputDescriptor, IApplication, IAudioProcessor, IColorPalette, IInputSystem, INetworkClient, INetworkServer, IRenderer, ISoundLoader, InputBindingLoadPacket, InputDescriptor, InputEnum, InputMessage, JoinMessage, JoinResponseMessage, KeyboardInputDescriptor, LeaveMessage, LoadMessage, MessageType, MouseInputDescriptor, NetworkClientOptions, NetworkEventHandler, NetworkMessage, NetworkServerOptions, PauseSoundCommand, PingMessage, PlaySoundCommand, PongMessage, RGBColor, RenderState, RenderedCell, ResumeSoundCommand, ServerEventHandler, SetListenerPositionCommand, SoundExternalEntry, SoundExternalLoadPacket, SoundFileEntry, SoundFormat, SoundInstanceId, SoundLoadPacket, SoundLoadType, SoundLoadedAck, SpatialAudioConfig, StopSoundCommand, TVRemoteInputDescriptor, TouchInputDescriptor, TypedInputDescriptor, UpdateMessage, UserMetadata, UserRenderState };
|
package/package.json
CHANGED