Add flexible recurring events

This commit is contained in:
Kiyomichi Kosaka 2025-06-20 00:26:11 +02:00
parent d11b8cf19f
commit 5e703813d7
2 changed files with 43 additions and 16 deletions

View File

@ -1,14 +1,22 @@
// Configuration of periodic events in CoBiE time // Configuration of periodic events in CoBiE time
// Each event repeats every cosmocycle. // Each object describes when the event occurs and how often it repeats.
// "cobie" is the timestamp within the cosmocycle when the event occurs. //
// "tag" is a short label that will be displayed on the calendar. // Fields:
// start - CoBiE timestamp when the first occurrence happens.
// end - optional CoBiE timestamp after which the event stops.
// unit - the unit of the recurrence ("second", "xenocycle", "quantic",
// "chronon", "eonstrip", "megasequence", "cosmocycle", ...).
// interval - how many units between occurrences (1 = every unit,
// 2 = every second unit, ...).
// label - short description displayed on the calendar.
// duration - optional length of the event in seconds.
window.SPECIAL_EVENTS = [ window.SPECIAL_EVENTS = [
{ cobie: '49f4.9332', label: 'Afina', megasequence: 'Mythran Epoch', eonstrip: 'Ventaso' }, { start: '49f4.9332', label: 'Afina', unit: 'cosmocycle', interval: 1 },
{ cobie: '11e5.f552', label: 'Oleks', megasequence: 'Umbral Echo', eonstrip: 'Ignisar' }, { start: '11e5.f552', label: 'Oleks', unit: 'cosmocycle', interval: 1 },
{ cobie: '4d07.a2b2', label: 'Vincent', megasequence: 'Azurean Tide', eonstrip: 'Floraen' }, { start: '4d07.a2b2', label: 'Vincent', unit: 'cosmocycle', interval: 1 },
{ cobie: '3edc.d430', label: 'Hochzeitstag', megasequence: 'Lustran Bounty', eonstrip: 'Electros' }, { start: '3edc.d430', label: 'Hochzeitstag', unit: 'cosmocycle', interval: 1 },
{ cobie: '330d.d4ae', label: 'Zusammentag', megasequence: 'Azurean Tide', eonstrip: 'Chronar' }, { start: '330d.d4ae', label: 'Zusammentag', unit: 'cosmocycle', interval: 1 },
{ cobie: '11de.0c52', label: 'Anna', megasequence: 'Lustran Bounty', eonstrip: 'Radiantae' }, { start: '11de.0c52', label: 'Anna', unit: 'cosmocycle', interval: 1 },
{ cobie: '467f.ae61', label: 'Iris', megasequence: 'Argent Veil', eonstrip: 'Etherion' } { start: '467f.ae61', label: 'Iris', unit: 'cosmocycle', interval: 1 }
]; ];

View File

@ -613,13 +613,32 @@ function updateCalendar() {
</div>`; </div>`;
if (Array.isArray(window.SPECIAL_EVENTS)) { if (Array.isArray(window.SPECIAL_EVENTS)) {
const offsetStart = ((cellCob % COBIE_UNITS.cosmocycle) + COBIE_UNITS.cosmocycle) % COBIE_UNITS.cosmocycle; const cellStart = cellCob;
const offsetEnd = offsetStart + COBIE_UNITS.eonstrip; const cellEnd = cellCob + COBIE_UNITS.eonstrip;
window.SPECIAL_EVENTS.forEach(ev => { window.SPECIAL_EVENTS.forEach(ev => {
const evCob = parseCobiets(ev.cobie); const startCob = parseCobiets(ev.start || ev.cobie);
if (evCob === null) return; if (startCob === null) return;
const evOffset = ((evCob % COBIE_UNITS.cosmocycle) + COBIE_UNITS.cosmocycle) % COBIE_UNITS.cosmocycle; const endCob = ev.end ? parseCobiets(ev.end) : Number.POSITIVE_INFINITY;
if (evOffset >= offsetStart && evOffset < offsetEnd) { const unitVal = COBIE_UNITS[ev.unit] || COBIE_UNITS.cosmocycle;
const interval = (ev.interval || 1) * unitVal;
let duration = 0;
if (typeof ev.duration === 'string') {
const d = parseCobiets(ev.duration);
if (d !== null) duration = d;
} else if (typeof ev.duration === 'number') {
duration = ev.duration;
}
if (cellStart > endCob) return;
let n = Math.floor((cellStart - startCob) / interval);
if (n < 0) n = 0;
let occ = startCob + n * interval;
if (occ + duration <= cellStart) {
occ += interval;
}
if (occ < cellEnd && occ + duration > cellStart && occ <= endCob) {
const tag = document.createElement('div'); const tag = document.createElement('div');
tag.className = 'event-tag'; tag.className = 'event-tag';
tag.textContent = ev.label; tag.textContent = ev.label;