mirror of
https://github.com/tobspr/shapez.io.git
synced 2026-03-02 03:39:21 +00:00
Optimize performance by using singletons for items
This commit is contained in:
@@ -1,15 +1,14 @@
|
||||
import { ConstantSignalComponent } from "../components/constant_signal";
|
||||
import { GameSystemWithFilter } from "../game_system_with_filter";
|
||||
import { Entity } from "../entity";
|
||||
import trim from "trim";
|
||||
import { DialogWithForm } from "../../core/modal_dialog_elements";
|
||||
import { FormElementInput } from "../../core/modal_dialog_forms";
|
||||
import { enumColors } from "../colors";
|
||||
import { ColorItem } from "../items/color_item";
|
||||
import trim from "trim";
|
||||
import { BOOL_TRUE_SINGLETON, BOOL_FALSE_SINGLETON } from "../items/boolean_item";
|
||||
import { ShapeDefinition } from "../shape_definition";
|
||||
import { ShapeItem } from "../items/shape_item";
|
||||
import { BaseItem } from "../base_item";
|
||||
import { enumColors } from "../colors";
|
||||
import { ConstantSignalComponent } from "../components/constant_signal";
|
||||
import { Entity } from "../entity";
|
||||
import { GameSystemWithFilter } from "../game_system_with_filter";
|
||||
import { BOOL_FALSE_SINGLETON, BOOL_TRUE_SINGLETON } from "../items/boolean_item";
|
||||
import { COLOR_ITEM_SINGLETONS } from "../items/color_item";
|
||||
import { ShapeDefinition } from "../shape_definition";
|
||||
|
||||
export class ConstantSignalSystem extends GameSystemWithFilter {
|
||||
constructor(root) {
|
||||
@@ -111,7 +110,7 @@ export class ConstantSignalSystem extends GameSystemWithFilter {
|
||||
const codeLower = code.toLowerCase();
|
||||
|
||||
if (enumColors[codeLower]) {
|
||||
return new ColorItem(codeLower);
|
||||
return COLOR_ITEM_SINGLETONS[codeLower];
|
||||
}
|
||||
if (code === "1" || codeLower === "true") {
|
||||
return BOOL_TRUE_SINGLETON;
|
||||
@@ -122,7 +121,7 @@ export class ConstantSignalSystem extends GameSystemWithFilter {
|
||||
}
|
||||
|
||||
if (ShapeDefinition.isValidShortKey(code)) {
|
||||
return new ShapeItem(this.root.shapeDefinitionMgr.getShapeFromShortKey(code));
|
||||
return this.root.shapeDefinitionMgr.getShapeItemFromShortKey(code);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { GameSystemWithFilter } from "../game_system_with_filter";
|
||||
import { HubComponent } from "../components/hub";
|
||||
import { DrawParameters } from "../../core/draw_parameters";
|
||||
import { Entity } from "../entity";
|
||||
import { formatBigNumber } from "../../core/utils";
|
||||
import { Loader } from "../../core/loader";
|
||||
import { formatBigNumber } from "../../core/utils";
|
||||
import { T } from "../../translations";
|
||||
import { ShapeItem } from "../items/shape_item";
|
||||
import { HubComponent } from "../components/hub";
|
||||
import { Entity } from "../entity";
|
||||
import { GameSystemWithFilter } from "../game_system_with_filter";
|
||||
|
||||
export class HubSystem extends GameSystemWithFilter {
|
||||
constructor(root) {
|
||||
@@ -23,7 +22,9 @@ export class HubSystem extends GameSystemWithFilter {
|
||||
// Set hub goal
|
||||
const entity = this.allEntities[i];
|
||||
const pinsComp = entity.components.WiredPins;
|
||||
pinsComp.slots[0].value = new ShapeItem(this.root.hubGoals.currentGoal.definition);
|
||||
pinsComp.slots[0].value = this.root.shapeDefinitionMgr.getShapeItemFromDefinition(
|
||||
this.root.hubGoals.currentGoal.definition
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import { enumItemProcessorTypes, ItemProcessorComponent } from "../components/it
|
||||
import { Entity } from "../entity";
|
||||
import { GameSystemWithFilter } from "../game_system_with_filter";
|
||||
import { BOOL_TRUE_SINGLETON } from "../items/boolean_item";
|
||||
import { ColorItem } from "../items/color_item";
|
||||
import { ColorItem, COLOR_ITEM_SINGLETONS } from "../items/color_item";
|
||||
import { ShapeItem } from "../items/shape_item";
|
||||
|
||||
export class ItemProcessorSystem extends GameSystemWithFilter {
|
||||
@@ -134,7 +134,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
||||
const definition = cutDefinitions[i];
|
||||
if (!definition.isEntirelyEmpty()) {
|
||||
outItems.push({
|
||||
item: new ShapeItem(definition),
|
||||
item: this.root.shapeDefinitionMgr.getShapeItemFromDefinition(definition),
|
||||
requiredSlot: i,
|
||||
});
|
||||
}
|
||||
@@ -155,7 +155,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
||||
const definition = cutDefinitions[i];
|
||||
if (!definition.isEntirelyEmpty()) {
|
||||
outItems.push({
|
||||
item: new ShapeItem(definition),
|
||||
item: this.root.shapeDefinitionMgr.getShapeItemFromDefinition(definition),
|
||||
requiredSlot: i,
|
||||
});
|
||||
}
|
||||
@@ -172,7 +172,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
||||
|
||||
const rotatedDefinition = this.root.shapeDefinitionMgr.shapeActionRotateCW(inputDefinition);
|
||||
outItems.push({
|
||||
item: new ShapeItem(rotatedDefinition),
|
||||
item: this.root.shapeDefinitionMgr.getShapeItemFromDefinition(rotatedDefinition),
|
||||
});
|
||||
break;
|
||||
}
|
||||
@@ -185,7 +185,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
||||
|
||||
const rotatedDefinition = this.root.shapeDefinitionMgr.shapeActionRotateCCW(inputDefinition);
|
||||
outItems.push({
|
||||
item: new ShapeItem(rotatedDefinition),
|
||||
item: this.root.shapeDefinitionMgr.getShapeItemFromDefinition(rotatedDefinition),
|
||||
});
|
||||
break;
|
||||
}
|
||||
@@ -198,7 +198,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
||||
|
||||
const rotatedDefinition = this.root.shapeDefinitionMgr.shapeActionRotateFL(inputDefinition);
|
||||
outItems.push({
|
||||
item: new ShapeItem(rotatedDefinition),
|
||||
item: this.root.shapeDefinitionMgr.getShapeItemFromDefinition(rotatedDefinition),
|
||||
});
|
||||
break;
|
||||
}
|
||||
@@ -217,7 +217,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
||||
upperItem.definition
|
||||
);
|
||||
outItems.push({
|
||||
item: new ShapeItem(stackedDefinition),
|
||||
item: this.root.shapeDefinitionMgr.getShapeItemFromDefinition(stackedDefinition),
|
||||
});
|
||||
break;
|
||||
}
|
||||
@@ -248,7 +248,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
||||
resultColor = mixedColor;
|
||||
}
|
||||
outItems.push({
|
||||
item: new ColorItem(resultColor),
|
||||
item: COLOR_ITEM_SINGLETONS[resultColor],
|
||||
});
|
||||
|
||||
break;
|
||||
@@ -266,7 +266,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
||||
);
|
||||
|
||||
outItems.push({
|
||||
item: new ShapeItem(colorizedDefinition),
|
||||
item: this.root.shapeDefinitionMgr.getShapeItemFromDefinition(colorizedDefinition),
|
||||
});
|
||||
|
||||
break;
|
||||
@@ -293,11 +293,11 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
||||
colorItem.color
|
||||
);
|
||||
outItems.push({
|
||||
item: new ShapeItem(colorizedDefinition1),
|
||||
item: this.root.shapeDefinitionMgr.getShapeItemFromDefinition(colorizedDefinition1),
|
||||
});
|
||||
|
||||
outItems.push({
|
||||
item: new ShapeItem(colorizedDefinition2),
|
||||
item: this.root.shapeDefinitionMgr.getShapeItemFromDefinition(colorizedDefinition2),
|
||||
});
|
||||
|
||||
break;
|
||||
@@ -324,7 +324,7 @@ export class ItemProcessorSystem extends GameSystemWithFilter {
|
||||
);
|
||||
|
||||
outItems.push({
|
||||
item: new ShapeItem(colorizedDefinition),
|
||||
item: this.root.shapeDefinitionMgr.getShapeItemFromDefinition(colorizedDefinition),
|
||||
});
|
||||
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user