Hard Refactor

This commit is contained in:
Maximilien Rigaut 2022-05-26 21:04:29 +02:00
parent f4a6c3e835
commit 8fccdd9f10
14 changed files with 94 additions and 94 deletions

View File

@ -10,8 +10,8 @@ export class SimpleActorSheet extends ActorSheet {
/** @inheritdoc */
static get defaultOptions() {
return foundry.utils.mergeObject(super.defaultOptions, {
classes: ["worldbuilding", "sheet", "actor"],
template: "systems/worldbuilding/templates/actor-sheet.html",
classes: ["vtt_sys_ravenous", "sheet", "actor"],
template: "systems/vtt_sys_ravenous/templates/actor-sheet.html",
width: 600,
height: 600,
tabs: [{navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description"}],
@ -26,7 +26,7 @@ export class SimpleActorSheet extends ActorSheet {
getData() {
const context = super.getData();
EntitySheetHelper.getAttributeData(context.data);
context.shorthand = !!game.settings.get("worldbuilding", "macroShorthand");
context.shorthand = !!game.settings.get("vtt_sys_ravenous", "macroShorthand");
context.systemData = context.data.data;
context.dtypes = ATTRIBUTE_TYPES;
return context;

View File

@ -28,7 +28,7 @@ export class SimpleActor extends Actor {
* @type {boolean}
*/
get isTemplate() {
return !!this.getFlag("worldbuilding", "isTemplate");
return !!this.getFlag("vtt_sys_ravenous", "isTemplate");
}
/* -------------------------------------------- */
@ -40,7 +40,7 @@ export class SimpleActor extends Actor {
// Copy the actor's system data
const data = this.toObject(false).data;
const shorthand = game.settings.get("worldbuilding", "macroShorthand");
const shorthand = game.settings.get("vtt_sys_ravenous", "macroShorthand");
const formulaAttributes = [];
const itemAttributes = [];

View File

@ -173,7 +173,7 @@ export class EntitySheetHelper {
const button = event.currentTarget;
const label = button.closest(".attribute").querySelector(".attribute-label")?.value;
const chatLabel = label ?? button.parentElement.querySelector(".attribute-key").value;
const shorthand = game.settings.get("worldbuilding", "macroShorthand");
const shorthand = game.settings.get("vtt_sys_ravenous", "macroShorthand");
// Use the actor for rollData so that formulas are always in reference to the parent actor.
const rollData = this.actor.getRollData();
@ -537,7 +537,7 @@ export class EntitySheetHelper {
// Identify the template Actor types
const collection = game.collections.get(this.documentName);
const templates = collection.filter(a => a.getFlag("worldbuilding", "isTemplate"));
const templates = collection.filter(a => a.getFlag("vtt_sys_ravenous", "isTemplate"));
const defaultType = this.metadata.types[0];
const types = {
[defaultType]: game.i18n.localize("SIMPLE.NoTemplate")
@ -547,7 +547,7 @@ export class EntitySheetHelper {
}
// Render the document creation form
const useEntity = game.worldbuilding.useEntity;
const useEntity = game.vtt_sys_ravenous.useEntity;
const template = `templates/sidebar/${useEntity ? "entity" : "document" }-create.html`;
const html = await renderTemplate(template, {
name: data.name || game.i18n.format("DOCUMENT.New", {type: label}),
@ -576,7 +576,7 @@ export class EntitySheetHelper {
if ( template ) {
createData = foundry.utils.mergeObject(template.toObject(), createData);
createData.type = template.data.type;
delete createData.flags.worldbuilding.isTemplate;
delete createData.flags.vtt_sys_ravenous.isTemplate;
}
// Merge provided override data

View File

@ -10,8 +10,8 @@ export class SimpleItemSheet extends ItemSheet {
/** @inheritdoc */
static get defaultOptions() {
return foundry.utils.mergeObject(super.defaultOptions, {
classes: ["worldbuilding", "sheet", "item"],
template: "systems/worldbuilding/templates/item-sheet.html",
classes: ["vtt_sys_ravenous", "sheet", "item"],
template: "systems/vtt_sys_ravenous/templates/item-sheet.html",
width: 520,
height: 480,
tabs: [{navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "description"}],

View File

@ -28,6 +28,6 @@ export class SimpleItem extends Item {
* @type {boolean}
*/
get isTemplate() {
return !!this.getFlag("worldbuilding", "isTemplate");
return !!this.getFlag("vtt_sys_ravenous", "isTemplate");
}
}

View File

@ -1,11 +1,11 @@
/**
* Create a Macro from an attribute drop.
* Get an existing worldbuilding macro if one exists, otherwise create a new one.
* Get an existing vtt_sys_ravenous macro if one exists, otherwise create a new one.
* @param {Object} data The dropped data
* @param {number} slot The hotbar slot to use
* @returns {Promise}
*/
export async function createWorldbuildingMacro(data, slot) {
export async function createvtt_sys_ravenousMacro(data, slot) {
if ( !data.roll || !data.label ) return false;
const command = `const roll = new Roll("${data.roll}", actor ? actor.getRollData() : {});
roll.toMessage({speaker, flavor: "${data.label}"});`;
@ -15,7 +15,7 @@ export async function createWorldbuildingMacro(data, slot) {
name: data.label,
type: "script",
command: command,
flags: { "worldbuilding.attrMacro": true }
flags: { "vtt_sys_ravenous.attrMacro": true }
});
}
game.user.assignHotbarMacro(macro, slot);

View File

@ -9,7 +9,7 @@ import { SimpleItem } from "./item.js";
import { SimpleItemSheet } from "./item-sheet.js";
import { SimpleActorSheet } from "./actor-sheet.js";
import { preloadHandlebarsTemplates } from "./templates.js";
import { createWorldbuildingMacro } from "./macro.js";
import { createvtt_sys_ravenousMacro } from "./macro.js";
import { SimpleToken, SimpleTokenDocument } from "./token.js";
/* -------------------------------------------- */
@ -20,7 +20,7 @@ import { SimpleToken, SimpleTokenDocument } from "./token.js";
* Init hook.
*/
Hooks.once("init", async function() {
console.log(`Initializing Simple Worldbuilding System`);
console.log(`Initializing Simple vtt_sys_ravenous System`);
/**
* Set an initiative formula for the system. This will be updated later.
@ -31,9 +31,9 @@ Hooks.once("init", async function() {
decimals: 2
};
game.worldbuilding = {
game.vtt_sys_ravenous = {
SimpleActor,
createWorldbuildingMacro,
createvtt_sys_ravenousMacro,
useEntity: foundry.utils.isNewerVersion("9", game.version ?? game.data.version)
};
@ -45,12 +45,12 @@ Hooks.once("init", async function() {
// Register sheet application classes
Actors.unregisterSheet("core", ActorSheet);
Actors.registerSheet("worldbuilding", SimpleActorSheet, { makeDefault: true });
Actors.registerSheet("vtt_sys_ravenous", SimpleActorSheet, { makeDefault: true });
Items.unregisterSheet("core", ItemSheet);
Items.registerSheet("worldbuilding", SimpleItemSheet, { makeDefault: true });
Items.registerSheet("vtt_sys_ravenous", SimpleItemSheet, { makeDefault: true });
// Register system settings
game.settings.register("worldbuilding", "macroShorthand", {
game.settings.register("vtt_sys_ravenous", "macroShorthand", {
name: "SETTINGS.SimpleMacroShorthandN",
hint: "SETTINGS.SimpleMacroShorthandL",
scope: "world",
@ -60,7 +60,7 @@ Hooks.once("init", async function() {
});
// Register initiative setting.
game.settings.register("worldbuilding", "initFormula", {
game.settings.register("vtt_sys_ravenous", "initFormula", {
name: "SETTINGS.SimpleInitFormulaN",
hint: "SETTINGS.SimpleInitFormulaL",
scope: "world",
@ -71,7 +71,7 @@ Hooks.once("init", async function() {
});
// Retrieve and assign the initiative formula setting.
const initFormula = game.settings.get("worldbuilding", "initFormula");
const initFormula = game.settings.get("vtt_sys_ravenous", "initFormula");
_simpleUpdateInit(initFormula);
/**
@ -102,13 +102,13 @@ Hooks.once("init", async function() {
/**
* Macrobar hook.
*/
Hooks.on("hotbarDrop", (bar, data, slot) => createWorldbuildingMacro(data, slot));
Hooks.on("hotbarDrop", (bar, data, slot) => createvtt_sys_ravenousMacro(data, slot));
/**
* Adds the actor template context menu.
*/
Hooks.on("getActorDirectoryEntryContext", (html, options) => {
const idAttr = game.worldbuilding.useEntity ? "entityId" : "documentId";
const idAttr = game.vtt_sys_ravenous.useEntity ? "entityId" : "documentId";
// Define an actor as a template.
options.push({
name: game.i18n.localize("SIMPLE.DefineTemplate"),
@ -119,7 +119,7 @@ Hooks.on("getActorDirectoryEntryContext", (html, options) => {
},
callback: li => {
const actor = game.actors.get(li.data(idAttr));
actor.setFlag("worldbuilding", "isTemplate", true);
actor.setFlag("vtt_sys_ravenous", "isTemplate", true);
}
});
@ -133,7 +133,7 @@ Hooks.on("getActorDirectoryEntryContext", (html, options) => {
},
callback: li => {
const actor = game.actors.get(li.data(idAttr));
actor.setFlag("worldbuilding", "isTemplate", false);
actor.setFlag("vtt_sys_ravenous", "isTemplate", false);
}
});
});
@ -142,7 +142,7 @@ Hooks.on("getActorDirectoryEntryContext", (html, options) => {
* Adds the item template context menu.
*/
Hooks.on("getItemDirectoryEntryContext", (html, options) => {
const idAttr = game.worldbuilding.useEntity ? "entityId" : "documentId";
const idAttr = game.vtt_sys_ravenous.useEntity ? "entityId" : "documentId";
// Define an item as a template.
options.push({
name: game.i18n.localize("SIMPLE.DefineTemplate"),
@ -153,7 +153,7 @@ Hooks.on("getItemDirectoryEntryContext", (html, options) => {
},
callback: li => {
const item = game.items.get(li.data(idAttr));
item.setFlag("worldbuilding", "isTemplate", true);
item.setFlag("vtt_sys_ravenous", "isTemplate", true);
}
});
@ -167,7 +167,7 @@ Hooks.on("getItemDirectoryEntryContext", (html, options) => {
},
callback: li => {
const item = game.items.get(li.data(idAttr));
item.setFlag("worldbuilding", "isTemplate", false);
item.setFlag("vtt_sys_ravenous", "isTemplate", false);
}
});
});

View File

@ -8,8 +8,8 @@ export const preloadHandlebarsTemplates = async function() {
// Define template paths to load
const templatePaths = [
// Attribute list partial.
"systems/worldbuilding/templates/parts/sheet-attributes.html",
"systems/worldbuilding/templates/parts/sheet-groups.html"
"systems/vtt_sys_ravenous/templates/parts/sheet-attributes.html",
"systems/vtt_sys_ravenous/templates/parts/sheet-groups.html"
];
// Load the template parts

View File

@ -1,7 +1,7 @@
{
"name": "worldbuilding",
"name": "vtt_sys_ravenous",
"version": "1.0.0",
"description": "CSS compiler for the Worldbuilding system",
"description": "CSS compiler for the vtt_sys_ravenous system",
"scripts": {
"css": "gulp css",
"watch": "gulp",

View File

@ -1,17 +1,17 @@
.worldbuilding {
.vtt_sys_ravenous {
/* Sheet Tabs */
/* Items List */
/* Attributes */
}
.worldbuilding .window-content {
.vtt_sys_ravenous .window-content {
height: 100%;
padding: 5px;
overflow-y: hidden;
}
.worldbuilding form {
.vtt_sys_ravenous form {
height: 100%;
}
.worldbuilding .sheet-header {
.vtt_sys_ravenous .sheet-header {
flex: 0 0 100px;
overflow: hidden;
display: flex;
@ -20,85 +20,85 @@
justify-content: flex-start;
margin-bottom: 10px;
}
.worldbuilding .sheet-header .profile-img {
.vtt_sys_ravenous .sheet-header .profile-img {
flex: 0 0 100px;
height: 100px;
margin-right: 10px;
}
.worldbuilding .sheet-header .header-fields {
.vtt_sys_ravenous .sheet-header .header-fields {
flex: 1;
height: 100px;
}
.worldbuilding .sheet-header h1.charname {
.vtt_sys_ravenous .sheet-header h1.charname {
height: 50px;
padding: 0px;
margin: 5px 0;
border-bottom: 0;
}
.worldbuilding .sheet-header h1.charname input {
.vtt_sys_ravenous .sheet-header h1.charname input {
width: 100%;
height: 100%;
margin: 0;
}
.worldbuilding .resource {
.vtt_sys_ravenous .resource {
width: 50%;
height: 40px;
margin-top: 10px;
float: left;
text-align: center;
}
.worldbuilding .resource input {
.vtt_sys_ravenous .resource input {
width: 100px;
height: 28px;
}
.worldbuilding .tabs {
.vtt_sys_ravenous .tabs {
flex: 0 0 40px;
border-top: 1px solid #AAA;
border-bottom: 1px solid #AAA;
}
.worldbuilding .tabs .item {
.vtt_sys_ravenous .tabs .item {
line-height: 40px;
font-weight: bold;
}
.worldbuilding .tabs .item.active {
.vtt_sys_ravenous .tabs .item.active {
text-decoration: underline;
text-shadow: none;
}
.worldbuilding .sheet-body {
.vtt_sys_ravenous .sheet-body {
overflow: hidden;
}
.worldbuilding .sheet-body .tab {
.vtt_sys_ravenous .sheet-body .tab {
height: 100%;
overflow-y: auto;
}
.worldbuilding .editor,
.worldbuilding .editor-content {
.vtt_sys_ravenous .editor,
.vtt_sys_ravenous .editor-content {
height: 100%;
}
.worldbuilding .item-list {
.vtt_sys_ravenous .item-list {
list-style: none;
margin: 7px 0;
padding: 0;
overflow-y: auto;
}
.worldbuilding .item-list .item {
.vtt_sys_ravenous .item-list .item {
min-height: 30px;
line-height: 24px;
padding: 3px 0;
border-bottom: 1px solid #BBB;
align-items: stretch;
}
.worldbuilding .item-list .item img {
.vtt_sys_ravenous .item-list .item img {
flex: 0 0 24px;
margin-right: 5px;
}
.worldbuilding .item-list .item-name {
.vtt_sys_ravenous .item-list .item-name {
margin: 0;
}
.worldbuilding .item-list .item-controls {
.vtt_sys_ravenous .item-list .item-controls {
flex: 0 0 36px;
}
.worldbuilding .item-list .item-buttons {
.vtt_sys_ravenous .item-list .item-buttons {
display: flex;
flex-wrap: wrap;
flex-direction: row;
@ -106,23 +106,23 @@
flex: 2;
justify-content: flex-start;
}
.worldbuilding .item-list .item-button {
.vtt_sys_ravenous .item-list .item-button {
line-height: 1;
font-size: 11px;
flex: none;
width: auto;
}
.worldbuilding .attributes {
.vtt_sys_ravenous .attributes {
position: relative;
}
.worldbuilding .attributes .attribute-control,
.worldbuilding .attributes .group-control {
.vtt_sys_ravenous .attributes .attribute-control,
.vtt_sys_ravenous .attributes .group-control {
flex: 0 0 20px;
text-align: center;
line-height: 28px;
border: none;
}
.worldbuilding .attributes .attribute-roll {
.vtt_sys_ravenous .attributes .attribute-roll {
flex: 0 0 20px;
text-align: center;
border-bottom: none;
@ -130,11 +130,11 @@
align-items: center;
justify-content: center;
}
.worldbuilding .attributes .group-prefix {
.vtt_sys_ravenous .attributes .group-prefix {
height: 31px;
margin-right: 10px;
}
.worldbuilding .attributes .button {
.vtt_sys_ravenous .attributes .button {
width: 100%;
flex: 1;
margin: 0;
@ -145,11 +145,11 @@
line-height: 28px;
display: block;
}
.worldbuilding .attributes .attribute-key {
.vtt_sys_ravenous .attributes .attribute-key {
background: transparent;
border: none;
}
.worldbuilding .attributes-header {
.vtt_sys_ravenous .attributes-header {
position: sticky;
top: 0;
left: 0;
@ -162,12 +162,12 @@
text-align: left;
font-weight: bold;
}
.worldbuilding .attributes-list {
.vtt_sys_ravenous .attributes-list {
list-style: none;
margin: 0;
padding: 0;
}
.worldbuilding .attributes-list li > * {
.vtt_sys_ravenous .attributes-list li > * {
margin: 0 3px;
height: 28px;
line-height: 24px;
@ -176,47 +176,47 @@
border-radius: 0;
border-bottom: 1px solid #AAA;
}
.worldbuilding .attributes-list .attribute-col label {
.vtt_sys_ravenous .attributes-list .attribute-col label {
font-size: 10px;
text-align: center;
line-height: 1;
}
.worldbuilding .attributes-list .attribute-col input {
.vtt_sys_ravenous .attributes-list .attribute-col input {
font-size: 11px;
text-align: center;
line-height: 1;
height: 50%;
}
.worldbuilding .attribute input[type="text"]::placeholder,
.worldbuilding .group-header input[type="text"]::placeholder {
.vtt_sys_ravenous .attribute input[type="text"]::placeholder,
.vtt_sys_ravenous .group-header input[type="text"]::placeholder {
opacity: 0;
transition: opacity 0.25s ease-in-out;
}
.worldbuilding .attribute input[type="text"]:focus::placeholder,
.worldbuilding .group-header input[type="text"]:focus::placeholder {
.vtt_sys_ravenous .attribute input[type="text"]:focus::placeholder,
.vtt_sys_ravenous .group-header input[type="text"]:focus::placeholder {
opacity: 1;
}
.worldbuilding .group-controls {
.vtt_sys_ravenous .group-controls {
margin: 5px;
}
.worldbuilding .groups-list {
.vtt_sys_ravenous .groups-list {
list-style: none;
margin: 0;
padding: 0;
}
.worldbuilding .group {
.vtt_sys_ravenous .group {
margin: 5px 0 0;
padding: 0;
}
.worldbuilding .group-header {
.vtt_sys_ravenous .group-header {
align-items: center;
background: rgba(0, 0, 0, 0.05);
border: 1px solid #AAA;
border-radius: 2px;
padding: 2px 5px;
}
.worldbuilding .group-key,
.worldbuilding .group-label {
.vtt_sys_ravenous .group-key,
.vtt_sys_ravenous .group-label {
font-weight: bold;
border: none;
border-bottom: 1px solid #AAA;
@ -224,22 +224,22 @@
border-radius: 0;
margin-right: 6px;
}
.worldbuilding .group-key {
.vtt_sys_ravenous .group-key {
opacity: 0.75;
}
.worldbuilding .group-label {
.vtt_sys_ravenous .group-label {
flex: 2;
}
.worldbuilding .group-dtype {
.vtt_sys_ravenous .group-dtype {
height: 24px;
flex: 0 0 116px;
margin: 0 5px;
}
.worldbuilding.sheet.actor {
.vtt_sys_ravenous.sheet.actor {
min-width: 560px;
min-height: 420px;
}
.worldbuilding.sheet.item {
.vtt_sys_ravenous.sheet.item {
min-width: 460px;
min-height: 400px;
}

View File

@ -1,4 +1,4 @@
.worldbuilding {
.vtt_sys_ravenous {
.window-content {
height: 100%;
padding: 5px;
@ -279,13 +279,13 @@
}
}
.worldbuilding.sheet.actor {
.vtt_sys_ravenous.sheet.actor {
min-width: 560px;
min-height: 420px;
}
.worldbuilding.sheet.item {
.vtt_sys_ravenous.sheet.item {
min-width: 460px;
min-height: 400px;
}

View File

@ -99,11 +99,11 @@
</header>
{{!-- Render the attribute list partial. --}}
{{> "systems/worldbuilding/templates/parts/sheet-attributes.html" attributes=systemData.ungroupedAttributes dtypes=dtypes}}
{{> "systems/vtt_sys_ravenous/templates/parts/sheet-attributes.html" attributes=systemData.ungroupedAttributes dtypes=dtypes}}
{{!-- Render the grouped attributes partial and control. --}}
<div class="groups">
{{> "systems/worldbuilding/templates/parts/sheet-groups.html" attributes=systemData.groupedAttributes groups=systemData.groups dtypes=dtypes}}
{{> "systems/vtt_sys_ravenous/templates/parts/sheet-groups.html" attributes=systemData.groupedAttributes groups=systemData.groups dtypes=dtypes}}
<div class="group-controls flexrow">
<input class="group-prefix" type="text" value=""/>

View File

@ -41,11 +41,11 @@
</header>
{{!-- Render the attribute list partial. --}}
{{> "systems/worldbuilding/templates/parts/sheet-attributes.html" attributes=systemData.ungroupedAttributes dtypes=dtypes}}
{{> "systems/vtt_sys_ravenous/templates/parts/sheet-attributes.html" attributes=systemData.ungroupedAttributes dtypes=dtypes}}
{{!-- Render the grouped attributes partial and control. --}}
<div class="groups">
{{> "systems/worldbuilding/templates/parts/sheet-groups.html" attributes=systemData.groupedAttributes groups=systemData.groups dtypes=dtypes}}
{{> "systems/vtt_sys_ravenous/templates/parts/sheet-groups.html" attributes=systemData.groupedAttributes groups=systemData.groups dtypes=dtypes}}
<div class="group-controls flexrow">
<input class="group-prefix" type="text" value=""/>
<a class="button group-control" data-action="create-group"><i class="fas fa-plus"></i>Add Attribute Group</a>

View File

@ -15,7 +15,7 @@
<a class="group-control" data-action="delete-group"><i class="fas fa-trash"></i></a>
</div>
{{> "systems/worldbuilding/templates/parts/sheet-attributes.html" attributes=group.attributes group=groupKey dtypes=../dtypes}}
{{> "systems/vtt_sys_ravenous/templates/parts/sheet-attributes.html" attributes=group.attributes group=groupKey dtypes=../dtypes}}
</li>
{{/each}}
</ol>