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,
// -----------------------------------------------------------------------------------
// Disables writing of savegames, useful for testing the same savegame over and over
disableSavegameWrite: true,
// disableSavegameWrite: true,
// -----------------------------------------------------------------------------------
// Shows bounds of all entities
// showEntityBounds: true,
@ -33,7 +33,7 @@ export default {
// allBuildingsUnlocked: true,
// -----------------------------------------------------------------------------------
// Disables cost of blueprints
blueprintsNoCost: true,
// blueprintsNoCost: true,
// -----------------------------------------------------------------------------------
// Disables cost of upgrades
// upgradesNoCost: true,
@ -75,7 +75,7 @@ export default {
// instantMiners: true,
// -----------------------------------------------------------------------------------
// 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
// renderForTrailer: true,

View File

@ -169,7 +169,7 @@ export class ReadWriteProxy {
// Check for errors during read
.catch(err => {
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
return Promise.resolve(null);

View File

@ -1,4 +1,3 @@
import { arrayDeleteValue, newEmptyMap, fastArrayDeleteValue } from "../core/utils";
import { Component } from "./component";
import { GameRoot } from "./root";
import { Entity } from "./entity";
@ -10,9 +9,6 @@ const logger = createLogger("entity_manager");
// 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 {string} ComponentId */
@ -37,11 +33,6 @@ export class EntityManager extends BasicSerializableObject {
/** @type {Array<Entity>} */
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
this.nextUid = 10000;
}

View File

@ -5,7 +5,6 @@ import { Entity } from "./entity";
import { GameRoot } from "./root";
import { GameSystem } from "./game_system";
import { arrayDelete, arrayDeleteValue, fastArrayDelete } from "../core/utils";
export class GameSystemWithFilter extends GameSystem {
/**
@ -71,7 +70,6 @@ export class GameSystemWithFilter extends GameSystem {
for (let i = 0; i < this.requiredComponentIds.length; ++i) {
if (!entity.components[this.requiredComponentIds[i]]) {
// Entity is not interesting anymore
//arrayDeleteValue(this.allEntities, entity);
this.allEntitiesArrayIsOutdated = this.allEntitiesSet.delete(entity);
}
}
@ -94,7 +92,6 @@ export class GameSystemWithFilter extends GameSystem {
}
refreshCaches() {
//this.allEntities.sort((a, b) => a.uid - b.uid);
// Remove all entities which are queued for destroy
if (this.entitiesQueuedToDelete.length > 0) {
for (let i = this.entitiesQueuedToDelete.length - 1; i >= 0; --i) {
@ -121,11 +118,6 @@ export class GameSystemWithFilter extends GameSystem {
internalRegisterEntity(entity) {
this.allEntitiesSet.add(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 { HUDLayerPreview } from "./parts/layer_preview";
import { HUDMinerHighlight } from "./parts/miner_highlight";
import { Entity } from "../entity";
import { HUDBetaOverlay } from "./parts/beta_overlay";
import { HUDStandaloneAdvantages } from "./parts/standalone_advantages";
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 { makeDiv, formatBigNumber, formatBigNumberFull, dirInterval } from "../../../core/utils";
import { DynamicDomAttach } from "../dynamic_dom_attach";
import { DrawParameters } from "../../../core/draw_parameters";
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 { Blueprint } from "../../blueprint";
import { enumMouseButton } from "../../camera";
import { Entity } from "../../entity";
import { KEYMAPPINGS } from "../../key_action_mapper";
import { THEME } from "../../theme";
import { enumHubGoalRewards } from "../../tutorial_goals";
import { Blueprint } from "../../blueprint";
import { BaseHUDPart } from "../base_hud_part";
const logger = createLogger("hud/mass_selector");
@ -52,16 +50,6 @@ export class HUDMassSelector extends BaseHUDPart {
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
* @param {Entity} entity
@ -115,7 +103,6 @@ export class HUDMassSelector extends BaseHUDPart {
/**
* @type {Map<number, Entity>}
*/
//const mapUidToEntity = this.root.entityMgr.getFrozenUidSearchMap();
this.root.logic.performBulkOperation(() => {
const arr = [...this.selectedEntities.values()];
@ -138,8 +125,8 @@ export class HUDMassSelector extends BaseHUDPart {
);
return;
}
const uids = [];
// @ts-ignore
this.root.hud.signals.buildingsSelectedForCopy.dispatch([...this.selectedEntities.values()]);
this.selectedEntities.clear();
this.root.soundProxy.playUiClick();

View File

@ -26,13 +26,13 @@ export class HubSystem extends GameSystemWithFilter {
*/
draw(parameters) {
for (let i = this.allEntitiesArray.length - 1; i >= 0; --i) {
const entity = this.allEntitiesArray[i];
this.drawEntity(parameters, entity);
this.drawEntity(parameters, this.allEntitiesArray[i]);
}
}
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 pinsComp = entity.components.WiredPins;
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);
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;
definition.drawCentered(45, 58, parameters, 36);
@ -104,6 +115,7 @@ export class HubSystem extends GameSystemWithFilter {
context.font = "13px GameFont";
context.fillStyle = "#a4a6b0";
context.fillText("/ " + formatBigNumber(goals.required), textOffsetX, textOffsetY + 13);
}
// Reward
const rewardText = T.storyRewards[goals.reward].title.toUpperCase();
@ -144,7 +156,6 @@ export class HubSystem extends GameSystemWithFilter {
context.textAlign = "left";
}
}
/**
* @param {DrawParameters} parameters

View File

@ -169,10 +169,13 @@ export class Savegame extends ReadWriteProxy {
* Returns if this game has a serialized game dump
*/
hasGameDump() {
return (
!!this.currentData.dump &&
(this.currentData.dump.entities.length > 0 || this.currentData.dump.entities.size > 0)
);
if(!this.currentData.dump) return false;
if(Array.isArray(this.currentData.dump.entities)) {
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
const entities = [...savegame.entities.values()];
for (let i = 0; i < entities.length; ++i) {
for (let i = entities.length - 1; i >= 0; --i) {
/** @type {Entity} */
const entity = entities[i];

View File

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