Start working on the Stats Viewer application

This commit is contained in:
Oliver-Akins 2025-04-21 00:50:58 -06:00
parent cb3bc7c86c
commit 91863d85a8
18 changed files with 422 additions and 1 deletions

View file

@ -0,0 +1,34 @@
/* eslint-disable no-unused-vars */
import { Table } from "./model.mjs";
export class MemoryDatabase {
static getTables() {
/** @type {Array<{ name: string; }>} */
return [
{ name: `Dice/d4` },
{ name: `Dice/d6` },
{ name: `Dice/d8` },
{ name: `Dice/d10` },
{ name: `Dice/d12` },
{ name: `Dice/d20` },
{ name: `Dice/d100` },
{ name: `Count of Successes` },
];
};
static createRow(table, user, row) {};
static getRows(tableId, ...users) {
if (users.length === 0) { users = [game.user] };
const datasets = {};
return datasets;
};
static updateRow(table, user, rowId, changes) {};
static deleteRow(table, user, rowId) {};
};
/* eslint-enable no-unused-vars */

View file

@ -0,0 +1,36 @@
/* eslint-disable no-unused-vars */
import { Table } from "./model.mjs";
const tablesFlag = `tables`;
export class UserFlagDatabase {
static getTables() {
/** @type {Array<{ name: string; }>} */
const tableConfig = game.settings.get(__ID__, `tables`);
return tableConfig ?? [];
};
static createRow(table, user, row) {};
static getRows(tableId, ...users) {
if (users.length === 0) { users = [game.user] };
const datasets = {};
for (const user of users) {
const tables = user.getFlag(__ID__, tablesFlag) ?? {};
if (tables[tableId] === undefined) {
datasets[user.id] = null;
continue;
};
const table = new Table(tables[tableId]);
}
return datasets;
};
static updateRow(table, user, rowId, changes) {};
static deleteRow(table, user, rowId) {};
};
/* eslint-enable no-unused-vars */

View file

@ -0,0 +1,43 @@
const { fields } = foundry.data;
// MARK: Table
export class Table extends foundry.abstract.DataModel {
static defineSchema() {
return {
name: new fields.StringField({
nullable: false,
required: true,
blank: false,
trim: true,
validate(value) {
return !value.match(/[^a-z0-9_\-:]/i);
},
}),
data: new fields.TypedObjectField(Row),
};
};
};
// MARK: Row
export class Row extends foundry.abstract.DataModel {
static defineSchema() {
return {
id: new fields.StringField({
nullable: false,
required: true,
blank: false,
}),
timestamp: new fields.NumberField({
min: 0,
required: true,
nullable: false,
}),
value: new fields.AnyField(),
private: new fields.BooleanField({
initial: false,
required: true,
nullable: false,
}),
};
};
};