matrix-engine-wgpu 1.2.0 → 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.
@@ -1,8 +1,8 @@
1
1
 
2
2
  export let settingsBox = `
3
- <div>
3
+ <div style="">
4
4
  <span style="font-size:170%" data-label="settings"></span>
5
- <div style="margin:20px;" >
5
+ <div style="justify-items: flex-end;margin:20px;" >
6
6
  <div>
7
7
  <span data-label="sounds"></span>
8
8
  <label class="switch">
@@ -10,25 +10,29 @@ export let settingsBox = `
10
10
  <span class="sliderSwitch round"></span>
11
11
  </label>
12
12
  </div>
13
- <div>
14
- <div>
15
- <span data-label="graphics"></span>
16
-
17
- <select id="physicsSpeed" class="setting-select">
18
- <option value="1">Slow</option>
19
- <option value="2">Normal</option>
20
- <option value="3">Fast</option>
21
- </select>
13
+ <div style="margin-top:20px;margin-bottom:15px;">
14
+ <span style="font-size: larger;margin-bottom:15px" data-label="graphics"></span>
15
+ <p></p>
16
+ <label>Anim speed:</label>
17
+ <select id="physicsSpeed" class="setting-select">
18
+ <option value="1">Slow</option>
19
+ <option value="2">Normal</option>
20
+ <option value="3">Fast</option>
21
+ </select>
22
+ </div>
22
23
 
23
- <select id="blurControl">
24
- <option value="0px">Blur: 0</option>
25
- <option value="1px">Blur: 1</option>
26
- <option value="2px">Blur: 2</option>
27
- <option value="3px">Blur: 3</option>
28
- </select>
24
+ <div>
25
+ <label>Blur:</label>
26
+ <select id="blurControl">
27
+ <option value="0px">Blur: 0</option>
28
+ <option value="1px">Blur: 1</option>
29
+ <option value="2px">Blur: 2</option>
30
+ <option value="3px">Blur: 3</option>
31
+ </select>
29
32
  </div>
30
33
 
31
34
  <div>
35
+ <label>Grayscale:</label>
32
36
  <select id="grayscaleControl">
33
37
  <option value="0%">Grayscale: 0%</option>
34
38
  <option value="25%">Grayscale: 25%</option>
@@ -92,13 +96,14 @@ export let settingsBox = `
92
96
  <option value="270deg">270°</option>
93
97
  </select>
94
98
  </div>
95
-
96
- </div>
97
- <div>
99
+
100
+ <div style="margin-top:20px;">
98
101
  <button class="btn" onclick="app.myDom.hideSettings()">
99
102
  <span data-label="hide"></span>
100
103
  </button>
101
104
  </div>
105
+
106
+ <img src="res/icons/512.png" style="position:absolute;left:10px;top:5%;width:300px;z-index:-1;"/>
102
107
  </div>
103
108
  </div>`;
104
109
 
@@ -151,6 +151,7 @@ export let dices = {
151
151
  this.C = 0;
152
152
  }
153
153
  },
154
+
154
155
  validatePass: function() {
155
156
  if(Object.keys(this.SAVED_DICES).length !== 5) {
156
157
  console.log('%cBLOCK', LOG_FUNNY)
@@ -193,6 +194,21 @@ export let myDom = {
193
194
  help.id = 'HELP';
194
195
  help.classList.add('btn')
195
196
  help.innerHTML = `<span data-label="help"></span>`;
197
+ help.addEventListener('click', () => {
198
+ if(byId('helpBox').style.display != 'none') {
199
+ byId('helpBox').style.display = 'none';
200
+ } else {
201
+ byId('helpBox').style.display = 'block';
202
+ }
203
+ });
204
+
205
+ var table = document.createElement('div')
206
+ table.id = 'showHideTableDOM';
207
+ table.classList.add('btn')
208
+ table.innerHTML = `<span data-label="table"></span>`;
209
+ table.addEventListener('click', () => {
210
+ this.showHideJambTable()
211
+ });
196
212
 
197
213
  var settings = document.createElement('div')
198
214
  settings.id = 'settings';
@@ -218,13 +234,31 @@ export let myDom = {
218
234
  }
219
235
  });
220
236
  setupCanvasFilters();
221
- byId('messageBox').setAttribute('data-loaded', 'loaded')
237
+ byId('messageBox').setAttribute('data-loaded', 'loaded');
238
+ document.getElementById('physicsSpeed').value = app.matrixAmmo.speedUpSimulation;
222
239
  byId("physicsSpeed").addEventListener("change", (e) => {
223
240
  app.matrixAmmo.speedUpSimulation = parseInt(e.target.value);
224
241
  });
225
242
 
226
243
  })
227
244
 
245
+ // test help
246
+ var helpBox = document.createElement('div')
247
+ helpBox.id = 'helpBox';
248
+ helpBox.style.position = 'absolute';
249
+ helpBox.style.right = '20%';
250
+ helpBox.style.zIndex = '2';
251
+ helpBox.style.top = '15%';
252
+ helpBox.style.width = '60%';
253
+ helpBox.style.height = '50%';
254
+ helpBox.style.fontSize = '100%';
255
+ helpBox.classList.add('btn');
256
+ helpBox.addEventListener('click', () => {
257
+ byId('helpBox').style.display = 'none';
258
+ });
259
+ document.body.appendChild(helpBox)
260
+ typeText('helpBox', app.label.get.about, 10);
261
+ //
228
262
  var roll = document.createElement('div')
229
263
  roll.id = 'hud-roll';
230
264
  roll.classList.add('btn');
@@ -237,6 +271,7 @@ export let myDom = {
237
271
  separator.innerHTML = `✨maximumroulette.com✨`;
238
272
 
239
273
  root.append(settings)
274
+ root.append(table);
240
275
  root.append(help)
241
276
  root.append(separator)
242
277
  root.append(roll)
@@ -291,6 +326,12 @@ export let myDom = {
291
326
  root.id = 'jambTable';
292
327
  root.style.position = 'absolute';
293
328
 
329
+ var dragHandler = document.createElement('div')
330
+ dragHandler.id = 'dragHandler';
331
+ dragHandler.classList.add('dragHandler')
332
+ dragHandler.innerHTML = "⇅ Drag";
333
+ root.append(dragHandler)
334
+
294
335
  var rowHeader = document.createElement('div')
295
336
  rowHeader.id = 'rowHeader';
296
337
  rowHeader.style.top = '10px';
@@ -376,12 +417,15 @@ export let myDom = {
376
417
  topTitleDOM.style.width = 'auto';
377
418
  topTitleDOM.style.position = 'absolute';
378
419
  topTitleDOM.style.left = '35%';
379
- topTitleDOM.style.top = '5%';
420
+ topTitleDOM.style.fontSize = '175%';
421
+ topTitleDOM.style.top = '4%';
380
422
  topTitleDOM.style.background = '#7d7d7d8c';
381
423
  topTitleDOM.innerHTML = app.label.get.ready + ", " + app.userState.name + '.';
424
+ topTitleDOM.setAttribute('data-gamestatus', 'FREE');
382
425
  document.body.appendChild(topTitleDOM);
383
426
  addEventListener('updateTitle', (e) => {
384
- typeText('topTitleDOM', e.detail);
427
+ typeText('topTitleDOM', e.detail.text);
428
+ topTitleDOM.setAttribute('data-gamestatus', e.detail.status);
385
429
  })
386
430
  },
387
431
 
@@ -783,9 +827,8 @@ export let myDom = {
783
827
  rowMin.style.width = 'auto';
784
828
  rowMin.style.background = '#7d7d7d8c';
785
829
  rowMin.innerHTML = `-`;
786
- this.rowMin = rowMin;
830
+ // this.rowMin = rowMin;
787
831
  myRoot.appendChild(rowMin);
788
- this.rowMin = rowMin;
789
832
  var rowMaxMinSum = document.createElement('div')
790
833
  rowMaxMinSum.id = 'down-rowMaxMinSum';
791
834
  rowMaxMinSum.style.width = 'auto';
@@ -1039,7 +1082,7 @@ export let myDom = {
1039
1082
  // console.log('<GAMEPLAY><FREE ROW IS FEELED>')
1040
1083
  var TEST = app.myDom.checkForAllDuplicate();
1041
1084
  for(var key in TEST) {
1042
- if(TEST[key] == 5 || TEST[key] > 5) {
1085
+ if(TEST[key] == 5) {
1043
1086
  // win
1044
1087
  var getDiceID = parseInt(key.replace('value__', ''))
1045
1088
  var win = getDiceID * 5;
@@ -1056,11 +1099,11 @@ export let myDom = {
1056
1099
  calcDownRowMax: (e) => {
1057
1100
  if(dices.validatePass() == false) return;
1058
1101
  e.target.classList.remove('canPlay');
1059
- this.rowMin.classList.add('canPlay');
1102
+ byId('down-rowMin').classList.add('canPlay');
1060
1103
  var test = 0;
1061
1104
  let keyLessNum = Object.keys(dices.R).reduce((key, v) => dices.R[v] < dices.R[key] ? v : key);
1062
1105
  // console.log('FIND MIN DICE TO REMOVE FROM SUM ', keyLessNum);
1063
- for(var key in dices.R) {
1106
+ for(var key in dices.SAVED_DICES) {
1064
1107
  if(key != keyLessNum) {
1065
1108
  test += parseFloat(dices.R[key]);
1066
1109
  }
@@ -1069,8 +1112,8 @@ export let myDom = {
1069
1112
  // now attach next event.
1070
1113
  dices.STATUS = "FREE_TO_PLAY";
1071
1114
  dispatchEvent(new CustomEvent('FREE_TO_PLAY', {}));
1072
- this.rowMax.removeEventListener("click", this.calcDownRowMax);
1073
- byId('down-rowMin').addEventListener('click', this.calcDownRowMin);
1115
+ byId('down-rowMax').removeEventListener("click", myDom.calcDownRowMax);
1116
+ byId('down-rowMin').addEventListener('click', myDom.calcDownRowMin);
1074
1117
  },
1075
1118
 
1076
1119
  incrasePoints: function(arg) {
@@ -1079,32 +1122,33 @@ export let myDom = {
1079
1122
 
1080
1123
  calcDownRowMin: () => {
1081
1124
  if(dices.validatePass() == false) return;
1082
- this.rowMin.classList.remove('canPlay')
1125
+ byId('down-rowMin').classList.remove('canPlay')
1083
1126
  console.log('MIN ENABLED')
1084
1127
  var maxTestKey = Object.keys(dices.R).reduce(function(a, b) {return dices.R[a] > dices.R[b] ? a : b});
1085
1128
  var test = 0;
1086
1129
  for(var key in dices.R) {
1087
- if(key != maxTestKey) {
1088
- test += parseFloat(dices.R[key])
1089
- } else {
1090
- console.log('not calc dice ', dices.R[key])
1091
- }
1130
+ // if(key != maxTestKey) {
1131
+ test += parseFloat(dices.R[key])
1132
+ // } else {
1133
+ // console.log('not calc dice ', dices.R[key])
1134
+ // }
1092
1135
  }
1093
- this.rowMin.innerHTML = test;
1094
- byId('down-rowMin').removeEventListener('click', this.calcDownRowMin);
1136
+ byId('down-rowMin').innerHTML = test;
1137
+ byId('down-rowMin').removeEventListener('click', myDom.calcDownRowMin);
1095
1138
  // calc max min dont forget rules for bonus +30
1096
- var SUMMINMAX = parseFloat(this.rowMax.innerHTML) - parseFloat(this.rowMin.innerHTML)
1139
+ var SUMMINMAX = parseFloat(byId('down-rowMax').innerHTML) - parseFloat(byId('down-rowMin').innerHTML)
1097
1140
  byId('down-rowMaxMinSum').innerHTML = SUMMINMAX;
1098
1141
  myDom.incrasePoints(SUMMINMAX);
1099
1142
  dices.STATUS = "FREE_TO_PLAY";
1100
1143
  dispatchEvent(new CustomEvent('FREE_TO_PLAY', {}))
1101
1144
  byId('down-largeStraight').classList.add('canPlay');
1102
- byId('down-largeStraight').addEventListener('click', this.attachKenta)
1145
+ byId('down-largeStraight').addEventListener('click', myDom.attachKenta)
1146
+ byId('down-rowMin').removeEventListener('click', myDom.calcDownRowMin);
1103
1147
  },
1104
1148
 
1105
1149
  checkForDuplicate: function() {
1106
1150
  var testArray = [];
1107
- for(var key in dices.R) {
1151
+ for(var key in dices.SAVED_DICES) {
1108
1152
  var gen = {myId: key, value: dices.R[key]};
1109
1153
  testArray.push(gen);
1110
1154
  }
@@ -1120,7 +1164,7 @@ export let myDom = {
1120
1164
 
1121
1165
  checkForAllDuplicate: function() {
1122
1166
  var testArray = [];
1123
- for(var key in dices.R) {
1167
+ for(var key in dices.SAVED_DICES) {
1124
1168
  var gen = {myId: key, value: dices.R[key]};
1125
1169
  testArray.push(gen);
1126
1170
  }
@@ -1143,13 +1187,13 @@ export let myDom = {
1143
1187
  },
1144
1188
 
1145
1189
  attachKenta: function() {
1146
- console.log('Test kenta ', dices.R)
1190
+ console.log('Test kenta ', dices.SAVED_DICES)
1147
1191
  byId('down-largeStraight').classList.remove('canPlay')
1148
1192
  var result = app.myDom.checkForDuplicate()[0];
1149
1193
  var testArray = app.myDom.checkForDuplicate()[1];
1150
- // console.log('TEST duplik: ' + result);
1151
- if(result.length == 2) {
1152
- console.log('TEST duplik less 3 : ' + result);
1194
+ console.log('TEST duplik: ' + result);
1195
+ if(result.length > 0) {
1196
+ console.log('TEST duplik l : ' + result);
1153
1197
  var locPrevent = false;
1154
1198
  testArray.forEach((item, index, array) => {
1155
1199
  if(result[0].value == item.value && locPrevent == false) {
@@ -1158,24 +1202,8 @@ export let myDom = {
1158
1202
  array.splice(index, 1);
1159
1203
  }
1160
1204
  })
1161
- // if we catch 1 and 6 in same stack then it is not possible for kenta...
1162
- var test1 = false, test6 = false;
1163
- testArray.forEach((item, index, array) => {
1164
- if(item.value == 1) {
1165
- test1 = true;
1166
- } else if(item.value == 6) {
1167
- test6 = true;
1168
- }
1169
- })
1170
- if(test1 == true && test6 == true) {
1171
- byId('down-largeStraight').innerHTML = `0`;
1172
- } else if(test1 == true) {
1173
- byId('down-largeStraight').innerHTML = 15 + 50;
1174
- myDom.incrasePoints(15 + 50);
1175
- } else if(test6 == true) {
1176
- byId('down-largeStraight').innerHTML = 20 + 50;
1177
- myDom.incrasePoints(20 + 50);
1178
- }
1205
+ byId('down-largeStraight').innerHTML = `0`;
1206
+
1179
1207
  } else if(result < 2) {
1180
1208
  byId('down-largeStraight').innerHTML = 66;
1181
1209
  myDom.incrasePoints(66);
@@ -1183,8 +1211,8 @@ export let myDom = {
1183
1211
  // zero value
1184
1212
  byId('down-largeStraight').innerHTML = `0`;
1185
1213
  }
1186
- byId('down-threeOfAKind').addEventListener('click', this.attachDownTrilling)
1187
- byId('down-largeStraight').removeEventListener('click', this.attachKenta)
1214
+ byId('down-threeOfAKind').addEventListener('click', myDom.attachDownTrilling)
1215
+ byId('down-largeStraight').removeEventListener('click', myDom.attachKenta)
1188
1216
  dices.STATUS = "FREE_TO_PLAY";
1189
1217
  dispatchEvent(new CustomEvent('FREE_TO_PLAY', {}))
1190
1218
  },
@@ -1210,8 +1238,8 @@ export let myDom = {
1210
1238
  } else {
1211
1239
  byId('down-threeOfAKind').innerHTML = 0;
1212
1240
  }
1213
- byId('down-threeOfAKind').removeEventListener('click', this.attachDownTrilling)
1214
- byId('down-fullHouse').addEventListener('click', this.attachDownFullHouse)
1241
+ byId('down-threeOfAKind').removeEventListener('click', myDom.attachDownTrilling)
1242
+ byId('down-fullHouse').addEventListener('click', myDom.attachDownFullHouse)
1215
1243
  dices.STATUS = "FREE_TO_PLAY";
1216
1244
  dispatchEvent(new CustomEvent('FREE_TO_PLAY', {}))
1217
1245
  },
@@ -1243,8 +1271,8 @@ export let myDom = {
1243
1271
  } else {
1244
1272
  byId('down-fullHouse').innerHTML = 0;
1245
1273
  }
1246
- byId('down-poker').addEventListener('click', this.attachDownPoker)
1247
- byId('down-fullHouse').removeEventListener('click', this.attachDownFullHouse)
1274
+ byId('down-poker').addEventListener('click', myDom.attachDownPoker)
1275
+ byId('down-fullHouse').removeEventListener('click', myDom.attachDownFullHouse)
1248
1276
  dices.STATUS = "FREE_TO_PLAY";
1249
1277
  dispatchEvent(new CustomEvent('FREE_TO_PLAY', {}))
1250
1278
  },
@@ -1261,14 +1289,14 @@ export let myDom = {
1261
1289
  myDom.incrasePoints(win + 40);
1262
1290
  }
1263
1291
  }
1264
- byId('down-poker').removeEventListener('click', this.attachDownPoker)
1265
- byId('down-jamb').addEventListener('click', this.attachDownJamb)
1292
+ byId('down-poker').removeEventListener('click', myDom.attachDownPoker)
1293
+ byId('down-jamb').addEventListener('click', myDom.attachDownJamb)
1266
1294
  dices.STATUS = "FREE_TO_PLAY";
1267
1295
  dispatchEvent(new CustomEvent('FREE_TO_PLAY', {}))
1268
1296
  },
1269
1297
 
1270
1298
  attachDownJamb: function() {
1271
- byId('down-jamb').removeEventListener('click', this.attachDownJamb)
1299
+ byId('down-jamb').removeEventListener('click', myDom.attachDownJamb)
1272
1300
  console.log('<GAMEPLAY><DOWN ROW IS FEELED>')
1273
1301
  var TEST = app.myDom.checkForAllDuplicate();
1274
1302
  for(var key in TEST) {
@@ -1282,5 +1310,31 @@ export let myDom = {
1282
1310
  }
1283
1311
  dices.STATUS = "FREE_TO_PLAY";
1284
1312
  dispatchEvent(new CustomEvent('FREE_TO_PLAY', {}))
1313
+ },
1314
+
1315
+ isDragging: false,
1316
+ offsetX: 0,
1317
+ offsetY: 0,
1318
+ addDraggerForTable: () => {
1319
+ byId('dragHandler').addEventListener('pointerdown', (e) => {
1320
+ myDom.isDragging = true;
1321
+ const rect = byId('jambTable').getBoundingClientRect();
1322
+ myDom.offsetX = e.clientX - rect.left;
1323
+ myDom.offsetY = e.clientY - rect.top;
1324
+ byId('dragHandler').setPointerCapture(e.pointerId);
1325
+ });
1326
+
1327
+ byId('dragHandler').addEventListener('pointermove', (e) => {
1328
+ if(myDom.isDragging) {
1329
+ byId('jambTable').style.left = `${e.clientX - myDom.offsetX}px`;
1330
+ byId('jambTable').style.top = `${e.clientY - myDom.offsetY}px`;
1331
+ }
1332
+ });
1333
+
1334
+ byId('dragHandler').addEventListener('pointerup', (e) => {
1335
+ myDom.isDragging = false;
1336
+ byId('dragHandler').releasePointerCapture(e.pointerId);
1337
+ });
1285
1338
  }
1339
+
1286
1340
  }
@@ -0,0 +1,3 @@
1
+
2
+
3
+ Sound Effect by <a href="https://pixabay.com/users/u_qpfzpydtro-29496424/?utm_source=link-attribution&utm_medium=referral&utm_campaign=music&utm_content=142528">u_qpfzpydtro</a> from <a href="https://pixabay.com//?utm_source=link-attribution&utm_medium=referral&utm_campaign=music&utm_content=142528">Pixabay</a>
package/index.js CHANGED
@@ -6,7 +6,7 @@
6
6
  import {degToRad} from "wgpu-matrix/dist/2.x/utils.js";
7
7
  import {downloadMeshes} from "./src/engine/loader-obj.js";
8
8
  import MatrixEngineWGPU from "./src/meWGPU.js";
9
- import {getRayFromMouse, rayIntersectsSphere} from "./src/engine/raycast.js";
9
+ import {addRaycastListener, getRayFromMouse, rayIntersectsSphere} from "./src/engine/raycast.js";
10
10
 
11
11
  var about = () => {
12
12
  console.log("Hi npm. matrix-engine for webgpu is ready...")