Only store changed properties for all components
This commit is contained in:
parent
bb431b8490
commit
9701a143ec
|
@ -3,12 +3,9 @@ import { enumAngleToDirection, enumDirection, Vector } from "../../core/vector";
|
||||||
import { SOUNDS } from "../../platform/sound";
|
import { SOUNDS } from "../../platform/sound";
|
||||||
import { T } from "../../translations";
|
import { T } from "../../translations";
|
||||||
import { BeltComponent } from "../components/belt";
|
import { BeltComponent } from "../components/belt";
|
||||||
import { ItemAcceptorComponent } from "../components/item_acceptor";
|
|
||||||
import { ItemEjectorComponent } from "../components/item_ejector";
|
|
||||||
import { ReplaceableMapEntityComponent } from "../components/replaceable_map_entity";
|
|
||||||
import { Entity } from "../entity";
|
import { Entity } from "../entity";
|
||||||
import { MetaBuilding } from "../meta_building";
|
import { MetaBuilding } from "../meta_building";
|
||||||
import { GameRoot, enumLayer } from "../root";
|
import { GameRoot } from "../root";
|
||||||
|
|
||||||
export const arrayBeltVariantToRotation = [enumDirection.top, enumDirection.left, enumDirection.right];
|
export const arrayBeltVariantToRotation = [enumDirection.top, enumDirection.left, enumDirection.right];
|
||||||
|
|
||||||
|
@ -43,6 +40,10 @@ export class MetaBeltBaseBuilding extends MetaBuilding {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getIsReplaceable() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the entity at the given location
|
* Creates the entity at the given location
|
||||||
* @param {Entity} entity
|
* @param {Entity} entity
|
||||||
|
@ -53,8 +54,6 @@ export class MetaBeltBaseBuilding extends MetaBuilding {
|
||||||
direction: enumDirection.top, // updated later
|
direction: enumDirection.top, // updated later
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
// Make this entity replaceable
|
|
||||||
entity.addComponent(new ReplaceableMapEntityComponent());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3,7 +3,6 @@ import { enumItemType } from "../base_item";
|
||||||
import { HubComponent } from "../components/hub";
|
import { HubComponent } from "../components/hub";
|
||||||
import { ItemAcceptorComponent } from "../components/item_acceptor";
|
import { ItemAcceptorComponent } from "../components/item_acceptor";
|
||||||
import { enumItemProcessorTypes, ItemProcessorComponent } from "../components/item_processor";
|
import { enumItemProcessorTypes, ItemProcessorComponent } from "../components/item_processor";
|
||||||
import { UnremovableComponent } from "../components/unremovable";
|
|
||||||
import { Entity } from "../entity";
|
import { Entity } from "../entity";
|
||||||
import { MetaBuilding } from "../meta_building";
|
import { MetaBuilding } from "../meta_building";
|
||||||
import { WiredPinsComponent, enumPinSlotType } from "../components/wired_pins";
|
import { WiredPinsComponent, enumPinSlotType } from "../components/wired_pins";
|
||||||
|
@ -34,6 +33,10 @@ export class MetaHubBuilding extends MetaBuilding {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getIsRemovable() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the entity at the given location
|
* Creates the entity at the given location
|
||||||
* @param {Entity} entity
|
* @param {Entity} entity
|
||||||
|
@ -47,8 +50,6 @@ export class MetaHubBuilding extends MetaBuilding {
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
entity.addComponent(new UnremovableComponent());
|
|
||||||
|
|
||||||
entity.addComponent(
|
entity.addComponent(
|
||||||
new WiredPinsComponent({
|
new WiredPinsComponent({
|
||||||
slots: [
|
slots: [
|
||||||
|
|
|
@ -5,9 +5,7 @@ import { ItemEjectorComponent } from "./components/item_ejector";
|
||||||
import { ItemAcceptorComponent } from "./components/item_acceptor";
|
import { ItemAcceptorComponent } from "./components/item_acceptor";
|
||||||
import { MinerComponent } from "./components/miner";
|
import { MinerComponent } from "./components/miner";
|
||||||
import { ItemProcessorComponent } from "./components/item_processor";
|
import { ItemProcessorComponent } from "./components/item_processor";
|
||||||
import { ReplaceableMapEntityComponent } from "./components/replaceable_map_entity";
|
|
||||||
import { UndergroundBeltComponent } from "./components/underground_belt";
|
import { UndergroundBeltComponent } from "./components/underground_belt";
|
||||||
import { UnremovableComponent } from "./components/unremovable";
|
|
||||||
import { HubComponent } from "./components/hub";
|
import { HubComponent } from "./components/hub";
|
||||||
import { StorageComponent } from "./components/storage";
|
import { StorageComponent } from "./components/storage";
|
||||||
import { WiredPinsComponent } from "./components/wired_pins";
|
import { WiredPinsComponent } from "./components/wired_pins";
|
||||||
|
@ -20,9 +18,7 @@ export function initComponentRegistry() {
|
||||||
gComponentRegistry.register(ItemAcceptorComponent);
|
gComponentRegistry.register(ItemAcceptorComponent);
|
||||||
gComponentRegistry.register(MinerComponent);
|
gComponentRegistry.register(MinerComponent);
|
||||||
gComponentRegistry.register(ItemProcessorComponent);
|
gComponentRegistry.register(ItemProcessorComponent);
|
||||||
gComponentRegistry.register(ReplaceableMapEntityComponent);
|
|
||||||
gComponentRegistry.register(UndergroundBeltComponent);
|
gComponentRegistry.register(UndergroundBeltComponent);
|
||||||
gComponentRegistry.register(UnremovableComponent);
|
|
||||||
gComponentRegistry.register(HubComponent);
|
gComponentRegistry.register(HubComponent);
|
||||||
gComponentRegistry.register(StorageComponent);
|
gComponentRegistry.register(StorageComponent);
|
||||||
gComponentRegistry.register(WiredPinsComponent);
|
gComponentRegistry.register(WiredPinsComponent);
|
||||||
|
|
|
@ -40,12 +40,6 @@ export class BeltComponent extends Component {
|
||||||
return "Belt";
|
return "Belt";
|
||||||
}
|
}
|
||||||
|
|
||||||
static getSchema() {
|
|
||||||
return {
|
|
||||||
direction: types.string,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
duplicateWithoutContents() {
|
duplicateWithoutContents() {
|
||||||
return new BeltComponent({ direction: this.direction });
|
return new BeltComponent({ direction: this.direction });
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,17 +7,6 @@ export class BeltUnderlaysComponent extends Component {
|
||||||
return "BeltUnderlays";
|
return "BeltUnderlays";
|
||||||
}
|
}
|
||||||
|
|
||||||
static getSchema() {
|
|
||||||
return {
|
|
||||||
underlays: types.array(
|
|
||||||
types.structured({
|
|
||||||
pos: types.vector,
|
|
||||||
direction: types.enum(enumDirection),
|
|
||||||
})
|
|
||||||
),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
duplicateWithoutContents() {
|
duplicateWithoutContents() {
|
||||||
const beltUnderlaysCopy = [];
|
const beltUnderlaysCopy = [];
|
||||||
for (let i = 0; i < this.underlays.length; ++i) {
|
for (let i = 0; i < this.underlays.length; ++i) {
|
||||||
|
|
|
@ -28,18 +28,6 @@ export class ItemAcceptorComponent extends Component {
|
||||||
return "ItemAcceptor";
|
return "ItemAcceptor";
|
||||||
}
|
}
|
||||||
|
|
||||||
static getSchema() {
|
|
||||||
return {
|
|
||||||
slots: types.array(
|
|
||||||
types.structured({
|
|
||||||
pos: types.vector,
|
|
||||||
directions: types.array(types.enum(enumDirection)),
|
|
||||||
filter: types.nullable(types.enum(enumItemType)),
|
|
||||||
})
|
|
||||||
),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
duplicateWithoutContents() {
|
duplicateWithoutContents() {
|
||||||
const slotsCopy = [];
|
const slotsCopy = [];
|
||||||
for (let i = 0; i < this.slots.length; ++i) {
|
for (let i = 0; i < this.slots.length; ++i) {
|
||||||
|
|
|
@ -29,8 +29,6 @@ export class ItemEjectorComponent extends Component {
|
||||||
return {
|
return {
|
||||||
slots: types.array(
|
slots: types.array(
|
||||||
types.structured({
|
types.structured({
|
||||||
pos: types.vector,
|
|
||||||
direction: types.enum(enumDirection),
|
|
||||||
item: types.nullable(types.obj(gItemRegistry)),
|
item: types.nullable(types.obj(gItemRegistry)),
|
||||||
progress: types.float,
|
progress: types.float,
|
||||||
})
|
})
|
||||||
|
|
|
@ -29,9 +29,6 @@ export class ItemProcessorComponent extends Component {
|
||||||
static getSchema() {
|
static getSchema() {
|
||||||
return {
|
return {
|
||||||
nextOutputSlot: types.uint,
|
nextOutputSlot: types.uint,
|
||||||
type: types.enum(enumItemProcessorTypes),
|
|
||||||
inputsPerCharge: types.uint,
|
|
||||||
|
|
||||||
inputSlots: types.array(
|
inputSlots: types.array(
|
||||||
types.structured({
|
types.structured({
|
||||||
item: types.obj(gItemRegistry),
|
item: types.obj(gItemRegistry),
|
||||||
|
|
|
@ -15,7 +15,6 @@ export class MinerComponent extends Component {
|
||||||
// cachedMinedItem is not serialized.
|
// cachedMinedItem is not serialized.
|
||||||
return {
|
return {
|
||||||
lastMiningTime: types.ufloat,
|
lastMiningTime: types.ufloat,
|
||||||
chainable: types.bool,
|
|
||||||
itemChainBuffer: types.array(types.obj(gItemRegistry)),
|
itemChainBuffer: types.array(types.obj(gItemRegistry)),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
import { Component } from "../component";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Marks an entity as replaceable, so that when other buildings are placed above him it
|
|
||||||
* simply gets deleted
|
|
||||||
*/
|
|
||||||
export class ReplaceableMapEntityComponent extends Component {
|
|
||||||
static getId() {
|
|
||||||
return "ReplaceableMapEntity";
|
|
||||||
}
|
|
||||||
|
|
||||||
duplicateWithoutContents() {
|
|
||||||
return new ReplaceableMapEntityComponent();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -6,6 +6,7 @@ import { enumDirection, Vector } from "../../core/vector";
|
||||||
import { types } from "../../savegame/serialization";
|
import { types } from "../../savegame/serialization";
|
||||||
import { Component } from "../component";
|
import { Component } from "../component";
|
||||||
import { getBuildingDataFromCode } from "../building_codes";
|
import { getBuildingDataFromCode } from "../building_codes";
|
||||||
|
import { MetaBuilding } from "../meta_building";
|
||||||
|
|
||||||
export class StaticMapEntityComponent extends Component {
|
export class StaticMapEntityComponent extends Component {
|
||||||
static getId() {
|
static getId() {
|
||||||
|
@ -15,7 +16,6 @@ export class StaticMapEntityComponent extends Component {
|
||||||
static getSchema() {
|
static getSchema() {
|
||||||
return {
|
return {
|
||||||
origin: types.tileVector,
|
origin: types.tileVector,
|
||||||
tileSize: types.tileVector,
|
|
||||||
rotation: types.float,
|
rotation: types.float,
|
||||||
originalRotation: types.float,
|
originalRotation: types.float,
|
||||||
|
|
||||||
|
@ -56,6 +56,14 @@ export class StaticMapEntityComponent extends Component {
|
||||||
return getBuildingDataFromCode(this.code).silhouetteColor;
|
return getBuildingDataFromCode(this.code).silhouetteColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the meta building
|
||||||
|
* @returns {MetaBuilding}
|
||||||
|
*/
|
||||||
|
getMetaBuilding() {
|
||||||
|
return getBuildingDataFromCode(this.code).metaInstance;
|
||||||
|
}
|
||||||
|
|
||||||
duplicateWithoutContents() {
|
duplicateWithoutContents() {
|
||||||
return new StaticMapEntityComponent({
|
return new StaticMapEntityComponent({
|
||||||
origin: this.origin.copy(),
|
origin: this.origin.copy(),
|
||||||
|
|
|
@ -12,10 +12,8 @@ export class StorageComponent extends Component {
|
||||||
|
|
||||||
static getSchema() {
|
static getSchema() {
|
||||||
return {
|
return {
|
||||||
maximumStorage: types.uint,
|
|
||||||
storedCount: types.uint,
|
storedCount: types.uint,
|
||||||
storedItem: types.nullable(types.obj(gItemRegistry)),
|
storedItem: types.nullable(types.obj(gItemRegistry)),
|
||||||
overlayOpacity: types.ufloat,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,9 +26,7 @@ export class UndergroundBeltComponent extends Component {
|
||||||
|
|
||||||
static getSchema() {
|
static getSchema() {
|
||||||
return {
|
return {
|
||||||
mode: types.enum(enumUndergroundBeltMode),
|
|
||||||
pendingItems: types.array(types.pair(types.obj(gItemRegistry), types.float)),
|
pendingItems: types.array(types.pair(types.obj(gItemRegistry), types.float)),
|
||||||
tier: types.uint,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
import { Component } from "../component";
|
|
||||||
|
|
||||||
export class UnremovableComponent extends Component {
|
|
||||||
static getId() {
|
|
||||||
return "Unremovable";
|
|
||||||
}
|
|
||||||
|
|
||||||
static getSchema() {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
duplicateWithoutContents() {
|
|
||||||
return new UnremovableComponent();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -29,17 +29,6 @@ export class WiredPinsComponent extends Component {
|
||||||
return "WiredPins";
|
return "WiredPins";
|
||||||
}
|
}
|
||||||
|
|
||||||
static getSchema() {
|
|
||||||
return {
|
|
||||||
slots: types.array(
|
|
||||||
types.structured({
|
|
||||||
pos: types.vector,
|
|
||||||
type: types.enum(enumPinSlotType),
|
|
||||||
})
|
|
||||||
),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {object} param0
|
* @param {object} param0
|
||||||
|
|
|
@ -76,8 +76,7 @@ export class Entity extends BasicSerializableObject {
|
||||||
static getSchema() {
|
static getSchema() {
|
||||||
return {
|
return {
|
||||||
uid: types.uint,
|
uid: types.uint,
|
||||||
components: types.keyValueMap(types.objData(gComponentRegistry)),
|
components: types.keyValueMap(types.objData(gComponentRegistry), false),
|
||||||
layer: types.enum(enumLayer),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,15 @@
|
||||||
/* typehints:start */
|
/* typehints:start */
|
||||||
import { StaticMapEntityComponent } from "./components/static_map_entity";
|
|
||||||
import { BeltComponent } from "./components/belt";
|
import { BeltComponent } from "./components/belt";
|
||||||
import { ItemEjectorComponent } from "./components/item_ejector";
|
|
||||||
import { ItemAcceptorComponent } from "./components/item_acceptor";
|
|
||||||
import { MinerComponent } from "./components/miner";
|
|
||||||
import { ItemProcessorComponent } from "./components/item_processor";
|
|
||||||
import { ReplaceableMapEntityComponent } from "./components/replaceable_map_entity";
|
|
||||||
import { UndergroundBeltComponent } from "./components/underground_belt";
|
|
||||||
import { UnremovableComponent } from "./components/unremovable";
|
|
||||||
import { HubComponent } from "./components/hub";
|
|
||||||
import { StorageComponent } from "./components/storage";
|
|
||||||
import { EnergyGeneratorComponent } from "./components/energy_generator";
|
|
||||||
import { WiredPinsComponent } from "./components/wired_pins";
|
|
||||||
import { EnergyConsumerComponent } from "./components/energy_consumer";
|
|
||||||
import { BeltUnderlaysComponent } from "./components/belt_underlays";
|
import { BeltUnderlaysComponent } from "./components/belt_underlays";
|
||||||
|
import { HubComponent } from "./components/hub";
|
||||||
|
import { ItemAcceptorComponent } from "./components/item_acceptor";
|
||||||
|
import { ItemEjectorComponent } from "./components/item_ejector";
|
||||||
|
import { ItemProcessorComponent } from "./components/item_processor";
|
||||||
|
import { MinerComponent } from "./components/miner";
|
||||||
|
import { StaticMapEntityComponent } from "./components/static_map_entity";
|
||||||
|
import { StorageComponent } from "./components/storage";
|
||||||
|
import { UndergroundBeltComponent } from "./components/underground_belt";
|
||||||
|
import { WiredPinsComponent } from "./components/wired_pins";
|
||||||
/* typehints:end */
|
/* typehints:end */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,30 +38,18 @@ export class EntityComponentStorage {
|
||||||
/** @type {ItemProcessorComponent} */
|
/** @type {ItemProcessorComponent} */
|
||||||
this.ItemProcessor;
|
this.ItemProcessor;
|
||||||
|
|
||||||
/** @type {ReplaceableMapEntityComponent} */
|
|
||||||
this.ReplaceableMapEntity;
|
|
||||||
|
|
||||||
/** @type {UndergroundBeltComponent} */
|
/** @type {UndergroundBeltComponent} */
|
||||||
this.UndergroundBelt;
|
this.UndergroundBelt;
|
||||||
|
|
||||||
/** @type {UnremovableComponent} */
|
|
||||||
this.Unremovable;
|
|
||||||
|
|
||||||
/** @type {HubComponent} */
|
/** @type {HubComponent} */
|
||||||
this.Hub;
|
this.Hub;
|
||||||
|
|
||||||
/** @type {StorageComponent} */
|
/** @type {StorageComponent} */
|
||||||
this.Storage;
|
this.Storage;
|
||||||
|
|
||||||
/** @type {EnergyGeneratorComponent} */
|
|
||||||
this.EnergyGenerator;
|
|
||||||
|
|
||||||
/** @type {WiredPinsComponent} */
|
/** @type {WiredPinsComponent} */
|
||||||
this.WiredPins;
|
this.WiredPins;
|
||||||
|
|
||||||
/** @type {EnergyConsumerComponent} */
|
|
||||||
this.EnergyConsumer;
|
|
||||||
|
|
||||||
/** @type {BeltUnderlaysComponent} */
|
/** @type {BeltUnderlaysComponent} */
|
||||||
this.BeltUnderlays;
|
this.BeltUnderlays;
|
||||||
|
|
||||||
|
|
|
@ -63,9 +63,12 @@ export class GameLogic {
|
||||||
for (let y = rect.y; y < rect.y + rect.h; ++y) {
|
for (let y = rect.y; y < rect.y + rect.h; ++y) {
|
||||||
// Check if there is any direct collision
|
// Check if there is any direct collision
|
||||||
const otherEntity = this.root.map.getLayerContentXY(x, y, entity.layer);
|
const otherEntity = this.root.map.getLayerContentXY(x, y, entity.layer);
|
||||||
if (otherEntity && !otherEntity.components.ReplaceableMapEntity) {
|
if (otherEntity) {
|
||||||
// This one is a direct blocker
|
const metaClass = otherEntity.components.StaticMapEntity.getMetaBuilding();
|
||||||
return false;
|
if (!metaClass.getIsReplaceable()) {
|
||||||
|
// This one is a direct blocker
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,7 +124,7 @@ export class GameLogic {
|
||||||
const contents = this.root.map.getLayerContentXY(x, y, entity.layer);
|
const contents = this.root.map.getLayerContentXY(x, y, entity.layer);
|
||||||
if (contents) {
|
if (contents) {
|
||||||
assertAlways(
|
assertAlways(
|
||||||
contents.components.ReplaceableMapEntity,
|
contents.components.StaticMapEntity.getMetaBuilding().getIsReplaceable(),
|
||||||
"Tried to replace non-repleaceable entity"
|
"Tried to replace non-repleaceable entity"
|
||||||
);
|
);
|
||||||
if (!this.tryDeleteBuilding(contents)) {
|
if (!this.tryDeleteBuilding(contents)) {
|
||||||
|
@ -158,7 +161,8 @@ export class GameLogic {
|
||||||
* @param {Entity} building
|
* @param {Entity} building
|
||||||
*/
|
*/
|
||||||
canDeleteBuilding(building) {
|
canDeleteBuilding(building) {
|
||||||
return building.components.StaticMapEntity && !building.components.Unremovable;
|
const staticComp = building.components.StaticMapEntity;
|
||||||
|
return staticComp.getMetaBuilding().getIsRemovable();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -64,6 +64,13 @@ export class MetaBuilding {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether this building can get replaced
|
||||||
|
*/
|
||||||
|
getIsReplaceable() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether to flip the orientation after a building has been placed - useful
|
* Whether to flip the orientation after a building has been placed - useful
|
||||||
* for tunnels.
|
* for tunnels.
|
||||||
|
@ -80,6 +87,14 @@ export class MetaBuilding {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether this building is removable
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
getIsRemovable() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the placement sound
|
* Returns the placement sound
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
|
|
|
@ -52,7 +52,7 @@ export class WiredPinsSystem extends GameSystemWithFilter {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (otherEntity.components.ReplaceableMapEntity) {
|
if (staticComp.getMetaBuilding().getIsReplaceable()) {
|
||||||
// Don't mind here, even if there would be a collision we
|
// Don't mind here, even if there would be a collision we
|
||||||
// could replace it
|
// could replace it
|
||||||
continue;
|
continue;
|
||||||
|
@ -105,8 +105,10 @@ export class WiredPinsSystem extends GameSystemWithFilter {
|
||||||
const collidingEntity = this.root.map.getLayerContentXY(worldPos.x, worldPos.y, enumLayer.wires);
|
const collidingEntity = this.root.map.getLayerContentXY(worldPos.x, worldPos.y, enumLayer.wires);
|
||||||
|
|
||||||
// If there's an entity, and it can't get removed -> That's a collision
|
// If there's an entity, and it can't get removed -> That's a collision
|
||||||
if (collidingEntity && !collidingEntity.components.ReplaceableMapEntity) {
|
if (collidingEntity) {
|
||||||
return true;
|
if (!collidingEntity.components.StaticMapEntity.getMetaBuilding().getIsReplaceable()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -130,7 +132,7 @@ export class WiredPinsSystem extends GameSystemWithFilter {
|
||||||
const collidingEntity = this.root.map.getLayerContentXY(worldPos.x, worldPos.y, enumLayer.wires);
|
const collidingEntity = this.root.map.getLayerContentXY(worldPos.x, worldPos.y, enumLayer.wires);
|
||||||
if (collidingEntity) {
|
if (collidingEntity) {
|
||||||
assertAlways(
|
assertAlways(
|
||||||
collidingEntity.components.ReplaceableMapEntity,
|
collidingEntity.components.StaticMapEntity.getMetaBuilding().getIsReplaceable(),
|
||||||
"Tried to replace non-repleaceable entity for pins"
|
"Tried to replace non-repleaceable entity for pins"
|
||||||
);
|
);
|
||||||
if (!this.root.logic.tryDeleteBuilding(collidingEntity)) {
|
if (!this.root.logic.tryDeleteBuilding(collidingEntity)) {
|
||||||
|
|
|
@ -871,14 +871,17 @@ export class TypeArray extends BaseDataType {
|
||||||
* @returns {string|void} String error code or null on success
|
* @returns {string|void} String error code or null on success
|
||||||
*/
|
*/
|
||||||
deserialize(value, targetObject, targetKey, root) {
|
deserialize(value, targetObject, targetKey, root) {
|
||||||
const result = new Array(value.length);
|
let destination = targetObject[targetKey];
|
||||||
|
if (!destination) {
|
||||||
|
targetObject[targetKey] = destination = new Array(value.length);
|
||||||
|
}
|
||||||
|
|
||||||
for (let i = 0; i < value.length; ++i) {
|
for (let i = 0; i < value.length; ++i) {
|
||||||
const errorStatus = this.innerType.deserializeWithVerify(value[i], result, i, root);
|
const errorStatus = this.innerType.deserializeWithVerify(value[i], destination, i, root);
|
||||||
if (errorStatus) {
|
if (errorStatus) {
|
||||||
return errorStatus;
|
return errorStatus;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
targetObject[targetKey] = result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getAsJsonSchemaUncached() {
|
getAsJsonSchemaUncached() {
|
||||||
|
@ -1226,15 +1229,18 @@ export class TypeStructuredObject extends BaseDataType {
|
||||||
* @returns {string|void} String error code or null on success
|
* @returns {string|void} String error code or null on success
|
||||||
*/
|
*/
|
||||||
deserialize(value, targetObject, targetKey, root) {
|
deserialize(value, targetObject, targetKey, root) {
|
||||||
let result = {};
|
let target = targetObject[targetKey];
|
||||||
|
if (!target) {
|
||||||
|
targetObject[targetKey] = target = {};
|
||||||
|
}
|
||||||
|
|
||||||
for (const key in value) {
|
for (const key in value) {
|
||||||
const valueType = this.descriptor[key];
|
const valueType = this.descriptor[key];
|
||||||
const errorCode = valueType.deserializeWithVerify(value[key], result, key, root);
|
const errorCode = valueType.deserializeWithVerify(value[key], target, key, root);
|
||||||
if (errorCode) {
|
if (errorCode) {
|
||||||
return errorCode;
|
return errorCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
targetObject[targetKey] = result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getAsJsonSchemaUncached() {
|
getAsJsonSchemaUncached() {
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
import { gComponentRegistry } from "../core/global_registries";
|
import { createLogger } from "../core/logging";
|
||||||
|
import { Vector } from "../core/vector";
|
||||||
|
import { getBuildingDataFromCode } from "../game/building_codes";
|
||||||
import { Entity } from "../game/entity";
|
import { Entity } from "../game/entity";
|
||||||
import { enumLayer, GameRoot } from "../game/root";
|
import { GameRoot } from "../game/root";
|
||||||
|
|
||||||
|
const logger = createLogger("serializer_internal");
|
||||||
|
|
||||||
// Internal serializer methods
|
// Internal serializer methods
|
||||||
export class SerializerInternal {
|
export class SerializerInternal {
|
||||||
|
@ -37,19 +41,27 @@ export class SerializerInternal {
|
||||||
* @param {Entity} payload
|
* @param {Entity} payload
|
||||||
*/
|
*/
|
||||||
deserializeEntity(root, payload) {
|
deserializeEntity(root, payload) {
|
||||||
const entity = new Entity(root);
|
const staticData = payload.components.StaticMapEntity;
|
||||||
this.deserializeComponents(entity, payload.components);
|
assert(staticData, "entity has no static data");
|
||||||
entity.layer = payload.layer;
|
|
||||||
|
|
||||||
if (!enumLayer[payload.layer]) {
|
const code = staticData.code;
|
||||||
assert(false, "Invalid layer: " + payload.layer);
|
const data = getBuildingDataFromCode(code);
|
||||||
}
|
|
||||||
|
const metaBuilding = data.metaInstance;
|
||||||
|
|
||||||
|
const entity = metaBuilding.createEntity({
|
||||||
|
root,
|
||||||
|
origin: Vector.fromSerializedObject(staticData.origin),
|
||||||
|
rotation: staticData.rotation,
|
||||||
|
originalRotation: staticData.originalRotation,
|
||||||
|
rotationVariant: data.rotationVariant,
|
||||||
|
variant: data.variant,
|
||||||
|
});
|
||||||
|
|
||||||
|
this.deserializeComponents(entity, payload.components);
|
||||||
|
|
||||||
root.entityMgr.registerEntity(entity, payload.uid);
|
root.entityMgr.registerEntity(entity, payload.uid);
|
||||||
|
root.map.placeStaticEntity(entity);
|
||||||
if (entity.components.StaticMapEntity) {
|
|
||||||
root.map.placeStaticEntity(entity);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/////// COMPONENTS ////
|
/////// COMPONENTS ////
|
||||||
|
@ -62,10 +74,12 @@ export class SerializerInternal {
|
||||||
*/
|
*/
|
||||||
deserializeComponents(entity, data) {
|
deserializeComponents(entity, data) {
|
||||||
for (const componentId in data) {
|
for (const componentId in data) {
|
||||||
const componentClass = gComponentRegistry.findById(componentId);
|
if (!entity.components[componentId]) {
|
||||||
const componentHandle = new componentClass({});
|
logger.warn("Entity no longer has component:", componentId);
|
||||||
entity.addComponent(componentHandle);
|
continue;
|
||||||
const errorStatus = componentHandle.deserialize(data[componentId]);
|
}
|
||||||
|
|
||||||
|
const errorStatus = entity.components[componentId].deserialize(data[componentId]);
|
||||||
if (errorStatus) {
|
if (errorStatus) {
|
||||||
return errorStatus;
|
return errorStatus;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue