Adds tracking for rotation per building type.

Adds a setting to go back to one global base rotation.
This commit is contained in:
Magnus Grimstvedt Saltnes 2020-06-18 22:18:32 +02:00
parent 4f747a1fc5
commit c7f8b50d13
3 changed files with 56 additions and 19 deletions

View File

@ -82,9 +82,9 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic {
this.buildingInfoElements.tutorialImage.setAttribute(
"data-icon",
"building_tutorials/" +
metaBuilding.getId() +
(variant === defaultBuildingVariant ? "" : "-" + variant) +
".png"
metaBuilding.getId() +
(variant === defaultBuildingVariant ? "" : "-" + variant) +
".png"
);
removeAllChildren(this.buildingInfoElements.additionalInfo);
@ -122,10 +122,10 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic {
T.ingame.buildingPlacement.cycleBuildingVariants.replace(
"<key>",
"<code class='keybinding'>" +
this.root.keyMapper
.getBinding(KEYMAPPINGS.placement.cycleBuildingVariants)
.getKeyCodeString() +
"</code>"
this.root.keyMapper
.getBinding(KEYMAPPINGS.placement.cycleBuildingVariants)
.getKeyCodeString() +
"</code>"
)
);
@ -201,7 +201,7 @@ export class HUDBuildingPlacer extends HUDBuildingPlacerLogic {
} = metaBuilding.computeOptimalDirectionAndRotationVariantAtTile(
this.root,
mouseTile,
this.currentBaseRotation,
this.getBaseRotation(),
this.currentVariant.get()
);

View File

@ -1,3 +1,4 @@
import { Math_abs, Math_degrees, Math_round } from "../../../core/builtins";
import { globalConfig } from "../../../core/config";
import { gMetaBuildingRegistry } from "../../../core/global_registries";
@ -45,7 +46,34 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
* The current rotation
* @type {number}
*/
this.currentBaseRotation = 0;
this.currentBaseRotationGeneral = 0;
/**
* The current rotation preference for each building.
* @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;
}
}
/**
* Whether we are currently dragging
@ -200,12 +228,12 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
const selectedBuilding = this.currentMetaBuilding.get();
if (selectedBuilding) {
if (this.root.keyMapper.getBinding(KEYMAPPINGS.placement.rotateInverseModifier).pressed) {
this.currentBaseRotation = (this.currentBaseRotation + 270) % 360;
this.setBaseRotation((this.getBaseRotation() + 270) % 360);
} else {
this.currentBaseRotation = (this.currentBaseRotation + 90) % 360;
this.setBaseRotation((this.getBaseRotation() + 90) % 360);
}
const staticComp = this.fakeEntity.components.StaticMapEntity;
staticComp.rotation = this.currentBaseRotation;
staticComp.rotation = this.getBaseRotation();
}
}
/**
@ -377,7 +405,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
const { rotation, rotationVariant } = metaBuilding.computeOptimalDirectionAndRotationVariantAtTile(
this.root,
tile,
this.currentBaseRotation,
this.getBaseRotation(),
this.currentVariant.get()
);
@ -385,7 +413,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
origin: tile,
rotation,
rotationVariant,
originalRotation: this.currentBaseRotation,
originalRotation: this.getBaseRotation(),
building: this.currentMetaBuilding.get(),
variant: this.currentVariant.get(),
});
@ -401,7 +429,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
KEYMAPPINGS.placementModifiers.placementDisableAutoOrientation
).pressed
) {
this.currentBaseRotation = (180 + this.currentBaseRotation) % 360;
this.setBaseRotation((180 + this.getBaseRotation()) % 360);
}
// Check if we should stop placement
@ -451,7 +479,7 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
for (let i = 0; i < path.length; ++i) {
const { rotation, tile } = path[i];
this.currentBaseRotation = rotation;
this.setBaseRotation(rotation);
this.tryPlaceCurrentBuildingAt(tile);
}
});
@ -634,11 +662,11 @@ export class HUDBuildingPlacerLogic extends BaseHUDPart {
) {
const delta = newPos.sub(oldPos);
const angleDeg = Math_degrees(delta.angle());
this.currentBaseRotation = (Math.round(angleDeg / 90) * 90 + 360) % 360;
this.setBaseRotation((Math.round(angleDeg / 90) * 90 + 360) % 360);
// Holding alt inverts the placement
if (this.root.keyMapper.getBinding(KEYMAPPINGS.placementModifiers.placeInverse).pressed) {
this.currentBaseRotation = (180 + this.currentBaseRotation) % 360;
this.setBaseRotation((180 + this.getBaseRotation()) % 360);
}
}

View File

@ -248,9 +248,10 @@ export const allApplicationSettings = [
new BoolSetting("alwaysMultiplace", categoryGame, (app, value) => {}),
new BoolSetting("enableTunnelSmartplace", categoryGame, (app, value) => {}),
new BoolSetting("vignette", categoryGame, (app, value) => {}),
new BoolSetting("vignette", categoryGame, (app, value) => {}),<<<<<<< HEAD
new BoolSetting("compactBuildingInfo", categoryGame, (app, value) => {}),
new BoolSetting("disableCutDeleteWarnings", categoryGame, (app, value) => {}),
new BoolSetting("rotationByBuilding", categoryGame, (app, value) => {}),
];
export function getApplicationSettingById(id) {
@ -277,6 +278,8 @@ class SettingsStorage {
this.vignette = true;
this.compactBuildingInfo = false;
this.disableCutDeleteWarnings = false;
this.rotationByBuilding = true;
this.enableColorBlindHelper = false;
@ -527,6 +530,7 @@ export class ApplicationSettings extends ReadWriteProxy {
}
if (data.version < 13) {
<<<<<<< HEAD
data.settings.compactBuildingInfo = false;
data.version = 13;
}
@ -550,6 +554,11 @@ export class ApplicationSettings extends ReadWriteProxy {
if (data.version < 17) {
data.settings.enableColorBlindHelper = false;
data.version = 17;
=======
data.settings.rotationByBuilding = true;
data.version = 13;
>>>>>>> 655c356... Adds tracking for rotation per building type.
}
return ExplainedResult.good();