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:
parent
e18a888210
commit
553ebb5ef6
@ -201,7 +201,7 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic {
|
||||
} = metaBuilding.computeOptimalDirectionAndRotationVariantAtTile(
|
||||
this.root,
|
||||
mouseTile,
|
||||
this.getBaseRotation(),
|
||||
this.currentBaseRotation,
|
||||
this.currentVariant.get()
|
||||
);
|
||||
|
||||
|
@ -49,28 +49,9 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
|
||||
|
||||
/**
|
||||
* The current rotation preference for each building.
|
||||
* @type {Object.<string, number>}
|
||||
* @type{Object.<string,number>}
|
||||
*/
|
||||
this.preferredRotations = {};
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
this.preferredBaseRotations = {};
|
||||
|
||||
/**
|
||||
* Whether we are currently dragging
|
||||
@ -139,6 +120,34 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
|
||||
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 {boolean}
|
||||
@ -225,12 +234,12 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
|
||||
const selectedBuilding = this.currentMetaBuilding.get();
|
||||
if (selectedBuilding) {
|
||||
if (this.root.keyMapper.getBinding(KEYMAPPINGS.placement.rotateInverseModifier).pressed) {
|
||||
this.setBaseRotation((this.getBaseRotation() + 270) % 360);
|
||||
this.currentBaseRotation = (this.currentBaseRotation + 270) % 360;
|
||||
} else {
|
||||
this.setBaseRotation((this.getBaseRotation() + 90) % 360);
|
||||
this.currentBaseRotation = (this.currentBaseRotation + 90) % 360;
|
||||
}
|
||||
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(
|
||||
this.root,
|
||||
tile,
|
||||
this.getBaseRotation(),
|
||||
this.currentBaseRotation,
|
||||
this.currentVariant.get()
|
||||
);
|
||||
|
||||
@ -410,7 +419,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
|
||||
origin: tile,
|
||||
rotation,
|
||||
rotationVariant,
|
||||
originalRotation: this.getBaseRotation(),
|
||||
originalRotation: this.currentBaseRotation,
|
||||
building: this.currentMetaBuilding.get(),
|
||||
variant: this.currentVariant.get(),
|
||||
});
|
||||
@ -426,7 +435,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
|
||||
KEYMAPPINGS.placementModifiers.placementDisableAutoOrientation
|
||||
).pressed
|
||||
) {
|
||||
this.setBaseRotation((180 + this.getBaseRotation()) % 360);
|
||||
this.currentBaseRotation = (180 + this.currentBaseRotation) % 360;
|
||||
}
|
||||
|
||||
// Check if we should stop placement
|
||||
@ -476,7 +485,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
|
||||
for (let i = 0; i < path.length; ++i) {
|
||||
const { rotation, tile } = path[i];
|
||||
|
||||
this.setBaseRotation(rotation);
|
||||
this.currentBaseRotation = rotation;
|
||||
this.tryPlaceCurrentBuildingAt(tile);
|
||||
}
|
||||
});
|
||||
@ -659,11 +668,11 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
|
||||
) {
|
||||
const delta = newPos.sub(oldPos);
|
||||
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
|
||||
if (this.root.keyMapper.getBinding(KEYMAPPINGS.placementModifiers.placeInverse).pressed) {
|
||||
this.setBaseRotation((180 + this.getBaseRotation()) % 360);
|
||||
this.currentBaseRotation = (180 + this.currentBaseRotation) % 360;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -248,7 +248,7 @@ export const allApplicationSettings = [
|
||||
|
||||
new BoolSetting("alwaysMultiplace", 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("disableCutDeleteWarnings", categoryGame, (app, value) => {}),
|
||||
new BoolSetting("rotationByBuilding", categoryGame, (app, value) => {}),
|
||||
@ -280,7 +280,6 @@ class SettingsStorage {
|
||||
this.disableCutDeleteWarnings = false;
|
||||
this.rotationByBuilding = true;
|
||||
|
||||
|
||||
this.enableColorBlindHelper = false;
|
||||
|
||||
/**
|
||||
@ -554,7 +553,7 @@ export class ApplicationSettings extends ReadWriteProxy {
|
||||
data.settings.enableColorBlindHelper = false;
|
||||
data.version = 17;
|
||||
}
|
||||
if(data.version < 18) {
|
||||
if (data.version < 18) {
|
||||
data.settings.rotationByBuilding = true;
|
||||
data.version = 18;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user