From 2a262fb17a1fb564cbc126e30855e11af44fa6a6 Mon Sep 17 00:00:00 2001
From: Kekilla0 <64717385+Kekilla0@users.noreply.github.com>
Date: Sun, 23 May 2021 22:25:39 -0400
Subject: [PATCH] update and fixes for 1.0
---
lang/en.json | 14 ++++++++++++++
module.json | 18 +++++++++++-------
packs/wsMacros.db | 2 ++
scripts/logger.js | 10 +++++-----
scripts/scripter.js | 18 +++++++++---------
scripts/settings.js | 21 +++++++++++++--------
6 files changed, 54 insertions(+), 29 deletions(-)
diff --git a/lang/en.json b/lang/en.json
index 077404a..8a2c539 100644
--- a/lang/en.json
+++ b/lang/en.json
@@ -1,3 +1,17 @@
{
+ "logger.debug" : "DEBUG",
+ "logger.error" : "ERROR",
+
+ "settings.debug.name" : "Debugging",
+ "settings.debug.hint" : "Enable for module debugging",
+
+ "error.scriptMissing" : "script pack missing",
+ "error.scriptFailure" : "Script Error",
+ "error.macroID" : "Macro ID Error",
+
+ "context.PreTitle" : "Add to",
+ "context.PostTitle" : "Compendium",
+
+ "" : ""
}
\ No newline at end of file
diff --git a/module.json b/module.json
index 1f0df2d..e17df37 100644
--- a/module.json
+++ b/module.json
@@ -2,11 +2,15 @@
"name" : "world-scripter",
"title" : "World Scripter",
"description" : "Allow you to write a script in game which executes as if it was a world script.",
- "author" : ["kekilla#7036"],
- "version" : "0.0.3",
- "minimumCoreVersion" : "0.6.6",
- "compatibleCoreVersion" : "0.8.3",
- "esmodules" : ["scripts/hooks.js"],
+ "author" : [
+ "kekilla#7036"
+ ],
+ "version" : "0.1.0",
+ "minimumCoreVersion" : "0.8.0",
+ "compatibleCoreVersion" : "0.8.5",
+ "esmodules" : [
+ "scripts/hooks.js"
+ ],
"languages" : [
{
"lang" : "en",
@@ -16,7 +20,7 @@
],
"packs" : [
{
- "name" : "world-scripter-macros",
+ "name" : "macros",
"label" : "World Scripter Macros",
"path" : "packs/wsMacros.db",
"entity" : "Macro",
@@ -25,5 +29,5 @@
],
"url" : "https://github.com/Kekilla0/world-scripter",
"manifest" : "https://raw.githubusercontent.com/Kekilla0/World-Scripter/main/module.json",
- "download" : "https://github.com/Kekilla0/World-Scripter/archive/v0.0.3.zip"
+ "download" : "https://github.com/Kekilla0/World-Scripter/archive/v0.1.0.zip"
}
\ No newline at end of file
diff --git a/packs/wsMacros.db b/packs/wsMacros.db
index d0c7ff9..9012764 100644
--- a/packs/wsMacros.db
+++ b/packs/wsMacros.db
@@ -4,3 +4,5 @@
{"_id":"L9W2eBAVcKmg2EDm","name":"Global Functions","permission":{"default":0,"rY3aSQCPtPJz0xsx":3},"type":"script","flags":{"core":{"sourceId":"Macro.gquC32RvjVE0P3tp"},"furnace":{"runAsGM":false},"combat-utility-belt":{"macroTrigger":""}},"scope":"global","command":"let windowFunctions = { buttonDialog, quickDialog };\n\nObject.entries(windowFunctions).forEach(([key,value])=> window[key] = value );\n\nArray.prototype.forEachAsync = async function (callback) {\n for(let index = 0; index < this.length; index++)\n await callback(this[index], index, this);\n}\n\nArray.prototype.shuffle = function() {\n var currentIndex = this.length, temporaryValue, randomIndex;\n\n // While there remain elements to shuffle...\n while (0 !== currentIndex) {\n\n // Pick a remaining element...\n randomIndex = Math.floor(Math.random() * currentIndex);\n currentIndex -= 1;\n\n // And swap it with the current element.\n temporaryValue = this[currentIndex];\n this[currentIndex] = this[randomIndex];\n this[randomIndex] = temporaryValue;\n }\n\n return this;\n}\n\nasync function buttonDialog(data){\n return await new Promise((resolve) => {\n let buttons = {}, dialog;\n\n data.buttons.forEach(([str, callback])=>{\n buttons[str] = {\n label : str,\n callback\n }\n });\n \n dialog = new Dialog({title : data.title , content : data.content, buttons, close : () => resolve(true) }).render(true);\n });\n}\n\nasync function quickDialog({data, title = `Quick Dialog`} = {}){\n data = data instanceof Array ? data : [data];\n\n return await new Promise((resolve) => {\n let content = `\n
`;\n\n new Dialog({\n title, content,\n buttons : {\n Ok : { label : `Ok`, callback : (html) => {\n resolve(Array(data.length).fill().map((e,i)=>{\n let {type} = data[i];\n if(type.toLowerCase() === `select`)\n {\n return html.find(`select#${i}qd`).val();\n }else{\n switch(type.toLowerCase())\n {\n case `text` :\n case `password` :\n case `radio` :\n return html.find(`input#${i}qd`)[0].value;\n case `checkbox` :\n return html.find(`input#${i}qd`)[0].checked;\n case `number` :\n return html.find(`input#${i}qd`)[0].valueAsNumber;\n }\n }\n }));\n }}\n }\n }).render(true);\n });\n}","author":"rY3aSQCPtPJz0xsx","img":"icons/svg/dice-target.svg","actorIds":[]}
{"_id":"Ze4poHGIZ7nEFz2K","name":"0 HP Death Overlay","permission":{"default":0,"rY3aSQCPtPJz0xsx":3},"type":"chat","flags":{"core":{"sourceId":"Macro.NmhRh7L9wKok8Gzi"}},"scope":"global","command":"/*\n World Scripter Macro : 0 HP Death Overlay\n*/\nconst config = {\n active : false,\n effectData : [\n {\n changes : [],\n duration : {},\n flags : { core : { overlay : true, statusId : \"dead\" }},\n icon : \"icons/svg/skull.svg\",\n label : \"dead\"\n }\n ]\n};\nif(config.active && game.user.isGM)\n Hooks.on(`preUpdateToken`, deathOverlay);\n\nfunction deathOverlay(scene, tokenData,updateData)\n{\n if(isZeroHealth() && isNPC())\n {\n setProperty(updateData, \"actorData.effects\", config.effectData);\n }\n function isZeroHealth()\n {\n return getProperty(updateData, \"actorData.data.attributes.hp.value\") === 0;\n }\n function isNPC()\n {\n return !game.actors.get(tokenData.actorId).hasPlayerOwner;\n }\n}","author":"rY3aSQCPtPJz0xsx","img":"icons/svg/dice-target.svg","actorIds":[]}
{"_id":"cLaFA6W5WQ4x5iVl","name":"Logo Removal","type":"script","author":"rY3aSQCPtPJz0xsx","img":"icons/svg/dice-target.svg","scope":"global","command":"const config = {\n active : true,\n};\n\n\nif(config.active){\n document.getElementById(\"logo\").src = \"\";\n setNavigation();\n Hooks.on(`renderSceneDirectory`, setNavigation)\n}\n\nfunction setNavigation(){\n let element = document.getElementById(\"navigation\");\n element.style.left = \"20px\";\n}","folder":null,"sort":0,"permission":{"default":0,"rY3aSQCPtPJz0xsx":3},"flags":{"furnace":{"runAsGM":false},"core":{"sourceId":"Macro.IeOh2UnxxgNxXkHn"},"combat-utility-belt":{"macroTrigger":""}}}
+{"name":"Clear Console","type":"script","author":"rY3aSQCPtPJz0xsx","img":"icons/svg/dice-target.svg","scope":"global","command":"console.clear();","folder":null,"sort":100001,"permission":{"default":2,"rY3aSQCPtPJz0xsx":2,"oN95dwBL7EYuwpti":2,"6k7j4c4xLMRc4Njh":2,"2btSSW80YOWoEPWx":2},"flags":{},"_id":"mWKDb3YnSdJrLR85"}
+{"$$deleted":true,"_id":"mWKDb3YnSdJrLR85"}
diff --git a/scripts/logger.js b/scripts/logger.js
index 2c565d6..6980cd7 100644
--- a/scripts/logger.js
+++ b/scripts/logger.js
@@ -2,16 +2,16 @@ import { settings } from './settings.js';
export class logger {
static info(...args) {
- console.log(`${settings.title} | `, ...args);
+ console.log(`${settings.TITLE} | `, ...args);
}
static debug(...args) {
- if (game.settings.get(settings.name, 'debug'))
- logger.info("DEBUG | ", ...args);
+ if (game.settings.get(settings.NAME, 'debug'))
+ logger.info(`${settings.i18n("logger.debug")} | `, ...args);
}
static error(...args){
- logger.info("ERROR | ", ...args);
- ui.notifications.error(`Error `, ...args);
+ logger.info(`${settings.i18n("logger.debug")} | `, ...args);
+ ui.notifications.error(`${settings.i18n("logger.debug")} `, ...args);
}
}
\ No newline at end of file
diff --git a/scripts/scripter.js b/scripts/scripter.js
index 7b9076e..98eeb87 100644
--- a/scripts/scripter.js
+++ b/scripts/scripter.js
@@ -3,9 +3,9 @@ import { settings } from './settings.js';
export class scripter{
static async execute_pack(){
- logger.info("Accessing Pack | ", settings.key);
- let pack = game.packs.get(settings.key);
- if(!pack) return logger.error(`${settings.title} script pack missing.`);
+ logger.debug("Accessing Pack | ", settings.KEY);
+ let pack = game.packs.get(settings.KEY);
+ if(!pack) return logger.error(`${settings.TITLE} ${settings.i18n("error.scriptMissing")}`);
let contents = await pack.getContent();
contents.forEach(macro => scripter.execute_macro(macro));
}
@@ -15,7 +15,7 @@ export class scripter{
try{
eval(macro.data.command);
}catch(err){
- logger.error(`Failed to execute | `, macro.data);
+ logger.error(`${settings.i18n("error.scriptFailure")} | `, macro.data);
console.error(err);
}
}
@@ -23,7 +23,7 @@ export class scripter{
static add_context(html, contextOptions){
logger.info("Adding Context Menu Items");
contextOptions.push({
- name : `Add to ${settings.title} Compendium`,
+ name : `${settings.i18n("context.PreTitle")} ${settings.TITLE} ${settings.i18n("context.PostTitle")}`,
icon : '',
condition : () => game.user.isGM,
callback : li => scripter.add_To_Compendium(li?.data("entityId")),
@@ -33,13 +33,13 @@ export class scripter{
static async add_To_Compendium(_id){
logger.info("Context Clicked | ", _id);
let macro = game.macros.get(_id);
- if(!macro) return logger.error(`Macro ID Error, ${_id}`);
- let pack = game.packs.get(settings.key);
- if(!pack) return logger.error(`${settings.title} script pack missing.`);
+ if(!macro) return logger.error(`${settings.i18n("error.macroID")}, ${_id}`);
+ let pack = game.packs.get(settings.KEY);
+ if(!pack) return logger.error(`${settings.TITLE} ${settings.i18n("error.scriptMissing")}`);
let index = await pack.getIndex();
if(index.find(ele => ele.name === macro.name))
await pack.updateEntity({_id : index.find(ele => ele.name === macro.name)._id, command : macro.data.command });
else
- await pack.createEntity(macro);
+ await pack.createEntity(macro.data);
}
}
diff --git a/scripts/settings.js b/scripts/settings.js
index 5e2953d..748cb0a 100644
--- a/scripts/settings.js
+++ b/scripts/settings.js
@@ -1,27 +1,30 @@
import { logger } from './logger.js';
export class settings{
- static title = "World Scripter";
- static name = "world-scripter";
- static key = "world-scripter.world-scripter-macros";
+ static TITLE = "World Scripter";
+ static NAME = "world-scripter";
+ static KEY = "world-scripter.macros";
static register(){
logger.info("Registering all Settings");
settings.register_logger();
}
- static value(str){
- return game.settings.get(settings.name, str);
+ static value(key){
+ return game.settings.get(settings.NAME, key);
+ }
+ static i18n(key){
+ return game.i18n.localize(key);
}
static register_logger(){
logger.info("Registering Logger Debugging");
game.settings.register(
- settings.name,
+ settings.NAME,
'debug',
{
- name : "",
- hint : "",
+ name : settings.i18n("settings.debug.name"),
+ hint : settings.i18n("settings.debug.hint"),
scope :"world",
config : false,
default : false,
@@ -29,4 +32,6 @@ export class settings{
},
);
}
+
+ //gmOnly edit
}
\ No newline at end of file