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

Switches to using ES6 get/set for currentBaseRotation.

This commit is contained in:
Magnus Grimstvedt Saltnes 2020-06-23 12:03:32 +02:00
parent e18a888210
commit 553ebb5ef6
3 changed files with 42 additions and 34 deletions

View File

@ -201,7 +201,7 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic {
} = metaBuilding.computeOptimalDirectionAndRotationVariantAtTile( } = metaBuilding.computeOptimalDirectionAndRotationVariantAtTile(
this.root, this.root,
mouseTile, mouseTile,
this.getBaseRotation(), this.currentBaseRotation,
this.currentVariant.get() this.currentVariant.get()
); );

View File

@ -49,28 +49,9 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
/** /**
* The current rotation preference for each building. * The current rotation preference for each building.
* @type {Object.<string, number>} * @type{Object.<string,number>}
*/ */
this.preferredRotations = {}; this.preferredBaseRotations = {};
this.getBaseRotation = function () {
const rotationByBuilding = this.root.app.settings.getAllSettings().rotationByBuilding;
if (!rotationByBuilding) {
return this.currentBaseRotationGeneral;
}
const id = this.currentMetaBuilding.get().getId();
return this.preferredRotations[id] || this.currentBaseRotationGeneral;
};
this.setBaseRotation = function (rotation) {
const rotationByBuilding = this.root.app.settings.getAllSettings().rotationByBuilding;
if (!rotationByBuilding) {
this.currentBaseRotationGeneral = rotation;
} else {
const id = this.currentMetaBuilding.get().getId();
this.preferredRotations[id] = rotation;
}
};
/** /**
* Whether we are currently dragging * Whether we are currently dragging
@ -139,6 +120,34 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
this.root.camera.upPostHandler.add(this.onMouseUp, this); this.root.camera.upPostHandler.add(this.onMouseUp, this);
} }
/**
* Returns the current base rotation for the current meta-building.
* @returns {number}
*/
get currentBaseRotation() {
const rotationByBuilding = this.root.app.settings.getAllSettings().rotationByBuilding;
if (!rotationByBuilding) {
return this.currentBaseRotationGeneral;
}
const id = this.currentMetaBuilding.get().getId();
return this.preferredBaseRotations[id] == null
? this.currentBaseRotationGeneral
: this.preferredBaseRotations[id];
}
/**
* Sets the base rotation for the current meta-building.
*/
set currentBaseRotation(rotation) {
const rotationByBuilding = this.root.app.settings.getAllSettings().rotationByBuilding;
if (!rotationByBuilding) {
this.currentBaseRotationGeneral = rotation;
} else {
const id = this.currentMetaBuilding.get().getId();
this.preferredBaseRotations[id] = rotation;
}
}
/** /**
* Returns if the direction lock is currently active * Returns if the direction lock is currently active
* @returns {boolean} * @returns {boolean}
@ -225,12 +234,12 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
const selectedBuilding = this.currentMetaBuilding.get(); const selectedBuilding = this.currentMetaBuilding.get();
if (selectedBuilding) { if (selectedBuilding) {
if (this.root.keyMapper.getBinding(KEYMAPPINGS.placement.rotateInverseModifier).pressed) { if (this.root.keyMapper.getBinding(KEYMAPPINGS.placement.rotateInverseModifier).pressed) {
this.setBaseRotation((this.getBaseRotation() + 270) % 360); this.currentBaseRotation = (this.currentBaseRotation + 270) % 360;
} else { } else {
this.setBaseRotation((this.getBaseRotation() + 90) % 360); this.currentBaseRotation = (this.currentBaseRotation + 90) % 360;
} }
const staticComp = this.fakeEntity.components.StaticMapEntity; const staticComp = this.fakeEntity.components.StaticMapEntity;
staticComp.rotation = this.getBaseRotation(); staticComp.rotation = this.currentBaseRotation;
} }
} }
/** /**
@ -402,7 +411,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
const { rotation, rotationVariant } = metaBuilding.computeOptimalDirectionAndRotationVariantAtTile( const { rotation, rotationVariant } = metaBuilding.computeOptimalDirectionAndRotationVariantAtTile(
this.root, this.root,
tile, tile,
this.getBaseRotation(), this.currentBaseRotation,
this.currentVariant.get() this.currentVariant.get()
); );
@ -410,7 +419,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
origin: tile, origin: tile,
rotation, rotation,
rotationVariant, rotationVariant,
originalRotation: this.getBaseRotation(), originalRotation: this.currentBaseRotation,
building: this.currentMetaBuilding.get(), building: this.currentMetaBuilding.get(),
variant: this.currentVariant.get(), variant: this.currentVariant.get(),
}); });
@ -426,7 +435,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
KEYMAPPINGS.placementModifiers.placementDisableAutoOrientation KEYMAPPINGS.placementModifiers.placementDisableAutoOrientation
).pressed ).pressed
) { ) {
this.setBaseRotation((180 + this.getBaseRotation()) % 360); this.currentBaseRotation = (180 + this.currentBaseRotation) % 360;
} }
// Check if we should stop placement // Check if we should stop placement
@ -476,7 +485,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
for (let i = 0; i < path.length; ++i) { for (let i = 0; i < path.length; ++i) {
const { rotation, tile } = path[i]; const { rotation, tile } = path[i];
this.setBaseRotation(rotation); this.currentBaseRotation = rotation;
this.tryPlaceCurrentBuildingAt(tile); this.tryPlaceCurrentBuildingAt(tile);
} }
}); });
@ -659,11 +668,11 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
) { ) {
const delta = newPos.sub(oldPos); const delta = newPos.sub(oldPos);
const angleDeg = Math_degrees(delta.angle()); const angleDeg = Math_degrees(delta.angle());
this.setBaseRotation((Math.round(angleDeg / 90) * 90 + 360) % 360); this.currentBaseRotation = (Math.round(angleDeg / 90) * 90 + 360) % 360;
// Holding alt inverts the placement // Holding alt inverts the placement
if (this.root.keyMapper.getBinding(KEYMAPPINGS.placementModifiers.placeInverse).pressed) { if (this.root.keyMapper.getBinding(KEYMAPPINGS.placementModifiers.placeInverse).pressed) {
this.setBaseRotation((180 + this.getBaseRotation()) % 360); this.currentBaseRotation = (180 + this.currentBaseRotation) % 360;
} }
} }

View File

@ -248,7 +248,7 @@ export const allApplicationSettings = [
new BoolSetting("alwaysMultiplace", categoryGame, (app, value) => {}), new BoolSetting("alwaysMultiplace", categoryGame, (app, value) => {}),
new BoolSetting("enableTunnelSmartplace", categoryGame, (app, value) => {}), new BoolSetting("enableTunnelSmartplace", categoryGame, (app, value) => {}),
new BoolSetting("vignette", categoryGame, (app, value) => {}),<<<<<<< HEAD new BoolSetting("vignette", categoryGame, (app, value) => {}),
new BoolSetting("compactBuildingInfo", categoryGame, (app, value) => {}), new BoolSetting("compactBuildingInfo", categoryGame, (app, value) => {}),
new BoolSetting("disableCutDeleteWarnings", categoryGame, (app, value) => {}), new BoolSetting("disableCutDeleteWarnings", categoryGame, (app, value) => {}),
new BoolSetting("rotationByBuilding", categoryGame, (app, value) => {}), new BoolSetting("rotationByBuilding", categoryGame, (app, value) => {}),
@ -280,7 +280,6 @@ class SettingsStorage {
this.disableCutDeleteWarnings = false; this.disableCutDeleteWarnings = false;
this.rotationByBuilding = true; this.rotationByBuilding = true;
this.enableColorBlindHelper = false; this.enableColorBlindHelper = false;
/** /**
@ -554,7 +553,7 @@ export class ApplicationSettings extends ReadWriteProxy {
data.settings.enableColorBlindHelper = false; data.settings.enableColorBlindHelper = false;
data.version = 17; data.version = 17;
} }
if(data.version < 18) { if (data.version < 18) {
data.settings.rotationByBuilding = true; data.settings.rotationByBuilding = true;
data.version = 18; data.version = 18;
} }