-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTile.js
More file actions
41 lines (40 loc) · 1.12 KB
/
Tile.js
File metadata and controls
41 lines (40 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
export default class Tile{
#tileElement
#x
#y
#value
constructor(tilecontainer,value = Math.random() >0.5 ? 2: 4){
this.#tileElement=document.createElement('div')
this.#tileElement.classList.add('tile')
this.value=value
tilecontainer.appendChild(this.#tileElement)
}
get value(){
return this.#value
}
set value(v){
this.#value=v
this.#tileElement.textContent=v
let bglightness=100-Math.log(v)*9
this.#tileElement.style.setProperty('--background-lightness',`${bglightness}%`)
this.#tileElement.style.setProperty('--text-lightness',`${bglightness<50 ? 90 :10}%`)
}
set x(values){
this.#x=values
this.#tileElement.style.setProperty('--x',values)
//this.#tileElement.style.left=`${2 + 22*values}vmin`
}
set y(values){
this.#y=values
this.#tileElement.style.setProperty('--y',values)
// this.#tileElement.style.top=`${2+22*values}vmin`
}
remove(){
this.#tileElement.remove()
}
waitfortrans(animation =false){
return new Promise(resolve =>{
this.#tileElement.addEventListener(animation ? 'animationend' : 'transitionend',resolve,{once:true})
})
}
}