2023-09-30 19:20:27 +00:00
|
|
|
class Rect extends HTMLElement {
|
2023-09-24 18:37:22 +00:00
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
|
2023-09-30 19:20:27 +00:00
|
|
|
this.perspective = 1200
|
|
|
|
this.topColor = '#666666'
|
|
|
|
this.botColor = this.topColor
|
|
|
|
this.rightColor = '#333333'
|
|
|
|
this.leftColor = this.rightColor
|
|
|
|
this.frontColor = 'rgba(255,255,255,0.3)'
|
|
|
|
this.backColor = this.frontColor
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
createRect() {
|
|
|
|
const wrapper = document.createElement("div")
|
|
|
|
wrapper.setAttribute("class", "wrapper")
|
2023-09-24 18:37:22 +00:00
|
|
|
|
2023-09-30 19:20:27 +00:00
|
|
|
const rect = document.createElement("span")
|
|
|
|
rect.setAttribute("class", "rect")
|
2023-09-24 18:37:22 +00:00
|
|
|
|
2023-09-30 19:20:27 +00:00
|
|
|
const topshelf = rect.appendChild(document.createElement("div"));
|
2023-09-24 18:37:22 +00:00
|
|
|
topshelf.setAttribute("class", "top-shelf face");
|
2023-09-30 19:20:27 +00:00
|
|
|
const leftshelf = rect.appendChild(document.createElement("div"));
|
2023-09-24 18:37:22 +00:00
|
|
|
leftshelf.setAttribute("class", "left-shelf small-face");
|
2023-09-30 19:20:27 +00:00
|
|
|
const rightshelf = rect.appendChild(document.createElement("div"));
|
2023-09-24 18:37:22 +00:00
|
|
|
rightshelf.setAttribute("class", "right-shelf small-face");
|
2023-09-30 19:20:27 +00:00
|
|
|
const back = rect.appendChild(document.createElement("div"));
|
2023-09-24 18:37:22 +00:00
|
|
|
back.setAttribute("class", "back-shelf face");
|
2023-09-30 19:20:27 +00:00
|
|
|
const bottomshelf = rect.appendChild(document.createElement("div"));
|
2023-09-24 18:37:22 +00:00
|
|
|
bottomshelf.setAttribute("class", "bottom-shelf face");
|
2023-09-30 19:20:27 +00:00
|
|
|
const front = rect.appendChild(document.createElement("div"));
|
2023-09-24 18:37:22 +00:00
|
|
|
front.setAttribute("class", "front-shelf face");
|
|
|
|
|
2023-09-30 19:20:27 +00:00
|
|
|
let style = document.createElement("style");
|
|
|
|
style.textContent = `
|
|
|
|
.wrapper {
|
|
|
|
width: ${this.width}px;
|
|
|
|
height: ${this.height}px;
|
|
|
|
display: block;
|
|
|
|
margin: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
.rect {
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
display: block;
|
|
|
|
perspective: ${this.perspective}px;
|
|
|
|
backface-visibility: visible;
|
|
|
|
transform-style: preserve-3d;
|
|
|
|
perspective-origin: 50% 50%;
|
|
|
|
transform: translateZ(-${this.depth / 2}px);
|
|
|
|
}
|
|
|
|
.top-shelf, .bottom-shelf {
|
|
|
|
width: ${this.width}px;
|
|
|
|
height: ${this.depth}px;
|
|
|
|
display: block;
|
|
|
|
position: absolute;
|
|
|
|
top: ${(this.height - this.depth) / 2}px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.left-shelf, .right-shelf {
|
|
|
|
width: ${this.depth}px;
|
|
|
|
height: ${this.height}px;
|
|
|
|
display: block;
|
|
|
|
position: absolute;
|
|
|
|
left: ${(this.width - this.depth) / 2}px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.front-shelf, .back-shelf {
|
|
|
|
width: ${this.width}px;
|
|
|
|
height: ${this.height}px;
|
|
|
|
display: block;
|
|
|
|
position: absolute;
|
|
|
|
}
|
2023-09-24 18:37:22 +00:00
|
|
|
|
2023-09-30 19:20:27 +00:00
|
|
|
.top-shelf {
|
|
|
|
transform: rotateX(90deg) translateZ(${this.height / 2}px);
|
|
|
|
background-color: ${this.topColor};
|
|
|
|
}
|
|
|
|
|
|
|
|
.bottom-shelf {
|
|
|
|
transform: rotateX(-90deg) translateZ(${this.height / 2}px);
|
|
|
|
background-color: ${this.botColor};
|
|
|
|
}
|
|
|
|
|
|
|
|
.right-shelf {
|
|
|
|
transform: rotateY(90deg) translateZ(${this.width / 2}px);
|
|
|
|
background-color: ${this.rightColor};
|
|
|
|
}
|
|
|
|
|
|
|
|
.left-shelf {
|
|
|
|
transform: rotateY(-90deg) translateZ(${this.width / 2}px);
|
|
|
|
background-color: ${this.leftColor};
|
|
|
|
}
|
|
|
|
|
|
|
|
.front-shelf {
|
|
|
|
transform: translateZ(${this.depth / 2}px);
|
|
|
|
background-color: ${this.frontColor};
|
|
|
|
}
|
|
|
|
|
|
|
|
.back-shelf {
|
|
|
|
transform: rotateY(180deg) translateZ(${this.depth / 2}px);
|
|
|
|
background-color: ${this.backColor};
|
|
|
|
}
|
|
|
|
`
|
|
|
|
|
|
|
|
wrapper.appendChild(rect);
|
|
|
|
wrapper.appendChild(style);
|
|
|
|
return wrapper;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ToyShelf extends Rect {
|
|
|
|
constructor() {
|
|
|
|
super();
|
2023-09-24 18:37:22 +00:00
|
|
|
|
2023-09-30 19:20:27 +00:00
|
|
|
const shadow = this.attachShadow({mode: "open", slotAssignment: "named"});
|
|
|
|
|
|
|
|
this.topColor = '#DAA06D'
|
|
|
|
this.botColor = this.topColor
|
|
|
|
this.rightColor = '#6F4E37'
|
|
|
|
this.leftColor = this.rightColor
|
|
|
|
this.frontColor = 'rgba(255, 255, 255, 0.1)'
|
|
|
|
this.backColor = '#6E260E'
|
|
|
|
this.perspective = 400
|
|
|
|
this.width = 300;
|
|
|
|
this.height = 100;
|
|
|
|
this.depth = 100;
|
|
|
|
|
2023-09-30 21:53:08 +00:00
|
|
|
const rect = this.createRect();
|
|
|
|
|
|
|
|
shadow.innerHTML = `
|
|
|
|
<div id="toy-list"><slot name="toy-list"></slot></div>
|
|
|
|
`
|
2023-09-30 19:20:27 +00:00
|
|
|
|
2023-09-30 21:53:08 +00:00
|
|
|
// TODO: change slot items to render on shelf
|
|
|
|
shadow.firstElementChild.addEventListener('slotchange', e => {
|
|
|
|
let slot = e.target;
|
|
|
|
if (slot.name == 'toy-list') {
|
|
|
|
this.items = slot.assignedElements().map(elem => elem.textContent);
|
|
|
|
console.log("Items: " + this.items);
|
2023-09-30 19:20:27 +00:00
|
|
|
}
|
2023-09-30 21:53:08 +00:00
|
|
|
});
|
2023-09-30 19:20:27 +00:00
|
|
|
|
|
|
|
shadow.appendChild(rect);
|
2023-09-24 18:37:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-30 19:20:27 +00:00
|
|
|
class ShopCounter extends Rect {
|
2023-09-24 18:37:22 +00:00
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
const shadow = this.attachShadow({mode: "open", slotAssignment: "named"});
|
|
|
|
|
2023-09-30 19:20:27 +00:00
|
|
|
this.width = 800;
|
|
|
|
this.height = 300;
|
|
|
|
this.depth = 200;
|
|
|
|
|
|
|
|
let style = document.createElement("style");
|
|
|
|
style.textContent = `
|
2023-09-24 18:37:22 +00:00
|
|
|
|
2023-09-30 19:20:27 +00:00
|
|
|
.rect {
|
|
|
|
transform: translateZ(-${this.depth / 2}px) rotateX(-30deg);
|
|
|
|
}
|
|
|
|
`
|
2023-09-27 04:21:18 +00:00
|
|
|
|
2023-09-30 19:20:27 +00:00
|
|
|
const rect = this.createRect();
|
2023-09-24 18:37:22 +00:00
|
|
|
|
2023-09-30 19:20:27 +00:00
|
|
|
shadow.appendChild(rect);
|
2023-09-24 18:37:22 +00:00
|
|
|
shadow.appendChild(style);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-30 19:20:27 +00:00
|
|
|
|
2023-09-24 18:37:22 +00:00
|
|
|
customElements.define("toy-shelf", ToyShelf);
|
2023-09-30 19:20:27 +00:00
|
|
|
customElements.define("shop-counter", ShopCounter);
|