q5play 4.0.2 → 4.0.4

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.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/q5play.d.ts +0 -16
  3. package/q5play.js +262 -53
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "q5play",
3
- "version": "4.0.2",
3
+ "version": "4.0.4",
4
4
  "author": "quinton-ashley",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "description": "A web-based game engine that uses q5.js WebGPU for graphics and Box2D v3 WASM for physics.",
package/q5play.d.ts CHANGED
@@ -41,17 +41,6 @@ declare global {
41
41
  * @default true
42
42
  */
43
43
  friendlyRounding: boolean;
44
- /**
45
- * Snaps sprites to the nearest `q5play.gridSize`
46
- * increment when they are moved.
47
- * @default false
48
- */
49
- snapToGrid: boolean;
50
- /**
51
- * The size of the grid cells that sprites are snapped to.
52
- * @default 0.5
53
- */
54
- gridSize: number;
55
44
  /**
56
45
  * Information about the operating system being used.
57
46
  */
@@ -596,11 +585,6 @@ declare global {
596
585
  */
597
586
  get heading(): string;
598
587
  set heading(val: string);
599
- /**
600
- * True if the sprite is moving.
601
- * @readonly
602
- */
603
- get isMoving(): boolean;
604
588
  /**
605
589
  * Set this to true if the sprite goes really fast to prevent
606
590
  * inaccurate physics simulation.
package/q5play.js CHANGED
@@ -30,8 +30,9 @@ if (typeof globalThis.Q5 == 'undefined') {
30
30
  let box2dPromise;
31
31
 
32
32
  // called when a new instance of Q5 is created
33
- async function q5playPreSetup($, q) {
34
- const log = console.log;
33
+ async function q5playPreSetup(q) {
34
+ const $ = this,
35
+ log = console.log;
35
36
 
36
37
  if (!box2dPromise) {
37
38
  box2dPromise = (async () => {
@@ -243,8 +244,6 @@ async function q5playPreSetup($, q) {
243
244
  this.spritesDrawn = 0;
244
245
  this.images = {};
245
246
  this.palettes = [];
246
- this.snapToGrid = false;
247
- this.gridSize = 0.5;
248
247
  this.emojiScale = 1;
249
248
  this.os = {};
250
249
  this.context = 'web';
@@ -1022,18 +1021,17 @@ async function q5playPreSetup($, q) {
1022
1021
  else y = 0;
1023
1022
  }
1024
1023
 
1025
- let rr;
1026
-
1027
1024
  let forcedBoxShape = false;
1028
1025
  if (w === undefined) {
1029
1026
  w = group.w || group.width || group.d || group.diameter;
1030
1027
  if (!h && !group.d && !group.diameter) {
1031
1028
  h = group.h || group.height;
1032
1029
  forcedBoxShape = true;
1033
- rr = group.roundedRadius;
1034
1030
  }
1035
1031
  }
1036
1032
 
1033
+ let rr = group.roundedRadius;
1034
+
1037
1035
  if (typeof x == 'function') x = x(group.length);
1038
1036
  if (typeof y == 'function') y = y(group.length);
1039
1037
  if (typeof w == 'function') w = w(group.length);
@@ -1875,10 +1873,6 @@ async function q5playPreSetup($, q) {
1875
1873
  this.direction = val;
1876
1874
  }
1877
1875
 
1878
- get isMoving() {
1879
- return this.vel.x != 0 || this.vel.y != 0;
1880
- }
1881
-
1882
1876
  get isSuperFast() {
1883
1877
  return b2Body_IsBullet(this.bdID);
1884
1878
  }
@@ -2301,6 +2295,21 @@ async function q5playPreSetup($, q) {
2301
2295
  this.d = val;
2302
2296
  }
2303
2297
 
2298
+ get roundedRadius() {
2299
+ return this._roundedRadius;
2300
+ }
2301
+ set roundedRadius(val) {
2302
+ if (val == this._roundedRadius) return;
2303
+
2304
+ this._roundedRadius = val;
2305
+ if (this.watch) this.mod[37] = true;
2306
+
2307
+ while (this._shapes.length) {
2308
+ this._shapes.at(-1).delete();
2309
+ }
2310
+ this._add(false, 0, 0, this._w, this._h, val);
2311
+ }
2312
+
2304
2313
  /*
2305
2314
  * Validates convexity.
2306
2315
  */
@@ -2338,13 +2347,6 @@ async function q5playPreSetup($, q) {
2338
2347
  this._customUpdate = val;
2339
2348
  }
2340
2349
 
2341
- get postDraw() {
2342
- return this._postDraw;
2343
- }
2344
- set postDraw(val) {
2345
- this._customPostDraw = val;
2346
- }
2347
-
2348
2350
  get vel() {
2349
2351
  return this._vel;
2350
2352
  }
@@ -2619,13 +2621,6 @@ async function q5playPreSetup($, q) {
2619
2621
  }
2620
2622
  }
2621
2623
 
2622
- _postDraw() {
2623
- if (this._customPostDraw) this._customPostDraw();
2624
-
2625
- this.autoDraw ??= true;
2626
- this.autoUpdate ??= true;
2627
- }
2628
-
2629
2624
  _args2Vec(x, y) {
2630
2625
  if (Array.isArray(x)) {
2631
2626
  return { x: x[0], y: x[1] };
@@ -3176,9 +3171,12 @@ async function q5playPreSetup($, q) {
3176
3171
  }
3177
3172
 
3178
3173
  // loading promise
3179
- this.promise = new Promise((resolve) => {
3180
- this._resolve = resolve;
3181
- });
3174
+ if (args.length) {
3175
+ this.promise = new Promise((resolve) => {
3176
+ this._resolve = resolve;
3177
+ });
3178
+ $._loaders.push(this.promise);
3179
+ }
3182
3180
 
3183
3181
  this._frame = 0;
3184
3182
  this._cycles = 0;
@@ -3393,12 +3391,16 @@ async function q5playPreSetup($, q) {
3393
3391
 
3394
3392
  // play by default but a single frame ani doesn't need to play
3395
3393
  this.playing = this.length != 1 && anis.playing != false;
3394
+
3395
+ if (this.length > 0 && !this.spriteSheet) {
3396
+ Promise.all(this.map((img) => img.promise)).then(() => this._resolve(this));
3397
+ }
3396
3398
  }
3397
3399
 
3398
- // make loading Ani objects awaitable
3399
- // then(resolve, reject) {
3400
- // return this.promise.then(resolve, reject);
3401
- // }
3400
+ // use a plain Array constructor for map/filter/etc.
3401
+ static get [Symbol.species]() {
3402
+ return Array;
3403
+ }
3402
3404
 
3403
3405
  get frame() {
3404
3406
  return this._frame;
@@ -4724,12 +4726,6 @@ async function q5playPreSetup($, q) {
4724
4726
 
4725
4727
  $.imageMode(ogImgMode);
4726
4728
  }
4727
-
4728
- postDraw() {
4729
- for (let s of this) {
4730
- s.postDraw();
4731
- }
4732
- }
4733
4729
  };
4734
4730
 
4735
4731
  $.Group.prototype.__step = $.Sprite.prototype.__step;
@@ -6120,8 +6116,11 @@ async function q5playPreSetup($, q) {
6120
6116
  }
6121
6117
 
6122
6118
  function isArrowFunction(fn) {
6123
- return !/^(?:(?:\/\*[^(?:\*\/)]*\*\/\s*)|(?:\/\/[^\r\n]*))*\s*(?:(?:(?:async\s(?:(?:\/\*[^(?:\*\/)]*\*\/\s*)|(?:\/\/[^\r\n]*))*\s*)?function|class)(?:\s|(?:(?:\/\*[^(?:\*\/)]*\*\/\s*)|(?:\/\/[^\r\n]*))*)|(?:[_$\w][\w0-9_$]*\s*(?:\/\*[^(?:\*\/)]*\*\/\s*)*\s*\()|(?:\[\s*(?:\/\*[^(?:\*\/)]*\*\/\s*)*\s*(?:(?:['][^']+['])|(?:["][^"]+["]))\s*(?:\/\*[^(?:\*\/)]*\*\/\s*)*\s*\]\())/.test(
6124
- fn.toString()
6119
+ return (
6120
+ fn.name == 'jsobj' || // brython lambda function check
6121
+ !/^(?:(?:\/\*[^(?:\*\/)]*\*\/\s*)|(?:\/\/[^\r\n]*))*\s*(?:(?:(?:async\s(?:(?:\/\*[^(?:\*\/)]*\*\/\s*)|(?:\/\/[^\r\n]*))*\s*)?function|class)(?:\s|(?:(?:\/\*[^(?:\*\/)]*\*\/\s*)|(?:\/\/[^\r\n]*))*)|(?:[_$\w][\w0-9_$]*\s*(?:\/\*[^(?:\*\/)]*\*\/\s*)*\s*\()|(?:\[\s*(?:\/\*[^(?:\*\/)]*\*\/\s*)*\s*(?:(?:['][^']+['])|(?:["][^"]+["]))\s*(?:\/\*[^(?:\*\/)]*\*\/\s*)*\s*\]\())/.test(
6122
+ fn.toString()
6123
+ )
6125
6124
  );
6126
6125
  }
6127
6126
 
@@ -6238,6 +6237,8 @@ async function q5playPreSetup($, q) {
6238
6237
 
6239
6238
  let img = g.get(left, top, right - left + 1, bottom - top + 1);
6240
6239
  img.src = emoji;
6240
+ img.defaultWidth = img.width;
6241
+ img.defaultHeight = img.height;
6241
6242
 
6242
6243
  g.remove();
6243
6244
 
@@ -6482,6 +6483,7 @@ async function q5playPreSetup($, q) {
6482
6483
  args[0] = window.innerWidth;
6483
6484
  args[1] = window.innerHeight;
6484
6485
  }
6486
+ args[1] ??= args[0];
6485
6487
  args[0] = Math.floor(args[0] / 2) * 2;
6486
6488
  args[1] = Math.floor(args[1] / 2) * 2;
6487
6489
  let rend = _createCanvas.call($, ...args);
@@ -7057,18 +7059,26 @@ async function q5playPreSetup($, q) {
7057
7059
  super();
7058
7060
  this._default = ' ';
7059
7061
 
7060
- this.alt = 0;
7061
- this.arrowUp = 0;
7062
- this.arrowDown = 0;
7063
- this.arrowLeft = 0;
7064
- this.arrowRight = 0;
7065
- this.backspace = 0;
7066
- this.capsLock = 0;
7067
- this.control = 0;
7068
- this.enter = 0;
7069
- this.meta = 0;
7070
- this.shift = 0;
7071
- this.tab = 0;
7062
+ let keys = [
7063
+ ' ',
7064
+ 'alt',
7065
+ 'arrowUp',
7066
+ 'arrowDown',
7067
+ 'arrowLeft',
7068
+ 'arrowRight',
7069
+ 'backspace',
7070
+ 'capsLock',
7071
+ 'control',
7072
+ 'enter',
7073
+ 'meta',
7074
+ 'shift',
7075
+ 'tab'
7076
+ ];
7077
+ keys = keys.concat("abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-=[];,./'".split(''));
7078
+ // initializing these props to 0 makes brython happy
7079
+ for (let key of keys) {
7080
+ this[key] = 0;
7081
+ }
7072
7082
 
7073
7083
  let k = (this._simpleKeyControls = {
7074
7084
  arrowUp: 'up',
@@ -7992,6 +8002,8 @@ async function q5playPreSetup($, q) {
7992
8002
  window[p] = $[p];
7993
8003
  }
7994
8004
  }
8005
+
8006
+ if (Q5.applyLang) Q5.applyLang(q, q5playLibLangs, q5playClassLangs);
7995
8007
  }
7996
8008
 
7997
8009
  // called once after setup
@@ -8120,7 +8132,10 @@ function q5playPostDraw() {
8120
8132
 
8121
8133
  if (cam.isActive) cam.off();
8122
8134
 
8123
- $.allSprites.postDraw();
8135
+ for (let s of $.allSprites) {
8136
+ s.autoDraw ??= true;
8137
+ s.autoUpdate ??= true;
8138
+ }
8124
8139
 
8125
8140
  if ($.q5play.renderStats) $.renderStats();
8126
8141
 
@@ -8167,6 +8182,200 @@ function q5playRemove() {
8167
8182
  this.world?.delete();
8168
8183
  }
8169
8184
 
8185
+ const q5playLibLangs = `
8186
+ allSprites -> es:todosLosSprites
8187
+ world -> es:mundo
8188
+ camera -> es:cámara
8189
+ mouse -> es:ratón
8190
+ kb -> es:tec
8191
+ keyboard -> es:teclado
8192
+ contro -> es:mando
8193
+ controllers -> es:mandos
8194
+ pointer -> es:puntero
8195
+ pointers -> es:punteros
8196
+ spriteArt -> es:arteSprite
8197
+ delay -> es:esperar
8198
+ animation -> es:animación
8199
+ renderStats -> es:estadísticasRenderizado
8200
+ EmojiImage -> es:ImagenEmoji
8201
+ parseTextureAtlas -> es:parsearAtlasTextura
8202
+ DYNAMIC -> es:DINÁMICO
8203
+ STATIC -> es:ESTÁTICO
8204
+ KINEMATIC -> es:CINEMÁTICO
8205
+ Group -> es:Grupo
8206
+ Joint -> es:Articulación
8207
+ `;
8208
+
8209
+ const q5playClassLangs = {
8210
+ Sprite: `
8211
+ rotation -> es:rotación
8212
+ rotationSpeed -> es:velocidadRotación
8213
+ rotationDrag -> es:resistenciaRotación
8214
+ rotationLock -> es:bloqueoRotación
8215
+ speed -> es:velocidad
8216
+ direction -> es:dirección
8217
+ drag -> es:amortiguación
8218
+ mass -> es:masa
8219
+ density -> es:densidad
8220
+ bounciness -> es:elasticidad
8221
+ friction -> es:fricción
8222
+ physicsEnabled -> es:físicaActivada
8223
+ physicsType -> es:tipoFísica
8224
+ physics -> es:física
8225
+ sleeping -> es:durmiendo
8226
+ allowSleeping -> es:permitirDormir
8227
+ layer -> es:capa
8228
+ life -> es:vida
8229
+ scale -> es:escala
8230
+ tint -> es:tinte
8231
+ opacity -> es:opacidad
8232
+ visible -> es:visible
8233
+ debug -> es:depurar
8234
+ deleted -> es:eliminado
8235
+ bearing -> es:rumbo
8236
+ heading -> es:orientación
8237
+ isSuperFast -> es:esUltraRápido
8238
+ pixelPerfect -> es:perfectoEnPíxeles
8239
+ gravityScale -> es:escalaGravedad
8240
+ diameter -> es:diámetro
8241
+ roundedRadius -> es:radioRedondeado
8242
+ centerOfMass -> es:centroMasa
8243
+ previousPosition -> es:posiciónAnterior
8244
+ previousRotation -> es:rotaciónAnterior
8245
+ velocity -> es:vectorVelocidad
8246
+ position -> es:posición
8247
+ canvasPos -> es:posiciónLienzo
8248
+ addCollider -> es:añadirColisionador
8249
+ addSensor -> es:añadirSensor
8250
+ deleteColliders -> es:eliminarColisionadores
8251
+ deleteSensors -> es:eliminarSensores
8252
+ collide -> es:colisionar
8253
+ collides -> es:colisiona
8254
+ colliding -> es:colisionando
8255
+ collided -> es:colisionó
8256
+ overlap -> es:solapar
8257
+ overlaps -> es:solapa
8258
+ overlapping -> es:solapando
8259
+ overlapped -> es:solapó
8260
+ passes -> es:pasa
8261
+ addAni -> es:añadirAni
8262
+ addAnis -> es:añadirAnis
8263
+ changeAni -> es:cambiarAni
8264
+ playAni -> es:reproducirAni
8265
+ playAnis -> es:reproducirAnis
8266
+ moveTowards -> es:moverHacia
8267
+ rotateTowards -> es:rotarHacia
8268
+ applyForce -> es:aplicarFuerza
8269
+ applyForceScaled -> es:aplicarFuerzaEscalada
8270
+ attractTo -> es:atraerA
8271
+ repelFrom -> es:repelerDe
8272
+ applyTorque -> es:aplicarTorque
8273
+ angleTo -> es:ánguloHacia
8274
+ rotationToFace -> es:rotaciónParaMirar
8275
+ angleToFace -> es:ánguloParaMirar
8276
+ setSpeedAndDirection -> es:establecerVelocidadYDirección
8277
+ scaleBy -> es:escalarPor
8278
+ resetMass -> es:reiniciarMasa
8279
+ distanceTo -> es:distanciaA
8280
+ delete -> es:eliminar
8281
+ addDefaultSensors -> es:añadirSensoresDefecto
8282
+ autoDraw -> es:autoDibujar
8283
+ draw -> es:dibujar
8284
+ autoUpdate -> es:autoActualizar
8285
+ update -> es:actualizar
8286
+ `,
8287
+ Group: `
8288
+ Group -> es:Grupo
8289
+ amount -> es:cantidad
8290
+ autoCull -> es:descartarFueraCampo
8291
+ cull -> es:descartar
8292
+ contains -> es:contiene
8293
+ remove -> es:quitar
8294
+ removeAll -> es:quitarTodo
8295
+ delete -> es:eliminar
8296
+ deleteAll -> es:eliminarTodo
8297
+ `,
8298
+ World: `
8299
+ gravity -> es:gravedad
8300
+ timeScale -> es:escalaVelocidad
8301
+ meterSize -> es:tamañoMetro
8302
+ allowSleeping -> es:permitirDormir
8303
+ awakeBodies -> es:cuerposDespiertos
8304
+ bounceThreshold -> es:umbralRebote
8305
+ hitThreshold -> es:umbralGolpe
8306
+ autoStep -> es:pasoAutomático
8307
+ subSteps -> es:subPasos
8308
+ explodeAt -> es:explosionEn
8309
+ delete -> es:eliminar
8310
+ `,
8311
+ Camera: `
8312
+ position -> es:posición
8313
+ zoom ->
8314
+ moveTo -> es:moverA
8315
+ zoomTo -> es:acercarA
8316
+ on -> es:activar
8317
+ off -> es:desactivar
8318
+ `,
8319
+ Ani: `
8320
+ play -> es:reproducir
8321
+ pause -> es:pausar
8322
+ stop -> es:parar
8323
+ loop -> es:bucle
8324
+ noLoop -> es:sinBucle
8325
+ rewind -> es:rebobinar
8326
+ nextFrame -> es:siguienteFotograma
8327
+ previousFrame -> es:fotogramaAnterior
8328
+ goToFrame -> es:irAlFotograma
8329
+ clone -> es:clonar
8330
+ frame -> es:fotograma
8331
+ lastFrame -> es:últimoFotograma
8332
+ frameImage -> es:imagenFotograma
8333
+ playing -> es:reproduciendo
8334
+ looping -> es:enBucle
8335
+ frameDelay -> es:retardoFotograma
8336
+ `,
8337
+ InputDevice: `
8338
+ presses -> es:presiona
8339
+ pressing -> es:presionando
8340
+ holds -> es:mantiene
8341
+ holding -> es:manteniendo
8342
+ held -> es:mantuvo
8343
+ released -> es:soltó
8344
+ releases -> es:suelta
8345
+ holdThreshold -> es:umbralMantener
8346
+ `,
8347
+ _Mouse: `
8348
+ position -> es:posición
8349
+ visible -> es:visible
8350
+ isOnCanvas -> es:estaEnLienzo
8351
+ scroll -> es:desplazamiento
8352
+ drags -> es:arrastra
8353
+ dragging -> es:arrastrando
8354
+ dragged -> es:arrastró
8355
+ scrolls -> es:desplaza
8356
+ scrolling -> es:desplazando
8357
+ scrolled -> es:desplazó
8358
+ `,
8359
+ _Pointer: `
8360
+ prev -> es:previo
8361
+ canvasPos -> es:posEnLienzo
8362
+ type -> es:tipo
8363
+ duration -> es:duración
8364
+ holdThreshold -> es:umbralDeSostenido
8365
+ drags -> es:arrastra
8366
+ dragging -> es:arrastrando
8367
+ dragged -> es:arrastró
8368
+ grabs -> es:agarra
8369
+ grabbing -> es:agarrando
8370
+ grabbed -> es:agarró
8371
+ overlaps -> es:superpone
8372
+ overlapping -> es:superponiendo
8373
+ overlapped -> es:superpuso
8374
+ pressure -> es:presión
8375
+ `
8376
+ };
8377
+ q5playClassLangs.Group += q5playClassLangs.Sprite;
8378
+
8170
8379
  Q5.addHook('presetup', q5playPreSetup);
8171
8380
  Q5.addHook('postsetup', q5playPostSetup);
8172
8381
  Q5.addHook('predraw', q5playPreDraw);