adds display buttons typescript

This commit is contained in:
circle-gon 2022-12-22 07:39:09 -05:00 committed by GitHub
parent d58a48f39d
commit 4c5b505add
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -808,6 +808,22 @@ const factory = createLayer(id, () => {
spriteContainer.addChild(sprite);
}
function removeFactoryComp(x: number, y: number) {
const data = compInternalData[x + "x" + y];
if (data === undefined) return;
if (data.type === "conveyor") {
const cData = data as FactoryInternalConveyor;
for (const p of cData.packages) {
p.sprite.destroy();
}
}
delete components.value[x + "x" + y];
delete compInternalData[x + "x" + y];
spriteContainer.removeChild(data.sprite);
}
// draw graphics
function updateGraphics() {
app.resize();
@ -928,19 +944,7 @@ const factory = createLayer(id, () => {
compInternalData[x + "x" + y].sprite.rotation += Math.PI / 2;
}
} else if (compSelected.value === "delete") {
const data = compInternalData[x + "x" + y];
if (data === undefined) return;
if (data.type === "conveyor") {
const cData = data as FactoryInternalConveyor;
for (const p of cData.packages) {
p.sprite.destroy();
}
}
delete components.value[x + "x" + y];
delete compInternalData[x + "x" + y];
spriteContainer.removeChild(data.sprite);
removeFactoryComp(x, y);
} else if (compSelected.value !== "cursor") {
if (components.value[x + "x" + y] == null) {
addFactoryComp(x, y, { type: compSelected.value });
@ -972,6 +976,46 @@ const factory = createLayer(id, () => {
compSelected.value = name;
}
function setTracks() {
for (const [key, comp] of Object.entries(compInternalData)) {
if (comp == null) continue;
if (comp.type === "conveyor") {
for (const pkg of [...comp.nextPackages, ...comp.packages]) {
pkg.sprite.destroy();
movingBlocks.removeChild(pkg.sprite);
}
comp.nextPackages = [];
comp.packages = [];
} else {
const producerComp = components.value[key] as FactoryComponentProducer;
if (producerComp.outputStock !== undefined) {
for (const key in producerComp.outputStock) {
delete producerComp.outputStock[key];
}
}
if (producerComp.inputStock !== undefined) {
for (const key in producerComp.inputStock) {
delete producerComp.inputStock[key];
}
}
producerComp.ticksDone = 0;
}
}
}
function clearFactory() {
for (const key of Object.keys(compInternalData)) {
const [x, y] = key.split("x").map(i => +i);
removeFactoryComp(x, y);
}
}
function moveToCenter() {
mapOffset.x = 0;
mapOffset.y = 0;
}
function togglePaused() {
paused.value = !paused.value;
// ------------------------------------------------------------------------------- Tabs
const tabs = createTabFamily(
@ -1013,6 +1057,45 @@ const factory = createLayer(id, () => {
onPointerleave={onFactoryMouseLeave}
onContextmenu={(e: MouseEvent) => e.preventDefault()}
/>
<div class="controls-container">
<button
class="control-btn"
style={{
"border-color": "purple"
}}
onClick={setTracks}
>
Clear Tracks
</button>
<button
class="control-btn"
style={{
"border-color": "red"
}}
onClick={clearFactory}
>
Clear Factory
</button>
<button
class="control-btn"
style={{
"border-color": "green"
}}
onClick={moveToCenter}
>
Go to Center
</button>
<button
class="control-btn"
style={{
"border-color": paused.value ? "green" : "red"
}}
onClick={togglePaused}
>
{paused.value ? "Unpause" : "Pause"} the Factory
</button>
</div>
<div class="comp-container">
<div
class={{