1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2026-02-12 02:49:20 +00:00

cleaned up code and fixed icons not always showing

This commit is contained in:
Sense101 2021-07-28 11:55:50 +01:00
parent 2442d6d655
commit bf8f9e989e
2 changed files with 38 additions and 32 deletions

View File

@ -34,13 +34,11 @@
}
&.import {
/* @load-async */
background: uiResource("icons/upload.png") center center / D(15px) no-repeat;
background: uiResource("icons/upload.png") center center / D(15px) no-repeat !important;
}
&.export {
/* @load-async */
background: uiResource("icons/download.png") center center / D(15px) no-repeat;
background: uiResource("icons/download.png") center center / D(15px) no-repeat !important;
}
}
}

View File

@ -5,6 +5,7 @@ import { makeDiv } from "../../../core/utils";
import { T } from "../../../translations";
import { MetaBlockBuilding } from "../../buildings/block";
import { MetaConstantProducerBuilding } from "../../buildings/constant_producer";
import { MetaGoalAcceptorBuilding } from "../../buildings/goal_acceptor";
import { StaticMapEntityComponent } from "../../components/static_map_entity";
import { Entity } from "../../entity";
import { PuzzleGameMode } from "../../modes/puzzle";
@ -94,47 +95,41 @@ export class HUDPuzzleEditorSettings extends BaseHUDPart {
}, 140);
if (this.testMode) {
const newSolution = [];
for (const entity of this.root.entityMgr.getAllWithComponent(StaticMapEntityComponent)) {
this.storedSolution.push(entity.clone());
const metaBuilding = entity.components.StaticMapEntity.getMetaBuilding();
const goalComp = entity.components.GoalAcceptor;
if (goalComp) {
goalComp.clear();
if (this.isExcludedEntity(entity)) {
continue;
}
if (
[MetaConstantProducerBuilding, MetaBlockBuilding]
.map(metaClass => gMetaBuildingRegistry.findByClass(metaClass).id)
.includes(metaBuilding.id)
) {
continue;
}
newSolution.push(entity.clone());
this.root.map.removeStaticEntity(entity);
this.root.entityMgr.destroyEntity(entity);
}
this.root.entityMgr.processDestroyList();
} else if (this.storedSolution.length > 0) {
this.storedSolution = newSolution;
} else if (this.storedSolution.length) {
this.root.logic.performBulkOperation(() => {
this.root.logic.performImmutableOperation(() => {
for (const entity of this.root.entityMgr.getAllWithComponent(StaticMapEntityComponent)) {
this.root.map.removeStaticEntity(entity);
this.root.entityMgr.destroyEntity(entity);
}
this.root.entityMgr.processDestroyList();
for (const entity of this.root.entityMgr.getAllWithComponent(StaticMapEntityComponent)) {
if (this.isExcludedEntity(entity)) continue;
for (const entity of this.storedSolution) {
const placedEntity = this.root.logic.tryPlaceEntity(entity);
this.root.map.removeStaticEntity(entity);
this.root.entityMgr.destroyEntity(entity);
}
this.root.entityMgr.processDestroyList();
for (const key in entity.components) {
/** @type {import("../../../core/global_registries").Component} */ (entity
.components[key]).copyAdditionalStateTo(placedEntity.components[key]);
}
for (let i = 0; i < this.storedSolution.length; ++i) {
const entity = this.storedSolution[i];
const placedEntity = this.root.logic.tryPlaceEntity(entity);
for (const key in entity.components) {
/** @type {import("../../../core/global_registries").Component} */ (entity.components[
key
]).copyAdditionalStateTo(placedEntity.components[key]);
}
this.storedSolution = [];
});
}
this.storedSolution = [];
});
}
}
@ -279,4 +274,17 @@ export class HUDPuzzleEditorSettings extends BaseHUDPart {
getIsTestMode() {
return this.testMode;
}
isExcludedEntity(entity) {
const metaBuilding = entity.components.StaticMapEntity.getMetaBuilding();
if (
[MetaConstantProducerBuilding, MetaBlockBuilding, MetaGoalAcceptorBuilding]
.map(metaClass => gMetaBuildingRegistry.findByClass(metaClass).id)
.includes(metaBuilding.id)
) {
return true;
}
return false;
}
}