Skip to content

Commit

Permalink
update and fixes for 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Kekilla0 committed May 24, 2021
1 parent f92ff2f commit 2a262fb
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 29 deletions.
14 changes: 14 additions & 0 deletions lang/en.json
Original file line number Diff line number Diff line change
@@ -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",

"" : ""
}
18 changes: 11 additions & 7 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -16,7 +20,7 @@
],
"packs" : [
{
"name" : "world-scripter-macros",
"name" : "macros",
"label" : "World Scripter Macros",
"path" : "packs/wsMacros.db",
"entity" : "Macro",
Expand All @@ -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"
}
2 changes: 2 additions & 0 deletions packs/wsMacros.db
Original file line number Diff line number Diff line change
Expand Up @@ -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 <table style=\"width:100%\">\n ${data.map(({type, label, options}, i)=> {\n if(type.toLowerCase() === `select`)\n {\n return `<tr><th style=\"width:50%\"><label>${label}</label></th><td style=\"width:50%\"><select id=\"${i}qd\">${options.map((e,i)=> `<option value=\"${e}\">${e}</option>`).join(``)}</td></tr>`;\n }else if(type.toLowerCase() === `checkbox`){\n return `<tr><th style=\"width:50%\"><label>${label}</label></th><td style=\"width:50%\"><input type=\"${type}\" id=\"${i}qd\" ${options || ``}/></td></tr>`;\n }else{\n return `<tr><th style=\"width:50%\"><label>${label}</label></th><td style=\"width:50%\"><input type=\"${type}\" id=\"${i}qd\" value=\"${options instanceof Array ? options[0] : options}\"/></td></tr>`;\n }\n }).join(``)}\n </table>`;\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"}
10 changes: 5 additions & 5 deletions scripts/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
18 changes: 9 additions & 9 deletions scripts/scripter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand All @@ -15,15 +15,15 @@ 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);
}
}

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 : '<i class="fas fa-download"></i>',
condition : () => game.user.isGM,
callback : li => scripter.add_To_Compendium(li?.data("entityId")),
Expand All @@ -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);
}
}
21 changes: 13 additions & 8 deletions scripts/settings.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
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,
type : Boolean
},
);
}

//gmOnly edit
}

0 comments on commit 2a262fb

Please sign in to comment.