diff --git a/lang/de.json b/lang/de.json index 13c5fe5..9f6f93c 100644 --- a/lang/de.json +++ b/lang/de.json @@ -21,7 +21,9 @@ "add-timer": { "timer name": "Timer Name", "duration": "Dauer", - "format-hint": "Nutze den Format n (nur Sekunden), mm:ss oder hh:mm:ss für Stunden/Minuten/Sekunden.hours/minutes/seconds." + "format-hint": "Nutze den Format n, mm:ss oder hh:mm:ss für Stunden/Minuten/Sekunden.", + "start-now": "Gleich anfangen" + } } } diff --git a/lang/en.json b/lang/en.json index 39537c1..5084a02 100644 --- a/lang/en.json +++ b/lang/en.json @@ -21,7 +21,8 @@ "add-timer": { "timer name": "Timer name", "duration": "Duration", - "format-hint": "Use format n (for seconds), mm:ss or hh:mm:ss for hours/minutes/seconds." + "format-hint": "Use format s, mm:ss or hh:mm:ss for hours/minutes/seconds.", + "start-now": "Start now" } } } diff --git a/lang/hr.json b/lang/hr.json index af7529a..509a198 100644 --- a/lang/hr.json +++ b/lang/hr.json @@ -21,7 +21,9 @@ "add-timer": { "timer name": "Ime timera", "duration": "Trajanje", - "format-hint": "Koristi šprancu n za sekunde, mm:ss ili hh:mm:ss za sate/minute/sekunde." + "format-hint": "Koristi šprancu s, mm:ss ili hh:mm:ss za sate/minute/sekunde.", + "start-now": "Pokreni odmah" + } } } diff --git a/module.json b/module.json index e05c2ef..157aa04 100644 --- a/module.json +++ b/module.json @@ -9,7 +9,7 @@ "url": "https://zlatko.dev" } ], - "version": "0.1.0", + "version": "0.1.1", "compatibility": { "minimum": 12, "verified": 12 @@ -18,7 +18,7 @@ "src/timer.js" ], "styles": [ - "styles/style.css" + "styles/yat-style.css" ], "languages": [ { diff --git a/src/add-timer-screen.js b/src/add-timer-screen.js index 86f25e3..9ca9e1f 100644 --- a/src/add-timer-screen.js +++ b/src/add-timer-screen.js @@ -1,4 +1,5 @@ import { logger } from './logger.js'; +import { getNextName, createTimer } from './timer.repository.js'; const templatePath = `modules/yet-another-timer/templates/add-timer.hbs`; @@ -11,12 +12,15 @@ export class AddTimerScreen extends FormApplication {a id: "yet-another-timer-add-timer", template: templatePath, title: game.i18n?.localize("YAT.status.add-timer") || "Add Timer", + closeOnSubmit: false, + submitOnChange: false, }; return Object.assign({}, defaults, overrides); } getData() { return { + nextName: getNextName() }; } @@ -26,6 +30,13 @@ export class AddTimerScreen extends FormApplication {a logger.debug('Activated.'); } + _updateObject(event, formData) { + logger.debug("Adding a timer", formData, event); + createTimer(formData.duration, formData.name, formData.startNow); + this.close(); + // also ping to update? + } + #handleClick(event) { logger.debug('**click**', event); const el = $(event.currentTarget); @@ -36,3 +47,5 @@ export class AddTimerScreen extends FormApplication {a logger.debug('Data:', data); } } + +export const showAddTimer = () => new AddTimerScreen().render(true); diff --git a/src/timer-complete-screen.js b/src/timer-complete-screen.js index 535fa26..04d5ad5 100644 --- a/src/timer-complete-screen.js +++ b/src/timer-complete-screen.js @@ -2,23 +2,30 @@ import { logger } from './logger.js'; const templatePath = `modules/yet-another-timer/templates/timer-complete.hbs`; -export class TimerCompleteScreen extends FormApplication {a +export class TimerCompleteScreen extends FormApplication { static get defaultOptions() { const defaults = super.defaultOptions; const overrides = { height: "auto", - id: "yet-another-timer-add-timer", + resizable: true, + id: "yet-another-timer-timer-complete", template: templatePath, title: game.i18n?.localize("YAT.timer.complete") || "Timer complete", }; return Object.assign({}, defaults, overrides); } - data = {}; + data = { + names: [], + }; setData(data) { - this.data = data; + logger.debug("Adding a completed timer", data); + if (data.name) { + // TODO: dynamically set the id somehow. + this.data.names.push(data.name); + } } getData() { diff --git a/src/timer-screen.js b/src/timer-screen.js index 11bea4a..af786e3 100644 --- a/src/timer-screen.js +++ b/src/timer-screen.js @@ -2,6 +2,7 @@ import { logger } from "./logger.js"; import { getTimers } from "./timer.repository.js"; import { getStatus, pauseTimer, resumeTimer, deleteTimer, flipTimers, subscribe } from './timer.loop.js'; import { TimerError } from "./error.js"; +import { showAddTimer } from './add-timer-screen.js'; const templatePath = `modules/yet-another-timer/templates/timer.hbs`; @@ -31,7 +32,7 @@ export class TimerScreen extends FormApplication { const overrides = { height: "auto", - width: "33rem", + resizable: true, id: "yet-another-timer", template: templatePath, title: game.i18n?.localize("YAT.title") || "Yet another timer", @@ -80,7 +81,7 @@ export class TimerScreen extends FormApplication { deleteTimer(timerName); break; case 'add-timer': - showAddAction() + showAddTimer() break; default: logger.error(`Unknown timer action: ${action}`); diff --git a/src/timer.loop.js b/src/timer.loop.js index 12c3029..5b3a9a5 100644 --- a/src/timer.loop.js +++ b/src/timer.loop.js @@ -110,6 +110,7 @@ function advance(timer, interval_ms) { function completeTimer(timer) { logger.log(`Timer ${timer.name} completed.`); timer.isPaused = true; + timer.isComplete = true; // ping? close something? const timerComplete = new TimerCompleteScreen(); timerComplete.setData({ name: timer.name }); diff --git a/src/timer.repository.js b/src/timer.repository.js index 338390e..d38be70 100644 --- a/src/timer.repository.js +++ b/src/timer.repository.js @@ -89,7 +89,7 @@ function assertValidName(name) { } } -function getNextName(prefix = 0) { +export function getNextName(prefix = 0) { const name = `timer-${prefix}-${timerMap.size}` if (timerMap.has(name)) { return getNextName(prefix + 1); diff --git a/styles/style.css b/styles/yat-style.css similarity index 63% rename from styles/style.css rename to styles/yat-style.css index 2ae4860..bf5d823 100644 --- a/styles/style.css +++ b/styles/yat-style.css @@ -1,4 +1,5 @@ -.timer-card { + +#yet-another-timer .timer-card { border: 1px solid #ccc; border-radius: 8px; padding: 15px; @@ -10,12 +11,12 @@ vertical-align: top; } -.timer-card.paused { +#yet-another-timer .timer-card.paused { background-color: #eee; opacity: 0.7; } -.timer-card .title { +#yet-another-timer .timer-card .title { font-weight: bold; font-size: 1.2em; margin-bottom: 10px; @@ -23,17 +24,17 @@ padding-bottom: 5px; } -.timer-card .content p { +#yet-another-timer .timer-card .content p { margin: 5px 0; font-size: 0.9em; } -.timer-card .actions { +#yet-another-timer .timer-card .actions { margin-top: 15px; text-align: right; } -.timer-card .button { +#yet-another-timer .timer-card .button { padding: 5px 10px; margin-left: 5px; cursor: pointer; @@ -42,16 +43,22 @@ background-color: #e0e0e0; } -.timer-card .button:hover { +#yet-another-timer .timer-card .button:hover { background-color: #d0d0d0; } -.timer-card .delete-button { +#yet-another-timer .timer-card .delete-button { background-color: #f8d7da; border-color: #f5c6cb; color: #721c24; } -.timer-card .delete-button:hover { +#yet-another-timer .timer-card .delete-button:hover { background-color: #f5c6cb; } + +.yat-add-form { + display: flex; + flex-flow: column; + gap: 1rem; +} diff --git a/templates/add-timer.hbs b/templates/add-timer.hbs index 07fb801..17e7afc 100644 --- a/templates/add-timer.hbs +++ b/templates/add-timer.hbs @@ -1,10 +1,20 @@
{{ localize "YAT.time-remaining" }}: {{ formatRemainingTime durationSeconds elapsedTimeSeconds }}