Skip to content

Commit

Permalink
Power production in node configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
andev0 committed Sep 9, 2024
1 parent 3c90805 commit bfc712e
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/Sankey/NodeConfiguration/NodeConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export class NodeConfiguration extends EventTarget
{
super();

this._recipe = recipe;

let closeSelector = `#${NodeConfiguration._modalContainer.id} .title-row .close`;
let closeButton = document.querySelector(closeSelector) as HTMLDivElement;

Expand Down Expand Up @@ -151,6 +153,20 @@ export class NodeConfiguration extends EventTarget
this._overclockConfigurators.outputsConfigurators.length === 0
);

/* Power production/consumption */

HtmlUtils.toggleClass(
NodeConfiguration._amountPowerColumn,
"hidden",
this._recipe.producedPower !== undefined
);

HtmlUtils.toggleClass(
NodeConfiguration._overclockPowerColumn,
"hidden",
this._recipe.producedPower !== undefined
);

/* Modal window */

NodeConfiguration._modalContainer.classList.remove("hidden");
Expand Down Expand Up @@ -262,6 +278,36 @@ export class NodeConfiguration extends EventTarget
this._overclockConfigurators.inputsConfigurators
));

if (recipe.producedPower != undefined)
{
this._amountConfigurators.outputsConfigurators.push(new ConfiguratorBuilder(this)
.setPowerSvgIcon()
.setInitialValue(recipe.producedPower)
.setUnits("MW")
.setMinimum(() => 0.0001)
.setMaximum(() => undefined)
.setRelatedProperty(
() => recipe.producedPower! * this.overclockRatio * this.machinesAmount,
(value) => this.machinesAmount = value / recipe.producedPower! / this.overclockRatio
)
.subscribeToMachinesAmount()
.subscribeToOverclock()
.build());

this._overclockConfigurators.outputsConfigurators.push(new ConfiguratorBuilder(this)
.setPowerSvgIcon()
.setInitialValue(recipe.producedPower)
.setUnits("MW")
.setMinimum(() => recipe.producedPower! * minOverclockRatio)
.setMaximum(() => recipe.producedPower! * maxOverclockRatio)
.setRelatedProperty(
() => recipe.producedPower! * this.overclockRatio,
(value) => this.overclockRatio = value / recipe.producedPower!
)
.subscribeToOverclock()
.build());
}

recipe.products.forEach(resource => createResourceConfigurators(
resource,
this._amountConfigurators.outputsConfigurators,
Expand Down Expand Up @@ -389,6 +435,7 @@ export class NodeConfiguration extends EventTarget
}

private _isOpened = false;
private _recipe: GameRecipe;

private _machinesAmount = 1;
private _overclockRatio = 1;
Expand Down

0 comments on commit bfc712e

Please sign in to comment.