@mborecki/memory-game 0.3.4 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/memory-game/index-Br8RptzJ.js +6135 -0
- package/dist/memory-game/index-Br8RptzJ.js.map +1 -0
- package/dist/memory-game/index.esm.js +4 -0
- package/dist/memory-game/index.esm.js.map +1 -0
- package/dist/{esm → memory-game}/mb-memory-game.entry.js +15 -6
- package/dist/memory-game/mb-memory-game.entry.js.map +1 -0
- package/dist/memory-game/memory-game.esm.js +50 -1
- package/dist/memory-game/memory-game.esm.js.map +1 -0
- package/dist/types/components/sliding-puzzle/memory-game.d.ts +2 -0
- package/dist/types/components.d.ts +8 -0
- package/dist/types/roboczy/mb-puzzle/apps/memory-game/.stencil/shared/grid/src/grid.d.ts +2 -0
- package/package.json +2 -2
- package/dist/cjs/app-globals-V2Kpy_OQ.js +0 -5
- package/dist/cjs/index-D_ddvJ2f.js +0 -3228
- package/dist/cjs/index.cjs.js +0 -2
- package/dist/cjs/loader.cjs.js +0 -13
- package/dist/cjs/mb-memory-game.cjs.entry.js +0 -211
- package/dist/cjs/memory-game.cjs.js +0 -25
- package/dist/collection/collection-manifest.json +0 -12
- package/dist/collection/components/sliding-puzzle/memory-game.css +0 -72
- package/dist/collection/components/sliding-puzzle/memory-game.js +0 -354
- package/dist/collection/components/sliding-puzzle/tile.js +0 -16
- package/dist/collection/components/sliding-puzzle/types.js +0 -1
- package/dist/collection/index.js +0 -1
- package/dist/collection/utils/get-set.js +0 -23
- package/dist/collection/utils/get-set.test.js +0 -31
- package/dist/components/index.js +0 -1
- package/dist/components/mb-memory-game.js +0 -1
- package/dist/esm/app-globals-DQuL1Twl.js +0 -3
- package/dist/esm/index-D2pBOsDL.js +0 -3221
- package/dist/esm/index.js +0 -1
- package/dist/esm/loader.js +0 -11
- package/dist/esm/memory-game.js +0 -21
- package/dist/index.cjs.js +0 -1
- package/dist/index.js +0 -1
- package/dist/memory-game/p-0918f52d.entry.js +0 -1
- package/dist/memory-game/p-D2pBOsDL.js +0 -2
- package/dist/memory-game/p-DQuL1Twl.js +0 -1
- package/dist/vitest.config.js +0 -4
package/dist/cjs/index.cjs.js
DELETED
package/dist/cjs/loader.cjs.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var index = require('./index-D_ddvJ2f.js');
|
|
4
|
-
var appGlobals = require('./app-globals-V2Kpy_OQ.js');
|
|
5
|
-
|
|
6
|
-
const defineCustomElements = async (win, options) => {
|
|
7
|
-
if (typeof window === 'undefined') return undefined;
|
|
8
|
-
await appGlobals.globalScripts();
|
|
9
|
-
return index.bootstrapLazy([["mb-memory-game.cjs",[[513,"mb-memory-game",{"tileGroups":[16],"reverseTile":[16],"init":[4],"cols":[2],"tiles":[32],"selected":[32],"matchedTiles":[32],"initGame":[64]},null,{"tileGroups":[{"watchTileGroups":0}],"matchedTiles":[{"watchMatchedTiles":0}]}]]]], options);
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
exports.setNonce = index.setNonce;
|
|
13
|
-
exports.defineCustomElements = defineCustomElements;
|
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var index = require('./index-D_ddvJ2f.js');
|
|
4
|
-
|
|
5
|
-
function getSet(items, count) {
|
|
6
|
-
console.log('getSet', items, count);
|
|
7
|
-
if (items.length <= 0)
|
|
8
|
-
throw new Error("getSet() - no items");
|
|
9
|
-
if (items.length === count) {
|
|
10
|
-
return [...items];
|
|
11
|
-
}
|
|
12
|
-
let result = [];
|
|
13
|
-
while (count - result.length > items.length) {
|
|
14
|
-
result = [
|
|
15
|
-
...result,
|
|
16
|
-
...items
|
|
17
|
-
];
|
|
18
|
-
}
|
|
19
|
-
const rest = new Set();
|
|
20
|
-
while (rest.size < count - result.length) {
|
|
21
|
-
rest.add(items[Math.floor(Math.random() * items.length)]);
|
|
22
|
-
}
|
|
23
|
-
return [
|
|
24
|
-
...result,
|
|
25
|
-
...rest
|
|
26
|
-
];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function Tile({ tile, selected, matched, uncovered, reversTile }) {
|
|
30
|
-
return index.h("div", { part: "tile", class: {
|
|
31
|
-
'tile-container': true,
|
|
32
|
-
selected,
|
|
33
|
-
matched
|
|
34
|
-
} }, index.h(TileRender, { tile: uncovered ? tile.data : reversTile }));
|
|
35
|
-
}
|
|
36
|
-
function TileRender({ tile }) {
|
|
37
|
-
if (tile.type === 'text') {
|
|
38
|
-
return index.h("button", { class: "tile tile-text" }, tile.text);
|
|
39
|
-
}
|
|
40
|
-
if (tile.type === 'image') {
|
|
41
|
-
return index.h("button", { class: "tile tile-image" }, index.h("img", { src: tile.imageSrc }));
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const memoryGameCss = () => `:host{box-sizing:border-box;display:grid;place-content:center;width:100%;height:100%;container-type:size}[part=container]{width:min(100cqw, 100cqh / var(--aspect, 1));height:min(100cqw * var(--aspect, 1), 100cqh);container-type:size}[part=list]{width:100cqw;height:100cqh;display:grid;grid-template-columns:repeat(var(--cols, 4), 1fr);grid-template-rows:repeat(var(--rows, 4), 1fr)}[part=tile-slot]{display:block;aspect-ratio:1;padding:5%}.tile-container{min-width:0;transition:scale 0.3s;width:100%;height:100%}.tile-container:hover{scale:1.05}.tile-container.selected{scale:1.1}.tile-container.matched{scale:0}.tile{border-radius:var(--tile-border-radius, 5px);border:var(--tile-border-width, 2px) solid var(--tile-border-color, black);overflow:hidden;padding:0;margin:0}.tile-text{width:100%;height:100%;aspect-ratio:1;background:#d9d9d9;display:grid;place-content:center}.tile-image{width:100%;height:100%}.tile-image img{display:block;width:100%;height:100%;object-fit:cover}`;
|
|
46
|
-
|
|
47
|
-
const MbMemoryGame = class {
|
|
48
|
-
constructor(hostRef) {
|
|
49
|
-
index.registerInstance(this, hostRef);
|
|
50
|
-
this.completed = index.createEvent(this, "completed");
|
|
51
|
-
this.matched = index.createEvent(this, "matched");
|
|
52
|
-
}
|
|
53
|
-
tileGroups = [];
|
|
54
|
-
watchTileGroups() {
|
|
55
|
-
console.log('watchTileGroups');
|
|
56
|
-
if (this.init) {
|
|
57
|
-
this.initGame();
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
reverseTile = { type: 'text', text: '?' };
|
|
61
|
-
init = true;
|
|
62
|
-
tiles = [];
|
|
63
|
-
selected = [];
|
|
64
|
-
matchedTiles = [];
|
|
65
|
-
watchMatchedTiles() {
|
|
66
|
-
if (this.matchedTiles.length === this.tiles.length) {
|
|
67
|
-
this.completed.emit();
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
cols;
|
|
71
|
-
blockUI = false;
|
|
72
|
-
completed;
|
|
73
|
-
matched;
|
|
74
|
-
componentWillLoad() {
|
|
75
|
-
console.log('componentDidLoad', this.init, this.tileGroups, this.reverseTile);
|
|
76
|
-
if (this.init && this.tileGroups.length) {
|
|
77
|
-
this.initGame();
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
slots = new Map();
|
|
81
|
-
get gridCols() {
|
|
82
|
-
if (this.cols) {
|
|
83
|
-
return this.cols;
|
|
84
|
-
}
|
|
85
|
-
return Math.floor(Math.sqrt(this.tiles.length));
|
|
86
|
-
}
|
|
87
|
-
get gridRows() {
|
|
88
|
-
return Math.ceil(this.tiles.length / this.gridCols);
|
|
89
|
-
}
|
|
90
|
-
get gridAspectRatio() {
|
|
91
|
-
return this.gridRows / this.gridCols;
|
|
92
|
-
}
|
|
93
|
-
async initGame(tileGroups = this.tileGroups, reverseTile = this.reverseTile) {
|
|
94
|
-
console.log('initGame', tileGroups);
|
|
95
|
-
this.reverseTile = reverseTile;
|
|
96
|
-
this.buildTiles(tileGroups);
|
|
97
|
-
}
|
|
98
|
-
buildTiles(tileGroups) {
|
|
99
|
-
let result = [];
|
|
100
|
-
let index = 0;
|
|
101
|
-
tileGroups.forEach(tg => {
|
|
102
|
-
const tiles = getSet(tg.tiles, tg.count);
|
|
103
|
-
result = [
|
|
104
|
-
...result,
|
|
105
|
-
...tiles.map(t => {
|
|
106
|
-
return {
|
|
107
|
-
id: index++,
|
|
108
|
-
data: { ...t },
|
|
109
|
-
groupId: tg.id,
|
|
110
|
-
uncovered: false,
|
|
111
|
-
matched: false
|
|
112
|
-
};
|
|
113
|
-
})
|
|
114
|
-
];
|
|
115
|
-
});
|
|
116
|
-
this.tiles = result.sort(() => Math.random() - .5);
|
|
117
|
-
}
|
|
118
|
-
async onTileClick(id) {
|
|
119
|
-
if (this.blockUI)
|
|
120
|
-
return;
|
|
121
|
-
if (this.selected.includes(id)) {
|
|
122
|
-
this.selected = this.selected.filter(i => i !== id);
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
this.selected = [...this.selected, id];
|
|
126
|
-
if (this.selected.length === 2) {
|
|
127
|
-
const t1 = this.tiles.find(t => t.id === this.selected[0]);
|
|
128
|
-
const t2 = this.tiles.find(t => t.id === this.selected[1]);
|
|
129
|
-
if (!t1 || !t2)
|
|
130
|
-
return;
|
|
131
|
-
this.blockUI = true;
|
|
132
|
-
if (t1.groupId === t2.groupId) {
|
|
133
|
-
await Promise.all([
|
|
134
|
-
this.markAsMatched(t1.id),
|
|
135
|
-
this.markAsMatched(t2.id)
|
|
136
|
-
]);
|
|
137
|
-
this.matched.emit({ t1: t1.data, t2: t2.data, groupId: t1.groupId });
|
|
138
|
-
this.matchedTiles = [
|
|
139
|
-
...this.matchedTiles, t1.id, t2.id
|
|
140
|
-
];
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
await Promise.all([
|
|
144
|
-
this.animateWrongMatch(t1.id),
|
|
145
|
-
this.animateWrongMatch(t2.id)
|
|
146
|
-
]);
|
|
147
|
-
}
|
|
148
|
-
this.blockUI = false;
|
|
149
|
-
this.selected = [];
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
markAsMatched(id) {
|
|
153
|
-
return new Promise(resolve => {
|
|
154
|
-
const slot = this.slots.get(id);
|
|
155
|
-
if (!slot)
|
|
156
|
-
return;
|
|
157
|
-
const tile = slot.children[0];
|
|
158
|
-
const anim = tile.animate([], { duration: 1000 });
|
|
159
|
-
anim.addEventListener('finish', () => {
|
|
160
|
-
resolve();
|
|
161
|
-
});
|
|
162
|
-
anim.addEventListener('cancel', () => {
|
|
163
|
-
resolve();
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
animateWrongMatch(id) {
|
|
168
|
-
return new Promise(resolve => {
|
|
169
|
-
const slot = this.slots.get(id);
|
|
170
|
-
if (!slot)
|
|
171
|
-
return;
|
|
172
|
-
const tile = slot.children[0];
|
|
173
|
-
const anim = tile.animate([
|
|
174
|
-
{ rotate: "0deg" },
|
|
175
|
-
{ rotate: "0deg" },
|
|
176
|
-
{ rotate: "30deg" },
|
|
177
|
-
{ rotate: "0deg" },
|
|
178
|
-
{ rotate: "-30deg" },
|
|
179
|
-
{ rotate: "0deg" },
|
|
180
|
-
{ rotate: "0deg" },
|
|
181
|
-
], { duration: 1500 });
|
|
182
|
-
anim.addEventListener('finish', () => {
|
|
183
|
-
resolve();
|
|
184
|
-
});
|
|
185
|
-
anim.addEventListener('cancel', () => {
|
|
186
|
-
resolve();
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
render() {
|
|
191
|
-
return index.h("div", { key: '18002b4e8ba84bb065f5ecbff5e1a3cde40065bd', part: "container", style: {
|
|
192
|
-
'--aspect': `${this.gridAspectRatio}`
|
|
193
|
-
} }, index.h("div", { key: '2ac6345adfd73b0690d3e5e3fc34e351c9f9bfd4', part: "list", style: {
|
|
194
|
-
'--cols': `${this.gridCols}`,
|
|
195
|
-
'--rows': `${this.gridRows}`
|
|
196
|
-
} }, this.tiles.map(t => {
|
|
197
|
-
return index.h("div", { part: "tile-slot", onClick: () => this.onTileClick(t.id), ref: el => this.slots.set(t.id, el) }, index.h(Tile, { tile: t, selected: this.selected.includes(t.id), matched: this.matchedTiles.includes(t.id), reversTile: this.reverseTile, uncovered: this.selected.includes(t.id) }));
|
|
198
|
-
})));
|
|
199
|
-
}
|
|
200
|
-
static get watchers() { return {
|
|
201
|
-
"tileGroups": [{
|
|
202
|
-
"watchTileGroups": 0
|
|
203
|
-
}],
|
|
204
|
-
"matchedTiles": [{
|
|
205
|
-
"watchMatchedTiles": 0
|
|
206
|
-
}]
|
|
207
|
-
}; }
|
|
208
|
-
};
|
|
209
|
-
MbMemoryGame.style = memoryGameCss();
|
|
210
|
-
|
|
211
|
-
exports.mb_memory_game = MbMemoryGame;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var index = require('./index-D_ddvJ2f.js');
|
|
4
|
-
var appGlobals = require('./app-globals-V2Kpy_OQ.js');
|
|
5
|
-
|
|
6
|
-
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
7
|
-
/*
|
|
8
|
-
Stencil Client Patch Browser v4.41.0 | MIT Licensed | https://stenciljs.com
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
var patchBrowser = () => {
|
|
12
|
-
const importMeta = (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('memory-game.cjs.js', document.baseURI).href));
|
|
13
|
-
const opts = {};
|
|
14
|
-
if (importMeta !== "") {
|
|
15
|
-
opts.resourcesUrl = new URL(".", importMeta).href;
|
|
16
|
-
}
|
|
17
|
-
return index.promiseResolve(opts);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
patchBrowser().then(async (options) => {
|
|
21
|
-
await appGlobals.globalScripts();
|
|
22
|
-
return index.bootstrapLazy([["mb-memory-game.cjs",[[513,"mb-memory-game",{"tileGroups":[16],"reverseTile":[16],"init":[4],"cols":[2],"tiles":[32],"selected":[32],"matchedTiles":[32],"initGame":[64]},null,{"tileGroups":[{"watchTileGroups":0}],"matchedTiles":[{"watchMatchedTiles":0}]}]]]], options);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
exports.setNonce = index.setNonce;
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
:host {
|
|
2
|
-
box-sizing: border-box;
|
|
3
|
-
display: grid;
|
|
4
|
-
place-content: center;
|
|
5
|
-
width: 100%;
|
|
6
|
-
height: 100%;
|
|
7
|
-
container-type: size;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
[part=container] {
|
|
11
|
-
width: min(100cqw, 100cqh / var(--aspect, 1));
|
|
12
|
-
height: min(100cqw * var(--aspect, 1), 100cqh);
|
|
13
|
-
container-type: size;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
[part=list] {
|
|
17
|
-
width: 100cqw;
|
|
18
|
-
height: 100cqh;
|
|
19
|
-
display: grid;
|
|
20
|
-
grid-template-columns: repeat(var(--cols, 4), 1fr);
|
|
21
|
-
grid-template-rows: repeat(var(--rows, 4), 1fr);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
[part=tile-slot] {
|
|
25
|
-
display: block;
|
|
26
|
-
aspect-ratio: 1;
|
|
27
|
-
padding: 5%;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
.tile-container {
|
|
31
|
-
min-width: 0;
|
|
32
|
-
transition: scale 0.3s;
|
|
33
|
-
width: 100%;
|
|
34
|
-
height: 100%;
|
|
35
|
-
}
|
|
36
|
-
.tile-container:hover {
|
|
37
|
-
scale: 1.05;
|
|
38
|
-
}
|
|
39
|
-
.tile-container.selected {
|
|
40
|
-
scale: 1.1;
|
|
41
|
-
}
|
|
42
|
-
.tile-container.matched {
|
|
43
|
-
scale: 0;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
.tile {
|
|
47
|
-
border-radius: var(--tile-border-radius, 5px);
|
|
48
|
-
border: var(--tile-border-width, 2px) solid var(--tile-border-color, black);
|
|
49
|
-
overflow: hidden;
|
|
50
|
-
padding: 0;
|
|
51
|
-
margin: 0;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
.tile-text {
|
|
55
|
-
width: 100%;
|
|
56
|
-
height: 100%;
|
|
57
|
-
aspect-ratio: 1;
|
|
58
|
-
background: #d9d9d9;
|
|
59
|
-
display: grid;
|
|
60
|
-
place-content: center;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
.tile-image {
|
|
64
|
-
width: 100%;
|
|
65
|
-
height: 100%;
|
|
66
|
-
}
|
|
67
|
-
.tile-image img {
|
|
68
|
-
display: block;
|
|
69
|
-
width: 100%;
|
|
70
|
-
height: 100%;
|
|
71
|
-
object-fit: cover;
|
|
72
|
-
}
|
|
@@ -1,354 +0,0 @@
|
|
|
1
|
-
import { h } from "@stencil/core";
|
|
2
|
-
import { getSet } from "../../utils/get-set";
|
|
3
|
-
import { Tile } from "./tile";
|
|
4
|
-
export class MbMemoryGame {
|
|
5
|
-
tileGroups = [];
|
|
6
|
-
watchTileGroups() {
|
|
7
|
-
console.log('watchTileGroups');
|
|
8
|
-
if (this.init) {
|
|
9
|
-
this.initGame();
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
reverseTile = { type: 'text', text: '?' };
|
|
13
|
-
init = true;
|
|
14
|
-
tiles = [];
|
|
15
|
-
selected = [];
|
|
16
|
-
matchedTiles = [];
|
|
17
|
-
watchMatchedTiles() {
|
|
18
|
-
if (this.matchedTiles.length === this.tiles.length) {
|
|
19
|
-
this.completed.emit();
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
cols;
|
|
23
|
-
blockUI = false;
|
|
24
|
-
completed;
|
|
25
|
-
matched;
|
|
26
|
-
componentWillLoad() {
|
|
27
|
-
console.log('componentDidLoad', this.init, this.tileGroups, this.reverseTile);
|
|
28
|
-
if (this.init && this.tileGroups.length) {
|
|
29
|
-
this.initGame();
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
slots = new Map();
|
|
33
|
-
get gridCols() {
|
|
34
|
-
if (this.cols) {
|
|
35
|
-
return this.cols;
|
|
36
|
-
}
|
|
37
|
-
return Math.floor(Math.sqrt(this.tiles.length));
|
|
38
|
-
}
|
|
39
|
-
get gridRows() {
|
|
40
|
-
return Math.ceil(this.tiles.length / this.gridCols);
|
|
41
|
-
}
|
|
42
|
-
get gridAspectRatio() {
|
|
43
|
-
return this.gridRows / this.gridCols;
|
|
44
|
-
}
|
|
45
|
-
async initGame(tileGroups = this.tileGroups, reverseTile = this.reverseTile) {
|
|
46
|
-
console.log('initGame', tileGroups);
|
|
47
|
-
this.reverseTile = reverseTile;
|
|
48
|
-
this.buildTiles(tileGroups);
|
|
49
|
-
}
|
|
50
|
-
buildTiles(tileGroups) {
|
|
51
|
-
let result = [];
|
|
52
|
-
let index = 0;
|
|
53
|
-
tileGroups.forEach(tg => {
|
|
54
|
-
const tiles = getSet(tg.tiles, tg.count);
|
|
55
|
-
result = [
|
|
56
|
-
...result,
|
|
57
|
-
...tiles.map(t => {
|
|
58
|
-
return {
|
|
59
|
-
id: index++,
|
|
60
|
-
data: { ...t },
|
|
61
|
-
groupId: tg.id,
|
|
62
|
-
uncovered: false,
|
|
63
|
-
matched: false
|
|
64
|
-
};
|
|
65
|
-
})
|
|
66
|
-
];
|
|
67
|
-
});
|
|
68
|
-
this.tiles = result.sort(() => Math.random() - .5);
|
|
69
|
-
}
|
|
70
|
-
async onTileClick(id) {
|
|
71
|
-
if (this.blockUI)
|
|
72
|
-
return;
|
|
73
|
-
if (this.selected.includes(id)) {
|
|
74
|
-
this.selected = this.selected.filter(i => i !== id);
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
this.selected = [...this.selected, id];
|
|
78
|
-
if (this.selected.length === 2) {
|
|
79
|
-
const t1 = this.tiles.find(t => t.id === this.selected[0]);
|
|
80
|
-
const t2 = this.tiles.find(t => t.id === this.selected[1]);
|
|
81
|
-
if (!t1 || !t2)
|
|
82
|
-
return;
|
|
83
|
-
this.blockUI = true;
|
|
84
|
-
if (t1.groupId === t2.groupId) {
|
|
85
|
-
await Promise.all([
|
|
86
|
-
this.markAsMatched(t1.id),
|
|
87
|
-
this.markAsMatched(t2.id)
|
|
88
|
-
]);
|
|
89
|
-
this.matched.emit({ t1: t1.data, t2: t2.data, groupId: t1.groupId });
|
|
90
|
-
this.matchedTiles = [
|
|
91
|
-
...this.matchedTiles, t1.id, t2.id
|
|
92
|
-
];
|
|
93
|
-
}
|
|
94
|
-
else {
|
|
95
|
-
await Promise.all([
|
|
96
|
-
this.animateWrongMatch(t1.id),
|
|
97
|
-
this.animateWrongMatch(t2.id)
|
|
98
|
-
]);
|
|
99
|
-
}
|
|
100
|
-
this.blockUI = false;
|
|
101
|
-
this.selected = [];
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
markAsMatched(id) {
|
|
105
|
-
return new Promise(resolve => {
|
|
106
|
-
const slot = this.slots.get(id);
|
|
107
|
-
if (!slot)
|
|
108
|
-
return;
|
|
109
|
-
const tile = slot.children[0];
|
|
110
|
-
const anim = tile.animate([], { duration: 1000 });
|
|
111
|
-
anim.addEventListener('finish', () => {
|
|
112
|
-
resolve();
|
|
113
|
-
});
|
|
114
|
-
anim.addEventListener('cancel', () => {
|
|
115
|
-
resolve();
|
|
116
|
-
});
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
animateWrongMatch(id) {
|
|
120
|
-
return new Promise(resolve => {
|
|
121
|
-
const slot = this.slots.get(id);
|
|
122
|
-
if (!slot)
|
|
123
|
-
return;
|
|
124
|
-
const tile = slot.children[0];
|
|
125
|
-
const anim = tile.animate([
|
|
126
|
-
{ rotate: "0deg" },
|
|
127
|
-
{ rotate: "0deg" },
|
|
128
|
-
{ rotate: "30deg" },
|
|
129
|
-
{ rotate: "0deg" },
|
|
130
|
-
{ rotate: "-30deg" },
|
|
131
|
-
{ rotate: "0deg" },
|
|
132
|
-
{ rotate: "0deg" },
|
|
133
|
-
], { duration: 1500 });
|
|
134
|
-
anim.addEventListener('finish', () => {
|
|
135
|
-
resolve();
|
|
136
|
-
});
|
|
137
|
-
anim.addEventListener('cancel', () => {
|
|
138
|
-
resolve();
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
render() {
|
|
143
|
-
return h("div", { key: '18002b4e8ba84bb065f5ecbff5e1a3cde40065bd', part: "container", style: {
|
|
144
|
-
'--aspect': `${this.gridAspectRatio}`
|
|
145
|
-
} }, h("div", { key: '2ac6345adfd73b0690d3e5e3fc34e351c9f9bfd4', part: "list", style: {
|
|
146
|
-
'--cols': `${this.gridCols}`,
|
|
147
|
-
'--rows': `${this.gridRows}`
|
|
148
|
-
} }, this.tiles.map(t => {
|
|
149
|
-
return h("div", { part: "tile-slot", onClick: () => this.onTileClick(t.id), ref: el => this.slots.set(t.id, el) }, h(Tile, { tile: t, selected: this.selected.includes(t.id), matched: this.matchedTiles.includes(t.id), reversTile: this.reverseTile, uncovered: this.selected.includes(t.id) }));
|
|
150
|
-
})));
|
|
151
|
-
}
|
|
152
|
-
static get is() { return "mb-memory-game"; }
|
|
153
|
-
static get encapsulation() { return "shadow"; }
|
|
154
|
-
static get originalStyleUrls() {
|
|
155
|
-
return {
|
|
156
|
-
"$": ["memory-game.scss"]
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
static get styleUrls() {
|
|
160
|
-
return {
|
|
161
|
-
"$": ["memory-game.css"]
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
static get properties() {
|
|
165
|
-
return {
|
|
166
|
-
"tileGroups": {
|
|
167
|
-
"type": "unknown",
|
|
168
|
-
"mutable": false,
|
|
169
|
-
"complexType": {
|
|
170
|
-
"original": "TileGroup[]",
|
|
171
|
-
"resolved": "TileGroup[]",
|
|
172
|
-
"references": {
|
|
173
|
-
"TileGroup": {
|
|
174
|
-
"location": "import",
|
|
175
|
-
"path": "./types",
|
|
176
|
-
"id": "src/components/sliding-puzzle/types.ts::TileGroup",
|
|
177
|
-
"referenceLocation": "TileGroup"
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
},
|
|
181
|
-
"required": false,
|
|
182
|
-
"optional": false,
|
|
183
|
-
"docs": {
|
|
184
|
-
"tags": [],
|
|
185
|
-
"text": ""
|
|
186
|
-
},
|
|
187
|
-
"getter": false,
|
|
188
|
-
"setter": false,
|
|
189
|
-
"defaultValue": "[]"
|
|
190
|
-
},
|
|
191
|
-
"reverseTile": {
|
|
192
|
-
"type": "unknown",
|
|
193
|
-
"mutable": false,
|
|
194
|
-
"complexType": {
|
|
195
|
-
"original": "TileDefinition",
|
|
196
|
-
"resolved": "TileDefinition",
|
|
197
|
-
"references": {
|
|
198
|
-
"TileDefinition": {
|
|
199
|
-
"location": "import",
|
|
200
|
-
"path": "./types",
|
|
201
|
-
"id": "src/components/sliding-puzzle/types.ts::TileDefinition",
|
|
202
|
-
"referenceLocation": "TileDefinition"
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
},
|
|
206
|
-
"required": false,
|
|
207
|
-
"optional": false,
|
|
208
|
-
"docs": {
|
|
209
|
-
"tags": [],
|
|
210
|
-
"text": ""
|
|
211
|
-
},
|
|
212
|
-
"getter": false,
|
|
213
|
-
"setter": false,
|
|
214
|
-
"defaultValue": "{ type: 'text', text: '?' }"
|
|
215
|
-
},
|
|
216
|
-
"init": {
|
|
217
|
-
"type": "boolean",
|
|
218
|
-
"mutable": false,
|
|
219
|
-
"complexType": {
|
|
220
|
-
"original": "boolean",
|
|
221
|
-
"resolved": "boolean",
|
|
222
|
-
"references": {}
|
|
223
|
-
},
|
|
224
|
-
"required": false,
|
|
225
|
-
"optional": false,
|
|
226
|
-
"docs": {
|
|
227
|
-
"tags": [],
|
|
228
|
-
"text": ""
|
|
229
|
-
},
|
|
230
|
-
"getter": false,
|
|
231
|
-
"setter": false,
|
|
232
|
-
"reflect": false,
|
|
233
|
-
"attribute": "init",
|
|
234
|
-
"defaultValue": "true"
|
|
235
|
-
},
|
|
236
|
-
"cols": {
|
|
237
|
-
"type": "number",
|
|
238
|
-
"mutable": false,
|
|
239
|
-
"complexType": {
|
|
240
|
-
"original": "number",
|
|
241
|
-
"resolved": "number",
|
|
242
|
-
"references": {}
|
|
243
|
-
},
|
|
244
|
-
"required": false,
|
|
245
|
-
"optional": true,
|
|
246
|
-
"docs": {
|
|
247
|
-
"tags": [],
|
|
248
|
-
"text": ""
|
|
249
|
-
},
|
|
250
|
-
"getter": false,
|
|
251
|
-
"setter": false,
|
|
252
|
-
"reflect": false,
|
|
253
|
-
"attribute": "cols"
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
}
|
|
257
|
-
static get states() {
|
|
258
|
-
return {
|
|
259
|
-
"tiles": {},
|
|
260
|
-
"selected": {},
|
|
261
|
-
"matchedTiles": {}
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
static get events() {
|
|
265
|
-
return [{
|
|
266
|
-
"method": "completed",
|
|
267
|
-
"name": "completed",
|
|
268
|
-
"bubbles": true,
|
|
269
|
-
"cancelable": true,
|
|
270
|
-
"composed": true,
|
|
271
|
-
"docs": {
|
|
272
|
-
"tags": [],
|
|
273
|
-
"text": ""
|
|
274
|
-
},
|
|
275
|
-
"complexType": {
|
|
276
|
-
"original": "void",
|
|
277
|
-
"resolved": "void",
|
|
278
|
-
"references": {}
|
|
279
|
-
}
|
|
280
|
-
}, {
|
|
281
|
-
"method": "matched",
|
|
282
|
-
"name": "matched",
|
|
283
|
-
"bubbles": true,
|
|
284
|
-
"cancelable": true,
|
|
285
|
-
"composed": true,
|
|
286
|
-
"docs": {
|
|
287
|
-
"tags": [],
|
|
288
|
-
"text": ""
|
|
289
|
-
},
|
|
290
|
-
"complexType": {
|
|
291
|
-
"original": "MatchedEvent",
|
|
292
|
-
"resolved": "MatchedEvent",
|
|
293
|
-
"references": {
|
|
294
|
-
"MatchedEvent": {
|
|
295
|
-
"location": "import",
|
|
296
|
-
"path": "./types",
|
|
297
|
-
"id": "src/components/sliding-puzzle/types.ts::MatchedEvent",
|
|
298
|
-
"referenceLocation": "MatchedEvent"
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
}];
|
|
303
|
-
}
|
|
304
|
-
static get methods() {
|
|
305
|
-
return {
|
|
306
|
-
"initGame": {
|
|
307
|
-
"complexType": {
|
|
308
|
-
"signature": "(tileGroups?: TileGroup[], reverseTile?: TileDefinition) => Promise<void>",
|
|
309
|
-
"parameters": [{
|
|
310
|
-
"name": "tileGroups",
|
|
311
|
-
"type": "TileGroup[]",
|
|
312
|
-
"docs": ""
|
|
313
|
-
}, {
|
|
314
|
-
"name": "reverseTile",
|
|
315
|
-
"type": "TileDefinition",
|
|
316
|
-
"docs": ""
|
|
317
|
-
}],
|
|
318
|
-
"references": {
|
|
319
|
-
"Promise": {
|
|
320
|
-
"location": "global",
|
|
321
|
-
"id": "global::Promise"
|
|
322
|
-
},
|
|
323
|
-
"TileGroup": {
|
|
324
|
-
"location": "import",
|
|
325
|
-
"path": "./types",
|
|
326
|
-
"id": "src/components/sliding-puzzle/types.ts::TileGroup",
|
|
327
|
-
"referenceLocation": "TileGroup"
|
|
328
|
-
},
|
|
329
|
-
"TileDefinition": {
|
|
330
|
-
"location": "import",
|
|
331
|
-
"path": "./types",
|
|
332
|
-
"id": "src/components/sliding-puzzle/types.ts::TileDefinition",
|
|
333
|
-
"referenceLocation": "TileDefinition"
|
|
334
|
-
}
|
|
335
|
-
},
|
|
336
|
-
"return": "Promise<void>"
|
|
337
|
-
},
|
|
338
|
-
"docs": {
|
|
339
|
-
"text": "",
|
|
340
|
-
"tags": []
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
static get watchers() {
|
|
346
|
-
return [{
|
|
347
|
-
"propName": "tileGroups",
|
|
348
|
-
"methodName": "watchTileGroups"
|
|
349
|
-
}, {
|
|
350
|
-
"propName": "matchedTiles",
|
|
351
|
-
"methodName": "watchMatchedTiles"
|
|
352
|
-
}];
|
|
353
|
-
}
|
|
354
|
-
}
|