@jamesrock/rockjs 1.30.0 → 1.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +45 -12
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -121,12 +121,13 @@ export const makeOutput = (rows = 7) => {
121
121
 
122
122
  export const makeContainer = (className) => makeNode('div', className);
123
123
 
124
- export const makeSelect = (options) => {
124
+ export const makeSelect = (options, defaultValue = options[0][1]) => {
125
125
  const node = makeNode('select');
126
126
  options.forEach(([label, value]) => {
127
127
  const option = makeOption(label, value);
128
128
  node.appendChild(option);
129
- })
129
+ });
130
+ node.value = defaultValue;
130
131
  return node;
131
132
  };
132
133
 
@@ -220,6 +221,47 @@ export const makeHexMap = (full = true) => {
220
221
  return out;
221
222
  };
222
223
 
224
+ export const makeMap = (items, key = 'id') => {
225
+ const out = {};
226
+ items.forEach((item) => {
227
+ out[item[key]] = item;
228
+ });
229
+ return out;
230
+ };
231
+
232
+ export const addDragListeners = (target, tolerance) => {
233
+
234
+ const rounder = new Rounder(tolerance);
235
+ let touch = null;
236
+
237
+ target.addEventListener('touchstart', (e) => {
238
+
239
+ touch = e.touches[0];
240
+ e.preventDefault();
241
+
242
+ });
243
+
244
+ target.addEventListener('touchmove', (e) => {
245
+
246
+ const {clientX: originalClientX, clientY: originalClientY} = touch;
247
+ const {clientX, clientY} = e.touches[0];
248
+ const x = rounder.round(clientX - originalClientX);
249
+ const y = rounder.round(clientY - originalClientY);
250
+
251
+ if(x) {
252
+ touch = e.touches[0];
253
+ target.dispatchEvent(new Event(x > 0 ? 'drag-right' : 'drag-left'));
254
+ };
255
+
256
+ if(y) {
257
+ touch = e.touches[0];
258
+ target.dispatchEvent(new Event(y > 0 ? 'drag-down' : 'drag-up'));
259
+ };
260
+
261
+ });
262
+
263
+ };
264
+
223
265
  export class Storage {
224
266
  constructor(namespace) {
225
267
 
@@ -699,7 +741,7 @@ export class DeckOfPlayingCards {
699
741
  this.sprite = sprite;
700
742
  this.cardMaker = cardMaker;
701
743
  this.cards = saved.length ? this.makeFromSaved(saved) : this.make();
702
- this.map = this.makeMap();
744
+ this.map = makeMap(this.cards);
703
745
  this.shuffledMap = this.makeShuffledMap();
704
746
 
705
747
  };
@@ -707,15 +749,6 @@ export class DeckOfPlayingCards {
707
749
 
708
750
  return shuffle(shuffle(this.makeDeckValues().map(([value, suit]) => this.cardMaker(this, value, suit))));
709
751
 
710
- };
711
- makeMap() {
712
-
713
- var out = {};
714
- this.cards.forEach((card) => {
715
- out[card.id] = card;
716
- });
717
- return out;
718
-
719
752
  };
720
753
  makeShuffledMap() {
721
754
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jamesrock/rockjs",
3
- "version": "1.30.0",
3
+ "version": "1.31.0",
4
4
  "description": "utility bliss",
5
5
  "license": "ISC",
6
6
  "author": "James Rock",