1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2024-10-27 20:34:29 +00:00

Minor PR adjustments

This commit is contained in:
tobspr 2021-06-24 19:13:21 +02:00
parent d24a4a848e
commit 7b18d54cbe
8 changed files with 42 additions and 30 deletions

View File

@ -4,7 +4,7 @@ export const CHANGELOG = [
date: "24.06.2021", date: "24.06.2021",
entries: [ entries: [
"Puzzle DLC: Goal acceptors now reset after getting no items for a while (This should prevent being able to 'cheat' puzzles) (by Sense101)", "Puzzle DLC: Goal acceptors now reset after getting no items for a while (This should prevent being able to 'cheat' puzzles) (by Sense101)",
"Puzzle DLC: Added button to clear all buildings (by Sense101)", "Puzzle DLC: Added button to clear all buildings / reset the puzzle (by Sense101)",
"Puzzle DLC: Allow copy-paste in puzzle mode (by Sense101)", "Puzzle DLC: Allow copy-paste in puzzle mode (by Sense101)",
], ],
}, },

View File

@ -101,10 +101,11 @@ export class Blueprint {
const entity = this.entities[i]; const entity = this.entities[i];
const staticComp = entity.components.StaticMapEntity; const staticComp = entity.components.StaticMapEntity;
if (staticComp.getMetaBuilding().getIsRotateable()) { // Actually keeping this in as an easter egg to rotate the trash can
staticComp.rotation = (staticComp.rotation + 90) % 360; // if (staticComp.getMetaBuilding().getIsRotateable()) {
staticComp.originalRotation = (staticComp.originalRotation + 90) % 360; staticComp.rotation = (staticComp.rotation + 90) % 360;
} staticComp.originalRotation = (staticComp.originalRotation + 90) % 360;
// }
staticComp.origin = staticComp.origin.rotateFastMultipleOf90(90); staticComp.origin = staticComp.origin.rotateFastMultipleOf90(90);
} }
@ -142,6 +143,9 @@ export class Blueprint {
* @param {GameRoot} root * @param {GameRoot} root
*/ */
canAfford(root) { canAfford(root) {
if (root.gameMode.getHasFreeCopyPaste()) {
return true;
}
return root.hubGoals.getShapesStoredByKey(root.gameMode.getBlueprintShapeKey()) >= this.getCost(); return root.hubGoals.getShapesStoredByKey(root.gameMode.getBlueprintShapeKey()) >= this.getCost();
} }

View File

@ -30,20 +30,23 @@ export class GoalAcceptorComponent extends Component {
} }
clear() { clear() {
// the last items we delivered /**
/** @type {{ item: BaseItem; time: number; }} */ * The last item we delivered
* @type {{ item: BaseItem; time: number; } | null} */
this.lastDelivery = null; this.lastDelivery = null;
// The amount of items we delivered so far
this.currentDeliveredItems = 0; this.currentDeliveredItems = 0;
// Used for animations // Used for animations
this.displayPercentage = 0; this.displayPercentage = 0;
} }
// clears items but doesn't instantly reset the progress bar /**
* Clears items but doesn't instantly reset the progress bar
*/
clearItems() { clearItems() {
this.lastDelivery = null; this.lastDelivery = null;
this.currentDeliveredItems = 0; this.currentDeliveredItems = 0;
} }

View File

@ -27,8 +27,6 @@ export class HUDBlueprintPlacer extends BaseHUDPart {
} }
initialize() { initialize() {
this.isCopyPasteFree = this.root.gameMode.getHasFreeCopyPaste();
this.root.hud.signals.buildingsSelectedForCopy.add(this.createBlueprintFromBuildings, this); this.root.hud.signals.buildingsSelectedForCopy.add(this.createBlueprintFromBuildings, this);
/** @type {TypedTrackedState<Blueprint?>} */ /** @type {TypedTrackedState<Blueprint?>} */
@ -52,6 +50,10 @@ export class HUDBlueprintPlacer extends BaseHUDPart {
this.trackedCanAfford = new TrackedState(this.onCanAffordChanged, this); this.trackedCanAfford = new TrackedState(this.onCanAffordChanged, this);
} }
getHasFreeCopyPaste() {
return this.root.gameMode.getHasFreeCopyPaste();
}
abortPlacement() { abortPlacement() {
if (this.currentBlueprint.get()) { if (this.currentBlueprint.get()) {
this.currentBlueprint.set(null); this.currentBlueprint.set(null);
@ -84,7 +86,9 @@ export class HUDBlueprintPlacer extends BaseHUDPart {
update() { update() {
const currentBlueprint = this.currentBlueprint.get(); const currentBlueprint = this.currentBlueprint.get();
this.domAttach.update(!this.isCopyPasteFree && currentBlueprint && currentBlueprint.getCost() > 0); this.domAttach.update(
!this.getHasFreeCopyPaste() && currentBlueprint && currentBlueprint.getCost() > 0
);
this.trackedCanAfford.set(currentBlueprint && currentBlueprint.canAfford(this.root)); this.trackedCanAfford.set(currentBlueprint && currentBlueprint.canAfford(this.root));
} }
@ -116,7 +120,7 @@ export class HUDBlueprintPlacer extends BaseHUDPart {
return; return;
} }
if (!this.isCopyPasteFree && !blueprint.canAfford(this.root)) { if (!this.getHasFreeCopyPaste() && !blueprint.canAfford(this.root)) {
this.root.soundProxy.playUiError(); this.root.soundProxy.playUiError();
return; return;
} }
@ -124,7 +128,7 @@ export class HUDBlueprintPlacer extends BaseHUDPart {
const worldPos = this.root.camera.screenToWorld(pos); const worldPos = this.root.camera.screenToWorld(pos);
const tile = worldPos.toTileSpace(); const tile = worldPos.toTileSpace();
if (blueprint.tryPlace(this.root, tile)) { if (blueprint.tryPlace(this.root, tile)) {
if (!this.isCopyPasteFree) { if (!this.getHasFreeCopyPaste()) {
const cost = blueprint.getCost(); const cost = blueprint.getCost();
this.root.hubGoals.takeShapeByKey(this.root.gameMode.getBlueprintShapeKey(), cost); this.root.hubGoals.takeShapeByKey(this.root.gameMode.getBlueprintShapeKey(), cost);
} }

View File

@ -1,16 +1,17 @@
/* typehints:start */ /* typehints:start */
import { PuzzleGameMode } from "../../modes/puzzle";
/* typehints:end */ /* typehints:end */
import { globalConfig } from "../../../core/config"; import { globalConfig } from "../../../core/config";
import { gMetaBuildingRegistry } from "../../../core/global_registries";
import { createLogger } from "../../../core/logging"; import { createLogger } from "../../../core/logging";
import { Rectangle } from "../../../core/rectangle"; import { Rectangle } from "../../../core/rectangle";
import { makeDiv } from "../../../core/utils"; import { makeDiv } from "../../../core/utils";
import { T } from "../../../translations"; import { T } from "../../../translations";
import { StaticMapEntityComponent } from "../../components/static_map_entity";
import { BaseHUDPart } from "../base_hud_part";
import { gMetaBuildingRegistry } from "../../../core/global_registries";
import { MetaBlockBuilding } from "../../buildings/block"; 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 { PuzzleGameMode } from "../../modes/puzzle";
import { BaseHUDPart } from "../base_hud_part";
const logger = createLogger("puzzle-editor"); const logger = createLogger("puzzle-editor");
@ -72,13 +73,11 @@ export class HUDPuzzleEditorSettings extends BaseHUDPart {
clearBuildings() { clearBuildings() {
for (const entity of this.root.entityMgr.getAllWithComponent(StaticMapEntityComponent)) { for (const entity of this.root.entityMgr.getAllWithComponent(StaticMapEntityComponent)) {
const staticComp = entity.components.StaticMapEntity; const staticComp = entity.components.StaticMapEntity;
const signalComp = entity.components.ConstantSignal;
const goalComp = entity.components.GoalAcceptor;
if ( if (
signalComp || [MetaGoalAcceptorBuilding, MetaConstantProducerBuilding, MetaBlockBuilding]
goalComp || .map(metaClass => gMetaBuildingRegistry.findByClass(metaClass).id)
staticComp.getMetaBuilding().id === gMetaBuildingRegistry.findByClass(MetaBlockBuilding).id .includes(staticComp.getMetaBuilding().id)
) { ) {
continue; continue;
} }

View File

@ -3,6 +3,8 @@ import { createLogger } from "../../../core/logging";
import { makeDiv } from "../../../core/utils"; import { makeDiv } from "../../../core/utils";
import { T } from "../../../translations"; import { T } from "../../../translations";
import { MetaBlockBuilding } from "../../buildings/block"; 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 { StaticMapEntityComponent } from "../../components/static_map_entity";
import { BaseHUDPart } from "../base_hud_part"; import { BaseHUDPart } from "../base_hud_part";
@ -21,7 +23,7 @@ export class HUDPuzzlePlaySettings extends BaseHUDPart {
["section"], ["section"],
` `
<button class="styledButton clearItems">${T.ingame.puzzleEditorSettings.clearItems}</button> <button class="styledButton clearItems">${T.ingame.puzzleEditorSettings.clearItems}</button>
<button class="styledButton clearBuildings">${T.ingame.puzzleEditorSettings.clearBuildings}</button> <button class="styledButton clearBuildings">${T.ingame.puzzleEditorSettings.resetPuzzle}</button>
` `
); );
@ -38,13 +40,11 @@ export class HUDPuzzlePlaySettings extends BaseHUDPart {
clearBuildings() { clearBuildings() {
for (const entity of this.root.entityMgr.getAllWithComponent(StaticMapEntityComponent)) { for (const entity of this.root.entityMgr.getAllWithComponent(StaticMapEntityComponent)) {
const staticComp = entity.components.StaticMapEntity; const staticComp = entity.components.StaticMapEntity;
const signalComp = entity.components.ConstantSignal;
const goalComp = entity.components.GoalAcceptor;
if ( if (
signalComp || [MetaGoalAcceptorBuilding, MetaConstantProducerBuilding, MetaBlockBuilding]
goalComp || .map(metaClass => gMetaBuildingRegistry.findByClass(metaClass).id)
staticComp.getMetaBuilding().id === gMetaBuildingRegistry.findByClass(MetaBlockBuilding).id .includes(staticComp.getMetaBuilding().id)
) { ) {
continue; continue;
} }

View File

@ -25,6 +25,7 @@ export class GoalAcceptorSystem extends GameSystemWithFilter {
const goalComp = entity.components.GoalAcceptor; const goalComp = entity.components.GoalAcceptor;
if (!goalComp.lastDelivery) { if (!goalComp.lastDelivery) {
allAccepted = false;
continue; continue;
} }

View File

@ -633,6 +633,7 @@ ingame:
trimZone: Trim trimZone: Trim
clearItems: Clear Items clearItems: Clear Items
clearBuildings: Clear Buildings clearBuildings: Clear Buildings
resetPuzzle: Reset Puzzle
share: Share share: Share
report: Report report: Report