Compare commits
No commits in common. "main" and "v0.1.1" have entirely different histories.
@ -3,7 +3,7 @@ import { getNextName, createTimer } from './timer.repository.js';
|
|||||||
|
|
||||||
const templatePath = `modules/yet-another-timer/templates/add-timer.hbs`;
|
const templatePath = `modules/yet-another-timer/templates/add-timer.hbs`;
|
||||||
|
|
||||||
export class AddTimerScreen extends FormApplication {
|
export class AddTimerScreen extends FormApplication {a
|
||||||
static get defaultOptions() {
|
static get defaultOptions() {
|
||||||
const defaults = super.defaultOptions;
|
const defaults = super.defaultOptions;
|
||||||
|
|
||||||
|
19
src/timer.js
19
src/timer.js
@ -1,5 +1,5 @@
|
|||||||
import { logger } from './logger.js';
|
import { logger } from './logger.js';
|
||||||
import { setScreen, startTimers, stopTimers, resumeTimer, triggerChatCommand, chatCommandName } from './timer.loop.js';
|
import { startTimers, stopTimers, resumeTimer } from './timer.loop.js';
|
||||||
import { createTimer } from './timer.repository.js';
|
import { createTimer } from './timer.repository.js';
|
||||||
import { TimerScreen } from "./timer-screen.js";
|
import { TimerScreen } from "./timer-screen.js";
|
||||||
|
|
||||||
@ -7,17 +7,8 @@ let isPaused = true;
|
|||||||
|
|
||||||
console.debug('Timer module booted!');
|
console.debug('Timer module booted!');
|
||||||
|
|
||||||
Hooks.once('init', function() {
|
Hooks.on('init', function() {
|
||||||
logger.log('Timer module init');
|
logger.log('Timer module init');
|
||||||
const screen = new TimerScreen();
|
|
||||||
setScreen(screen);
|
|
||||||
});
|
|
||||||
|
|
||||||
Hooks.on('chatMessage', (chatLog, messageText, chatData) => {
|
|
||||||
if (messageText.trim().toLowerCase().startsWith(chatCommandName)) {
|
|
||||||
return triggerChatCommand(chatLog, messageText, chatData);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Hooks.on('ready', function(details) {
|
Hooks.on('ready', function(details) {
|
||||||
@ -27,6 +18,12 @@ Hooks.on('ready', function(details) {
|
|||||||
isPaused = false;
|
isPaused = false;
|
||||||
|
|
||||||
addSomeTimers();
|
addSomeTimers();
|
||||||
|
|
||||||
|
const screen = new TimerScreen();
|
||||||
|
logger.log(screen);
|
||||||
|
const result = screen.render(true);
|
||||||
|
logger.log(result);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Hooks.on('error', function(location, error, payload) {
|
Hooks.on('error', function(location, error, payload) {
|
||||||
|
@ -3,88 +3,18 @@ import { TimerError } from "./error.js";
|
|||||||
import { getActiveTimers, getTimer, deleteTimer as repoDeleteTimer } from "./timer.repository.js";
|
import { getActiveTimers, getTimer, deleteTimer as repoDeleteTimer } from "./timer.repository.js";
|
||||||
import { logTimer } from "./timer-screen.js";
|
import { logTimer } from "./timer-screen.js";
|
||||||
import { TimerCompleteScreen } from "./timer-complete-screen.js";
|
import { TimerCompleteScreen } from "./timer-complete-screen.js";
|
||||||
import { showAddTimer } from './add-timer-screen.js';
|
|
||||||
|
|
||||||
const INTERVAL_MS = 1000; // main loop interval
|
const INTERVAL_MS = 1000; // main loop interval
|
||||||
|
|
||||||
const state = {
|
const state = {
|
||||||
timerInterval: null,
|
timerInterval: null,
|
||||||
subscribers: [],
|
subscribers: [],
|
||||||
screen: null,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const chatCommandName = '/timers';
|
|
||||||
|
|
||||||
export function getStatus() {
|
export function getStatus() {
|
||||||
return state.timerInterval === null;
|
return state.timerInterval === null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setScreen(screen) {
|
|
||||||
state.screen = screen;
|
|
||||||
}
|
|
||||||
|
|
||||||
function showChatHelpMessage() {
|
|
||||||
ChatMessage.create({
|
|
||||||
user: game.user.id,
|
|
||||||
speaker: ChatMessage.getSpeaker(),
|
|
||||||
content: `<em>${game.user.name} used "/timers"!</em><br>
|
|
||||||
|
|
||||||
Usage: /timers <command><br/>
|
|
||||||
|
|
||||||
Commands:
|
|
||||||
|
|
||||||
<li><strong>show</strong> - shows timers</li>
|
|
||||||
<li><strong>hide</strong> - hide timers</li>
|
|
||||||
<li><strong>pause</strong> - pause the timer runners</li>
|
|
||||||
<li><strong>resume</strong> - resume timer runners</li>
|
|
||||||
<li><strong>add</strong> - add a timer</li>
|
|
||||||
`,
|
|
||||||
type: CONST.CHAT_MESSAGE_STYLES.OOC,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function triggerChatCommand(log, msg, data) {
|
|
||||||
logger.debug('Chat message:', log, msg, data);
|
|
||||||
try {
|
|
||||||
const parts = msg.split(' ')
|
|
||||||
.map(part => part.trim())
|
|
||||||
.filter(Boolean);
|
|
||||||
const op = parts[1];
|
|
||||||
if (!op) {
|
|
||||||
logger.error('No chat command given.');
|
|
||||||
showChatHelpMessage();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
logger.debug('Parts:', parts);
|
|
||||||
switch (op) {
|
|
||||||
case 'show':
|
|
||||||
state.screen?.render(true);
|
|
||||||
break;
|
|
||||||
case 'hide':
|
|
||||||
state.screen?.close();
|
|
||||||
break;
|
|
||||||
case 'pause':
|
|
||||||
stopTimers();
|
|
||||||
break;
|
|
||||||
case 'stop':
|
|
||||||
stopTimers();
|
|
||||||
break;
|
|
||||||
case 'resume':
|
|
||||||
startTimers();
|
|
||||||
break;
|
|
||||||
case 'add':
|
|
||||||
showAddTimer();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
showChatHelpMessage();
|
|
||||||
logger.error(`Invalid chat command "${op}".`);
|
|
||||||
}
|
|
||||||
} catch(error) {
|
|
||||||
logger.error(`Error processing errors:`, error);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function flipTimers() {
|
export function flipTimers() {
|
||||||
if (getStatus()) {
|
if (getStatus()) {
|
||||||
startTimers();
|
startTimers();
|
||||||
|
@ -27,7 +27,6 @@
|
|||||||
#yet-another-timer .timer-card .content p {
|
#yet-another-timer .timer-card .content p {
|
||||||
margin: 5px 0;
|
margin: 5px 0;
|
||||||
font-size: 0.9em;
|
font-size: 0.9em;
|
||||||
max-width: 33em;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#yet-another-timer .timer-card .actions {
|
#yet-another-timer .timer-card .actions {
|
||||||
@ -63,8 +62,3 @@
|
|||||||
flex-flow: column;
|
flex-flow: column;
|
||||||
gap: 1rem;
|
gap: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
img {
|
|
||||||
height: 40px;
|
|
||||||
width: 40px;
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user