Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Commit

Permalink
feat(workshop): Remove redundant stock warning
Browse files Browse the repository at this point in the history
Stock indicators have already been added in a more visible way. If stock indicators should be extended or improved, it should happen on the established code path.
  • Loading branch information
oliversalzburg committed Sep 30, 2022
1 parent 3361052 commit b72b33c
Showing 1 changed file with 1 addition and 25 deletions.
26 changes: 1 addition & 25 deletions packages/userscript/source/ui/WorkshopSettingsUi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { ResourcesSettingsItem } from "../options/ResourcesSettings";
import { CraftSettingsItem, WorkshopSettings } from "../options/WorkshopSettings";
import { objectEntries } from "../tools/Entries";
import { ucfirst } from "../tools/Format";
import { cwarn } from "../tools/Log";
import { isNil, Maybe, mustExist } from "../tools/Maybe";
import { Maybe, mustExist } from "../tools/Maybe";
import { Resource } from "../types";
import { UserScript } from "../UserScript";
import { SettingLimitedMaxUi } from "./SettingLimitedMaxUi";
Expand Down Expand Up @@ -342,11 +341,6 @@ export class WorkshopSettingsUi extends SettingsSectionUi {

container.append(stockElement, consumeElement);

// once created, set color if relevant
if (setting !== undefined && setting.stock !== undefined) {
this._setStockWarning(name, setting.stock);
}

stockElement.on("click", () => {
const value = SettingsSectionUi.promptLimit(
this._host.i18n("resources.stock.set", [title]),
Expand Down Expand Up @@ -380,24 +374,6 @@ export class WorkshopSettingsUi extends SettingsSectionUi {
return container;
}

private _setStockWarning(name: Resource, value: number, forReset = false): void {
// simplest way to ensure it doesn't stick around too often; always do
// a remove first then re-add only if needed
const path = forReset ? `#resource-reset-${name}` : `#resource-${name}`;
$(path).removeClass("stockWarn");

const resource = this._host.gamePage.resPool.resources.filter(i => i.name === name)[0];
if (isNil(resource)) {
cwarn(`Unable to find resource '${name}'!`);
return;
}

const maxValue = resource.maxValue;
if ((value > maxValue && !(maxValue === 0)) || value === Infinity) {
$(path).addClass("stockWarn");
}
}

setState(state: WorkshopSettings): void {
this._settings.enabled = state.enabled;
this._settings.trigger = state.trigger;
Expand Down

0 comments on commit b72b33c

Please sign in to comment.