Skip to content

Commit

Permalink
Update for 2.14.0-beta.dev.20240827.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Spacetech committed Aug 27, 2024
1 parent deb3f40 commit 38f9db5
Show file tree
Hide file tree
Showing 8 changed files with 206 additions and 6 deletions.
11 changes: 10 additions & 1 deletion lang/english.json
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,16 @@
"conditionUnmet": "Unmet",
"conditionAlwaysActive": "Always Active",
"labelWanderIntent": "Wander Intent:",
"buttonCreatureZone": "Highlight Zone"
"buttonCreatureZone": "Highlight Zone",
"panelNPCs": "NPCs",
"headingNPCInterval": "{0} Spawn Interval",
"labelNPCIntervalTimeUntil": "Ends In",
"labelNPCIntervalLength": "Length",
"labelNPCIntervalSpawned": "Spawned",
"labelNPCIntervalChancesWere": "Chances Were",
"nPCIntervalInactive": "Inactive",
"resetSpawnInterval": "Reset Interval",
"labelNPCCount": "Current Count"
},
"item": {
"none": "none"
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"watch": "npx tsc --build --watch --pretty --preserveWatchOutput"
},
"devDependencies": {
"@wayward/types": "^2.14.0-beta.dev.20240826.1",
"@wayward/types": "^2.14.0-beta.dev.20240827.1",
"rimraf": "3.0.2",
"typescript": "^5.6.1-rc"
}
Expand Down
4 changes: 4 additions & 0 deletions src/DebugTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import PlaceTemplate from "./action/PlaceTemplate";
import Remove from "./action/Remove";
import RenameIsland from "./action/RenameIsland";
import ReplacePlayerData from "./action/ReplacePlayerData";
import ResetNPCSpawnInterval from "./action/ResetNPCSpawnInterval";
import SelectionExecute from "./action/SelectionExecute";
import SetDecay from "./action/SetDecay";
import SetDecayBulk from "./action/SetDecayBulk";
Expand Down Expand Up @@ -335,6 +336,9 @@ export default class DebugTools extends Mod {
@Register.action("ToggleAiMask", ToggleAiMask)
public readonly actionToggleAiMask: ActionType;

@Register.action("ResetNPCSpawnInterval", ResetNPCSpawnInterval)
public readonly actionResetNPCSpawnInterval: ActionType;

////////////////////////////////////
// UI
//
Expand Down
11 changes: 11 additions & 0 deletions src/IDebugTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,17 @@ export enum DebugToolsTranslation {
PanelZones,
HeadingZonesOverlay,

// npcs
PanelNPCs,
HeadingNPCInterval,
LabelNPCIntervalTimeUntil,
LabelNPCIntervalLength,
LabelNPCIntervalSpawned,
LabelNPCIntervalChancesWere,
NPCIntervalInactive,
ResetSpawnInterval,
LabelNPCCount,

////////////////////////////////////
// Inspect Dialog
//
Expand Down
24 changes: 24 additions & 0 deletions src/action/ResetNPCSpawnInterval.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*!
* Copyright 2011-2024 Unlok
* https://www.unlok.ca
*
* Credits & Thanks:
* https://www.unlok.ca/credits-thanks/
*
* Wayward is a copyrighted and licensed work. Modification and/or distribution of any source files is prohibited. If you wish to modify the game in any way, please refer to the modding guide:
* https://github.com/WaywardGame/types/wiki
*/

import { Action } from "@wayward/game/game/entity/action/Action";
import { ActionArgument } from "@wayward/game/game/entity/action/IAction";
import { EntityType } from "@wayward/game/game/entity/IEntity";
import { NPCType } from "@wayward/game/game/entity/npc/INPCs";
import { defaultCanUseHandler, defaultUsability } from "../Actions";

export default new Action(ActionArgument.ENUM(NPCType))
.setUsableBy(EntityType.Human)
.setUsableWhen(...defaultUsability)
.setCanUse(defaultCanUseHandler)
.setHandler((action, type) => {
action.executor.island.npcs.resetSpawnInterval(type);
});
2 changes: 2 additions & 0 deletions src/ui/DebugToolsDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import DebugToolsPanel from "./component/DebugToolsPanel";
import DisplayPanel from "./panel/DisplayPanel";
import GeneralPanel from "./panel/GeneralPanel";
import HistoryPanel from "./panel/HistoryPanel";
import NPCPanel from "./panel/NPCPanel";
import PaintPanel from "./panel/PaintPanel";
import SelectionPanel from "./panel/SelectionPanel";
import TemperaturePanel from "./panel/TemperaturePanel";
Expand All @@ -44,6 +45,7 @@ const subpanelClasses: DebugToolsDialogPanelClass[] = [
SelectionPanel,
TemplatePanel,
ZonesPanel,
NPCPanel,
TemperaturePanel,
HistoryPanel,
];
Expand Down
150 changes: 150 additions & 0 deletions src/ui/panel/NPCPanel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/*!
* Copyright 2011-2024 Unlok
* https://www.unlok.ca
*
* Credits & Thanks:
* https://www.unlok.ca/credits-thanks/
*
* Wayward is a copyrighted and licensed work. Modification and/or distribution of any source files is prohibited. If you wish to modify the game in any way, please refer to the modding guide:
* https://github.com/WaywardGame/types/wiki
*/

import { EventBus } from "@wayward/game/event/EventBuses";
import { EventHandler } from "@wayward/game/event/EventManager";
import { NPCType } from "@wayward/game/game/entity/npc/INPCs";
import { INPCManagerSpawnTracker } from "@wayward/game/game/entity/npc/NPCManager";
import Dictionary from "@wayward/game/language/Dictionary";
import { MiscTranslation } from "@wayward/game/language/dictionary/Misc";
import { TextContext } from "@wayward/game/language/ITranslation";
import Translation from "@wayward/game/language/Translation";
import Mod from "@wayward/game/mod/Mod";
import Button from "@wayward/game/ui/component/Button";
import { LabelledRow } from "@wayward/game/ui/component/LabelledRow";
import Text, { Heading } from "@wayward/game/ui/component/Text";
import Enums from "@wayward/game/utilities/enum/Enums";
import Arrays from "@wayward/utilities/collection/Arrays";
import { OwnEventHandler } from "@wayward/utilities/event/EventManager";
import Time, { days } from "@wayward/utilities/Time";
import ResetNPCSpawnInterval from "../../action/ResetNPCSpawnInterval";
import DebugTools from "../../DebugTools";
import { DebugToolsTranslation, ISaveData, translation } from "../../IDebugTools";
import DebugToolsPanel from "../component/DebugToolsPanel";

export default class NPCPanel extends DebugToolsPanel {

@Mod.instance<DebugTools>("Debug Tools")
public readonly DEBUG_TOOLS: DebugTools;

@Mod.saveData<DebugTools>("Debug Tools")
public saveData: ISaveData;

public readonly refreshables: Text[] = [];

public constructor() {
super();

for (const type of Enums.values(NPCType)) {
const options = localIsland.getGameOptions().npcs.spawning.get(type);
if (!options?.chanceMultiplier || !options.count) {
continue;
}

new Heading()
.setText(translation(DebugToolsTranslation.HeadingNPCInterval)
.addArgs(Translation.get(Dictionary.Npc, type).inContext(TextContext.Title)))
.appendTo(this);

new LabelledRow()
.setLabel(label => label.setText(translation(DebugToolsTranslation.LabelNPCIntervalTimeUntil)
.passTo(Translation.colorizeImportance("secondary"))))
.append(new Text().setText(Translation.colorizeImportance("primary")
.addArgs(() => this.getTimeUntilIntervalEnd(type)))
.schedule(Arrays.pushTo(this.refreshables)))
.appendTo(this);

new LabelledRow()
.setLabel(label => label.setText(translation(DebugToolsTranslation.LabelNPCIntervalLength)
.passTo(Translation.colorizeImportance("secondary"))))
.append(new Text().setText(Translation.colorizeImportance("primary")
.addArgs(() => this.getTicksAsTotalTimeString(this.getSpawnInterval(type)?.length)
?? Translation.misc(MiscTranslation.Unknown)))
.schedule(Arrays.pushTo(this.refreshables)))
.appendTo(this);

new LabelledRow()
.setLabel(label => label.setText(translation(DebugToolsTranslation.LabelNPCIntervalSpawned)
.passTo(Translation.colorizeImportance("secondary"))))
.append(new Text().setText(Translation.colorizeImportance("primary")
.addArgs(() => Translation.misc(MiscTranslation.ASlashB)
.addArgs(this.getSpawnInterval(type)?.spawned ?? 0)
.addArgs(this.getSpawnInterval(type)?.potentialSpawnCount ?? 0)))
.schedule(Arrays.pushTo(this.refreshables)))
.appendTo(this);

new LabelledRow()
.setLabel(label => label.setText(translation(DebugToolsTranslation.LabelNPCIntervalChancesWere)
.passTo(Translation.colorizeImportance("secondary"))))
.append(new Text().setText(Translation.colorizeImportance("primary")
.addArgs(() => this.getSpawnInterval(type)?.chances
.map(chance => Translation.misc(MiscTranslation.Percent).addArgs(chance))
.collect(Translation.formatList)))
.schedule(Arrays.pushTo(this.refreshables)))
.appendTo(this);

new Button()
.setText(translation(DebugToolsTranslation.ResetSpawnInterval))
.event.subscribe("activate", () => ResetNPCSpawnInterval.execute(localPlayer, type))
.appendTo(this);

new LabelledRow()
.setLabel(label => label.setText(translation(DebugToolsTranslation.LabelNPCCount)
.passTo(Translation.colorizeImportance("secondary"))))
.append(new Text().setText(Translation.colorizeImportance("primary")
.addArgs(() => localIsland.npcs["getNPCTypeCount"](type)))
.schedule(Arrays.pushTo(this.refreshables)))
.appendTo(this);
}
}

public override getTranslation(): DebugToolsTranslation {
return DebugToolsTranslation.PanelNPCs;
}

@EventHandler(EventBus.LocalIsland, "tickEnd")
@EventHandler(EventBus.NPCManager, "endInterval")
@EventHandler(EventBus.NPCManager, "startInterval")
@EventHandler(EventBus.NPCManager, "intervalSpawn")
protected onTickEnd() {
for (const refreshable of this.refreshables) {
refreshable.refresh();
}
}

@OwnEventHandler(NPCPanel, "switchTo")
protected onSwitchTo(): void {
}

private getSpawnInterval(type: NPCType): INPCManagerSpawnTracker | undefined {
return localIsland.npcs["spawnIntervals"][type];
}

private getTimeUntilIntervalEnd(type: NPCType) {
const intervalEnd = this.getSpawnInterval(type)?.intervalEnd;
const now = game.time.ticks;
if (intervalEnd === undefined || now >= intervalEnd) {
return translation(DebugToolsTranslation.NPCIntervalInactive);
}

return this.getTicksAsTotalTimeString(intervalEnd - now);
}

private getTicksAsTotalTimeString(ticks?: number) {
if (ticks === undefined) {
return undefined;
}

const realTimeDayCount = Math.floor(days(ticks / game.time.dayLength));
return Time.total(realTimeDayCount);
}

}

0 comments on commit 38f9db5

Please sign in to comment.