mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-13 13:04:03 +00:00
Some Performance Updates And Wireless Display's Copy/Paste Bug Fixed
This commit is contained in:
parent
ee28cb8435
commit
3226b59b96
@ -12,6 +12,7 @@ import { Loader } from "../core/loader";
|
||||
import { drawRotatedSprite } from "../core/draw_utils";
|
||||
import { gComponentRegistry } from "../core/global_registries";
|
||||
import { getBuildingDataFromCode } from "./building_codes";
|
||||
import { WirelessDisplayComponent } from "./components/wireless_display";
|
||||
|
||||
export class Entity extends BasicSerializableObject {
|
||||
/**
|
||||
@ -66,8 +67,9 @@ export class Entity extends BasicSerializableObject {
|
||||
|
||||
/**
|
||||
* Stores wireless code of this entity
|
||||
* @type {string}
|
||||
*/
|
||||
this.wireless_code = 0;
|
||||
this.wireless_code;
|
||||
|
||||
/* typehints:end */
|
||||
}
|
||||
@ -81,6 +83,7 @@ export class Entity extends BasicSerializableObject {
|
||||
* @returns {import("../savegame/serialization").Schema}
|
||||
*/
|
||||
static getSchema() {
|
||||
console.log(types);
|
||||
return {
|
||||
uid: types.uint,
|
||||
components: types.keyValueMap(types.objData(gComponentRegistry), false),
|
||||
@ -91,6 +94,7 @@ export class Entity extends BasicSerializableObject {
|
||||
* Returns a clone of this entity
|
||||
*/
|
||||
clone() {
|
||||
const wireless_code = this.wireless_code;
|
||||
const staticComp = this.components.StaticMapEntity;
|
||||
const buildingData = getBuildingDataFromCode(staticComp.code);
|
||||
|
||||
@ -101,6 +105,7 @@ export class Entity extends BasicSerializableObject {
|
||||
rotation: staticComp.rotation,
|
||||
rotationVariant: buildingData.rotationVariant,
|
||||
variant: buildingData.variant,
|
||||
wirelessCode: this.wireless_code,
|
||||
});
|
||||
|
||||
for (const key in this.components) {
|
||||
|
@ -199,7 +199,7 @@ export class MetaBuilding {
|
||||
* @param {number} param0.rotationVariant Rotation variant
|
||||
* @param {string} param0.variant
|
||||
*/
|
||||
createEntity({ root, origin, rotation, originalRotation, rotationVariant, variant }) {
|
||||
createEntity({ root, origin, rotation, originalRotation, rotationVariant, variant, wirelessCode }) {
|
||||
const entity = new Entity(root);
|
||||
entity.layer = this.getLayer();
|
||||
entity.addComponent(
|
||||
@ -213,6 +213,9 @@ export class MetaBuilding {
|
||||
);
|
||||
this.setupEntityComponents(entity, root);
|
||||
this.updateVariants(entity, rotationVariant, variant);
|
||||
if (wirelessCode) {
|
||||
entity.wireless_code = wirelessCode;
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,8 @@ import { Entity } from "../entity";
|
||||
import { ShapeDefinition } from "../shape_definition";
|
||||
import { BOOL_FALSE_SINGLETON, BOOL_TRUE_SINGLETON } from "../items/boolean_item";
|
||||
import { init } from "logrocket";
|
||||
import { Signal } from "../../core/signal";
|
||||
import { serializeError } from "../../core/logging";
|
||||
|
||||
export class WirelessDisplaySystem extends GameSystemWithFilter {
|
||||
constructor(root) {
|
||||
@ -33,7 +35,10 @@ export class WirelessDisplaySystem extends GameSystemWithFilter {
|
||||
}
|
||||
this.displaySprites[colorId] = Loader.getSprite("sprites/wires/display/" + colorId + ".png");
|
||||
}
|
||||
this.wirelessMachineList = [];
|
||||
|
||||
this.wirelessMachineList = {};
|
||||
|
||||
this.displayNumber = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -86,7 +91,7 @@ export class WirelessDisplaySystem extends GameSystemWithFilter {
|
||||
entity.wireless_code = signalValueInput.getValue();
|
||||
} else if (signalValueInput.getValue() && entity.components.WiredPins){
|
||||
entity.wireless_code = signalValueInput.getValue();
|
||||
this.wirelessMachineList.push(entity);
|
||||
this.wirelessMachineList[entity.wireless_code] = entity;
|
||||
}
|
||||
};
|
||||
|
||||
@ -156,39 +161,41 @@ export class WirelessDisplaySystem extends GameSystemWithFilter {
|
||||
for (let i = 0; i < contents.length; ++i) {
|
||||
const entity_a = contents[i];
|
||||
if (entity_a && !entity_a.components.WiredPins && entity_a.components.WirelessDisplay) {
|
||||
for (let j = 0; j < this.wirelessMachineList.length; ++j) {
|
||||
const entity_b = this.wirelessMachineList[j];
|
||||
if (entity_a.wireless_code == entity_b.wireless_code) {
|
||||
const origin = entity_a.components.StaticMapEntity.origin;
|
||||
const pinsComp = entity_b.components.WiredPins;
|
||||
const network = pinsComp.slots[0].linkedNetwork;
|
||||
|
||||
if (!network || !network.hasValue()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const value = this.getDisplayItem(network.currentValue);
|
||||
|
||||
if (!value) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (value.getItemType()) {
|
||||
if (value.getItemType() === "color") {
|
||||
this.displaySprites[/** @type {ColorItem} */ (value).color].drawCachedCentered(
|
||||
parameters,
|
||||
(origin.x + 0.5) * globalConfig.tileSize,
|
||||
(origin.y + 0.5) * globalConfig.tileSize,
|
||||
globalConfig.tileSize
|
||||
);
|
||||
} else if (value.getItemType() === "shape") {
|
||||
value.drawItemCenteredClipped(
|
||||
(origin.x + 0.5) * globalConfig.tileSize,
|
||||
(origin.y + 0.5) * globalConfig.tileSize,
|
||||
parameters,
|
||||
30
|
||||
);
|
||||
}
|
||||
const entity_b = this.wirelessMachineList[entity_a.wireless_code];
|
||||
if (entity_b) {
|
||||
if (!this.allEntities.includes(entity_b)) {
|
||||
this.wirelessMachineList[entity_b] = undefined;
|
||||
return;
|
||||
}
|
||||
const origin = entity_a.components.StaticMapEntity.origin;
|
||||
const pinsComp = entity_b.components.WiredPins;
|
||||
const network = pinsComp.slots[0].linkedNetwork;
|
||||
|
||||
if (!network) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const value = this.getDisplayItem(network.currentValue);
|
||||
|
||||
if (!value) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (value.getItemType()) {
|
||||
if (value.getItemType() === "color") {
|
||||
this.displaySprites[/** @type {ColorItem} */ (value).color].drawCachedCentered(
|
||||
parameters,
|
||||
(origin.x + 0.5) * globalConfig.tileSize,
|
||||
(origin.y + 0.5) * globalConfig.tileSize,
|
||||
globalConfig.tileSize
|
||||
);
|
||||
} else if (value.getItemType() === "shape") {
|
||||
value.drawItemCenteredClipped(
|
||||
(origin.x + 0.5) * globalConfig.tileSize,
|
||||
(origin.y + 0.5) * globalConfig.tileSize,
|
||||
parameters,
|
||||
30
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user