1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-06-13 13:04:03 +00:00

cleanedup and fixed files, ready for pr

This commit is contained in:
dgs4349 2020-10-09 18:21:36 -04:00
parent fac84a472c
commit 6f29a5fb42
11 changed files with 320 additions and 336 deletions

View File

@ -9,7 +9,7 @@ export default {
// noArtificialDelays: true, // noArtificialDelays: true,
// ----------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------
// Disables writing of savegames, useful for testing the same savegame over and over // Disables writing of savegames, useful for testing the same savegame over and over
disableSavegameWrite: true, // disableSavegameWrite: true,
// ----------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------
// Shows bounds of all entities // Shows bounds of all entities
// showEntityBounds: true, // showEntityBounds: true,
@ -33,7 +33,7 @@ export default {
// allBuildingsUnlocked: true, // allBuildingsUnlocked: true,
// ----------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------
// Disables cost of blueprints // Disables cost of blueprints
blueprintsNoCost: true, // blueprintsNoCost: true,
// ----------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------
// Disables cost of upgrades // Disables cost of upgrades
// upgradesNoCost: true, // upgradesNoCost: true,
@ -75,7 +75,7 @@ export default {
// instantMiners: true, // instantMiners: true,
// ----------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------
// When using fastGameEnter, controls whether a new game is started or the last one is resumed // When using fastGameEnter, controls whether a new game is started or the last one is resumed
resumeGameOnFastEnter: true, // resumeGameOnFastEnter: true,
// ----------------------------------------------------------------------------------- // -----------------------------------------------------------------------------------
// Special option used to render the trailer // Special option used to render the trailer
// renderForTrailer: true, // renderForTrailer: true,

View File

@ -169,7 +169,7 @@ export class ReadWriteProxy {
// Check for errors during read // Check for errors during read
.catch(err => { .catch(err => {
if (err === FILE_NOT_FOUND) { if (err === FILE_NOT_FOUND) {
logger.error("File not found, using default data"); logger.log("File not found, using default data");
// File not found or unreadable, assume default file // File not found or unreadable, assume default file
return Promise.resolve(null); return Promise.resolve(null);

View File

@ -1,4 +1,3 @@
import { arrayDeleteValue, newEmptyMap, fastArrayDeleteValue } from "../core/utils";
import { Component } from "./component"; import { Component } from "./component";
import { GameRoot } from "./root"; import { GameRoot } from "./root";
import { Entity } from "./entity"; import { Entity } from "./entity";
@ -10,9 +9,6 @@ const logger = createLogger("entity_manager");
// Manages all entities // Manages all entities
// NOTICE: We use arrayDeleteValue instead of fastArrayDeleteValue since that does not preserve the order
// This is slower but we need it for the street path generation
/** @typedef {number} EntityUid */ /** @typedef {number} EntityUid */
/** @typedef {string} ComponentId */ /** @typedef {string} ComponentId */
@ -37,11 +33,6 @@ export class EntityManager extends BasicSerializableObject {
/** @type {Array<Entity>} */ /** @type {Array<Entity>} */
this.destroyList = []; this.destroyList = [];
// Store a map from componentid to entities - This is used by the game system
// for faster processing
///** @type {Object.<string, Array<Entity>>} */
//this.componentToEntity = newEmptyMap();
// Store the next uid to use // Store the next uid to use
this.nextUid = 10000; this.nextUid = 10000;
} }

View File

@ -5,7 +5,6 @@ import { Entity } from "./entity";
import { GameRoot } from "./root"; import { GameRoot } from "./root";
import { GameSystem } from "./game_system"; import { GameSystem } from "./game_system";
import { arrayDelete, arrayDeleteValue, fastArrayDelete } from "../core/utils";
export class GameSystemWithFilter extends GameSystem { export class GameSystemWithFilter extends GameSystem {
/** /**
@ -71,7 +70,6 @@ export class GameSystemWithFilter extends GameSystem {
for (let i = 0; i < this.requiredComponentIds.length; ++i) { for (let i = 0; i < this.requiredComponentIds.length; ++i) {
if (!entity.components[this.requiredComponentIds[i]]) { if (!entity.components[this.requiredComponentIds[i]]) {
// Entity is not interesting anymore // Entity is not interesting anymore
//arrayDeleteValue(this.allEntities, entity);
this.allEntitiesArrayIsOutdated = this.allEntitiesSet.delete(entity); this.allEntitiesArrayIsOutdated = this.allEntitiesSet.delete(entity);
} }
} }
@ -94,7 +92,6 @@ export class GameSystemWithFilter extends GameSystem {
} }
refreshCaches() { refreshCaches() {
//this.allEntities.sort((a, b) => a.uid - b.uid);
// Remove all entities which are queued for destroy // Remove all entities which are queued for destroy
if (this.entitiesQueuedToDelete.length > 0) { if (this.entitiesQueuedToDelete.length > 0) {
for (let i = this.entitiesQueuedToDelete.length - 1; i >= 0; --i) { for (let i = this.entitiesQueuedToDelete.length - 1; i >= 0; --i) {
@ -121,11 +118,6 @@ export class GameSystemWithFilter extends GameSystem {
internalRegisterEntity(entity) { internalRegisterEntity(entity) {
this.allEntitiesSet.add(entity); this.allEntitiesSet.add(entity);
this.allEntitiesArray.push(entity); this.allEntitiesArray.push(entity);
// if (this.root.gameInitialized && !this.root.bulkOperationRunning) {
// // Sort entities by uid so behaviour is predictable
// this.allEntities.sort((a, b) => a.uid - b.uid);
// }
} }
/** /**

View File

@ -44,7 +44,6 @@ import { HUDWireInfo } from "./parts/wire_info";
import { HUDLeverToggle } from "./parts/lever_toggle"; import { HUDLeverToggle } from "./parts/lever_toggle";
import { HUDLayerPreview } from "./parts/layer_preview"; import { HUDLayerPreview } from "./parts/layer_preview";
import { HUDMinerHighlight } from "./parts/miner_highlight"; import { HUDMinerHighlight } from "./parts/miner_highlight";
import { Entity } from "../entity";
import { HUDBetaOverlay } from "./parts/beta_overlay"; import { HUDBetaOverlay } from "./parts/beta_overlay";
import { HUDStandaloneAdvantages } from "./parts/standalone_advantages"; import { HUDStandaloneAdvantages } from "./parts/standalone_advantages";
import { HUDCatMemes } from "./parts/cat_memes"; import { HUDCatMemes } from "./parts/cat_memes";

View File

@ -1,19 +1,17 @@
import { BaseHUDPart } from "../base_hud_part";
import { Vector } from "../../../core/vector";
import { STOP_PROPAGATION } from "../../../core/signal";
import { DrawParameters } from "../../../core/draw_parameters";
import { Entity } from "../../entity";
import { Loader } from "../../../core/loader";
import { globalConfig } from "../../../core/config"; import { globalConfig } from "../../../core/config";
import { makeDiv, formatBigNumber, formatBigNumberFull, dirInterval } from "../../../core/utils"; import { DrawParameters } from "../../../core/draw_parameters";
import { DynamicDomAttach } from "../dynamic_dom_attach";
import { createLogger } from "../../../core/logging"; import { createLogger } from "../../../core/logging";
import { enumMouseButton } from "../../camera"; import { STOP_PROPAGATION } from "../../../core/signal";
import { formatBigNumberFull } from "../../../core/utils";
import { Vector } from "../../../core/vector";
import { T } from "../../../translations"; import { T } from "../../../translations";
import { Blueprint } from "../../blueprint";
import { enumMouseButton } from "../../camera";
import { Entity } from "../../entity";
import { KEYMAPPINGS } from "../../key_action_mapper"; import { KEYMAPPINGS } from "../../key_action_mapper";
import { THEME } from "../../theme"; import { THEME } from "../../theme";
import { enumHubGoalRewards } from "../../tutorial_goals"; import { enumHubGoalRewards } from "../../tutorial_goals";
import { Blueprint } from "../../blueprint"; import { BaseHUDPart } from "../base_hud_part";
const logger = createLogger("hud/mass_selector"); const logger = createLogger("hud/mass_selector");
@ -52,16 +50,6 @@ export class HUDMassSelector extends BaseHUDPart {
this.selectedEntities.clear(); this.selectedEntities.clear();
} }
// getUidArray() {
// if (this.selectedEntities.size <= 0) return [];
// const uids = [];
// const arr = [...this.selectedEntities.values()];
// for (let i = arr.length - 1; i >= 0; --i) {
// uids.push(arr[i].uid);
// }
// return uids;
// }
/** /**
* Handles the destroy callback and makes sure we clean our list * Handles the destroy callback and makes sure we clean our list
* @param {Entity} entity * @param {Entity} entity
@ -115,7 +103,6 @@ export class HUDMassSelector extends BaseHUDPart {
/** /**
* @type {Map<number, Entity>} * @type {Map<number, Entity>}
*/ */
//const mapUidToEntity = this.root.entityMgr.getFrozenUidSearchMap();
this.root.logic.performBulkOperation(() => { this.root.logic.performBulkOperation(() => {
const arr = [...this.selectedEntities.values()]; const arr = [...this.selectedEntities.values()];
@ -138,8 +125,8 @@ export class HUDMassSelector extends BaseHUDPart {
); );
return; return;
} }
const uids = [];
// @ts-ignore
this.root.hud.signals.buildingsSelectedForCopy.dispatch([...this.selectedEntities.values()]); this.root.hud.signals.buildingsSelectedForCopy.dispatch([...this.selectedEntities.values()]);
this.selectedEntities.clear(); this.selectedEntities.clear();
this.root.soundProxy.playUiClick(); this.root.soundProxy.playUiClick();

View File

@ -1,185 +1,196 @@
import { globalConfig } from "../../core/config"; import { globalConfig } from "../../core/config";
import { smoothenDpi } from "../../core/dpi_manager"; import { smoothenDpi } from "../../core/dpi_manager";
import { DrawParameters } from "../../core/draw_parameters"; import { DrawParameters } from "../../core/draw_parameters";
import { drawSpriteClipped } from "../../core/draw_utils"; import { drawSpriteClipped } from "../../core/draw_utils";
import { Loader } from "../../core/loader"; import { Loader } from "../../core/loader";
import { Rectangle } from "../../core/rectangle"; import { Rectangle } from "../../core/rectangle";
import { ORIGINAL_SPRITE_SCALE } from "../../core/sprites"; import { ORIGINAL_SPRITE_SCALE } from "../../core/sprites";
import { formatBigNumber } from "../../core/utils"; import { formatBigNumber } from "../../core/utils";
import { T } from "../../translations"; import { T } from "../../translations";
import { HubComponent } from "../components/hub"; import { HubComponent } from "../components/hub";
import { Entity } from "../entity"; import { Entity } from "../entity";
import { GameSystemWithFilter } from "../game_system_with_filter"; import { GameSystemWithFilter } from "../game_system_with_filter";
const HUB_SIZE_TILES = 4; const HUB_SIZE_TILES = 4;
const HUB_SIZE_PIXELS = HUB_SIZE_TILES * globalConfig.tileSize; const HUB_SIZE_PIXELS = HUB_SIZE_TILES * globalConfig.tileSize;
export class HubSystem extends GameSystemWithFilter { export class HubSystem extends GameSystemWithFilter {
constructor(root) { constructor(root) {
super(root, [HubComponent]); super(root, [HubComponent]);
this.hubSprite = Loader.getSprite("sprites/buildings/hub.png"); this.hubSprite = Loader.getSprite("sprites/buildings/hub.png");
} }
/** /**
* @param {DrawParameters} parameters * @param {DrawParameters} parameters
*/ */
draw(parameters) { draw(parameters) {
for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) { for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) {
const entity = this.allEntitiesArray[i]; this.drawEntity(parameters, this.allEntitiesArray[i]);
this.drawEntity(parameters, entity); }
} }
}
update() {
update() { for (let i = 0; i < this.allEntitiesArray.length; ++i) {
for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) { // Set hub goal
const entity = this.allEntitiesArray[i]; const entity = this.allEntitiesArray[i];
const pinsComp = entity.components.WiredPins; const pinsComp = entity.components.WiredPins;
pinsComp.slots[0].value = this.root.shapeDefinitionMgr.getShapeItemFromDefinition( pinsComp.slots[0].value = this.root.shapeDefinitionMgr.getShapeItemFromDefinition(
this.root.hubGoals.currentGoal.definition this.root.hubGoals.currentGoal.definition
); );
} }
} }
/** /**
* *
* @param {HTMLCanvasElement} canvas * @param {HTMLCanvasElement} canvas
* @param {CanvasRenderingContext2D} context * @param {CanvasRenderingContext2D} context
* @param {number} w * @param {number} w
* @param {number} h * @param {number} h
* @param {number} dpi * @param {number} dpi
*/ */
redrawHubBaseTexture(canvas, context, w, h, dpi) { redrawHubBaseTexture(canvas, context, w, h, dpi) {
// This method is quite ugly, please ignore it! // This method is quite ugly, please ignore it!
context.scale(dpi, dpi); context.scale(dpi, dpi);
const parameters = new DrawParameters({ const parameters = new DrawParameters({
context, context,
visibleRect: new Rectangle(0, 0, w, h), visibleRect: new Rectangle(0, 0, w, h),
desiredAtlasScale: ORIGINAL_SPRITE_SCALE, desiredAtlasScale: ORIGINAL_SPRITE_SCALE,
zoomLevel: dpi * 0.75, zoomLevel: dpi * 0.75,
root: this.root, root: this.root,
}); });
context.clearRect(0, 0, w, h); context.clearRect(0, 0, w, h);
this.hubSprite.draw(context, 0, 0, w, h); this.hubSprite.draw(context, 0, 0, w, h);
const definition = this.root.hubGoals.currentGoal.definition; if (this.root.hubGoals.isEndOfDemoReached()) {
definition.drawCentered(45, 58, parameters, 36); // End of demo
context.font = "bold 12px GameFont";
const goals = this.root.hubGoals.currentGoal; context.fillStyle = "#fd0752";
context.textAlign = "center";
const textOffsetX = 70; context.fillText(T.buildings.hub.endOfDemo.toUpperCase(), w / 2, h / 2 + 6);
const textOffsetY = 61; context.textAlign = "left";
if (goals.throughputOnly) { return;
// Throughput }
const deliveredText = T.ingame.statistics.shapesDisplayUnits.second.replace(
"<shapes>", const definition = this.root.hubGoals.currentGoal.definition;
formatBigNumber(goals.required) definition.drawCentered(45, 58, parameters, 36);
);
const goals = this.root.hubGoals.currentGoal;
context.font = "bold 12px GameFont";
context.fillStyle = "#64666e"; const textOffsetX = 70;
context.textAlign = "left"; const textOffsetY = 61;
context.fillText(deliveredText, textOffsetX, textOffsetY);
} else { if (goals.throughputOnly) {
// Deliver count // Throughput
const delivered = this.root.hubGoals.getCurrentGoalDelivered(); const deliveredText = T.ingame.statistics.shapesDisplayUnits.second.replace(
const deliveredText = "" + formatBigNumber(delivered); "<shapes>",
formatBigNumber(goals.required)
if (delivered > 9999) { );
context.font = "bold 16px GameFont";
} else if (delivered > 999) { context.font = "bold 12px GameFont";
context.font = "bold 20px GameFont"; context.fillStyle = "#64666e";
} else { context.textAlign = "left";
context.font = "bold 25px GameFont"; context.fillText(deliveredText, textOffsetX, textOffsetY);
} } else {
context.fillStyle = "#64666e"; // Deliver count
context.textAlign = "left"; const delivered = this.root.hubGoals.getCurrentGoalDelivered();
context.fillText(deliveredText, textOffsetX, textOffsetY); const deliveredText = "" + formatBigNumber(delivered);
// Required if (delivered > 9999) {
context.font = "13px GameFont"; context.font = "bold 16px GameFont";
context.fillStyle = "#a4a6b0"; } else if (delivered > 999) {
context.fillText("/ " + formatBigNumber(goals.required), textOffsetX, textOffsetY + 13); context.font = "bold 20px GameFont";
} else {
// Reward context.font = "bold 25px GameFont";
const rewardText = T.storyRewards[goals.reward].title.toUpperCase(); }
if (rewardText.length > 12) { context.fillStyle = "#64666e";
context.font = "bold 8px GameFont"; context.textAlign = "left";
} else { context.fillText(deliveredText, textOffsetX, textOffsetY);
context.font = "bold 10px GameFont";
} // Required
context.fillStyle = "#fd0752"; context.font = "13px GameFont";
context.textAlign = "center"; context.fillStyle = "#a4a6b0";
context.fillText("/ " + formatBigNumber(goals.required), textOffsetX, textOffsetY + 13);
context.fillText(rewardText, HUB_SIZE_PIXELS / 2, 105); }
// Level "8" // Reward
context.font = "bold 10px GameFont"; const rewardText = T.storyRewards[goals.reward].title.toUpperCase();
context.fillStyle = "#fff"; if (rewardText.length > 12) {
context.fillText("" + this.root.hubGoals.level, 27, 32); context.font = "bold 8px GameFont";
} else {
// "LVL" context.font = "bold 10px GameFont";
context.textAlign = "center"; }
context.fillStyle = "#fff"; context.fillStyle = "#fd0752";
context.font = "bold 6px GameFont"; context.textAlign = "center";
context.fillText(T.buildings.hub.levelShortcut, 27, 22);
context.fillText(rewardText, HUB_SIZE_PIXELS / 2, 105);
// "Deliver"
context.fillStyle = "#64666e"; // Level "8"
context.font = "bold 10px GameFont"; context.font = "bold 10px GameFont";
context.fillText(T.buildings.hub.deliver.toUpperCase(), HUB_SIZE_PIXELS / 2, 30); context.fillStyle = "#fff";
context.fillText("" + this.root.hubGoals.level, 27, 32);
// "To unlock"
const unlockText = T.buildings.hub.toUnlock.toUpperCase(); // "LVL"
if (unlockText.length > 15) { context.textAlign = "center";
context.font = "bold 8px GameFont"; context.fillStyle = "#fff";
} else { context.font = "bold 6px GameFont";
context.font = "bold 10px GameFont"; context.fillText(T.buildings.hub.levelShortcut, 27, 22);
}
context.fillText(T.buildings.hub.toUnlock.toUpperCase(), HUB_SIZE_PIXELS / 2, 92); // "Deliver"
context.fillStyle = "#64666e";
context.textAlign = "left"; context.font = "bold 10px GameFont";
} context.fillText(T.buildings.hub.deliver.toUpperCase(), HUB_SIZE_PIXELS / 2, 30);
}
// "To unlock"
/** const unlockText = T.buildings.hub.toUnlock.toUpperCase();
* @param {DrawParameters} parameters if (unlockText.length > 15) {
* @param {Entity} entity context.font = "bold 8px GameFont";
*/ } else {
drawEntity(parameters, entity) { context.font = "bold 10px GameFont";
const staticComp = entity.components.StaticMapEntity; }
if (!staticComp.shouldBeDrawn(parameters)) { context.fillText(T.buildings.hub.toUnlock.toUpperCase(), HUB_SIZE_PIXELS / 2, 92);
return;
} context.textAlign = "left";
}
// Deliver count
const delivered = this.root.hubGoals.getCurrentGoalDelivered(); /**
const deliveredText = "" + formatBigNumber(delivered); * @param {DrawParameters} parameters
* @param {Entity} entity
const dpi = smoothenDpi(globalConfig.shapesSharpness * parameters.zoomLevel); */
const canvas = parameters.root.buffers.getForKey({ drawEntity(parameters, entity) {
key: "hub", const staticComp = entity.components.StaticMapEntity;
subKey: dpi + "/" + this.root.hubGoals.level + "/" + deliveredText, if (!staticComp.shouldBeDrawn(parameters)) {
w: globalConfig.tileSize * 4, return;
h: globalConfig.tileSize * 4, }
dpi,
redrawMethod: this.redrawHubBaseTexture.bind(this), // Deliver count
}); const delivered = this.root.hubGoals.getCurrentGoalDelivered();
const deliveredText = "" + formatBigNumber(delivered);
const extrude = 8;
drawSpriteClipped({ const dpi = smoothenDpi(globalConfig.shapesSharpness * parameters.zoomLevel);
parameters, const canvas = parameters.root.buffers.getForKey({
sprite: canvas, key: "hub",
x: staticComp.origin.x * globalConfig.tileSize - extrude, subKey: dpi + "/" + this.root.hubGoals.level + "/" + deliveredText,
y: staticComp.origin.y * globalConfig.tileSize - extrude, w: globalConfig.tileSize * 4,
w: HUB_SIZE_PIXELS + 2 * extrude, h: globalConfig.tileSize * 4,
h: HUB_SIZE_PIXELS + 2 * extrude, dpi,
originalW: HUB_SIZE_PIXELS * dpi, redrawMethod: this.redrawHubBaseTexture.bind(this),
originalH: HUB_SIZE_PIXELS * dpi, });
});
} const extrude = 8;
} drawSpriteClipped({
parameters,
sprite: canvas,
x: staticComp.origin.x * globalConfig.tileSize - extrude,
y: staticComp.origin.y * globalConfig.tileSize - extrude,
w: HUB_SIZE_PIXELS + 2 * extrude,
h: HUB_SIZE_PIXELS + 2 * extrude,
originalW: HUB_SIZE_PIXELS * dpi,
originalH: HUB_SIZE_PIXELS * dpi,
});
}
}

View File

@ -1,101 +1,101 @@
import { GameSystemWithFilter } from "../game_system_with_filter"; import { GameSystemWithFilter } from "../game_system_with_filter";
import { StorageComponent } from "../components/storage"; import { StorageComponent } from "../components/storage";
import { DrawParameters } from "../../core/draw_parameters"; import { DrawParameters } from "../../core/draw_parameters";
import { formatBigNumber, lerp } from "../../core/utils"; import { formatBigNumber, lerp } from "../../core/utils";
import { Loader } from "../../core/loader"; import { Loader } from "../../core/loader";
import { BOOL_TRUE_SINGLETON, BOOL_FALSE_SINGLETON } from "../items/boolean_item"; import { BOOL_TRUE_SINGLETON, BOOL_FALSE_SINGLETON } from "../items/boolean_item";
import { MapChunkView } from "../map_chunk_view"; import { MapChunkView } from "../map_chunk_view";
export class StorageSystem extends GameSystemWithFilter { export class StorageSystem extends GameSystemWithFilter {
constructor(root) { constructor(root) {
super(root, [StorageComponent]); super(root, [StorageComponent]);
this.storageOverlaySprite = Loader.getSprite("sprites/misc/storage_overlay.png"); this.storageOverlaySprite = Loader.getSprite("sprites/misc/storage_overlay.png");
/** /**
* Stores which uids were already drawn to avoid drawing entities twice * Stores which uids were already drawn to avoid drawing entities twice
* @type {Set<number>} * @type {Set<number>}
*/ */
this.drawnUids = new Set(); this.drawnUids = new Set();
this.root.signals.gameFrameStarted.add(this.clearDrawnUids, this); this.root.signals.gameFrameStarted.add(this.clearDrawnUids, this);
} }
clearDrawnUids() { clearDrawnUids() {
this.drawnUids.clear(); this.drawnUids.clear();
} }
update() { update() {
for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) { for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) {
const entity = this.allEntitiesArray[i]; const entity = this.allEntitiesArray[i];
const storageComp = entity.components.Storage; const storageComp = entity.components.Storage;
const pinsComp = entity.components.WiredPins; const pinsComp = entity.components.WiredPins;
// Eject from storage // Eject from storage
if (storageComp.storedItem && storageComp.storedCount > 0) { if (storageComp.storedItem && storageComp.storedCount > 0) {
const ejectorComp = entity.components.ItemEjector; const ejectorComp = entity.components.ItemEjector;
const nextSlot = ejectorComp.getFirstFreeSlot(); const nextSlot = ejectorComp.getFirstFreeSlot();
if (nextSlot !== null) { if (nextSlot !== null) {
if (ejectorComp.tryEject(nextSlot, storageComp.storedItem)) { if (ejectorComp.tryEject(nextSlot, storageComp.storedItem)) {
storageComp.storedCount--; storageComp.storedCount--;
if (storageComp.storedCount === 0) { if (storageComp.storedCount === 0) {
storageComp.storedItem = null; storageComp.storedItem = null;
} }
} }
} }
} }
let targetAlpha = storageComp.storedCount > 0 ? 1 : 0; let targetAlpha = storageComp.storedCount > 0 ? 1 : 0;
storageComp.overlayOpacity = lerp(storageComp.overlayOpacity, targetAlpha, 0.05); storageComp.overlayOpacity = lerp(storageComp.overlayOpacity, targetAlpha, 0.05);
pinsComp.slots[0].value = storageComp.storedItem; pinsComp.slots[0].value = storageComp.storedItem;
pinsComp.slots[1].value = storageComp.getIsFull() ? BOOL_TRUE_SINGLETON : BOOL_FALSE_SINGLETON; pinsComp.slots[1].value = storageComp.getIsFull() ? BOOL_TRUE_SINGLETON : BOOL_FALSE_SINGLETON;
} }
} }
/** /**
* @param {DrawParameters} parameters * @param {DrawParameters} parameters
* @param {MapChunkView} chunk * @param {MapChunkView} chunk
*/ */
drawChunk(parameters, chunk) { drawChunk(parameters, chunk) {
const contents = chunk.containedEntitiesByLayer.regular; const contents = chunk.containedEntitiesByLayer.regular;
for (let i = 0; i < contents.length; ++i) { for (let i = 0; i < contents.length; ++i) {
const entity = contents[i]; const entity = contents[i];
const storageComp = entity.components.Storage; const storageComp = entity.components.Storage;
if (!storageComp) { if (!storageComp) {
continue; continue;
} }
const storedItem = storageComp.storedItem; const storedItem = storageComp.storedItem;
if (!storedItem) { if (!storedItem) {
continue; continue;
} }
if (this.drawnUids.has(entity.uid)) { if (this.drawnUids.has(entity.uid)) {
continue; continue;
} }
this.drawnUids.add(entity.uid); this.drawnUids.add(entity.uid);
const staticComp = entity.components.StaticMapEntity; const staticComp = entity.components.StaticMapEntity;
const context = parameters.context; const context = parameters.context;
context.globalAlpha = storageComp.overlayOpacity; context.globalAlpha = storageComp.overlayOpacity;
const center = staticComp.getTileSpaceBounds().getCenter().toWorldSpace(); const center = staticComp.getTileSpaceBounds().getCenter().toWorldSpace();
storedItem.drawItemCenteredClipped(center.x, center.y, parameters, 30); storedItem.drawItemCenteredClipped(center.x, center.y, parameters, 30);
this.storageOverlaySprite.drawCached(parameters, center.x - 15, center.y + 15, 30, 15); this.storageOverlaySprite.drawCached(parameters, center.x - 15, center.y + 15, 30, 15);
if (parameters.visibleRect.containsCircle(center.x, center.y + 25, 20)) { if (parameters.visibleRect.containsCircle(center.x, center.y + 25, 20)) {
context.font = "bold 10px GameFont"; context.font = "bold 10px GameFont";
context.textAlign = "center"; context.textAlign = "center";
context.fillStyle = "#64666e"; context.fillStyle = "#64666e";
context.fillText(formatBigNumber(storageComp.storedCount), center.x, center.y + 25.5); context.fillText(formatBigNumber(storageComp.storedCount), center.x, center.y + 25.5);
context.textAlign = "left"; context.textAlign = "left";
} }
context.globalAlpha = 1; context.globalAlpha = 1;
} }
} }
} }

View File

@ -169,10 +169,13 @@ export class Savegame extends ReadWriteProxy {
* Returns if this game has a serialized game dump * Returns if this game has a serialized game dump
*/ */
hasGameDump() { hasGameDump() {
return ( if(!this.currentData.dump) return false;
!!this.currentData.dump && if(Array.isArray(this.currentData.dump.entities)) {
(this.currentData.dump.entities.length > 0 || this.currentData.dump.entities.size > 0) return this.currentData.dump.entities.length;
); }
else {
return this.currentData.dump.entities.size;
}
} }
/** /**

View File

@ -68,7 +68,7 @@ export class SavegameSerializer {
// Check for duplicate UIDS // Check for duplicate UIDS
const entities = [...savegame.entities.values()]; const entities = [...savegame.entities.values()];
for (let i = 0; i < entities.length; ++i) { for (let i = entities.length - 1; i >= 0; --i) {
/** @type {Entity} */ /** @type {Entity} */
const entity = entities[i]; const entity = entities[i];

View File

@ -10,7 +10,8 @@
"no-console": false, "no-console": false,
"forin": false, "forin": false,
"no-empty": false, "no-empty": false,
"space-before-function-paren": ["always"] "space-before-function-paren": ["always"],
"no-unused-declaration": true
}, },
"rulesDirectory": [] "rulesDirectory": []
} }