Skip to content

Commit

Permalink
feat: Statuses can now have amounts associated
Browse files Browse the repository at this point in the history
  • Loading branch information
valentine195 committed Apr 23, 2023
1 parent 28f63cf commit 84b358b
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 8 deletions.
15 changes: 12 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,20 @@ export interface TrackerViewState {
creatures: HomebrewCreature[];
}

export interface Condition {
export type Condition = {
name: string;
description: string;
id: string;
}
resetOnRound?: boolean;
hasAmount?: boolean;
startingAmount?: number;
} & (
| {
hasAmount: true;
startingAmount: number;
}
| {}
);

export interface InputValidate {
input: HTMLInputElement;
Expand Down Expand Up @@ -190,7 +199,7 @@ export interface UpdateLogMessage {
name: string;
hp: number | null;
temp: boolean;
status: string | null;
status: string[] | null;
saved: boolean;
unc: boolean;
}
Expand Down
15 changes: 13 additions & 2 deletions src/logger/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,21 @@ export default class Logger {
} else {
perCreature.push(message.name);
}
let status;
if (message.status.length > 1) {
status = [
message.status
.slice(0, Math.min(message.status.length - 1, 1))
.join(", ")
];
status.push(message.status[message.status.length - 1]);
} else {
status = [message.status[0]];
}
if (message.saved) {
perCreature.push(`saved against ${message.status}`);
perCreature.push(`saved against ${status.join(" and ")}`);
} else {
perCreature.push(`took ${message.status} status`);
perCreature.push(`took ${status.join(" and ")} status`);
}
}
toLog.push(perCreature.join(" "));
Expand Down
8 changes: 7 additions & 1 deletion src/main.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
body {
--text-warning: #EAAF00;
--text-warning: #eaaf00;
--text-success: green;
}

.status-metadata-container,
.status-name-container {
display: flex;
gap: 0.5rem;
}

.initiative-tracker-add-player-modal .has-error {
border-color: var(--background-modifier-error-hover);
}
Expand Down
65 changes: 63 additions & 2 deletions src/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,34 @@ export default class InitiativeTrackerSettings extends PluginSettingTab {
const additional = additionalContainer.createDiv("additional");
for (const status of this.plugin.data.statuses) {
new Setting(additional)
.setName(status.name)
.setName(
createFragment((e) => {
const div = e.createDiv("status-name-container");
div.createSpan({ text: status.name });

div.createDiv("status-metadata-container");
if (status.resetOnRound) {
setIcon(
div.createDiv({
attr: {
"aria-label": "Reset Each Round"
}
}),
"timer-reset"
);
}
if (status.hasAmount) {
setIcon(
div.createDiv({
attr: {
"aria-label": "Has Amount"
}
}),
"hash"
);
}
})
)
.setDesc(status.description)
.addExtraButton((b) =>
b.setIcon("pencil").onClick(() => {
Expand Down Expand Up @@ -1378,7 +1405,7 @@ class StatusModal extends Modal {
warned = false;
onOpen() {
this.titleEl.setText(this.editing ? "Edit Status" : "New Status");

this.contentEl.empty();
const name = new Setting(this.contentEl)
.setName("Name")
.addText((t) => {
Expand Down Expand Up @@ -1417,6 +1444,40 @@ class StatusModal extends Modal {
(v) => (this.status.description = v)
);
});
new Setting(this.contentEl)
.setName("Remove Each Round")
.setDesc(
"This status will be removed from all creatures at the start of a new round."
)
.addToggle((t) =>
t
.setValue(this.status.resetOnRound)
.onChange((v) => (this.status.resetOnRound = v))
);
new Setting(this.contentEl)
.setName("Has Amount")
.setDesc(
"This status has an amount that can be increased or decreased during combat."
)
.addToggle((t) =>
t.setValue(this.status.hasAmount).onChange((v) => {
this.status.hasAmount = v;
this.onOpen();
})
);
if (this.status.hasAmount) {
new Setting(this.contentEl)
.setName("Starting Amount")
.setDesc("The status will default to this amount when added.")
.addText(
(t) =>
(t
.setValue(`${this.status.startingAmount}`)
.onChange((v) => {
this.status.startingAmount = Number(v);
}).inputEl.type = "number")
);
}

new ButtonComponent(
this.contentEl.createDiv("initiative-tracker-cancel")
Expand Down

0 comments on commit 84b358b

Please sign in to comment.