matrix-engine-wgpu 1.1.1 → 1.2.1

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 (128) hide show
  1. package/examples/games/jamb/html-content.js +128 -0
  2. package/examples/games/jamb/jamb.js +344 -137
  3. package/examples/games/jamb/readme.md +3 -0
  4. package/examples/unlit-textures.js +18 -17
  5. package/index.js +1 -1
  6. package/main.js +625 -453
  7. package/package.json +1 -1
  8. package/public/app.js +1058 -280
  9. package/public/css/style.css +248 -80
  10. package/public/empty.js +10140 -9865
  11. package/public/examples.js +837 -241
  12. package/public/index.html +0 -3
  13. package/public/res/audios/dice-roll.mp3 +0 -0
  14. package/public/res/audios/kenney/Kenney.url +2 -0
  15. package/public/res/audios/kenney/License.txt +22 -0
  16. package/public/res/audios/kenney/Patreon.url +2 -0
  17. package/public/res/audios/kenney/audios/back_001.ogg +0 -0
  18. package/public/res/audios/kenney/audios/back_002.ogg +0 -0
  19. package/public/res/audios/kenney/audios/back_003.ogg +0 -0
  20. package/public/res/audios/kenney/audios/back_004.ogg +0 -0
  21. package/public/res/audios/kenney/audios/bong_001.ogg +0 -0
  22. package/public/res/audios/kenney/audios/click_001.ogg +0 -0
  23. package/public/res/audios/kenney/audios/click_002.ogg +0 -0
  24. package/public/res/audios/kenney/audios/click_003.ogg +0 -0
  25. package/public/res/audios/kenney/audios/click_004.ogg +0 -0
  26. package/public/res/audios/kenney/audios/click_005.ogg +0 -0
  27. package/public/res/audios/kenney/audios/close_001.ogg +0 -0
  28. package/public/res/audios/kenney/audios/close_002.ogg +0 -0
  29. package/public/res/audios/kenney/audios/close_003.ogg +0 -0
  30. package/public/res/audios/kenney/audios/close_004.ogg +0 -0
  31. package/public/res/audios/kenney/audios/confirmation_001.ogg +0 -0
  32. package/public/res/audios/kenney/audios/confirmation_002.ogg +0 -0
  33. package/public/res/audios/kenney/audios/confirmation_003.ogg +0 -0
  34. package/public/res/audios/kenney/audios/confirmation_004.ogg +0 -0
  35. package/public/res/audios/kenney/audios/drop_001.ogg +0 -0
  36. package/public/res/audios/kenney/audios/drop_002.ogg +0 -0
  37. package/public/res/audios/kenney/audios/drop_003.ogg +0 -0
  38. package/public/res/audios/kenney/audios/drop_004.ogg +0 -0
  39. package/public/res/audios/kenney/audios/error_001.ogg +0 -0
  40. package/public/res/audios/kenney/audios/error_002.ogg +0 -0
  41. package/public/res/audios/kenney/audios/error_003.ogg +0 -0
  42. package/public/res/audios/kenney/audios/error_004.ogg +0 -0
  43. package/public/res/audios/kenney/audios/error_005.ogg +0 -0
  44. package/public/res/audios/kenney/audios/error_006.ogg +0 -0
  45. package/public/res/audios/kenney/audios/error_007.ogg +0 -0
  46. package/public/res/audios/kenney/audios/error_008.ogg +0 -0
  47. package/public/res/audios/kenney/audios/glass_001.ogg +0 -0
  48. package/public/res/audios/kenney/audios/glass_002.ogg +0 -0
  49. package/public/res/audios/kenney/audios/glass_003.ogg +0 -0
  50. package/public/res/audios/kenney/audios/glass_004.ogg +0 -0
  51. package/public/res/audios/kenney/audios/glass_005.ogg +0 -0
  52. package/public/res/audios/kenney/audios/glass_006.ogg +0 -0
  53. package/public/res/audios/kenney/audios/glitch_001.ogg +0 -0
  54. package/public/res/audios/kenney/audios/glitch_002.ogg +0 -0
  55. package/public/res/audios/kenney/audios/glitch_003.ogg +0 -0
  56. package/public/res/audios/kenney/audios/glitch_004.ogg +0 -0
  57. package/public/res/audios/kenney/audios/maximize_001.ogg +0 -0
  58. package/public/res/audios/kenney/audios/maximize_002.ogg +0 -0
  59. package/public/res/audios/kenney/audios/maximize_003.ogg +0 -0
  60. package/public/res/audios/kenney/audios/maximize_004.ogg +0 -0
  61. package/public/res/audios/kenney/audios/maximize_005.ogg +0 -0
  62. package/public/res/audios/kenney/audios/maximize_006.ogg +0 -0
  63. package/public/res/audios/kenney/audios/maximize_007.ogg +0 -0
  64. package/public/res/audios/kenney/audios/maximize_008.ogg +0 -0
  65. package/public/res/audios/kenney/audios/maximize_009.ogg +0 -0
  66. package/public/res/audios/kenney/audios/minimize_001.ogg +0 -0
  67. package/public/res/audios/kenney/audios/minimize_002.ogg +0 -0
  68. package/public/res/audios/kenney/audios/minimize_003.ogg +0 -0
  69. package/public/res/audios/kenney/audios/minimize_004.ogg +0 -0
  70. package/public/res/audios/kenney/audios/minimize_005.ogg +0 -0
  71. package/public/res/audios/kenney/audios/minimize_006.ogg +0 -0
  72. package/public/res/audios/kenney/audios/minimize_007.ogg +0 -0
  73. package/public/res/audios/kenney/audios/minimize_008.ogg +0 -0
  74. package/public/res/audios/kenney/audios/minimize_009.ogg +0 -0
  75. package/public/res/audios/kenney/audios/open_001.ogg +0 -0
  76. package/public/res/audios/kenney/audios/open_002.ogg +0 -0
  77. package/public/res/audios/kenney/audios/open_003.ogg +0 -0
  78. package/public/res/audios/kenney/audios/open_004.ogg +0 -0
  79. package/public/res/audios/kenney/audios/pluck_001.ogg +0 -0
  80. package/public/res/audios/kenney/audios/pluck_002.ogg +0 -0
  81. package/public/res/audios/kenney/audios/question_001.ogg +0 -0
  82. package/public/res/audios/kenney/audios/question_002.ogg +0 -0
  83. package/public/res/audios/kenney/audios/question_003.ogg +0 -0
  84. package/public/res/audios/kenney/audios/question_004.ogg +0 -0
  85. package/public/res/audios/kenney/audios/scratch_001.ogg +0 -0
  86. package/public/res/audios/kenney/audios/scratch_002.ogg +0 -0
  87. package/public/res/audios/kenney/audios/scratch_003.ogg +0 -0
  88. package/public/res/audios/kenney/audios/scratch_004.ogg +0 -0
  89. package/public/res/audios/kenney/audios/scratch_005.ogg +0 -0
  90. package/public/res/audios/kenney/audios/scroll_001.ogg +0 -0
  91. package/public/res/audios/kenney/audios/scroll_002.ogg +0 -0
  92. package/public/res/audios/kenney/audios/scroll_003.ogg +0 -0
  93. package/public/res/audios/kenney/audios/scroll_004.ogg +0 -0
  94. package/public/res/audios/kenney/audios/scroll_005.ogg +0 -0
  95. package/public/res/audios/kenney/audios/select_001.ogg +0 -0
  96. package/public/res/audios/kenney/audios/select_002.ogg +0 -0
  97. package/public/res/audios/kenney/audios/select_003.ogg +0 -0
  98. package/public/res/audios/kenney/audios/select_004.ogg +0 -0
  99. package/public/res/audios/kenney/audios/select_005.ogg +0 -0
  100. package/public/res/audios/kenney/audios/select_006.ogg +0 -0
  101. package/public/res/audios/kenney/audios/select_007.ogg +0 -0
  102. package/public/res/audios/kenney/audios/select_008.ogg +0 -0
  103. package/public/res/audios/kenney/audios/switch_001.ogg +0 -0
  104. package/public/res/audios/kenney/audios/switch_002.ogg +0 -0
  105. package/public/res/audios/kenney/audios/switch_003.ogg +0 -0
  106. package/public/res/audios/kenney/audios/switch_004.ogg +0 -0
  107. package/public/res/audios/kenney/audios/switch_005.ogg +0 -0
  108. package/public/res/audios/kenney/audios/switch_006.ogg +0 -0
  109. package/public/res/audios/kenney/audios/switch_007.ogg +0 -0
  110. package/public/res/audios/kenney/audios/tick_001.ogg +0 -0
  111. package/public/res/audios/kenney/audios/tick_002.ogg +0 -0
  112. package/public/res/audios/kenney/audios/tick_004.ogg +0 -0
  113. package/public/res/audios/kenney/audios/toggle_001.ogg +0 -0
  114. package/public/res/audios/kenney/audios/toggle_002.ogg +0 -0
  115. package/public/res/audios/kenney/audios/toggle_003.ogg +0 -0
  116. package/public/res/audios/kenney/audios/toggle_004.ogg +0 -0
  117. package/public/res/audios/toggle_002.mp3 +0 -0
  118. package/public/res/meshes/shapes/star1.obj +60 -0
  119. package/public/res/multilang/en.json +13 -1
  120. package/public/res/multilang/sr.json +13 -1
  121. package/readme.md +18 -0
  122. package/src/engine/ball.js +0 -3
  123. package/src/engine/cube.js +0 -1
  124. package/src/engine/mesh-obj.js +0 -7
  125. package/src/engine/utils.js +158 -1
  126. package/src/physics/matrix-ammo.js +64 -26
  127. package/src/sounds/sounds.js +32 -10
  128. package/src/world.js +361 -307
package/public/app.js CHANGED
@@ -1,27 +1,279 @@
1
1
  (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
2
2
  "use strict";
3
3
 
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.welcomeBoxHTML = exports.settingsBox = void 0;
8
+ let settingsBox = exports.settingsBox = `
9
+ <div style="">
10
+ <span style="font-size:170%" data-label="settings"></span>
11
+ <div style="justify-items: flex-end;margin:20px;" >
12
+ <div>
13
+ <span data-label="sounds"></span>
14
+ <label class="switch">
15
+ <input id="settingsAudios" type="checkbox">
16
+ <span class="sliderSwitch round"></span>
17
+ </label>
18
+ </div>
19
+ <div style="margin-top:20px;margin-bottom:15px;">
20
+ <span style="font-size: larger;margin-bottom:15px" data-label="graphics"></span>
21
+ <p></p>
22
+ <label>Anim speed:</label>
23
+ <select id="physicsSpeed" class="setting-select">
24
+ <option value="1">Slow</option>
25
+ <option value="2">Normal</option>
26
+ <option value="3">Fast</option>
27
+ </select>
28
+ </div>
29
+
30
+ <div>
31
+ <label>Blur:</label>
32
+ <select id="blurControl">
33
+ <option value="0px">Blur: 0</option>
34
+ <option value="1px">Blur: 1</option>
35
+ <option value="2px">Blur: 2</option>
36
+ <option value="3px">Blur: 3</option>
37
+ </select>
38
+ </div>
39
+
40
+ <div>
41
+ <label>Grayscale:</label>
42
+ <select id="grayscaleControl">
43
+ <option value="0%">Grayscale: 0%</option>
44
+ <option value="25%">Grayscale: 25%</option>
45
+ <option value="50%">Grayscale: 50%</option>
46
+ <option value="75%">Grayscale: 75%</option>
47
+ <option value="100%">Grayscale: 100%</option>
48
+ </select>
49
+ </div>
50
+
51
+ <div>
52
+ <label>Brightness:</label>
53
+ <select id="brightnessControl">
54
+ <option value="100%">100%</option>
55
+ <option value="150%">150%</option>
56
+ <option value="200%">200%</option>
57
+ </select>
58
+ </div>
59
+
60
+ <div>
61
+ <label>Contrast:</label>
62
+ <select id="contrastControl">
63
+ <option value="100%">100%</option>
64
+ <option value="150%">150%</option>
65
+ <option value="200%">200%</option>
66
+ </select>
67
+ </div>
68
+
69
+ <div>
70
+ <label>Saturate:</label>
71
+ <select id="saturateControl">
72
+ <option value="100%">100%</option>
73
+ <option value="150%">150%</option>
74
+ <option value="200%">200%</option>
75
+ </select>
76
+ </div>
77
+
78
+ <div>
79
+ <label>Sepia:</label>
80
+ <select id="sepiaControl">
81
+ <option value="0%">0%</option>
82
+ <option value="50%">50%</option>
83
+ <option value="100%">100%</option>
84
+ </select>
85
+ </div>
86
+
87
+ <div>
88
+ <label>Invert:</label>
89
+ <select id="invertControl">
90
+ <option value="0%">0%</option>
91
+ <option value="50%">50%</option>
92
+ <option value="100%">100%</option>
93
+ </select>
94
+ </div>
95
+
96
+ <div>
97
+ <label>Hue Rotate:</label>
98
+ <select id="hueControl">
99
+ <option value="0deg">0°</option>
100
+ <option value="90deg">90°</option>
101
+ <option value="180deg">180°</option>
102
+ <option value="270deg">270°</option>
103
+ </select>
104
+ </div>
105
+
106
+ <div style="margin-top:20px;">
107
+ <button class="btn" onclick="app.myDom.hideSettings()">
108
+ <span data-label="hide"></span>
109
+ </button>
110
+ </div>
111
+
112
+ <img src="res/icons/512.png" style="position:absolute;left:10px;top:5%;width:300px;z-index:-1;"/>
113
+ </div>
114
+ </div>`;
115
+ let welcomeBoxHTML = exports.welcomeBoxHTML = `<span class="fancy-title" data-label="welcomeMsg"></span>
116
+ <a href="https://github.com/zlatnaspirala/matrix-engine-wgpu">zlatnaspirala/matrix-engine-wgpu</a><br><br>
117
+ <div style="display:flex;flex-direction:column;align-items: center;margin:20px;padding: 10px;">
118
+ <span style="width:100%" data-label="choosename"></span>
119
+ <input style="text-align: center;height:50px;font-size:100%;width:250px" class="fancy-label" type="text" value="Guest" />
120
+ </div>
121
+ <button id="startFromWelcome" class="btn" ><span style="font-size:30px;margin:15px;padding:10px" data-label="startGame"></span></button> <br>
122
+ <div><span class="fancy-label" data-label="changeLang"></span></div>
123
+ <button class="btn" onclick="
124
+ app.label.loadMultilang('en').then(r => {
125
+ app.label.get = r;
126
+ app.label.update()
127
+ });
128
+ " ><span data-label="english"></span></button>
129
+ <button class="btn" onclick="app.label.loadMultilang('sr').then(r => {
130
+ app.label.get = r
131
+ app.label.update() })" ><span data-label="serbian"></span></button>
132
+ `;
133
+
134
+ },{}],2:[function(require,module,exports){
135
+ "use strict";
136
+
4
137
  Object.defineProperty(exports, "__esModule", {
5
138
  value: true
6
139
  });
7
140
  exports.myDom = exports.dices = void 0;
8
- var _world = _interopRequireDefault(require("../../../src/world.js"));
9
- var _loaderObj = require("../../../src/engine/loader-obj.js");
10
141
  var _utils = require("../../../src/engine/utils.js");
11
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
142
+ var _htmlContent = require("./html-content.js");
12
143
  let dices = exports.dices = {
13
144
  C: 0,
14
145
  STATUS: 'FREE_TO_PLAY',
15
- STATUS_H2: 'WAIT',
16
- STATUS_H3: 'WAIT',
17
146
  R: {},
18
147
  SAVED_DICES: {},
19
- pickDice: dice => {
20
- (void 0).SAVED_DICES[dice] = (void 0).R[dice];
148
+ pickDice: function (dice) {
149
+ if (Object.keys(this.SAVED_DICES).length >= 5) {
150
+ console.log("⚠️ You can only select up to 5 dice!");
151
+ return; // prevent adding more
152
+ }
153
+ this.SAVED_DICES[dice] = this.R[dice];
154
+ this.refreshSelectedBox();
155
+ },
156
+ setStartUpPosition: () => {
157
+ //
158
+ let currentIndex = 0;
159
+ for (var x = 1; x < 7; x++) {
160
+ app.matrixAmmo.getBodyByName('CubePhysics' + x).MEObject.position.setPosition(-5 + currentIndex * 5, 2, -15);
161
+ }
162
+ },
163
+ refreshSelectedBox: function (arg) {
164
+ let currentIndex = 0;
165
+ for (var key in this.SAVED_DICES) {
166
+ let B = app.matrixAmmo.getBodyByName(key);
167
+ this.deactivatePhysics(B);
168
+ const transform = new Ammo.btTransform();
169
+ transform.setIdentity();
170
+ transform.setOrigin(new Ammo.btVector3(0, 0, 0));
171
+ B.setWorldTransform(transform);
172
+ B.MEObject.position.setPosition(-5 + currentIndex, 5, -16);
173
+ currentIndex += 3;
174
+ }
175
+ },
176
+ deactivatePhysics: function (body) {
177
+ const CF_KINEMATIC_OBJECT = 2;
178
+ const DISABLE_DEACTIVATION = 4;
179
+ // 1. Remove from world
180
+ app.matrixAmmo.dynamicsWorld.removeRigidBody(body);
181
+ // 2. Set body to kinematic
182
+ const flags = body.getCollisionFlags();
183
+ body.setCollisionFlags(flags | CF_KINEMATIC_OBJECT);
184
+ body.setActivationState(DISABLE_DEACTIVATION); // no auto-wakeup
185
+ // 3. Clear motion
186
+ const zero = new Ammo.btVector3(0, 0, 0);
187
+ body.setLinearVelocity(zero);
188
+ body.setAngularVelocity(zero);
189
+ // 4. Reset transform to current position (optional — preserves pose)
190
+ const currentTransform = body.getWorldTransform();
191
+ body.setWorldTransform(currentTransform);
192
+ body.getMotionState().setWorldTransform(currentTransform);
193
+ // 5. Add back to physics world
194
+ app.matrixAmmo.dynamicsWorld.addRigidBody(body);
195
+ // 6. Mark it manually (logic flag)
196
+ body.isKinematic = true;
197
+ },
198
+ resetBodyAboveFloor: function (body, z = -14) {
199
+ const transform = new Ammo.btTransform();
200
+ transform.setIdentity();
201
+ transform.setOrigin(new Ammo.btVector3(-1 + Math.random(), 3, z));
202
+ body.setWorldTransform(transform);
203
+ body.getMotionState().setWorldTransform(transform);
204
+ },
205
+ activatePhysics: function (body) {
206
+ // 1. Make it dynamic again
207
+ body.setCollisionFlags(body.getCollisionFlags() & ~2); // remove kinematic
208
+ body.setActivationState(1); // ACTIVE_TAG
209
+ body.isKinematic = false;
210
+
211
+ // 2. Reset position ABOVE the floor — force it out of collision
212
+ // const newY = 3 + Math.random(); // ensure it’s above the floor
213
+ const transform = new Ammo.btTransform();
214
+ transform.setIdentity();
215
+ const newX = (Math.random() - 0.5) * 4; // spread from -2 to +2 on X
216
+ const newY = 3; // fixed height above floor
217
+ transform.setOrigin(new Ammo.btVector3(newX, newY, 0));
218
+ body.setWorldTransform(transform);
219
+
220
+ // 3. Clear velocities
221
+ body.setLinearVelocity(new Ammo.btVector3(0, 0, 0));
222
+ body.setAngularVelocity(new Ammo.btVector3(0, 0, 0));
223
+
224
+ // 4. Enable CCD (to prevent tunneling)
225
+ const size = 1; // cube side length
226
+ body.setCcdMotionThreshold(1e-7);
227
+ body.setCcdSweptSphereRadius(size * 0.5);
228
+
229
+ // Re-add to world if needed
230
+ // Optionally: remove and re-add if not responding
231
+ app.matrixAmmo.dynamicsWorld.removeRigidBody(body);
232
+ app.matrixAmmo.dynamicsWorld.addRigidBody(body);
233
+
234
+ // 5. Reactivate it
235
+ body.activate(true);
236
+ this.resetBodyAboveFloor(body);
237
+ },
238
+ activateAllDicesPhysics: function () {
239
+ this.getAllDices()
240
+ // .filter((item) => {
241
+ // let test = app.matrixAmmo.getBodyByName(item.name)?.isKinematicObject();
242
+ // if(test === true) {
243
+ // return true;
244
+ // } else {
245
+ // return false;
246
+ // }
247
+ // })
248
+ .forEach(dice => {
249
+ const body = app.matrixAmmo.getBodyByName(dice.name);
250
+ if (body) {
251
+ this.activatePhysics(body); // <--- FIX: pass the physics body, not the dice object
252
+ }
253
+ });
254
+ },
255
+ getAllDices: function () {
256
+ return app.mainRenderBundle.filter(item => item.name.indexOf("CubePhysics") !== -1);
257
+ },
258
+ getDiceByName: function (name) {
259
+ return app.mainRenderBundle.find(item => item.name === name);
21
260
  },
22
261
  checkAll: function () {
23
262
  this.C++;
24
- if (typeof this.R.CubePhysics1 != 'undefined' && typeof this.R.CubePhysics2 != 'undefined' && typeof this.R.CubePhysics3 != 'undefined' && typeof this.R.CubePhysics4 != 'undefined' && typeof this.R.CubePhysics5 != 'undefined' && typeof this.R.CubePhysics6 != 'undefined' && this.C > 1200) {
263
+ let activeRollingCount = 0;
264
+ let allReady = true;
265
+ for (let i = 1; i <= 6; i++) {
266
+ const key = "CubePhysics" + i;
267
+ if (key in this.SAVED_DICES) continue; // skip saved ones
268
+ activeRollingCount++; // count how many are still active
269
+ if (typeof this.R[key] === 'undefined') {
270
+ allReady = false;
271
+ break;
272
+ }
273
+ }
274
+ // Dynamic threshold: min wait time based on rolling dice
275
+ const minWait = Math.max(200, activeRollingCount * 200); // e.g. 1 die => 200, 5 dice => 1000, 6 dice => 1200
276
+ if (allReady && this.C > minWait) {
25
277
  dispatchEvent(new CustomEvent('all-done', {
26
278
  detail: {}
27
279
  }));
@@ -29,10 +281,14 @@ let dices = exports.dices = {
29
281
  }
30
282
  },
31
283
  validatePass: function () {
32
- if (dices.STATUS == "IN_PLAY" || dices.STATUS == "FREE_TO_PLAY") {
33
- // console.log('%cBLOCK', LOG_FUNNY)
34
- if (dices.STATUS == "IN_PLAY") _utils.mb.error(`STATUS IS ${dices.STATUS}, please wait for results...`);
35
- if (dices.STATUS == "FREE_TO_PLAY") _utils.mb.error(`STATUS IS ${dices.STATUS}, you need to roll dice first.`);
284
+ if (Object.keys(this.SAVED_DICES).length !== 5) {
285
+ console.log('%cBLOCK', _utils.LOG_FUNNY);
286
+ _utils.mb.error(`Must select (minimum) 5 dices before add results...`);
287
+ return false;
288
+ }
289
+ if (dices.STATUS != "FINISHED") {
290
+ console.log('%cBLOCK', _utils.LOG_FUNNY);
291
+ _utils.mb.error(`STATUS IS ${dices.STATUS}, please wait for results...`);
36
292
  app.matrixSounds.play('block');
37
293
  return false;
38
294
  } else {
@@ -57,41 +313,69 @@ let myDom = exports.myDom = {
57
313
  root.style.top = '10%';
58
314
  var help = document.createElement('div');
59
315
  help.id = 'HELP';
60
- help.classList.add('btn2');
316
+ help.classList.add('btn');
61
317
  help.innerHTML = `<span data-label="help"></span>`;
318
+ help.addEventListener('click', () => {
319
+ if ((0, _utils.byId)('helpBox').style.display != 'none') {
320
+ (0, _utils.byId)('helpBox').style.display = 'none';
321
+ } else {
322
+ (0, _utils.byId)('helpBox').style.display = 'block';
323
+ }
324
+ });
325
+ var table = document.createElement('div');
326
+ table.id = 'showHideTableDOM';
327
+ table.classList.add('btn');
328
+ table.innerHTML = `<span data-label="table"></span>`;
329
+ table.addEventListener('click', () => {
330
+ this.showHideJambTable();
331
+ });
62
332
  var settings = document.createElement('div');
63
333
  settings.id = 'settings';
64
- settings.classList.add('btn2');
334
+ settings.classList.add('btn');
65
335
  settings.innerHTML = `<span data-label="settings"></span>`;
66
336
  settings.addEventListener('click', () => {
67
- (0, _utils.byId)('messageBox').innerHTML = `
68
- <div>
69
- <span data-label="settings"></span>
70
- <div>
71
-
72
- <div>
73
- <span data-label="sounds"></span>
74
-
75
- <label class="switch">
76
- <input type="checkbox">
77
- <span class="sliderSwitch round"></span>
78
- </label>
79
-
80
- </div>
81
-
82
- <div>
83
- <button class="btn2" onclick="app.myDom.hideSettings()">
84
- <span data-label="hide"></span>
85
- </button>
86
- </div>
87
-
88
- </div>
89
- </div>
90
- `;
337
+ if (document.getElementById('messageBox').getAttribute('data-loaded') != null) {
338
+ (0, _utils.byId)('blocker').style.display = 'flex';
339
+ (0, _utils.byId)('messageBox').style.display = 'unset';
340
+ return;
341
+ }
342
+ (0, _utils.byId)('messageBox').innerHTML = _htmlContent.settingsBox;
91
343
  (0, _utils.byId)('blocker').style.display = 'flex';
92
- (0, _utils.byId)('messageBox').style.display = 'flex';
344
+ (0, _utils.byId)('messageBox').style.display = 'unset';
93
345
  dispatchEvent(new CustomEvent('updateLang', {}));
346
+ (0, _utils.byId)('settingsAudios').click();
347
+ (0, _utils.byId)('settingsAudios').addEventListener('change', e => {
348
+ if (e.target.checked == true) {
349
+ app.matrixSounds.unmuteAll();
350
+ } else {
351
+ app.matrixSounds.muteAll();
352
+ }
353
+ });
354
+ (0, _utils.setupCanvasFilters)();
355
+ (0, _utils.byId)('messageBox').setAttribute('data-loaded', 'loaded');
356
+ document.getElementById('physicsSpeed').value = app.matrixAmmo.speedUpSimulation;
357
+ (0, _utils.byId)("physicsSpeed").addEventListener("change", e => {
358
+ app.matrixAmmo.speedUpSimulation = parseInt(e.target.value);
359
+ });
360
+ });
361
+
362
+ // test help
363
+ var helpBox = document.createElement('div');
364
+ helpBox.id = 'helpBox';
365
+ helpBox.style.position = 'absolute';
366
+ helpBox.style.right = '20%';
367
+ helpBox.style.zIndex = '2';
368
+ helpBox.style.top = '15%';
369
+ helpBox.style.width = '60%';
370
+ helpBox.style.height = '50%';
371
+ helpBox.style.fontSize = '100%';
372
+ helpBox.classList.add('btn');
373
+ helpBox.addEventListener('click', () => {
374
+ (0, _utils.byId)('helpBox').style.display = 'none';
94
375
  });
376
+ document.body.appendChild(helpBox);
377
+ (0, _utils.typeText)('helpBox', app.label.get.about, 10);
378
+ //
95
379
  var roll = document.createElement('div');
96
380
  roll.id = 'hud-roll';
97
381
  roll.classList.add('btn');
@@ -100,8 +384,9 @@ let myDom = exports.myDom = {
100
384
  app.ROLL();
101
385
  });
102
386
  var separator = document.createElement('div');
103
- separator.innerHTML = `=======`;
387
+ separator.innerHTML = `✨maximumroulette.com✨`;
104
388
  root.append(settings);
389
+ root.append(table);
105
390
  root.append(help);
106
391
  root.append(separator);
107
392
  root.append(roll);
@@ -118,42 +403,40 @@ let myDom = exports.myDom = {
118
403
  messageBox.id = 'messageBox';
119
404
 
120
405
  // console.log('TEST', app.label.get)
121
- messageBox.innerHTML = `
122
- <span data-label="welcomeMsg"></span>
123
- <a href="https://github.com/zlatnaspirala/matrix-engine-wgpu">zlatnaspirala/matrix-engine-wgpu</a><br><br>
124
- <button class="btn" ><span style="font-size:30px;margin:15px;padding:10px" data-label="startGame"></span></button> <br>
125
- <div><span data-label="changeLang"></span></div>
126
- <button class="btn" onclick="
127
- app.label.loadMultilang('en').then(r => {
128
- app.label.get = r;
129
- app.label.update()
130
- });
131
- " ><span data-label="english"></span></button>
132
- <button class="btn" onclick="app.label.loadMultilang('sr').then(r => {
133
- app.label.get = r
134
- app.label.update() })" ><span data-label="serbian"></span></button>
135
- `;
406
+ messageBox.innerHTML = _htmlContent.welcomeBoxHTML;
136
407
  let initialMsgBoxEvent = function () {
137
408
  console.log('click on msgbox');
138
409
  (0, _utils.byId)('messageBox').innerHTML = ``;
139
410
  (0, _utils.byId)('blocker').style.display = 'none';
140
411
  myDom.createMenu();
141
412
  messageBox.removeEventListener('click', initialMsgBoxEvent);
413
+ document.querySelectorAll('.btn, .fancy-label, .fancy-title').forEach(el => {
414
+ el.addEventListener('mouseenter', () => {
415
+ app.matrixSounds.play('hover');
416
+ });
417
+ });
142
418
  };
143
- messageBox.addEventListener('click', initialMsgBoxEvent);
144
419
  root.append(messageBox);
145
420
  document.body.appendChild(root);
146
421
  app.label.update();
422
+ document.querySelectorAll('.btn, .fancy-label, .fancy-title').forEach(el => {
423
+ el.addEventListener('mouseenter', () => {
424
+ app.matrixSounds.play('hover');
425
+ });
426
+ });
427
+ setTimeout(() => {
428
+ (0, _utils.byId)('startFromWelcome').addEventListener('click', initialMsgBoxEvent);
429
+ }, 200);
147
430
  },
148
431
  createJamb: function () {
149
432
  var root = document.createElement('div');
150
433
  root.id = 'jambTable';
151
434
  root.style.position = 'absolute';
152
- root.style.display = 'flex';
153
- root.style.top = '10px';
154
- root.style.left = '10px';
155
- root.style.width = '200px';
156
- root.style.background = '#7d7d7d8c';
435
+ var dragHandler = document.createElement('div');
436
+ dragHandler.id = 'dragHandler';
437
+ dragHandler.classList.add('dragHandler');
438
+ dragHandler.innerHTML = "⇅ Drag";
439
+ root.append(dragHandler);
157
440
  var rowHeader = document.createElement('div');
158
441
  rowHeader.id = 'rowHeader';
159
442
  rowHeader.style.top = '10px';
@@ -161,30 +444,33 @@ let myDom = exports.myDom = {
161
444
  rowHeader.style.width = '200px';
162
445
  rowHeader.innerHTML = '<span data-label="cornerText"></span><span id="user-points">0</span>';
163
446
  root.appendChild(rowHeader);
164
- rowHeader.classList.add('myTheme1');
447
+ rowHeader.classList.add('fancy-label');
165
448
  var rowDown = document.createElement('div');
166
449
  rowDown.id = 'rowDown';
167
450
  rowDown.style.top = '10px';
168
451
  rowDown.style.left = '10px';
169
452
  rowDown.style.width = '200px';
170
- rowDown.innerHTML = '';
171
- rowDown.classList.add('myTheme1');
453
+ rowDown.innerHTML = '↓<span data-label="down"></span>';
454
+ rowDown.classList.add('fancy-label');
455
+ rowDown.classList.add('btn');
172
456
  root.appendChild(rowDown);
173
457
  var rowFree = document.createElement('div');
174
458
  rowFree.id = 'rowFree';
175
459
  rowFree.style.top = '10px';
176
460
  rowFree.style.left = '10px';
177
461
  rowFree.style.width = '200px';
178
- rowFree.innerHTML = '';
179
- rowFree.classList.add('myTheme1');
462
+ rowFree.innerHTML = '↕<span data-label="free"></span>';
463
+ rowFree.classList.add('fancy-label');
464
+ rowFree.classList.add('btn');
180
465
  root.appendChild(rowFree);
181
466
  var rowUp = document.createElement('div');
182
467
  rowUp.id = 'rowUp';
183
468
  rowUp.style.top = '10px';
184
469
  rowUp.style.left = '10px';
185
470
  rowUp.style.width = '200px';
186
- rowUp.innerHTML = '';
187
- rowUp.classList.add('myTheme1');
471
+ rowUp.innerHTML = '↑<span data-label="up"></span>';
472
+ rowUp.classList.add('fancy-label');
473
+ rowUp.classList.add('btn');
188
474
  root.appendChild(rowUp);
189
475
  var rowHand = document.createElement('div');
190
476
  rowHand.id = 'rowHand';
@@ -192,7 +478,8 @@ let myDom = exports.myDom = {
192
478
  rowHand.style.left = '10px';
193
479
  rowHand.style.width = '200px';
194
480
  rowHand.innerHTML = '<span data-label="hand"></span>';
195
- rowHand.classList.add('myTheme1');
481
+ rowHand.classList.add('fancy-label');
482
+ rowHand.classList.add('btn');
196
483
  root.appendChild(rowHand);
197
484
 
198
485
  // INJECT TABLE HEADER ROW
@@ -201,9 +488,44 @@ let myDom = exports.myDom = {
201
488
  this.createRowFree(rowFree);
202
489
  this.createRow(rowUp);
203
490
  this.createRow(rowHand);
491
+ this.createSelectedBox();
204
492
  document.body.appendChild(root);
205
493
  // console.log('JambTable added.')
206
494
  },
495
+ showHideJambTable: () => {
496
+ const panel = document.getElementById('jambTable');
497
+ if (panel.classList.contains('show')) {
498
+ panel.classList.remove('show');
499
+ panel.classList.add('hide');
500
+ // Delay actual hiding from layout to finish animation
501
+ setTimeout(() => {
502
+ panel.style.display = 'none';
503
+ }, 300);
504
+ } else {
505
+ panel.style.display = 'flex';
506
+ setTimeout(() => {
507
+ panel.classList.remove('hide');
508
+ panel.classList.add('show');
509
+ }, 10); // allow repaint
510
+ }
511
+ },
512
+ createSelectedBox: function () {
513
+ var topTitleDOM = document.createElement('div');
514
+ topTitleDOM.id = 'topTitleDOM';
515
+ topTitleDOM.style.width = 'auto';
516
+ topTitleDOM.style.position = 'absolute';
517
+ topTitleDOM.style.left = '35%';
518
+ topTitleDOM.style.fontSize = '175%';
519
+ topTitleDOM.style.top = '4%';
520
+ topTitleDOM.style.background = '#7d7d7d8c';
521
+ topTitleDOM.innerHTML = app.label.get.ready + ", " + app.userState.name + '.';
522
+ topTitleDOM.setAttribute('data-gamestatus', 'FREE');
523
+ document.body.appendChild(topTitleDOM);
524
+ addEventListener('updateTitle', e => {
525
+ (0, _utils.typeText)('topTitleDOM', e.detail.text);
526
+ topTitleDOM.setAttribute('data-gamestatus', e.detail.status);
527
+ });
528
+ },
207
529
  createLeftHeaderRow: function (myRoot) {
208
530
  for (var x = 1; x < 7; x++) {
209
531
  var rowNumber = document.createElement('div');
@@ -376,7 +698,7 @@ let myDom = exports.myDom = {
376
698
  var getName = e.target.id;
377
699
  getName = getName.replace('free-rowNumber', '');
378
700
  var count23456 = 0;
379
- for (let key in dices.R) {
701
+ for (let key in dices.SAVED_DICES) {
380
702
  if (parseInt(dices.R[key]) == parseInt(getName)) {
381
703
  count23456++;
382
704
  }
@@ -467,6 +789,7 @@ let myDom = exports.myDom = {
467
789
  rowNumber.style.left = '10px';
468
790
  rowNumber.style.width = 'auto';
469
791
  rowNumber.style.background = '#7d7d7d8c';
792
+ rowNumber.style.cursor = 'pointer';
470
793
  rowNumber.innerHTML = `-`;
471
794
  this.memoNumberRow.push(rowNumber);
472
795
  // initial
@@ -481,7 +804,7 @@ let myDom = exports.myDom = {
481
804
  console.log('LOG ', getName);
482
805
  if (parseInt(getName) == 1) {
483
806
  var count1 = 0;
484
- for (let key in dices.R) {
807
+ for (let key in dices.SAVED_DICES) {
485
808
  if (parseInt(dices.R[key]) == 1) {
486
809
  console.log('yeap', dices.R);
487
810
  count1++;
@@ -501,7 +824,7 @@ let myDom = exports.myDom = {
501
824
  if (parseInt(getName) == this.state.rowDown.length + 1) {
502
825
  console.log('moze za ', parseInt(getName));
503
826
  var count23456 = 0;
504
- for (let key in dices.R) {
827
+ for (let key in dices.SAVED_DICES) {
505
828
  if (parseInt(dices.R[key]) == parseInt(getName)) {
506
829
  console.log('yeap', dices.R);
507
830
  count23456++;
@@ -554,9 +877,8 @@ let myDom = exports.myDom = {
554
877
  rowMin.style.width = 'auto';
555
878
  rowMin.style.background = '#7d7d7d8c';
556
879
  rowMin.innerHTML = `-`;
557
- this.rowMin = rowMin;
880
+ // this.rowMin = rowMin;
558
881
  myRoot.appendChild(rowMin);
559
- this.rowMin = rowMin;
560
882
  var rowMaxMinSum = document.createElement('div');
561
883
  rowMaxMinSum.id = 'down-rowMaxMinSum';
562
884
  rowMaxMinSum.style.width = 'auto';
@@ -792,7 +1114,7 @@ let myDom = exports.myDom = {
792
1114
  // console.log('<GAMEPLAY><FREE ROW IS FEELED>')
793
1115
  var TEST = app.myDom.checkForAllDuplicate();
794
1116
  for (var key in TEST) {
795
- if (TEST[key] == 5 || TEST[key] > 5) {
1117
+ if (TEST[key] == 5) {
796
1118
  // win
797
1119
  var getDiceID = parseInt(key.replace('value__', ''));
798
1120
  var win = getDiceID * 5;
@@ -809,11 +1131,11 @@ let myDom = exports.myDom = {
809
1131
  calcDownRowMax: e => {
810
1132
  if (dices.validatePass() == false) return;
811
1133
  e.target.classList.remove('canPlay');
812
- (void 0).rowMin.classList.add('canPlay');
1134
+ (0, _utils.byId)('down-rowMin').classList.add('canPlay');
813
1135
  var test = 0;
814
1136
  let keyLessNum = Object.keys(dices.R).reduce((key, v) => dices.R[v] < dices.R[key] ? v : key);
815
1137
  // console.log('FIND MIN DICE TO REMOVE FROM SUM ', keyLessNum);
816
- for (var key in dices.R) {
1138
+ for (var key in dices.SAVED_DICES) {
817
1139
  if (key != keyLessNum) {
818
1140
  test += parseFloat(dices.R[key]);
819
1141
  }
@@ -822,41 +1144,42 @@ let myDom = exports.myDom = {
822
1144
  // now attach next event.
823
1145
  dices.STATUS = "FREE_TO_PLAY";
824
1146
  dispatchEvent(new CustomEvent('FREE_TO_PLAY', {}));
825
- (void 0).rowMax.removeEventListener("click", (void 0).calcDownRowMax);
826
- (0, _utils.byId)('down-rowMin').addEventListener('click', (void 0).calcDownRowMin);
1147
+ (0, _utils.byId)('down-rowMax').removeEventListener("click", myDom.calcDownRowMax);
1148
+ (0, _utils.byId)('down-rowMin').addEventListener('click', myDom.calcDownRowMin);
827
1149
  },
828
1150
  incrasePoints: function (arg) {
829
1151
  (0, _utils.byId)('user-points').innerHTML = parseInt((0, _utils.byId)('user-points').innerHTML) + parseInt(arg);
830
1152
  },
831
1153
  calcDownRowMin: () => {
832
1154
  if (dices.validatePass() == false) return;
833
- (void 0).rowMin.classList.remove('canPlay');
1155
+ (0, _utils.byId)('down-rowMin').classList.remove('canPlay');
834
1156
  console.log('MIN ENABLED');
835
1157
  var maxTestKey = Object.keys(dices.R).reduce(function (a, b) {
836
1158
  return dices.R[a] > dices.R[b] ? a : b;
837
1159
  });
838
1160
  var test = 0;
839
1161
  for (var key in dices.R) {
840
- if (key != maxTestKey) {
841
- test += parseFloat(dices.R[key]);
842
- } else {
843
- console.log('not calc dice ', dices.R[key]);
844
- }
845
- }
846
- (void 0).rowMin.innerHTML = test;
847
- (0, _utils.byId)('down-rowMin').removeEventListener('click', (void 0).calcDownRowMin);
1162
+ // if(key != maxTestKey) {
1163
+ test += parseFloat(dices.R[key]);
1164
+ // } else {
1165
+ // console.log('not calc dice ', dices.R[key])
1166
+ // }
1167
+ }
1168
+ (0, _utils.byId)('down-rowMin').innerHTML = test;
1169
+ (0, _utils.byId)('down-rowMin').removeEventListener('click', myDom.calcDownRowMin);
848
1170
  // calc max min dont forget rules for bonus +30
849
- var SUMMINMAX = parseFloat((void 0).rowMax.innerHTML) - parseFloat((void 0).rowMin.innerHTML);
1171
+ var SUMMINMAX = parseFloat((0, _utils.byId)('down-rowMax').innerHTML) - parseFloat((0, _utils.byId)('down-rowMin').innerHTML);
850
1172
  (0, _utils.byId)('down-rowMaxMinSum').innerHTML = SUMMINMAX;
851
1173
  myDom.incrasePoints(SUMMINMAX);
852
1174
  dices.STATUS = "FREE_TO_PLAY";
853
1175
  dispatchEvent(new CustomEvent('FREE_TO_PLAY', {}));
854
1176
  (0, _utils.byId)('down-largeStraight').classList.add('canPlay');
855
- (0, _utils.byId)('down-largeStraight').addEventListener('click', (void 0).attachKenta);
1177
+ (0, _utils.byId)('down-largeStraight').addEventListener('click', myDom.attachKenta);
1178
+ (0, _utils.byId)('down-rowMin').removeEventListener('click', myDom.calcDownRowMin);
856
1179
  },
857
1180
  checkForDuplicate: function () {
858
1181
  var testArray = [];
859
- for (var key in dices.R) {
1182
+ for (var key in dices.SAVED_DICES) {
860
1183
  var gen = {
861
1184
  myId: key,
862
1185
  value: dices.R[key]
@@ -873,7 +1196,7 @@ let myDom = exports.myDom = {
873
1196
  },
874
1197
  checkForAllDuplicate: function () {
875
1198
  var testArray = [];
876
- for (var key in dices.R) {
1199
+ for (var key in dices.SAVED_DICES) {
877
1200
  var gen = {
878
1201
  myId: key,
879
1202
  value: dices.R[key]
@@ -898,13 +1221,13 @@ let myDom = exports.myDom = {
898
1221
  return discret;
899
1222
  },
900
1223
  attachKenta: function () {
901
- console.log('Test kenta ', dices.R);
1224
+ console.log('Test kenta ', dices.SAVED_DICES);
902
1225
  (0, _utils.byId)('down-largeStraight').classList.remove('canPlay');
903
1226
  var result = app.myDom.checkForDuplicate()[0];
904
1227
  var testArray = app.myDom.checkForDuplicate()[1];
905
- // console.log('TEST duplik: ' + result);
906
- if (result.length == 2) {
907
- console.log('TEST duplik less 3 : ' + result);
1228
+ console.log('TEST duplik: ' + result);
1229
+ if (result.length > 0) {
1230
+ console.log('TEST duplik l : ' + result);
908
1231
  var locPrevent = false;
909
1232
  testArray.forEach((item, index, array) => {
910
1233
  if (result[0].value == item.value && locPrevent == false) {
@@ -913,25 +1236,7 @@ let myDom = exports.myDom = {
913
1236
  array.splice(index, 1);
914
1237
  }
915
1238
  });
916
- // if we catch 1 and 6 in same stack then it is not possible for kenta...
917
- var test1 = false,
918
- test6 = false;
919
- testArray.forEach((item, index, array) => {
920
- if (item.value == 1) {
921
- test1 = true;
922
- } else if (item.value == 6) {
923
- test6 = true;
924
- }
925
- });
926
- if (test1 == true && test6 == true) {
927
- (0, _utils.byId)('down-largeStraight').innerHTML = `0`;
928
- } else if (test1 == true) {
929
- (0, _utils.byId)('down-largeStraight').innerHTML = 15 + 50;
930
- myDom.incrasePoints(15 + 50);
931
- } else if (test6 == true) {
932
- (0, _utils.byId)('down-largeStraight').innerHTML = 20 + 50;
933
- myDom.incrasePoints(20 + 50);
934
- }
1239
+ (0, _utils.byId)('down-largeStraight').innerHTML = `0`;
935
1240
  } else if (result < 2) {
936
1241
  (0, _utils.byId)('down-largeStraight').innerHTML = 66;
937
1242
  myDom.incrasePoints(66);
@@ -939,8 +1244,8 @@ let myDom = exports.myDom = {
939
1244
  // zero value
940
1245
  (0, _utils.byId)('down-largeStraight').innerHTML = `0`;
941
1246
  }
942
- (0, _utils.byId)('down-threeOfAKind').addEventListener('click', this.attachDownTrilling);
943
- (0, _utils.byId)('down-largeStraight').removeEventListener('click', this.attachKenta);
1247
+ (0, _utils.byId)('down-threeOfAKind').addEventListener('click', myDom.attachDownTrilling);
1248
+ (0, _utils.byId)('down-largeStraight').removeEventListener('click', myDom.attachKenta);
944
1249
  dices.STATUS = "FREE_TO_PLAY";
945
1250
  dispatchEvent(new CustomEvent('FREE_TO_PLAY', {}));
946
1251
  },
@@ -965,8 +1270,8 @@ let myDom = exports.myDom = {
965
1270
  } else {
966
1271
  (0, _utils.byId)('down-threeOfAKind').innerHTML = 0;
967
1272
  }
968
- (0, _utils.byId)('down-threeOfAKind').removeEventListener('click', this.attachDownTrilling);
969
- (0, _utils.byId)('down-fullHouse').addEventListener('click', this.attachDownFullHouse);
1273
+ (0, _utils.byId)('down-threeOfAKind').removeEventListener('click', myDom.attachDownTrilling);
1274
+ (0, _utils.byId)('down-fullHouse').addEventListener('click', myDom.attachDownFullHouse);
970
1275
  dices.STATUS = "FREE_TO_PLAY";
971
1276
  dispatchEvent(new CustomEvent('FREE_TO_PLAY', {}));
972
1277
  },
@@ -997,8 +1302,8 @@ let myDom = exports.myDom = {
997
1302
  } else {
998
1303
  (0, _utils.byId)('down-fullHouse').innerHTML = 0;
999
1304
  }
1000
- (0, _utils.byId)('down-poker').addEventListener('click', this.attachDownPoker);
1001
- (0, _utils.byId)('down-fullHouse').removeEventListener('click', this.attachDownFullHouse);
1305
+ (0, _utils.byId)('down-poker').addEventListener('click', myDom.attachDownPoker);
1306
+ (0, _utils.byId)('down-fullHouse').removeEventListener('click', myDom.attachDownFullHouse);
1002
1307
  dices.STATUS = "FREE_TO_PLAY";
1003
1308
  dispatchEvent(new CustomEvent('FREE_TO_PLAY', {}));
1004
1309
  },
@@ -1014,13 +1319,13 @@ let myDom = exports.myDom = {
1014
1319
  myDom.incrasePoints(win + 40);
1015
1320
  }
1016
1321
  }
1017
- (0, _utils.byId)('down-poker').removeEventListener('click', this.attachDownPoker);
1018
- (0, _utils.byId)('down-jamb').addEventListener('click', this.attachDownJamb);
1322
+ (0, _utils.byId)('down-poker').removeEventListener('click', myDom.attachDownPoker);
1323
+ (0, _utils.byId)('down-jamb').addEventListener('click', myDom.attachDownJamb);
1019
1324
  dices.STATUS = "FREE_TO_PLAY";
1020
1325
  dispatchEvent(new CustomEvent('FREE_TO_PLAY', {}));
1021
1326
  },
1022
1327
  attachDownJamb: function () {
1023
- (0, _utils.byId)('down-jamb').removeEventListener('click', this.attachDownJamb);
1328
+ (0, _utils.byId)('down-jamb').removeEventListener('click', myDom.attachDownJamb);
1024
1329
  console.log('<GAMEPLAY><DOWN ROW IS FEELED>');
1025
1330
  var TEST = app.myDom.checkForAllDuplicate();
1026
1331
  for (var key in TEST) {
@@ -1034,10 +1339,32 @@ let myDom = exports.myDom = {
1034
1339
  }
1035
1340
  dices.STATUS = "FREE_TO_PLAY";
1036
1341
  dispatchEvent(new CustomEvent('FREE_TO_PLAY', {}));
1342
+ },
1343
+ isDragging: false,
1344
+ offsetX: 0,
1345
+ offsetY: 0,
1346
+ addDraggerForTable: () => {
1347
+ (0, _utils.byId)('dragHandler').addEventListener('pointerdown', e => {
1348
+ myDom.isDragging = true;
1349
+ const rect = (0, _utils.byId)('jambTable').getBoundingClientRect();
1350
+ myDom.offsetX = e.clientX - rect.left;
1351
+ myDom.offsetY = e.clientY - rect.top;
1352
+ (0, _utils.byId)('dragHandler').setPointerCapture(e.pointerId);
1353
+ });
1354
+ (0, _utils.byId)('dragHandler').addEventListener('pointermove', e => {
1355
+ if (myDom.isDragging) {
1356
+ (0, _utils.byId)('jambTable').style.left = `${e.clientX - myDom.offsetX}px`;
1357
+ (0, _utils.byId)('jambTable').style.top = `${e.clientY - myDom.offsetY}px`;
1358
+ }
1359
+ });
1360
+ (0, _utils.byId)('dragHandler').addEventListener('pointerup', e => {
1361
+ myDom.isDragging = false;
1362
+ (0, _utils.byId)('dragHandler').releasePointerCapture(e.pointerId);
1363
+ });
1037
1364
  }
1038
1365
  };
1039
1366
 
1040
- },{"../../../src/engine/loader-obj.js":7,"../../../src/engine/utils.js":12,"../../../src/world.js":20}],2:[function(require,module,exports){
1367
+ },{"../../../src/engine/utils.js":13,"./html-content.js":1}],3:[function(require,module,exports){
1041
1368
  "use strict";
1042
1369
 
1043
1370
  Object.defineProperty(exports, "__esModule", {
@@ -1048,7 +1375,6 @@ var _world = _interopRequireDefault(require("./src/world.js"));
1048
1375
  var _loaderObj = require("./src/engine/loader-obj.js");
1049
1376
  var _utils = require("./src/engine/utils.js");
1050
1377
  var _jamb = require("./examples/games/jamb/jamb.js");
1051
- var _sounds = require("./src/sounds/sounds.js");
1052
1378
  var _raycast = require("./src/engine/raycast.js");
1053
1379
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
1054
1380
  let application = exports.application = new _world.default({
@@ -1060,12 +1386,83 @@ let application = exports.application = new _world.default({
1060
1386
  }
1061
1387
  }, () => {
1062
1388
  // Dom operations
1389
+ application.userState = {
1390
+ name: 'Guest',
1391
+ points: 0
1392
+ };
1063
1393
  application.myDom = _jamb.myDom;
1064
1394
  _jamb.myDom.createJamb();
1395
+ _jamb.myDom.addDraggerForTable();
1065
1396
  _jamb.myDom.createBlocker();
1066
1397
  application.dices = _jamb.dices;
1067
-
1068
- // this code must be on top
1398
+ application.activateDiceClickListener = null;
1399
+
1400
+ // -------------------------
1401
+ // TEST
1402
+ application.matrixAmmo.detectTopFaceFromQuat = q => {
1403
+ // Define based on *visual face* → object-space normal mapping
1404
+ const faces = [{
1405
+ face: 1,
1406
+ vec: [0, 1, 0]
1407
+ },
1408
+ // top
1409
+ {
1410
+ face: 2,
1411
+ vec: [0, -1, 0]
1412
+ },
1413
+ // bottom
1414
+ {
1415
+ face: 3,
1416
+ vec: [0, 0, 1]
1417
+ },
1418
+ // front
1419
+ {
1420
+ face: 4,
1421
+ vec: [0, 0, -1]
1422
+ },
1423
+ // back
1424
+ {
1425
+ face: 5,
1426
+ vec: [1, 0, 0]
1427
+ },
1428
+ // right
1429
+ {
1430
+ face: 6,
1431
+ vec: [-1, 0, 0]
1432
+ } // left
1433
+ ];
1434
+ let maxDot = -Infinity;
1435
+ let topFace = null;
1436
+ for (const f of faces) {
1437
+ const v = application.matrixAmmo.applyQuatToVec(q, f.vec);
1438
+ const dot = v.y; // Compare with world up (0, 1, 0)
1439
+ if (dot > maxDot) {
1440
+ maxDot = dot;
1441
+ topFace = f.face;
1442
+ }
1443
+ }
1444
+ return topFace;
1445
+ };
1446
+ application.matrixAmmo.applyQuatToVec = (q, vec) => {
1447
+ const [x, y, z] = vec;
1448
+ const qx = q.x(),
1449
+ qy = q.y(),
1450
+ qz = q.z(),
1451
+ qw = q.w();
1452
+
1453
+ // Quaternion * vector * inverse(quaternion)
1454
+ const ix = qw * x + qy * z - qz * y;
1455
+ const iy = qw * y + qz * x - qx * z;
1456
+ const iz = qw * z + qx * y - qy * x;
1457
+ const iw = -qx * x - qy * y - qz * z;
1458
+ return {
1459
+ x: ix * qw + iw * -qx + iy * -qz - iz * -qy,
1460
+ y: iy * qw + iw * -qy + iz * -qx - ix * -qz,
1461
+ z: iz * qw + iw * -qz + ix * -qy - iy * -qx
1462
+ };
1463
+ };
1464
+ // -------------------------
1465
+ // This code must be on top (Physics)
1069
1466
  application.matrixAmmo.detectCollision = function () {
1070
1467
  this.lastRoll = '';
1071
1468
  this.presentScore = '';
@@ -1086,57 +1483,73 @@ let application = exports.application = new _world.default({
1086
1483
  var testR = contactManifold.getBody0().getWorldTransform().getRotation();
1087
1484
  }
1088
1485
  var passed = false;
1089
- if (Math.abs(testR.y()) < 0.00001) {
1090
- this.lastRoll = "3";
1091
- this.presentScore += 4;
1092
- passed = true;
1093
- }
1094
- if (Math.abs(testR.x()) < 0.00001) {
1095
- this.lastRoll = "5";
1096
- this.presentScore += 3;
1097
- passed = true;
1098
- }
1099
- if (testR.x().toString().substring(0, 5) == testR.y().toString().substring(1, 6)) {
1100
- this.lastRoll = "6";
1101
- this.presentScore += 2;
1102
- passed = true;
1103
- }
1104
- if (testR.x().toString().substring(0, 5) == testR.y().toString().substring(0, 5)) {
1105
- this.lastRoll = "2";
1106
- this.presentScore += 1;
1107
- passed = true;
1108
- }
1109
- if (testR.z().toString().substring(0, 5) == testR.y().toString().substring(1, 6)) {
1110
- this.lastRoll = "4";
1111
- this.presentScore += 6;
1112
- passed = true;
1113
- }
1114
- if (testR.z().toString().substring(0, 5) == testR.y().toString().substring(0, 5)) {
1115
- this.lastRoll = "1";
1116
- this.presentScore += 5;
1117
- passed = true;
1486
+ const face = application.matrixAmmo.detectTopFaceFromQuat(testR);
1487
+ if (face) {
1488
+ this.lastRoll = face.toString();
1489
+ // Update score logic
1490
+ dispatchEvent(new CustomEvent(`dice-${face}`, {
1491
+ detail: {
1492
+ result: `dice-${face}`,
1493
+ cubeId: MY_DICE_NAME
1494
+ }
1495
+ }));
1118
1496
  }
1119
- if (passed == true) dispatchEvent(new CustomEvent(`dice-${this.lastRoll}`, {
1120
- detail: {
1121
- result: `dice-${this.lastRoll}`,
1122
- cubeId: MY_DICE_NAME
1123
- }
1124
- }));
1497
+ // if(Math.abs(testR.y()) < 0.00001) {
1498
+ // this.lastRoll = "3";
1499
+ // this.presentScore += 4;
1500
+ // passed = true;
1501
+ // }
1502
+ // if(Math.abs(testR.x()) < 0.00001) {
1503
+ // this.lastRoll = "5";
1504
+ // this.presentScore += 3;
1505
+ // passed = true;
1506
+ // }
1507
+ // if(testR.x().toString().substring(0, 5) == testR.y().toString().substring(1, 6)) {
1508
+ // this.lastRoll = "6";
1509
+ // this.presentScore += 2;
1510
+ // passed = true;
1511
+ // }
1512
+ // if(testR.x().toString().substring(0, 5) == testR.y().toString().substring(0, 5)) {
1513
+ // this.lastRoll = "2";
1514
+ // this.presentScore += 1;
1515
+ // passed = true;
1516
+ // }
1517
+ // if(testR.z().toString().substring(0, 5) == testR.y().toString().substring(1, 6)) {
1518
+ // this.lastRoll = "4";
1519
+ // this.presentScore += 6;
1520
+ // passed = true;
1521
+ // }
1522
+ // if(testR.z().toString().substring(0, 5) == testR.y().toString().substring(0, 5)) {
1523
+ // this.lastRoll = "1";
1524
+ // this.presentScore += 5;
1525
+ // passed = true;
1526
+ // }
1527
+ // if(passed == true) dispatchEvent(new CustomEvent(`dice-${this.lastRoll}`, {
1528
+ // detail: {
1529
+ // result: `dice-${this.lastRoll}`,
1530
+ // cubeId: MY_DICE_NAME
1531
+ // }
1532
+ // }))
1125
1533
  }
1126
1534
  }
1127
1535
  };
1128
1536
  (0, _raycast.addRaycastListener)();
1129
1537
  addEventListener("ray.hit.event", e => {
1130
- console.log("hit cube ", e.detail.hitObject.name);
1538
+ if ((0, _utils.byId)('topTitleDOM') && (0, _utils.byId)('topTitleDOM').getAttribute('data-gamestatus') != 'FREE' && (0, _utils.byId)('topTitleDOM').getAttribute('data-gamestatus') != 'status-select') {
1539
+ console.log('no hit in middle of game ...');
1540
+ return;
1541
+ }
1131
1542
  if (application.dices.STATUS == "FREE_TO_PLAY") {
1132
1543
  console.log("hit cube status free to play prevent pick. ", e.detail.hitObject.name);
1133
- } else if (application.dices.STATUS == "SELECT_DICES_1") {
1134
- console.log("hit cube status SELECT1 pick.", e.detail.hitObject.name);
1544
+ } else if (application.dices.STATUS == "SELECT_DICES_1" || application.dices.STATUS == "SELECT_DICES_2" || application.dices.STATUS == "FINISHED") {
1545
+ if (Object.keys(application.dices.SAVED_DICES).length >= 5) {
1546
+ console.log("PREVENTED SELECT1/2 pick.", e.detail.hitObject.name);
1547
+ return;
1548
+ }
1549
+ console.log("hit cube status SELECT1/2 pick.", e.detail.hitObject.name);
1135
1550
  application.dices.pickDice(e.detail.hitObject.name);
1136
1551
  }
1137
1552
  });
1138
- // OR add manual see readme
1139
-
1140
1553
  addEventListener('mousemove', e => {
1141
1554
  // console.log('only on click')
1142
1555
  _raycast.touchCoordinate.enabled = true;
@@ -1147,13 +1560,58 @@ let application = exports.application = new _world.default({
1147
1560
  application.matrixSounds.createAudio('block', 'res/audios/block.mp3', 6);
1148
1561
  application.matrixSounds.createAudio('dice1', 'res/audios/dice1.mp3', 6);
1149
1562
  application.matrixSounds.createAudio('dice2', 'res/audios/dice2.mp3', 6);
1563
+ application.matrixSounds.createAudio('hover', 'res/audios/toggle_002.mp3', 3);
1564
+ application.matrixSounds.createAudio('roll', 'res/audios/dice-roll.mp3', 2);
1150
1565
  addEventListener('AmmoReady', () => {
1566
+ app.matrixAmmo.speedUpSimulation = 2;
1151
1567
  (0, _loaderObj.downloadMeshes)({
1152
1568
  cube: "./res/meshes/jamb/dice.obj"
1153
1569
  }, onLoadObj, {
1154
1570
  scale: [1, 1, 1],
1155
1571
  swap: [null]
1156
1572
  });
1573
+ (0, _loaderObj.downloadMeshes)({
1574
+ star1: "./res/meshes/shapes/star1.obj"
1575
+ }, m => {
1576
+ let o = {
1577
+ scale: 2,
1578
+ position: {
1579
+ x: 3,
1580
+ y: 0,
1581
+ z: -10
1582
+ },
1583
+ rotation: {
1584
+ x: 0,
1585
+ y: 0,
1586
+ z: 0
1587
+ },
1588
+ rotationSpeed: {
1589
+ x: 10,
1590
+ y: 0,
1591
+ z: 0
1592
+ },
1593
+ texturesPaths: ['./res/textures/default.png']
1594
+ };
1595
+ // application.addCube(o)
1596
+
1597
+ // application.addMeshObj({
1598
+ // position: {x: 0, y: 6, z: -5},
1599
+ // rotation: {x: 0, y: 0, z: 0},
1600
+ // rotationSpeed: {x: 0, y: 0, z: 0},
1601
+ // texturesPaths: ['./res/meshes/jamb/dice.png'],
1602
+ // useUVShema4x2: true,
1603
+ // name: 'star1',
1604
+ // mesh: m.star1,
1605
+ // raycast: {enabled: true, radius: 2},
1606
+ // physics: {
1607
+ // enabled: true,
1608
+ // geometry: "Cube"
1609
+ // }
1610
+ // })
1611
+ }, {
1612
+ scale: [11, 11, 11],
1613
+ swap: [null]
1614
+ });
1157
1615
  (0, _loaderObj.downloadMeshes)({
1158
1616
  bg: "./res/meshes/jamb/bg.obj"
1159
1617
  }, onLoadObjFloor, {
@@ -1257,9 +1715,6 @@ let application = exports.application = new _world.default({
1257
1715
  }
1258
1716
  function onLoadObjOther(m) {
1259
1717
  application.myLoadedMeshes = m;
1260
- for (var key in m) {
1261
- // console.log(`%c Loaded objs -> : ${key} `, LOG_MATRIX);
1262
- }
1263
1718
  // Add logo text top
1264
1719
  application.addMeshObj({
1265
1720
  position: {
@@ -1281,7 +1736,6 @@ let application = exports.application = new _world.default({
1281
1736
  geometry: "Cube"
1282
1737
  }
1283
1738
  });
1284
- // console.log('camera set')
1285
1739
  // application.cameras.WASD.pitch = 0.2
1286
1740
  setTimeout(() => {
1287
1741
  app.cameras.WASD.velocity[1] = 18;
@@ -1289,14 +1743,11 @@ let application = exports.application = new _world.default({
1289
1743
  app.matrixAmmo.setKinematicTransform(app.matrixAmmo.getBodyByName('mainTitle'), 0, 0, 0, 1);
1290
1744
  app.matrixAmmo.setKinematicTransform(app.matrixAmmo.getBodyByName('bg'), 0, -10, 0, 0, 0, 0);
1291
1745
  // Better access getBodyByName
1292
- console.log(' app.matrixAmmo. ', app.matrixAmmo.getBodyByName('CubePhysics1'));
1293
- }, 1225);
1746
+ // console.log(' app.matrixAmmo. ', app.matrixAmmo.getBodyByName('CubePhysics1'))
1747
+ }, 1200);
1294
1748
  }
1295
1749
  function onLoadObjFloor(m) {
1296
1750
  application.myLoadedMeshes = m;
1297
- for (var key in m) {
1298
- // console.log(`%c Loaded objs -> : ${key} `, LOG_MATRIX);
1299
- }
1300
1751
  application.addMeshObj({
1301
1752
  scale: [10, 0.1, 0.1],
1302
1753
  position: {
@@ -1309,7 +1760,6 @@ let application = exports.application = new _world.default({
1309
1760
  y: 0,
1310
1761
  z: 0
1311
1762
  },
1312
- // rotationSpeed: {x: 0, y: 0, z: 0},
1313
1763
  texturesPaths: ['./res/meshes/jamb/bg.png'],
1314
1764
  name: 'bg',
1315
1765
  mesh: m.bg,
@@ -1323,10 +1773,6 @@ let application = exports.application = new _world.default({
1323
1773
  }
1324
1774
  function onLoadObj(m) {
1325
1775
  application.myLoadedMeshes = m;
1326
- for (var key in m) {
1327
- // console.log(`%c Loaded objs -> : ${key} `, LOG_MATRIX);
1328
- }
1329
-
1330
1776
  // Add dices
1331
1777
  application.addMeshObj({
1332
1778
  position: {
@@ -1504,7 +1950,7 @@ let application = exports.application = new _world.default({
1504
1950
  });
1505
1951
  application.TOLERANCE = 0;
1506
1952
  let allDiceDoneProcedure = () => {
1507
- console.log("ALL DONE");
1953
+ console.log("ALL DONE", application.TOLERANCE);
1508
1954
  application.TOLERANCE++;
1509
1955
  if (application.TOLERANCE >= 1) {
1510
1956
  removeEventListener('dice-1', dice1Click);
@@ -1513,92 +1959,171 @@ let application = exports.application = new _world.default({
1513
1959
  removeEventListener('dice-4', dice4Click);
1514
1960
  removeEventListener('dice-5', dice5Click);
1515
1961
  removeEventListener('dice-6', dice6Click);
1516
- console.log('FINAL >>>> ', _jamb.dices.R);
1962
+ console.log(`%cFINAL<preliminar> ${_jamb.dices.R}`, _utils.LOG_FUNNY);
1517
1963
  application.TOLERANCE = 0;
1518
1964
  app.cameras.WASD.yaw = 0.01;
1519
1965
  app.cameras.WASD.pitch = -1.26;
1520
1966
  app.cameras.WASD.position[2] = -18;
1521
1967
  app.cameras.WASD.position[1] = 19;
1522
-
1523
- // dices.STATUS = "PLACE_RESULT";
1524
- _jamb.dices.STATUS = "SELECT_DICES_1";
1525
- // application.dices.STATUS = "FREE_TO_PLAY";
1968
+ // ?? ?
1969
+ if (_jamb.dices.STATUS == "FREE_TO_PLAY" || _jamb.dices.STATUS == "IN_PLAY") {
1970
+ _jamb.dices.STATUS = "SELECT_DICES_1";
1971
+ console.log(`%cStatus<SELECT_DICES_1>`, _utils.LOG_FUNNY);
1972
+ setTimeout(() => {
1973
+ dispatchEvent(new CustomEvent('updateTitle', {
1974
+ detail: {
1975
+ text: app.label.get.freetoroll,
1976
+ status: 'FREE'
1977
+ }
1978
+ }));
1979
+ }, 500);
1980
+ } else if (_jamb.dices.STATUS == "SELECT_DICES_1") {
1981
+ _jamb.dices.STATUS = "SELECT_DICES_2";
1982
+ setTimeout(() => {
1983
+ dispatchEvent(new CustomEvent('updateTitle', {
1984
+ detail: {
1985
+ text: app.label.get.freetoroll,
1986
+ status: 'FREE'
1987
+ }
1988
+ }));
1989
+ }, 500);
1990
+ console.log(`%cStatus<SELECT_DICES_2>`, _utils.LOG_FUNNY);
1991
+ } else if (_jamb.dices.STATUS == "SELECT_DICES_2") {
1992
+ _jamb.dices.STATUS = "FINISHED";
1993
+ console.log(`%cStatus<FINISHED>`, _utils.LOG_FUNNY);
1994
+ dispatchEvent(new CustomEvent('updateTitle', {
1995
+ detail: {
1996
+ text: app.label.get.pick5,
1997
+ status: 'status-select'
1998
+ }
1999
+ }));
2000
+ }
1526
2001
  }
1527
2002
  };
1528
2003
  addEventListener('all-done', allDiceDoneProcedure);
1529
2004
  addEventListener('FREE_TO_PLAY', () => {
1530
- // setup againt 3d space loc
1531
- console.info(' setup againt 3d space loc make some logic for pos ...');
1532
- app.matrixAmmo.getBodyByName('CubePhysics1').setLinearVelocity(new Ammo.btVector3(2, 2, 12));
1533
- app.matrixAmmo.getBodyByName('CubePhysics2').setLinearVelocity(new Ammo.btVector3(2, 2, 12));
1534
- app.matrixAmmo.getBodyByName('CubePhysics3').setLinearVelocity(new Ammo.btVector3(2, 2, 12));
1535
- app.matrixAmmo.getBodyByName('CubePhysics4').setLinearVelocity(new Ammo.btVector3(2, 2, 12));
1536
- app.matrixAmmo.getBodyByName('CubePhysics5').setLinearVelocity(new Ammo.btVector3(2, 2, 12));
1537
- app.matrixAmmo.getBodyByName('CubePhysics6').setLinearVelocity(new Ammo.btVector3(2, 2, 12));
2005
+ // Big reset
2006
+ console.log(`%c<Big reset needed ...>`, _utils.LOG_FUNNY);
2007
+ app.dices.SAVED_DICES = {};
2008
+ app.dices.setStartUpPosition();
2009
+ setTimeout(() => {
2010
+ app.dices.activateAllDicesPhysics();
2011
+ }, 1000);
2012
+ app.cameras.WASD.yaw = 0;
2013
+ app.cameras.WASD.pitch = 0;
2014
+ app.cameras.WASD.position[2] = 0;
2015
+ app.cameras.WASD.position[1] = 3.76;
2016
+ dispatchEvent(new CustomEvent('updateTitle', {
2017
+ detail: {
2018
+ text: app.label.get.hand1,
2019
+ status: 'FREE'
2020
+ }
2021
+ }));
1538
2022
  });
1539
2023
 
1540
2024
  // ACTIONS
1541
2025
  let dice1Click = e => {
1542
- // console.info('DICE 1', e.detail)
2026
+ // console.info('DICE 1 click ?????????', e.detail)
1543
2027
  _jamb.dices.R[e.detail.cubeId] = '1';
1544
2028
  _jamb.dices.checkAll();
1545
2029
  };
1546
- // addEventListener('dice-1', dice1Click)
1547
-
1548
2030
  let dice2Click = e => {
1549
2031
  // console.info('DICE 2', e.detail)
1550
2032
  _jamb.dices.R[e.detail.cubeId] = '2';
1551
2033
  _jamb.dices.checkAll();
1552
2034
  };
1553
- // addEventListener('dice-2', dice2Click)
1554
-
1555
2035
  let dice3Click = e => {
1556
2036
  // console.info('DICE 3', e.detail)
1557
2037
  _jamb.dices.R[e.detail.cubeId] = '3';
1558
2038
  _jamb.dices.checkAll();
1559
2039
  };
1560
- // addEventListener('dice-3', dice3Click)
1561
-
1562
2040
  let dice4Click = e => {
1563
2041
  // console.info('DICE 4', e.detail)
1564
2042
  _jamb.dices.R[e.detail.cubeId] = '4';
1565
2043
  _jamb.dices.checkAll();
1566
2044
  };
1567
- // addEventListener('dice-4', dice4Click)
1568
-
1569
2045
  let dice5Click = e => {
1570
2046
  // console.info('DICE 5', e.detail)
1571
2047
  _jamb.dices.R[e.detail.cubeId] = '5';
1572
2048
  _jamb.dices.checkAll();
1573
2049
  };
1574
- // addEventListener('dice-5', dice5Click)
1575
-
1576
2050
  let dice6Click = e => {
1577
2051
  // console.info('DICE 6', e.detail)
1578
2052
  _jamb.dices.R[e.detail.cubeId] = '6';
1579
2053
  _jamb.dices.checkAll();
1580
2054
  };
1581
- // addEventListener('dice-6', dice6Click)
1582
-
2055
+ function shootDice(x) {
2056
+ setTimeout(() => {
2057
+ app.matrixAmmo.getBodyByName(`CubePhysics${x}`).setAngularVelocity(new Ammo.btVector3((0, _utils.randomFloatFromTo)(3, 12), 9, 9));
2058
+ app.matrixAmmo.getBodyByName(`CubePhysics${x}`).setLinearVelocity(new Ammo.btVector3((0, _utils.randomFloatFromTo)(-5, 5), 15, -20));
2059
+ setTimeout(() => app.matrixSounds.play('roll'), 1500);
2060
+ }, 200 * x);
2061
+ }
2062
+ application.activateDiceClickListener = index => {
2063
+ index = parseInt(index);
2064
+ switch (index) {
2065
+ case 1:
2066
+ addEventListener('dice-1', dice1Click);
2067
+ case 2:
2068
+ addEventListener('dice-2', dice2Click);
2069
+ case 3:
2070
+ addEventListener('dice-3', dice3Click);
2071
+ case 4:
2072
+ addEventListener('dice-4', dice4Click);
2073
+ case 5:
2074
+ addEventListener('dice-5', dice5Click);
2075
+ case 6:
2076
+ addEventListener('dice-6', dice6Click);
2077
+ }
2078
+ };
1583
2079
  let rollProcedure = () => {
2080
+ if (topTitleDOM.getAttribute('data-gamestatus') != 'FREE') {
2081
+ console.log('validation fails...');
2082
+ return;
2083
+ }
1584
2084
  if (_jamb.dices.STATUS == "FREE_TO_PLAY") {
1585
2085
  app.matrixSounds.play('start');
1586
2086
  _jamb.dices.STATUS = "IN_PLAY";
2087
+ dispatchEvent(new CustomEvent('updateTitle', {
2088
+ detail: {
2089
+ text: app.label.get.hand1,
2090
+ status: 'inplay'
2091
+ }
2092
+ }));
1587
2093
  addEventListener('dice-1', dice1Click);
1588
2094
  addEventListener('dice-2', dice2Click);
1589
2095
  addEventListener('dice-3', dice3Click);
1590
2096
  addEventListener('dice-4', dice4Click);
1591
2097
  addEventListener('dice-5', dice5Click);
1592
2098
  addEventListener('dice-6', dice6Click);
1593
- function shootDice(x) {
1594
- setTimeout(() => {
1595
- app.matrixAmmo.getBodyByName(`CubePhysics${x}`).setAngularVelocity(new Ammo.btVector3((0, _utils.randomFloatFromTo)(3, 12), 9, 9));
1596
- app.matrixAmmo.getBodyByName(`CubePhysics${x}`).setLinearVelocity(new Ammo.btVector3((0, _utils.randomFloatFromTo)(-5, 5), 15, -20));
1597
- }, 200 * x);
1598
- }
1599
2099
  for (var x = 1; x < 7; x++) {
1600
2100
  shootDice(x);
1601
2101
  }
2102
+ } else if (_jamb.dices.STATUS == "SELECT_DICES_1" || _jamb.dices.STATUS == "SELECT_DICES_2") {
2103
+ // Now no selected dices still rolling
2104
+ for (let i = 1; i <= 6; i++) {
2105
+ const key = "CubePhysics" + i;
2106
+ if (!(key in app.dices.SAVED_DICES)) {
2107
+ console.log("Still in game last char is id : ", key[key.length - 1]);
2108
+ application.activateDiceClickListener(parseInt(key[key.length - 1]));
2109
+ shootDice(key[key.length - 1]);
2110
+ } else {
2111
+ console.log("??????????Still in game last char is id : ", key[key.length - 1]);
2112
+ application.activateDiceClickListener(parseInt(key[key.length - 1]));
2113
+ }
2114
+ }
2115
+ // ????
2116
+ // application.activateDiceClickListener(1);
2117
+
2118
+ dispatchEvent(new CustomEvent('updateTitle', {
2119
+ detail: {
2120
+ text: _jamb.dices.STATUS == "SELECT_DICES_1" ? app.label.get.hand1 : app.label.get.hand2,
2121
+ status: 'inplay'
2122
+ }
2123
+ }));
2124
+ } else if (_jamb.dices.STATUS == "FINISHED") {
2125
+ _utils.mb.error('No more roll...');
2126
+ _utils.mb.show('Pick up 5 dices');
1602
2127
  }
1603
2128
  };
1604
2129
  addEventListener('DICE.ROLL', rollProcedure);
@@ -1609,7 +2134,7 @@ let application = exports.application = new _world.default({
1609
2134
  });
1610
2135
  window.app = application;
1611
2136
 
1612
- },{"./examples/games/jamb/jamb.js":1,"./src/engine/loader-obj.js":7,"./src/engine/raycast.js":11,"./src/engine/utils.js":12,"./src/sounds/sounds.js":19,"./src/world.js":20}],3:[function(require,module,exports){
2137
+ },{"./examples/games/jamb/jamb.js":2,"./src/engine/loader-obj.js":8,"./src/engine/raycast.js":12,"./src/engine/utils.js":13,"./src/world.js":21}],4:[function(require,module,exports){
1613
2138
  "use strict";
1614
2139
 
1615
2140
  Object.defineProperty(exports, "__esModule", {
@@ -6956,7 +7481,7 @@ function setDefaultType(ctor) {
6956
7481
  setDefaultType$1(ctor);
6957
7482
  }
6958
7483
 
6959
- },{}],4:[function(require,module,exports){
7484
+ },{}],5:[function(require,module,exports){
6960
7485
  "use strict";
6961
7486
 
6962
7487
  Object.defineProperty(exports, "__esModule", {
@@ -7341,7 +7866,6 @@ class MEBall {
7341
7866
  if (typeof this.renderables === 'undefined') return;
7342
7867
  passEncoder.setPipeline(this.pipeline);
7343
7868
  passEncoder.setBindGroup(0, this.frameBindGroup);
7344
-
7345
7869
  // Loop through every renderable object and draw them individually.
7346
7870
  // (Because many of these meshes are repeated, with only the transforms
7347
7871
  // differing, instancing would be highly effective here. This sample
@@ -7371,7 +7895,7 @@ class MEBall {
7371
7895
  }
7372
7896
  exports.default = MEBall;
7373
7897
 
7374
- },{"../shaders/shaders":16,"./engine":6,"./matrix-class":8,"wgpu-matrix":3}],5:[function(require,module,exports){
7898
+ },{"../shaders/shaders":17,"./engine":7,"./matrix-class":9,"wgpu-matrix":4}],6:[function(require,module,exports){
7375
7899
  "use strict";
7376
7900
 
7377
7901
  Object.defineProperty(exports, "__esModule", {
@@ -7796,7 +8320,7 @@ class MECube {
7796
8320
  }
7797
8321
  exports.default = MECube;
7798
8322
 
7799
- },{"../shaders/shaders":16,"./engine":6,"./matrix-class":8,"wgpu-matrix":3}],6:[function(require,module,exports){
8323
+ },{"../shaders/shaders":17,"./engine":7,"./matrix-class":9,"wgpu-matrix":4}],7:[function(require,module,exports){
7800
8324
  "use strict";
7801
8325
 
7802
8326
  Object.defineProperty(exports, "__esModule", {
@@ -8256,7 +8780,7 @@ function createInputHandler(window, canvas) {
8256
8780
  };
8257
8781
  }
8258
8782
 
8259
- },{"./utils":12,"wgpu-matrix":3}],7:[function(require,module,exports){
8783
+ },{"./utils":13,"wgpu-matrix":4}],8:[function(require,module,exports){
8260
8784
  "use strict";
8261
8785
 
8262
8786
  Object.defineProperty(exports, "__esModule", {
@@ -8723,7 +9247,7 @@ function play(nameAni) {
8723
9247
  this.animation.currentAni = this.animation.anims[this.animation.anims.active].from;
8724
9248
  }
8725
9249
 
8726
- },{}],8:[function(require,module,exports){
9250
+ },{}],9:[function(require,module,exports){
8727
9251
  "use strict";
8728
9252
 
8729
9253
  Object.defineProperty(exports, "__esModule", {
@@ -8959,7 +9483,7 @@ class Rotation {
8959
9483
  }
8960
9484
  exports.Rotation = Rotation;
8961
9485
 
8962
- },{"./utils":12}],9:[function(require,module,exports){
9486
+ },{"./utils":13}],10:[function(require,module,exports){
8963
9487
  "use strict";
8964
9488
 
8965
9489
  Object.defineProperty(exports, "__esModule", {
@@ -9439,12 +9963,6 @@ class MEMeshObj {
9439
9963
  renderPass.setVertexBuffer(2, this.vertexTexCoordsBuffer);
9440
9964
  renderPass.setIndexBuffer(this.indexBuffer, 'uint16');
9441
9965
  renderPass.drawIndexed(this.indexCount);
9442
-
9443
- // test ray
9444
-
9445
- // try{ OLD
9446
- // if(this.raycast.enabled == true) checkingRay(this)
9447
- // } catch(e) {}
9448
9966
  };
9449
9967
  drawShadows = shadowPass => {
9450
9968
  shadowPass.setBindGroup(0, this.sceneBindGroupForShadow);
@@ -9458,7 +9976,7 @@ class MEMeshObj {
9458
9976
  }
9459
9977
  exports.default = MEMeshObj;
9460
9978
 
9461
- },{"../shaders/fragment.wgsl":15,"../shaders/vertex.wgsl":17,"../shaders/vertexShadow.wgsl":18,"./engine":6,"./matrix-class":8,"./raycast":11,"./utils":12,"wgpu-matrix":3}],10:[function(require,module,exports){
9979
+ },{"../shaders/fragment.wgsl":16,"../shaders/vertex.wgsl":18,"../shaders/vertexShadow.wgsl":19,"./engine":7,"./matrix-class":9,"./raycast":12,"./utils":13,"wgpu-matrix":4}],11:[function(require,module,exports){
9462
9980
  "use strict";
9463
9981
 
9464
9982
  Object.defineProperty(exports, "__esModule", {
@@ -9856,7 +10374,7 @@ class MEMesh {
9856
10374
  }
9857
10375
  exports.default = MEMesh;
9858
10376
 
9859
- },{"../shaders/fragment.wgsl":15,"../shaders/vertex.wgsl":17,"../shaders/vertexShadow.wgsl":18,"./engine":6,"./loader-obj":7,"./matrix-class":8,"wgpu-matrix":3}],11:[function(require,module,exports){
10377
+ },{"../shaders/fragment.wgsl":16,"../shaders/vertex.wgsl":18,"../shaders/vertexShadow.wgsl":19,"./engine":7,"./loader-obj":8,"./matrix-class":9,"wgpu-matrix":4}],12:[function(require,module,exports){
9860
10378
  "use strict";
9861
10379
 
9862
10380
  Object.defineProperty(exports, "__esModule", {
@@ -9960,7 +10478,7 @@ function addRaycastListener() {
9960
10478
  });
9961
10479
  }
9962
10480
 
9963
- },{"wgpu-matrix":3}],12:[function(require,module,exports){
10481
+ },{"wgpu-matrix":4}],13:[function(require,module,exports){
9964
10482
  "use strict";
9965
10483
 
9966
10484
  Object.defineProperty(exports, "__esModule", {
@@ -9983,7 +10501,10 @@ exports.quaternion_rotation_matrix = quaternion_rotation_matrix;
9983
10501
  exports.radToDeg = radToDeg;
9984
10502
  exports.randomFloatFromTo = randomFloatFromTo;
9985
10503
  exports.randomIntFromTo = randomIntFromTo;
9986
- exports.vec3 = exports.urlQuery = exports.scriptManager = void 0;
10504
+ exports.scriptManager = void 0;
10505
+ exports.setupCanvasFilters = setupCanvasFilters;
10506
+ exports.typeText = typeText;
10507
+ exports.vec3 = exports.urlQuery = void 0;
9987
10508
  const vec3 = exports.vec3 = {
9988
10509
  cross(a, b, dst) {
9989
10510
  dst = dst || new Float32Array(3);
@@ -10700,7 +11221,148 @@ let mb = exports.mb = {
10700
11221
  }
10701
11222
  };
10702
11223
 
10703
- },{}],13:[function(require,module,exports){
11224
+ // Registry to track running animations per element
11225
+ const typingStates = new Map();
11226
+ function typeText(elementId, htmlString, delay = 50) {
11227
+ const el = document.getElementById(elementId);
11228
+ if (!el) return;
11229
+
11230
+ // If an existing typing is running for this element, cancel it
11231
+ if (typingStates.has(elementId)) {
11232
+ clearTimeout(typingStates.get(elementId).timeoutId);
11233
+ typingStates.delete(elementId);
11234
+ }
11235
+ el.innerHTML = ''; // Clear previous content
11236
+
11237
+ const tempEl = document.createElement('div');
11238
+ tempEl.innerHTML = htmlString;
11239
+ const queue = [];
11240
+ function flatten(node) {
11241
+ if (node.nodeType === Node.TEXT_NODE) {
11242
+ queue.push({
11243
+ type: 'text',
11244
+ text: node.textContent
11245
+ });
11246
+ } else if (node.nodeType === Node.ELEMENT_NODE) {
11247
+ if (node.tagName.toLowerCase() === 'img') {
11248
+ queue.push({
11249
+ type: 'img',
11250
+ src: node.getAttribute('src'),
11251
+ alt: node.getAttribute('alt') || ''
11252
+ });
11253
+ } else {
11254
+ queue.push({
11255
+ type: 'element',
11256
+ tag: node.tagName.toLowerCase(),
11257
+ attributes: Object.fromEntries([...node.attributes].map(attr => [attr.name, attr.value]))
11258
+ });
11259
+ for (const child of node.childNodes) flatten(child);
11260
+ queue.push({
11261
+ type: 'end'
11262
+ });
11263
+ }
11264
+ }
11265
+ }
11266
+ for (const node of tempEl.childNodes) flatten(node);
11267
+ let stack = [];
11268
+ let currentElement = el;
11269
+ function typeNextChar() {
11270
+ if (queue.length === 0) {
11271
+ typingStates.delete(elementId); // Cleanup after finish
11272
+ return;
11273
+ }
11274
+ const item = queue[0];
11275
+ if (item.type === 'text') {
11276
+ if (!item.index) item.index = 0;
11277
+ const ch = item.text[item.index];
11278
+ if (ch === '\n') {
11279
+ currentElement.appendChild(document.createElement('br'));
11280
+ } else {
11281
+ currentElement.appendChild(document.createTextNode(ch));
11282
+ }
11283
+ item.index++;
11284
+ if (item.index >= item.text.length) queue.shift();
11285
+ } else if (item.type === 'element') {
11286
+ const newEl = document.createElement(item.tag);
11287
+ if (item.attributes) {
11288
+ for (let [key, val] of Object.entries(item.attributes)) {
11289
+ newEl.setAttribute(key, val);
11290
+ }
11291
+ }
11292
+ currentElement.appendChild(newEl);
11293
+ stack.push(currentElement);
11294
+ currentElement = newEl;
11295
+ queue.shift();
11296
+ } else if (item.type === 'end') {
11297
+ currentElement = stack.pop();
11298
+ queue.shift();
11299
+ } else if (item.type === 'img') {
11300
+ const img = document.createElement('img');
11301
+ img.src = item.src;
11302
+ img.alt = item.alt;
11303
+ img.style.maxWidth = '100px';
11304
+ img.style.verticalAlign = 'middle';
11305
+ currentElement.appendChild(img);
11306
+ queue.shift();
11307
+ }
11308
+
11309
+ // Schedule next step and store timeoutId for control
11310
+ const timeoutId = setTimeout(typeNextChar, delay);
11311
+ typingStates.set(elementId, {
11312
+ timeoutId
11313
+ });
11314
+ }
11315
+ typeNextChar();
11316
+ }
11317
+ function setupCanvasFilters(canvasId) {
11318
+ let canvas = document.getElementById(canvasId);
11319
+ if (canvas == null) {
11320
+ canvas = document.getElementsByTagName('canvas')[0];
11321
+ }
11322
+ const filterState = {
11323
+ blur: "0px",
11324
+ grayscale: "0%",
11325
+ brightness: "100%",
11326
+ contrast: "100%",
11327
+ saturate: "100%",
11328
+ sepia: "0%",
11329
+ invert: "0%",
11330
+ hueRotate: "0deg"
11331
+ };
11332
+ function updateFilter() {
11333
+ const filterString = `
11334
+ blur(${filterState.blur})
11335
+ grayscale(${filterState.grayscale})
11336
+ brightness(${filterState.brightness})
11337
+ contrast(${filterState.contrast})
11338
+ saturate(${filterState.saturate})
11339
+ sepia(${filterState.sepia})
11340
+ invert(${filterState.invert})
11341
+ hue-rotate(${filterState.hueRotate})
11342
+ `.trim();
11343
+ canvas.style.filter = filterString;
11344
+ }
11345
+ const bindings = {
11346
+ blurControl: "blur",
11347
+ grayscaleControl: "grayscale",
11348
+ brightnessControl: "brightness",
11349
+ contrastControl: "contrast",
11350
+ saturateControl: "saturate",
11351
+ sepiaControl: "sepia",
11352
+ invertControl: "invert",
11353
+ hueControl: "hueRotate"
11354
+ };
11355
+ Object.entries(bindings).forEach(([selectId, key]) => {
11356
+ const el = document.getElementById(selectId);
11357
+ el.addEventListener("change", e => {
11358
+ filterState[key] = e.target.value;
11359
+ updateFilter();
11360
+ });
11361
+ });
11362
+ updateFilter(); // Initial
11363
+ }
11364
+
11365
+ },{}],14:[function(require,module,exports){
10704
11366
  "use strict";
10705
11367
 
10706
11368
  Object.defineProperty(exports, "__esModule", {
@@ -10740,7 +11402,7 @@ class MultiLang {
10740
11402
  }
10741
11403
  exports.MultiLang = MultiLang;
10742
11404
 
10743
- },{"../engine/utils":12}],14:[function(require,module,exports){
11405
+ },{"../engine/utils":13}],15:[function(require,module,exports){
10744
11406
  "use strict";
10745
11407
 
10746
11408
  Object.defineProperty(exports, "__esModule", {
@@ -10756,6 +11418,7 @@ class MatrixAmmo {
10756
11418
  _utils.scriptManager.LOAD("./ammojs/ammo.js", "ammojs", undefined, undefined, this.init);
10757
11419
  this.lastRoll = '';
10758
11420
  this.presentScore = '';
11421
+ this.speedUpSimulation = 1;
10759
11422
  }
10760
11423
  init = () => {
10761
11424
  // console.log('pre ammo')
@@ -10817,6 +11480,7 @@ class MatrixAmmo {
10817
11480
  var myMotionState = new Ammo.btDefaultMotionState(startTransform),
10818
11481
  rbInfo = new Ammo.btRigidBodyConstructionInfo(mass, myMotionState, colShape, localInertia),
10819
11482
  body = new Ammo.btRigidBody(rbInfo);
11483
+ console.log("TEST ADDING PHYSICS ");
10820
11484
  body.MEObject = MEObject;
10821
11485
  this.dynamicsWorld.addRigidBody(body);
10822
11486
  this.rigidBodies.push(body);
@@ -10890,8 +11554,6 @@ class MatrixAmmo {
10890
11554
  pos.setX(pos.x() + x);
10891
11555
  pos.setY(pos.y() + y);
10892
11556
  pos.setZ(pos.z() + z);
10893
- // console.log('position kinematic move : ', pos)
10894
- // console.log('position localRot : ', localRot)
10895
11557
  localRot.setX(rx);
10896
11558
  localRot.setY(ry);
10897
11559
  localRot.setZ(rz);
@@ -10899,14 +11561,12 @@ class MatrixAmmo {
10899
11561
  let ms = physicsBody.getMotionState();
10900
11562
  if (ms) {
10901
11563
  var tmpTrans = new Ammo.btTransform();
10902
-
10903
11564
  // quat.setValue(quat.x(), quat.y(), quat.z(), quat.w());
10904
11565
  tmpTrans.setIdentity();
10905
11566
  tmpTrans.setOrigin(pos);
10906
11567
  tmpTrans.setRotation(localRot);
10907
11568
  ms.setWorldTransform(tmpTrans);
10908
11569
  }
10909
- // console.log('body, ', body)
10910
11570
  }
10911
11571
  getBodyByName(name) {
10912
11572
  var b = null;
@@ -10985,34 +11645,53 @@ class MatrixAmmo {
10985
11645
  }
10986
11646
  }
10987
11647
  updatePhysics() {
10988
- // Step world
10989
- this.dynamicsWorld.stepSimulation(1 / 60, 10);
10990
- // Update rigid bodies
10991
- var trans = new Ammo.btTransform();
11648
+ if (!Ammo) return;
11649
+ const trans = new Ammo.btTransform();
11650
+ const transform = new Ammo.btTransform();
10992
11651
  this.rigidBodies.forEach(function (body) {
10993
- if (body.getMotionState()) {
11652
+ if (body.isKinematic) {
11653
+ transform.setIdentity();
11654
+ transform.setOrigin(new Ammo.btVector3(body.MEObject.position.x, body.MEObject.position.y, body.MEObject.position.z));
11655
+ const quat = new Ammo.btQuaternion();
11656
+ quat.setRotation(new Ammo.btVector3(body.MEObject.rotation.axis.x, body.MEObject.rotation.axis.y, body.MEObject.rotation.axis.z), (0, _utils.degToRad)(body.MEObject.rotation.angle));
11657
+ transform.setRotation(quat);
11658
+ body.setWorldTransform(transform);
11659
+ const ms = body.getMotionState();
11660
+ if (ms) ms.setWorldTransform(transform);
11661
+ }
11662
+ });
11663
+ Ammo.destroy(transform);
11664
+
11665
+ // Step simulation AFTER setting kinematic transforms
11666
+ const timeStep = 1 / 60;
11667
+ const maxSubSteps = 10;
11668
+ for (let i = 0; i < this.speedUpSimulation; i++) {
11669
+ this.dynamicsWorld.stepSimulation(timeStep, maxSubSteps);
11670
+ }
11671
+ this.rigidBodies.forEach(function (body) {
11672
+ if (!body.isKinematic && body.getMotionState()) {
10994
11673
  body.getMotionState().getWorldTransform(trans);
10995
- var _x = trans.getOrigin().x().toFixed(2);
10996
- var _y = trans.getOrigin().y().toFixed(2);
10997
- var _z = trans.getOrigin().z().toFixed(2);
11674
+ const _x = +trans.getOrigin().x().toFixed(2);
11675
+ const _y = +trans.getOrigin().y().toFixed(2);
11676
+ const _z = +trans.getOrigin().z().toFixed(2);
10998
11677
  body.MEObject.position.setPosition(_x, _y, _z);
10999
- var test = trans.getRotation();
11000
- var testAxis = test.getAxis();
11001
- test.normalize();
11002
- body.MEObject.rotation.axis.x = testAxis.x();
11003
- body.MEObject.rotation.axis.y = testAxis.y();
11004
- body.MEObject.rotation.axis.z = testAxis.z();
11005
- body.MEObject.rotation.matrixRotation = (0, _utils.quaternion_rotation_matrix)(test);
11006
- body.MEObject.rotation.angle = (0, _utils.radToDeg)(parseFloat(test.getAngle().toFixed(2)));
11678
+ const rot = trans.getRotation();
11679
+ const rotAxis = rot.getAxis();
11680
+ rot.normalize();
11681
+ body.MEObject.rotation.axis.x = rotAxis.x();
11682
+ body.MEObject.rotation.axis.y = rotAxis.y();
11683
+ body.MEObject.rotation.axis.z = rotAxis.z();
11684
+ body.MEObject.rotation.matrixRotation = (0, _utils.quaternion_rotation_matrix)(rot);
11685
+ body.MEObject.rotation.angle = (0, _utils.radToDeg)(parseFloat(rot.getAngle().toFixed(2)));
11007
11686
  }
11008
11687
  });
11009
- // collision detect
11688
+ Ammo.destroy(trans);
11010
11689
  this.detectCollision();
11011
11690
  }
11012
11691
  }
11013
11692
  exports.default = MatrixAmmo;
11014
11693
 
11015
- },{"../engine/utils":12}],15:[function(require,module,exports){
11694
+ },{"../engine/utils":13}],16:[function(require,module,exports){
11016
11695
  "use strict";
11017
11696
 
11018
11697
  Object.defineProperty(exports, "__esModule", {
@@ -11070,7 +11749,7 @@ fn main(input : FragmentInput) -> @location(0) vec4f {
11070
11749
  // return vec4(textureColor.rgb , 0.5);
11071
11750
  }`;
11072
11751
 
11073
- },{}],16:[function(require,module,exports){
11752
+ },{}],17:[function(require,module,exports){
11074
11753
  "use strict";
11075
11754
 
11076
11755
  Object.defineProperty(exports, "__esModule", {
@@ -11128,7 +11807,7 @@ fn fragmentMain(input: VertexOutput) -> @location(0) vec4f {
11128
11807
  return vec4f(textureColor.rgb * lightColor, textureColor.a);
11129
11808
  }`;
11130
11809
 
11131
- },{}],17:[function(require,module,exports){
11810
+ },{}],18:[function(require,module,exports){
11132
11811
  "use strict";
11133
11812
 
11134
11813
  Object.defineProperty(exports, "__esModule", {
@@ -11185,7 +11864,7 @@ fn main(
11185
11864
  }
11186
11865
  `;
11187
11866
 
11188
- },{}],18:[function(require,module,exports){
11867
+ },{}],19:[function(require,module,exports){
11189
11868
  "use strict";
11190
11869
 
11191
11870
  Object.defineProperty(exports, "__esModule", {
@@ -11213,7 +11892,7 @@ fn main(
11213
11892
  }
11214
11893
  `;
11215
11894
 
11216
- },{}],19:[function(require,module,exports){
11895
+ },{}],20:[function(require,module,exports){
11217
11896
  "use strict";
11218
11897
 
11219
11898
  Object.defineProperty(exports, "__esModule", {
@@ -11224,10 +11903,18 @@ class MatrixSounds {
11224
11903
  constructor() {
11225
11904
  this.volume = 0.5;
11226
11905
  this.audios = {};
11906
+ this.enabled = true; // 🔇 global flag to mute/allow audio
11907
+ }
11908
+ muteAll() {
11909
+ this.enabled = false;
11910
+ Object.values(this.audios).forEach(audio => audio.pause());
11911
+ }
11912
+ unmuteAll() {
11913
+ this.enabled = true;
11227
11914
  }
11228
11915
  createClones(c, name, path) {
11229
- for (var x = 1; x < c; x++) {
11230
- let a = new Audio(path);
11916
+ for (let x = 1; x < c; x++) {
11917
+ const a = new Audio(path);
11231
11918
  a.id = name + x;
11232
11919
  a.volume = this.volume;
11233
11920
  this.audios[name + x] = a;
@@ -11235,7 +11922,7 @@ class MatrixSounds {
11235
11922
  }
11236
11923
  }
11237
11924
  createAudio(name, path, useClones) {
11238
- let a = new Audio(path);
11925
+ const a = new Audio(path);
11239
11926
  a.id = name;
11240
11927
  a.volume = this.volume;
11241
11928
  this.audios[name] = a;
@@ -11245,25 +11932,37 @@ class MatrixSounds {
11245
11932
  }
11246
11933
  }
11247
11934
  play(name) {
11248
- if (this.audios[name].paused == true) {
11249
- this.audios[name].play();
11935
+ if (!this.enabled) return; // 🔇 prevent playing if muted
11936
+
11937
+ const audio = this.audios[name];
11938
+ if (!audio) return;
11939
+ if (audio.paused) {
11940
+ audio.play().catch(e => {
11941
+ if (e.name !== 'NotAllowedError') console.warn("sounds error:", e);
11942
+ });
11250
11943
  } else {
11251
11944
  this.tryClone(name);
11252
11945
  }
11253
11946
  }
11254
11947
  tryClone(name) {
11255
- var cc = 1;
11948
+ if (!this.enabled) return; // 🔇 prevent playing clones
11949
+
11950
+ let cc = 1;
11256
11951
  try {
11257
- while (this.audios[name + cc].paused == false) {
11952
+ while (this.audios[name + cc] && this.audios[name + cc].paused === false) {
11258
11953
  cc++;
11259
11954
  }
11260
- if (this.audios[name + cc]) this.audios[name + cc].play();
11261
- } catch (err) {}
11955
+ if (this.audios[name + cc]) {
11956
+ this.audios[name + cc].play();
11957
+ }
11958
+ } catch (err) {
11959
+ console.warn("Clone play failed:", err);
11960
+ }
11262
11961
  }
11263
11962
  }
11264
11963
  exports.MatrixSounds = MatrixSounds;
11265
11964
 
11266
- },{}],20:[function(require,module,exports){
11965
+ },{}],21:[function(require,module,exports){
11267
11966
  "use strict";
11268
11967
 
11269
11968
  Object.defineProperty(exports, "__esModule", {
@@ -11453,7 +12152,44 @@ class MatrixEngineWGPU {
11453
12152
  o.entityArgPass = this.entityArgPass;
11454
12153
  o.cameras = this.cameras;
11455
12154
  }
12155
+ if (typeof o.physics === 'undefined') {
12156
+ o.physics = {
12157
+ scale: [1, 1, 1],
12158
+ enabled: true,
12159
+ geometry: "Sphere",
12160
+ radius: o.scale,
12161
+ name: o.name,
12162
+ rotation: o.rotation
12163
+ };
12164
+ }
12165
+ if (typeof o.position !== 'undefined') {
12166
+ o.physics.position = o.position;
12167
+ }
12168
+ if (typeof o.physics.enabled === 'undefined') {
12169
+ o.physics.enabled = true;
12170
+ }
12171
+ if (typeof o.physics.geometry === 'undefined') {
12172
+ o.physics.geometry = "Sphere";
12173
+ }
12174
+ if (typeof o.physics.radius === 'undefined') {
12175
+ o.physics.radius = o.scale;
12176
+ }
12177
+ if (typeof o.physics.mass === 'undefined') {
12178
+ o.physics.mass = 1;
12179
+ }
12180
+ if (typeof o.physics.name === 'undefined') {
12181
+ o.physics.name = o.name;
12182
+ }
12183
+ if (typeof o.physics.scale === 'undefined') {
12184
+ o.physics.scale = o.scale;
12185
+ }
12186
+ if (typeof o.physics.rotation === 'undefined') {
12187
+ o.physics.rotation = o.rotation;
12188
+ }
11456
12189
  let myCube1 = new _cube.default(this.canvas, this.device, this.context, o);
12190
+ if (o.physics.enabled == true) {
12191
+ this.matrixAmmo.addPhysics(myCube1, o.physics);
12192
+ }
11457
12193
  this.mainRenderBundle.push(myCube1);
11458
12194
  };
11459
12195
 
@@ -11516,7 +12252,44 @@ class MatrixEngineWGPU {
11516
12252
  o.entityArgPass = this.entityArgPass;
11517
12253
  o.cameras = this.cameras;
11518
12254
  }
12255
+ if (typeof o.physics === 'undefined') {
12256
+ o.physics = {
12257
+ scale: [1, 1, 1],
12258
+ enabled: true,
12259
+ geometry: "Sphere",
12260
+ radius: o.scale,
12261
+ name: o.name,
12262
+ rotation: o.rotation
12263
+ };
12264
+ }
12265
+ if (typeof o.position !== 'undefined') {
12266
+ o.physics.position = o.position;
12267
+ }
12268
+ if (typeof o.physics.enabled === 'undefined') {
12269
+ o.physics.enabled = true;
12270
+ }
12271
+ if (typeof o.physics.geometry === 'undefined') {
12272
+ o.physics.geometry = "Sphere";
12273
+ }
12274
+ if (typeof o.physics.radius === 'undefined') {
12275
+ o.physics.radius = o.scale;
12276
+ }
12277
+ if (typeof o.physics.mass === 'undefined') {
12278
+ o.physics.mass = 1;
12279
+ }
12280
+ if (typeof o.physics.name === 'undefined') {
12281
+ o.physics.name = o.name;
12282
+ }
12283
+ if (typeof o.physics.scale === 'undefined') {
12284
+ o.physics.scale = o.scale;
12285
+ }
12286
+ if (typeof o.physics.rotation === 'undefined') {
12287
+ o.physics.rotation = o.rotation;
12288
+ }
11519
12289
  let myBall1 = new _ball.default(this.canvas, this.device, this.context, o);
12290
+ if (o.physics.enabled == true) {
12291
+ this.matrixAmmo.addPhysics(myBall1, o.physics);
12292
+ }
11520
12293
  this.mainRenderBundle.push(myBall1);
11521
12294
  };
11522
12295
 
@@ -11700,19 +12473,24 @@ class MatrixEngineWGPU {
11700
12473
  }
11701
12474
  };
11702
12475
  framePassPerObject = () => {
11703
- // console.log('framePassPerObject')
11704
12476
  let commandEncoder = this.device.createCommandEncoder();
11705
- this.rbContainer = [];
11706
- let passEncoder;
12477
+ this.matrixAmmo.updatePhysics();
11707
12478
  this.mainRenderBundle.forEach((meItem, index) => {
11708
- meItem.draw(commandEncoder);
12479
+ if (index === 0) {
12480
+ if (meItem.renderPassDescriptor) meItem.renderPassDescriptor.colorAttachments[0].loadOp = 'clear';
12481
+ } else {
12482
+ if (meItem.renderPassDescriptor) meItem.renderPassDescriptor.colorAttachments[0].loadOp = 'load';
12483
+ }
12484
+ // Update transforms, physics, etc. (optional)
12485
+ meItem.draw(commandEncoder); // optional: if this does per-frame updates
11709
12486
  if (meItem.renderBundle) {
11710
- this.rbContainer.push(meItem.renderBundle);
11711
- passEncoder = commandEncoder.beginRenderPass(meItem.renderPassDescriptor);
11712
- passEncoder.executeBundles(this.rbContainer);
12487
+ // Set up view per object
12488
+ meItem.renderPassDescriptor.colorAttachments[0].view = this.context.getCurrentTexture().createView();
12489
+ const passEncoder = commandEncoder.beginRenderPass(meItem.renderPassDescriptor);
12490
+ passEncoder.executeBundles([meItem.renderBundle]); // ✅ Use only this bundle
11713
12491
  passEncoder.end();
11714
12492
  } else {
11715
- meItem.draw(commandEncoder);
12493
+ meItem.draw(commandEncoder); // fallback if no renderBundle
11716
12494
  }
11717
12495
  });
11718
12496
  this.device.queue.submit([commandEncoder.finish()]);
@@ -11721,4 +12499,4 @@ class MatrixEngineWGPU {
11721
12499
  }
11722
12500
  exports.default = MatrixEngineWGPU;
11723
12501
 
11724
- },{"./engine/ball.js":4,"./engine/cube.js":5,"./engine/engine.js":6,"./engine/mesh-obj.js":9,"./engine/mesh.js":10,"./engine/utils.js":12,"./multilang/lang.js":13,"./physics/matrix-ammo.js":14,"./sounds/sounds.js":19,"wgpu-matrix":3}]},{},[2]);
12502
+ },{"./engine/ball.js":5,"./engine/cube.js":6,"./engine/engine.js":7,"./engine/mesh-obj.js":10,"./engine/mesh.js":11,"./engine/utils.js":13,"./multilang/lang.js":14,"./physics/matrix-ammo.js":15,"./sounds/sounds.js":20,"wgpu-matrix":4}]},{},[3]);