1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2026-03-02 03:39:21 +00:00

Multiple improvements, fix saves on underground belts

This commit is contained in:
tobspr
2020-05-18 22:08:33 +02:00
parent 8c42827f4e
commit a60d23da77
17 changed files with 171 additions and 31 deletions

View File

@@ -0,0 +1,68 @@
import { BaseHUDPart } from "../base_hud_part";
import { makeDiv, removeAllChildren } from "../../../core/utils";
import { globalConfig } from "../../../core/config";
export class HUDEntityDebugger extends BaseHUDPart {
createElements(parent) {
this.element = makeDiv(
parent,
"ingame_HUD_EntityDebugger",
[],
`
Tile below cursor: <span class="mousePos"></span><br>
Chunk below cursor: <span class="chunkPos"></span><br>
<div class="entityInfo"></div>
`
);
this.mousePosElem = this.element.querySelector(".mousePos");
this.chunkPosElem = this.element.querySelector(".chunkPos");
this.entityInfoElem = this.element.querySelector(".entityInfo");
}
initialize() {
this.root.camera.downPreHandler.add(this.onMouseDown, this);
}
update() {
const mousePos = this.root.app.mousePosition;
const worldPos = this.root.camera.screenToWorld(mousePos);
const worldTile = worldPos.toTileSpace();
const chunk = worldTile.divideScalar(globalConfig.mapChunkSize).floor();
this.mousePosElem.innerText = worldTile.x + " / " + worldTile.y;
this.chunkPosElem.innerText = chunk.x + " / " + chunk.y;
const entity = this.root.map.getTileContent(worldTile);
if (entity) {
removeAllChildren(this.entityInfoElem);
let html = "Entity";
const flag = (name, val) =>
`<span class='flag' data-value='${val ? "1" : "0"}'><u>${name}</u> ${val}</span>`;
html += "<div class='entityFlags'>";
html += flag("registered", entity.registered);
html += flag("uid", entity.uid);
html += flag("destroyed", entity.destroyed);
html += "</div>";
html += "<div class='components'>";
for (const componentId in entity.components) {
const data = entity.components[componentId];
html += "<div class='component'>";
html += "<strong class='name'>" + componentId + "</strong>";
html += "<textarea class='data'>" + JSON.stringify(data.serialize(), null, 2) + "</textarea>";
html += "</div>";
}
html += "</div>";
this.entityInfoElem.innerHTML = html;
}
}
onMouseDown() {}
}

View File

@@ -1,9 +1,12 @@
import { BaseHUDPart } from "../base_hud_part";
import { makeDiv, formatSeconds } from "../../../core/utils";
import { makeDiv, formatSeconds, formatBigNumberFull } from "../../../core/utils";
import { DynamicDomAttach } from "../dynamic_dom_attach";
import { InputReceiver } from "../../../core/input_receiver";
import { KeyActionMapper } from "../../key_action_mapper";
import { T } from "../../../translations";
import { StaticMapEntityComponent } from "../../components/static_map_entity";
import { ItemProcessorComponent } from "../../components/item_processor";
import { BeltComponent } from "../../components/belt";
export class HUDSettingsMenu extends BaseHUDPart {
createElements(parent) {
@@ -11,11 +14,16 @@ export class HUDSettingsMenu extends BaseHUDPart {
this.menuElement = makeDiv(this.background, null, ["menuElement"]);
this.timePlayed = makeDiv(
this.statsElement = makeDiv(
this.background,
null,
["timePlayed"],
`<strong>${T.ingame.settingsMenu.playtime}</strong><span class="playtime"></span>`
["statsElement"],
`
<strong>${T.ingame.settingsMenu.beltsPlaced}</strong><span class="beltsPlaced"></span>
<strong>${T.ingame.settingsMenu.buildingsPlaced}</strong><span class="buildingsPlaced"></span>
<strong>${T.ingame.settingsMenu.playtime}</strong><span class="playtime"></span>
`
);
this.buttonContainer = makeDiv(this.menuElement, null, ["buttons"]);
@@ -89,10 +97,18 @@ export class HUDSettingsMenu extends BaseHUDPart {
this.root.app.inputMgr.makeSureAttachedAndOnTop(this.inputReciever);
const totalMinutesPlayed = Math.ceil(this.root.time.now() / 60);
this.timePlayed.querySelector(".playtime").innerText = T.global.time.xMinutes.replace(
this.statsElement.querySelector(".playtime").innerText = T.global.time.xMinutes.replace(
"<x>",
"" + totalMinutesPlayed
);
this.statsElement.querySelector(".buildingsPlaced").innerText = formatBigNumberFull(
this.root.entityMgr.getAllWithComponent(StaticMapEntityComponent).length -
this.root.entityMgr.getAllWithComponent(BeltComponent).length
);
this.statsElement.querySelector(".beltsPlaced").innerText = formatBigNumberFull(
this.root.entityMgr.getAllWithComponent(BeltComponent).length
);
}
close() {