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

@ -26,13 +26,13 @@ export class HubSystem extends GameSystemWithFilter {
*/ */
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 = this.allEntitiesArray.length - 1; i >= 0; --i) { for (let i = 0; i < this.allEntitiesArray.length; ++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(
@ -65,6 +65,17 @@ export class HubSystem extends GameSystemWithFilter {
this.hubSprite.draw(context, 0, 0, w, h); this.hubSprite.draw(context, 0, 0, w, h);
if (this.root.hubGoals.isEndOfDemoReached()) {
// End of demo
context.font = "bold 12px GameFont";
context.fillStyle = "#fd0752";
context.textAlign = "center";
context.fillText(T.buildings.hub.endOfDemo.toUpperCase(), w / 2, h / 2 + 6);
context.textAlign = "left";
return;
}
const definition = this.root.hubGoals.currentGoal.definition; const definition = this.root.hubGoals.currentGoal.definition;
definition.drawCentered(45, 58, parameters, 36); definition.drawCentered(45, 58, parameters, 36);
@ -104,46 +115,46 @@ export class HubSystem extends GameSystemWithFilter {
context.font = "13px GameFont"; context.font = "13px GameFont";
context.fillStyle = "#a4a6b0"; context.fillStyle = "#a4a6b0";
context.fillText("/ " + formatBigNumber(goals.required), textOffsetX, textOffsetY + 13); context.fillText("/ " + formatBigNumber(goals.required), textOffsetX, textOffsetY + 13);
// Reward
const rewardText = T.storyRewards[goals.reward].title.toUpperCase();
if (rewardText.length > 12) {
context.font = "bold 8px GameFont";
} else {
context.font = "bold 10px GameFont";
}
context.fillStyle = "#fd0752";
context.textAlign = "center";
context.fillText(rewardText, HUB_SIZE_PIXELS / 2, 105);
// Level "8"
context.font = "bold 10px GameFont";
context.fillStyle = "#fff";
context.fillText("" + this.root.hubGoals.level, 27, 32);
// "LVL"
context.textAlign = "center";
context.fillStyle = "#fff";
context.font = "bold 6px GameFont";
context.fillText(T.buildings.hub.levelShortcut, 27, 22);
// "Deliver"
context.fillStyle = "#64666e";
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();
if (unlockText.length > 15) {
context.font = "bold 8px GameFont";
} else {
context.font = "bold 10px GameFont";
}
context.fillText(T.buildings.hub.toUnlock.toUpperCase(), HUB_SIZE_PIXELS / 2, 92);
context.textAlign = "left";
} }
// Reward
const rewardText = T.storyRewards[goals.reward].title.toUpperCase();
if (rewardText.length > 12) {
context.font = "bold 8px GameFont";
} else {
context.font = "bold 10px GameFont";
}
context.fillStyle = "#fd0752";
context.textAlign = "center";
context.fillText(rewardText, HUB_SIZE_PIXELS / 2, 105);
// Level "8"
context.font = "bold 10px GameFont";
context.fillStyle = "#fff";
context.fillText("" + this.root.hubGoals.level, 27, 32);
// "LVL"
context.textAlign = "center";
context.fillStyle = "#fff";
context.font = "bold 6px GameFont";
context.fillText(T.buildings.hub.levelShortcut, 27, 22);
// "Deliver"
context.fillStyle = "#64666e";
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();
if (unlockText.length > 15) {
context.font = "bold 8px GameFont";
} else {
context.font = "bold 10px GameFont";
}
context.fillText(T.buildings.hub.toUnlock.toUpperCase(), HUB_SIZE_PIXELS / 2, 92);
context.textAlign = "left";
} }
/** /**

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": []
} }