From b67f90f4aa0d12286edf25132e2e6724698a3a25 Mon Sep 17 00:00:00 2001 From: thekingofspace <37231416+thekingofspace@users.noreply.github.com> Date: Mon, 15 Apr 2024 14:08:36 -0700 Subject: [PATCH 01/23] Updated with 2 things Added create primitive mod Added seperator mod --- actions/canvas_create_primitive_MOD.js | 101 +++++++++++++++++++++++ actions/seperator_MOD.js | 110 +++++++++++++++++++++++++ 2 files changed, 211 insertions(+) create mode 100644 actions/canvas_create_primitive_MOD.js create mode 100644 actions/seperator_MOD.js diff --git a/actions/canvas_create_primitive_MOD.js b/actions/canvas_create_primitive_MOD.js new file mode 100644 index 00000000..5c7bb9c9 --- /dev/null +++ b/actions/canvas_create_primitive_MOD.js @@ -0,0 +1,101 @@ +module.exports = { + name: 'Canvas Create Shape', + section: 'Image Editing', + meta: { + version: '1.0.0', + author: 'Your Name', + authorUrl: 'https://yourwebsite.com', + downloadURL: 'https://github.com/yourrepository/your-script.js', + }, + + subtitle(data) { + const info = parseInt(data.info, 10); + if (info === 0) { + return data.color ? `Create Circle with Color ${data.color}` : 'No color circle has been created'; + } + if (info === 1) { + return data.color ? `Create Rectangle with Color ${data.color}` : 'No color rectangle has been created'; + } + // Add more cases for different shapes as needed + }, + + variableStorage(data, varType) { + if (parseInt(data.storage, 10) !== varType) return; + return [data.varName, 'Image']; + }, + + fields: ['shapeType', 'width', 'height', 'color', 'storage', 'varName'], + + html() { + return ` +
+
+ Shape Type + +
+
+

+ +
+
+ Width (px) +
+
+
+ Height (px) +
+
+
+

+ +
+
+ Color +
+
+
+

+ + +`; + }, + + async action(cache) { + const data = cache.actions[cache.index]; + const Canvas = require('canvas'); + const shapeType = parseInt(data.shapeType, 10); + const width = parseInt(this.evalMessage(data.width, cache), 10); + const height = parseInt(this.evalMessage(data.height, cache), 10); + const canvas = Canvas.createCanvas(width, height); + const ctx = canvas.getContext('2d'); + let color = this.evalMessage(data.color, cache); + + switch (shapeType) { + case 0: // Circle + ctx.beginPath(); + ctx.arc(width / 2, height / 2, Math.min(width, height) / 2, 0, 2 * Math.PI); + ctx.fillStyle = color; + ctx.fill(); + break; + case 1: // Rectangle + ctx.fillStyle = color; + ctx.fillRect(0, 0, width, height); + break; + // Add more cases for different shapes + default: + break; + } + + const result = canvas.toDataURL('image/png').replace('image/png', 'image/octet-stream'); + const varName = this.evalMessage(data.varName, cache); + const storage = parseInt(data.storage, 10); + this.storeValue(result, storage, varName, cache); + this.callNextAction(cache); + }, + + mod() {}, +}; diff --git a/actions/seperator_MOD.js b/actions/seperator_MOD.js new file mode 100644 index 00000000..1bb66ab2 --- /dev/null +++ b/actions/seperator_MOD.js @@ -0,0 +1,110 @@ +module.exports = { + name: 'Separator', + section: 'Other', + fields: ['separator', 'color', 'bold', 'underline', 'fontSize'], + + meta: { + version: '2.1.7', + author: 'DBM Mods', + authorUrl: 'https://github.com/dbm-network/mods', + downloadURL: 'https://github.com/dbm-network/mods/blob/master/actions/file_control_separator.js', + }, + + subtitle(data) { + let style = ''; + if (data.bold === 'true') style += 'font-weight: bold;'; + if (data.underline === 'true') style += 'text-decoration: underline;'; + if (data.fontSize) style += `font-size: ${parseInt(data.fontSize, 10)}px;`; + const separator = data.separator || 'No separator provided'; + const color = data.color || '#000000'; + return `${separator}`; + }, + + html() { + return ` +
+
+ Separator +
+ Color:
+

+ Bold:
+
+ Underline:
+
+ Font Size (px):
+

+
+
`; + }, + + init() { + const { document } = this; + const separatorField = document.getElementById('separator'); + const colorField = document.getElementById('color'); + const boldField = document.getElementById('bold'); + const underlineField = document.getElementById('underline'); + const fontSizeField = document.getElementById('fontSize'); + + function updateSubtitle() { + const separatorValue = separatorField.value.trim(); + const colorValue = colorField.value; + const boldValue = boldField.value === 'true'; + const underlineValue = underlineField.value === 'true'; + const fontSizeValue = fontSizeField.value; + const subtitle = document.querySelector('.subtitle'); + let style = ''; + if (boldValue) style += 'font-weight: bold;'; + if (underlineValue) style += 'text-decoration: underline;'; + if (fontSizeValue) style += `font-size: ${parseInt(fontSizeValue, 10)}px;`; + subtitle.innerHTML = `${separatorValue || 'No separator provided'}`; + } + + separatorField.addEventListener('input', updateSubtitle); + colorField.addEventListener('input', updateSubtitle); + boldField.addEventListener('change', updateSubtitle); + underlineField.addEventListener('change', updateSubtitle); + fontSizeField.addEventListener('input', updateSubtitle); + + // Trigger subtitle update on initialization + updateSubtitle(); + }, + + async action(cache) { + const data = cache.actions[cache.index]; + const separator = this.evalMessage(data.separator, cache); + const color = this.evalMessage(data.color, cache); + const bold = data.bold === 'true'; + const underline = data.underline === 'true'; + + // Store separator value if provided + if (separator !== undefined) { + cache.separator = separator; + } + + // Store color value if provided + if (color !== undefined) { + cache.color = color; + } + + // Store bold value if provided + if (bold !== undefined) { + cache.bold = bold; + } + + // Store underline value if provided + if (underline !== undefined) { + cache.underline = underline; + } + + this.callNextAction(cache); + }, + + mod() {}, +}; From a6a0b260fb94465972e33205f3db618b2a4e5da6 Mon Sep 17 00:00:00 2001 From: thekingofspace <37231416+thekingofspace@users.noreply.github.com> Date: Thu, 18 Apr 2024 21:17:36 -0700 Subject: [PATCH 02/23] Updated these with lint --- actions/canvas_create_primitive_MOD.js | 2 +- actions/seperator_MOD.js | 222 +++++++++++++------------ 2 files changed, 113 insertions(+), 111 deletions(-) diff --git a/actions/canvas_create_primitive_MOD.js b/actions/canvas_create_primitive_MOD.js index 5c7bb9c9..01db6a59 100644 --- a/actions/canvas_create_primitive_MOD.js +++ b/actions/canvas_create_primitive_MOD.js @@ -72,7 +72,7 @@ module.exports = { const height = parseInt(this.evalMessage(data.height, cache), 10); const canvas = Canvas.createCanvas(width, height); const ctx = canvas.getContext('2d'); - let color = this.evalMessage(data.color, cache); + const color = this.evalMessage(data.color, cache); switch (shapeType) { case 0: // Circle diff --git a/actions/seperator_MOD.js b/actions/seperator_MOD.js index 1bb66ab2..8ab631a7 100644 --- a/actions/seperator_MOD.js +++ b/actions/seperator_MOD.js @@ -1,110 +1,112 @@ -module.exports = { - name: 'Separator', - section: 'Other', - fields: ['separator', 'color', 'bold', 'underline', 'fontSize'], - - meta: { - version: '2.1.7', - author: 'DBM Mods', - authorUrl: 'https://github.com/dbm-network/mods', - downloadURL: 'https://github.com/dbm-network/mods/blob/master/actions/file_control_separator.js', - }, - - subtitle(data) { - let style = ''; - if (data.bold === 'true') style += 'font-weight: bold;'; - if (data.underline === 'true') style += 'text-decoration: underline;'; - if (data.fontSize) style += `font-size: ${parseInt(data.fontSize, 10)}px;`; - const separator = data.separator || 'No separator provided'; - const color = data.color || '#000000'; - return `${separator}`; - }, - - html() { - return ` -
-
- Separator -
- Color:
-

- Bold:
-
- Underline:
-
- Font Size (px):
-

-
-
`; - }, - - init() { - const { document } = this; - const separatorField = document.getElementById('separator'); - const colorField = document.getElementById('color'); - const boldField = document.getElementById('bold'); - const underlineField = document.getElementById('underline'); - const fontSizeField = document.getElementById('fontSize'); - - function updateSubtitle() { - const separatorValue = separatorField.value.trim(); - const colorValue = colorField.value; - const boldValue = boldField.value === 'true'; - const underlineValue = underlineField.value === 'true'; - const fontSizeValue = fontSizeField.value; - const subtitle = document.querySelector('.subtitle'); - let style = ''; - if (boldValue) style += 'font-weight: bold;'; - if (underlineValue) style += 'text-decoration: underline;'; - if (fontSizeValue) style += `font-size: ${parseInt(fontSizeValue, 10)}px;`; - subtitle.innerHTML = `${separatorValue || 'No separator provided'}`; - } - - separatorField.addEventListener('input', updateSubtitle); - colorField.addEventListener('input', updateSubtitle); - boldField.addEventListener('change', updateSubtitle); - underlineField.addEventListener('change', updateSubtitle); - fontSizeField.addEventListener('input', updateSubtitle); - - // Trigger subtitle update on initialization - updateSubtitle(); - }, - - async action(cache) { - const data = cache.actions[cache.index]; - const separator = this.evalMessage(data.separator, cache); - const color = this.evalMessage(data.color, cache); - const bold = data.bold === 'true'; - const underline = data.underline === 'true'; - - // Store separator value if provided - if (separator !== undefined) { - cache.separator = separator; - } - - // Store color value if provided - if (color !== undefined) { - cache.color = color; - } - - // Store bold value if provided - if (bold !== undefined) { - cache.bold = bold; - } - - // Store underline value if provided - if (underline !== undefined) { - cache.underline = underline; - } - - this.callNextAction(cache); - }, - - mod() {}, -}; +module.exports = { + name: 'Separator', + section: 'Other', + fields: ['separator', 'color', 'bold', 'underline', 'fontSize'], + + meta: { + version: '2.1.7', + author: 'DBM Mods', + authorUrl: 'https://github.com/dbm-network/mods', + downloadURL: 'https://github.com/dbm-network/mods/blob/master/actions/file_control_separator.js', + }, + + subtitle(data) { + let style = ''; + if (data.bold === 'true') style += 'font-weight: bold;'; + if (data.underline === 'true') style += 'text-decoration: underline;'; + if (data.fontSize) style += `font-size: ${parseInt(data.fontSize, 10)}px;`; + const separator = data.separator || 'No separator provided'; + const color = data.color || '#000000'; + return `${separator}`; + }, + + html() { + return ` +
+
+ Separator +
+ Color:
+

+ Bold:
+
+ Underline:
+
+ Font Size (px):
+

+
+
`; + }, + + init() { + const { document } = this; + const separatorField = document.getElementById('separator'); + const colorField = document.getElementById('color'); + const boldField = document.getElementById('bold'); + const underlineField = document.getElementById('underline'); + const fontSizeField = document.getElementById('fontSize'); + + function updateSubtitle() { + const separatorValue = separatorField.value.trim(); + const colorValue = colorField.value; + const boldValue = boldField.value === 'true'; + const underlineValue = underlineField.value === 'true'; + const fontSizeValue = fontSizeField.value; + const subtitle = document.querySelector('.subtitle'); + let style = ''; + if (boldValue) style += 'font-weight: bold;'; + if (underlineValue) style += 'text-decoration: underline;'; + if (fontSizeValue) style += `font-size: ${parseInt(fontSizeValue, 10)}px;`; + subtitle.innerHTML = `${ + separatorValue || 'No separator provided' + }`; + } + + separatorField.addEventListener('input', updateSubtitle); + colorField.addEventListener('input', updateSubtitle); + boldField.addEventListener('change', updateSubtitle); + underlineField.addEventListener('change', updateSubtitle); + fontSizeField.addEventListener('input', updateSubtitle); + + // Trigger subtitle update on initialization + updateSubtitle(); + }, + + async action(cache) { + const data = cache.actions[cache.index]; + const separator = this.evalMessage(data.separator, cache); + const color = this.evalMessage(data.color, cache); + const bold = data.bold === 'true'; + const underline = data.underline === 'true'; + + // Store separator value if provided + if (separator !== undefined) { + cache.separator = separator; + } + + // Store color value if provided + if (color !== undefined) { + cache.color = color; + } + + // Store bold value if provided + if (bold !== undefined) { + cache.bold = bold; + } + + // Store underline value if provided + if (underline !== undefined) { + cache.underline = underline; + } + + this.callNextAction(cache); + }, + + mod() {}, +}; From 051774d53ec3aac6ef4290adeb5055f318e28d0f Mon Sep 17 00:00:00 2001 From: thekingofspace <37231416+thekingofspace@users.noreply.github.com> Date: Thu, 18 Apr 2024 21:21:02 -0700 Subject: [PATCH 03/23] Updated these with lint --- actions/canvas_create_primitive_MOD.js | 9 +++++---- actions/seperator_MOD.js | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/actions/canvas_create_primitive_MOD.js b/actions/canvas_create_primitive_MOD.js index 01db6a59..ebb0db46 100644 --- a/actions/canvas_create_primitive_MOD.js +++ b/actions/canvas_create_primitive_MOD.js @@ -2,10 +2,11 @@ module.exports = { name: 'Canvas Create Shape', section: 'Image Editing', meta: { - version: '1.0.0', - author: 'Your Name', - authorUrl: 'https://yourwebsite.com', - downloadURL: 'https://github.com/yourrepository/your-script.js', + version: '2.1.7', + preciseCheck: false, + author: 'DBM Mods', + authorUrl: 'https://github.com/dbm-network/mods', + downloadURL: 'https://github.com/dbm-network/mods/blob/master/actions/canvas_create_primitive_MOD.js', }, subtitle(data) { diff --git a/actions/seperator_MOD.js b/actions/seperator_MOD.js index 8ab631a7..717675c7 100644 --- a/actions/seperator_MOD.js +++ b/actions/seperator_MOD.js @@ -7,7 +7,7 @@ module.exports = { version: '2.1.7', author: 'DBM Mods', authorUrl: 'https://github.com/dbm-network/mods', - downloadURL: 'https://github.com/dbm-network/mods/blob/master/actions/file_control_separator.js', + downloadURL: 'https://github.com/dbm-network/mods/blob/master/actions/seperator_MOD.js', }, subtitle(data) { From 6ab1d2361da4ce55a04d5ecfaa6df087de58268b Mon Sep 17 00:00:00 2001 From: thekingofspace <37231416+thekingofspace@users.noreply.github.com> Date: Wed, 24 Apr 2024 10:05:36 -0700 Subject: [PATCH 04/23] Updated canvas_create_primitive_MOD.js --- actions/canvas_create_primitive_MOD.js | 99 ++++++++++++++++++++++---- 1 file changed, 86 insertions(+), 13 deletions(-) diff --git a/actions/canvas_create_primitive_MOD.js b/actions/canvas_create_primitive_MOD.js index ebb0db46..05d06199 100644 --- a/actions/canvas_create_primitive_MOD.js +++ b/actions/canvas_create_primitive_MOD.js @@ -11,13 +11,24 @@ module.exports = { subtitle(data) { const info = parseInt(data.info, 10); - if (info === 0) { - return data.color ? `Create Circle with Color ${data.color}` : 'No color circle has been created'; - } - if (info === 1) { - return data.color ? `Create Rectangle with Color ${data.color}` : 'No color rectangle has been created'; + switch (info) { + case 0: + return data.color ? `Create Circle with Color ${data.color}` : 'No color circle has been created'; + case 1: + return data.color ? `Create Rectangle with Color ${data.color}` : 'No color rectangle has been created'; + case 2: + return data.color ? `Create Triangle with Color ${data.color}` : 'No color triangle has been created'; + case 3: + return data.color ? `Create Hexagon with Color ${data.color}` : 'No color hexagon has been created'; + case 4: + return data.color ? `Create Pentagon with Color ${data.color}` : 'No color pentagon has been created'; + case 5: + return data.color ? `Create Ellipse with Color ${data.color}` : 'No color ellipse has been created'; + case 6: + return data.color ? `Create Star with Color ${data.color}` : 'No color star has been created'; + default: + return ''; } - // Add more cases for different shapes as needed }, variableStorage(data, varType) { @@ -35,12 +46,15 @@ module.exports = {

-
Width (px) @@ -52,7 +66,6 @@ module.exports = {


-
Color @@ -60,7 +73,6 @@ module.exports = {


- `; }, @@ -76,17 +88,78 @@ module.exports = { const color = this.evalMessage(data.color, cache); switch (shapeType) { - case 0: // Circle + case 0: ctx.beginPath(); ctx.arc(width / 2, height / 2, Math.min(width, height) / 2, 0, 2 * Math.PI); ctx.fillStyle = color; ctx.fill(); break; - case 1: // Rectangle + case 1: ctx.fillStyle = color; ctx.fillRect(0, 0, width, height); break; - // Add more cases for different shapes + case 2: + ctx.beginPath(); + ctx.moveTo(width / 2, 0); + ctx.lineTo(width, height); + ctx.lineTo(0, height); + ctx.closePath(); + ctx.fillStyle = color; + ctx.fill(); + break; + case 3: + ctx.beginPath(); + const sideLength = Math.min(width, height) / 2; + const xCenter = width / 2; + const yCenter = height / 2; + for (let i = 0; i < 6; i++) { + const angle = (Math.PI / 3) * i; + const x = xCenter + sideLength * Math.cos(angle); + const y = yCenter + sideLength * Math.sin(angle); + if (i === 0) { + ctx.moveTo(x, y); + } else { + ctx.lineTo(x, y); + } + } + ctx.closePath(); + ctx.fillStyle = color; + ctx.fill(); + break; + case 4: + ctx.beginPath(); + const angleStep = (2 * Math.PI) / 5; + const radius = Math.min(width, height) / 2; + const centerX = width / 2; + const centerY = height / 2; + ctx.moveTo(centerX + radius * Math.cos(0), centerY + radius * Math.sin(0)); + for (let i = 1; i <= 5; i++) { + ctx.lineTo(centerX + radius * Math.cos(angleStep * i), centerY + radius * Math.sin(angleStep * i)); + } + ctx.closePath(); + ctx.fillStyle = color; + ctx.fill(); + break; + case 5: + ctx.beginPath(); + ctx.ellipse(width / 2, height / 2, width / 2, height / 2, 0, 0, 2 * Math.PI); + ctx.fillStyle = color; + ctx.fill(); + break; + case 6: + const numPoints = 5; + const outerRadius = Math.min(width, height) / 2; + const innerRadius = outerRadius * 0.5; + ctx.beginPath(); + for (let i = 0; i < numPoints * 2; i++) { + const radius = i % 2 === 0 ? outerRadius : innerRadius; + const angle = (i * Math.PI) / numPoints - Math.PI / 2; + ctx.lineTo(width / 2 + radius * Math.cos(angle), height / 2 + radius * Math.sin(angle)); + } + ctx.closePath(); + ctx.fillStyle = color; + ctx.fill(); + break; default: break; } From 3ae7fbdc1a083ca486bcd5fd34d075587b9eca02 Mon Sep 17 00:00:00 2001 From: thekingofspace <37231416+thekingofspace@users.noreply.github.com> Date: Sun, 2 Jun 2024 20:48:00 -0700 Subject: [PATCH 05/23] Added json_read_MOD added json_write_MOD.js --- actions/json_read_MOD.js | 99 ++++++++++++++++++++ actions/json_write_MOD.js | 184 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 283 insertions(+) create mode 100644 actions/json_read_MOD.js create mode 100644 actions/json_write_MOD.js diff --git a/actions/json_read_MOD.js b/actions/json_read_MOD.js new file mode 100644 index 00000000..fb221b0b --- /dev/null +++ b/actions/json_read_MOD.js @@ -0,0 +1,99 @@ +const fs = require('fs'); +const path = require('path'); + +module.exports = { + name: 'Read JSON File', + section: 'File Stuff', + fields: ['filepath', 'title', 'contentTitle', 'storage', 'varName'], + meta: { + version: '2.1.7', + preciseCheck: false, + author: 'DBM Mods', + authorUrl: 'https://github.com/dbm-network/mods', + }, + + subtitle(data) { + return `Read JSON file ${data.filepath} content ${data.contentTitle}`; + }, + + variableStorage(data, varType) { + if (parseInt(data.storage, 10) !== varType) return; + return [data.varName, 'Unknown']; + }, + + html() { + return ` +
+
+ File Path + +
+
+ Title + +
+
+ Content Title + +
+
+ +
+
+ `; + }, + + init() {}, + + async action(cache) { + const data = cache.actions[cache.index]; + let filepath = this.evalMessage(data.filepath, cache); + const title = this.evalMessage(data.title, cache); + const contentTitle = this.evalMessage(data.contentTitle, cache); + const storage = parseInt(data.storage, 10); + const varName = this.evalMessage(data.varName, cache); + + if (filepath.startsWith('./')) { + filepath = path.join(__dirname, '..', filepath.substring(2)); + } + + let jsonData; + + try { + if (fs.existsSync(filepath)) { + const fileData = fs.readFileSync(filepath); + jsonData = JSON.parse(fileData); + } else { + throw new Error('File does not exist'); + } + } catch (error) { + console.error(`Error reading JSON file: ${error}`); + this.storeValue(undefined, storage, varName, cache); + return this.callNextAction(cache); + } + + let result; + try { + const titleData = jsonData.find((item) => item.Title === title); + if (!titleData) throw new Error('Title not found'); + + // Split the contentTitle by '/' to handle nested content + const contentKeys = contentTitle.split('/'); + let nestedContent = titleData; + for (const key of contentKeys) { + nestedContent = nestedContent[key]; + if (nestedContent === undefined) throw new Error(`Content Key '${key}' not found`); + } + result = nestedContent; + } catch (error) { + console.error(`Error accessing data: ${error}`); + this.storeValue(undefined, storage, varName, cache); + return this.callNextAction(cache); + } + + this.storeValue(result, storage, varName, cache); + this.callNextAction(cache); + }, + + mod() {}, +}; diff --git a/actions/json_write_MOD.js b/actions/json_write_MOD.js new file mode 100644 index 00000000..7b8611c2 --- /dev/null +++ b/actions/json_write_MOD.js @@ -0,0 +1,184 @@ +const fs = require('fs'); +const path = require('path'); + +module.exports = { + name: 'JSON File Control', + section: 'File Stuff', + fields: ['filepath', 'action', 'title', 'contentTitle', 'contentText', 'newTitle', 'oldTitle', 'deleteContentTitle'], + meta: { + version: '2.1.7', + preciseCheck: false, + author: 'DBM Mods', + authorUrl: 'https://github.com/dbm-network/mods', + }, + + subtitle(data) { + return `JSON edit on ${data.filepath} with ${data.action}`; + }, + + html() { + return ` +
+
+ File Path + +
+
+ Action + +
+
+ Title + +
+ + + +
+ `; + }, + + init() { + const { glob, document } = this; + + glob.onChangeAction = function (event) { + const value = event.value; + document.getElementById('titleSection').style.display = + value === 'addTitle' || value === 'addContent' || value === 'renameContent' ? 'block' : 'none'; + document.getElementById('contentSection').style.display = value === 'addContent' ? 'block' : 'none'; + document.getElementById('renameSection').style.display = + value === 'renameContent' || value === 'renameTitle' ? 'block' : 'none'; + document.getElementById('deleteSection').style.display = value === 'deleteContent' ? 'block' : 'none'; + }; + + glob.onChangeAction(document.getElementById('action')); + }, + + async action(cache) { + const data = cache.actions[cache.index]; + let filepath = this.evalMessage(data.filepath, cache); + + if (filepath.startsWith('./')) { + filepath = path.join(__dirname, '..', filepath.substring(2)); + } + + const action = data.action; + const title = this.evalMessage(data.title, cache); + const contentTitle = this.evalMessage(data.contentTitle, cache); + const contentText = this.evalMessage(data.contentText, cache); + const oldTitle = this.evalMessage(data.oldTitle, cache); + const newTitle = this.evalMessage(data.newTitle, cache); + const deleteContentTitle = this.evalMessage(data.deleteContentTitle, cache); + + // Load JSON file + let jsonData; + try { + if (fs.existsSync(filepath)) { + const fileData = fs.readFileSync(filepath); + jsonData = JSON.parse(fileData); + } else { + jsonData = []; + } + } catch (error) { + console.error(`Error reading JSON file: ${error}`); + jsonData = []; + } + + switch (action) { + case 'addTitle': + if (title) { + jsonData.push({ Title: title }); + } + break; + case 'addContent': + let target = jsonData.find((item) => item.Title === title); + if (!target) { + target = { Title: title }; + jsonData.push(target); + } + if (contentTitle.includes('/')) { + const keys = contentTitle.split('/'); + keys.reduce((obj, key, index) => { + if (index === keys.length - 1) { + obj[key] = isNaN(contentText) ? contentText : parseFloat(contentText); + } else { + obj[key] = obj[key] || {}; + } + return obj[key]; + }, target); + } else { + target[contentTitle] = isNaN(contentText) ? contentText : parseFloat(contentText); + } + break; + case 'renameContent': + jsonData.forEach((item) => { + if (item.Title === title && item[contentTitle]) { + item[newTitle] = item[contentTitle]; + delete item[contentTitle]; + } + }); + break; + case 'renameTitle': + jsonData.forEach((item) => { + if (item.Title === oldTitle) { + item.Title = newTitle; + } + }); + break; + case 'deleteContent': + jsonData.forEach((item) => { + if (item.Title === title) { + if (deleteContentTitle.includes('/')) { + const keys = deleteContentTitle.split('/'); + keys.reduce((obj, key, index) => { + if (index === keys.length - 1) { + delete obj[key]; + } else { + return obj[key]; + } + }, item); + } else { + delete item[deleteContentTitle]; + } + } + }); + break; + case 'deleteTitle': + jsonData = jsonData.filter((item) => item.Title !== title); + break; + } + + // Save JSON file + try { + fs.writeFileSync(filepath, JSON.stringify(jsonData, null, 2)); + } catch (error) { + console.error(`Error writing JSON file: ${error}`); + } + + this.callNextAction(cache); + }, + + mod() {}, +}; From b31b4817c19ce4e64ffba87e2ecbe535ac5e92e8 Mon Sep 17 00:00:00 2001 From: thekingofspace <37231416+thekingofspace@users.noreply.github.com> Date: Sun, 2 Jun 2024 21:24:41 -0700 Subject: [PATCH 06/23] Added json_read_MOD added json_write_MOD.js --- actions/json_read_MOD.js | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/actions/json_read_MOD.js b/actions/json_read_MOD.js index fb221b0b..ca01e309 100644 --- a/actions/json_read_MOD.js +++ b/actions/json_read_MOD.js @@ -5,15 +5,9 @@ module.exports = { name: 'Read JSON File', section: 'File Stuff', fields: ['filepath', 'title', 'contentTitle', 'storage', 'varName'], - meta: { - version: '2.1.7', - preciseCheck: false, - author: 'DBM Mods', - authorUrl: 'https://github.com/dbm-network/mods', - }, subtitle(data) { - return `Read JSON file ${data.filepath} content ${data.contentTitle}`; + return `Read JSON file "${data.filepath}"`; }, variableStorage(data, varType) { @@ -62,6 +56,11 @@ module.exports = { try { if (fs.existsSync(filepath)) { const fileData = fs.readFileSync(filepath); + if (fileData.length === 0) { + console.warn('JSON file is empty.'); + this.storeValue(undefined, storage, varName, cache); + return this.callNextAction(cache); + } jsonData = JSON.parse(fileData); } else { throw new Error('File does not exist'); @@ -74,17 +73,21 @@ module.exports = { let result; try { - const titleData = jsonData.find((item) => item.Title === title); + const titleData = jsonData.find(item => item.Title === title); if (!titleData) throw new Error('Title not found'); - // Split the contentTitle by '/' to handle nested content - const contentKeys = contentTitle.split('/'); - let nestedContent = titleData; - for (const key of contentKeys) { - nestedContent = nestedContent[key]; - if (nestedContent === undefined) throw new Error(`Content Key '${key}' not found`); + if (contentTitle.includes('/')) { + const contentKeys = contentTitle.split('/'); + result = {}; + for (const key of contentKeys) { + if (titleData[key] !== undefined) { + result[key] = titleData[key]; + } + } + } else { + if (titleData[contentTitle] === undefined) throw new Error('Content Title not found'); + result = titleData[contentTitle]; } - result = nestedContent; } catch (error) { console.error(`Error accessing data: ${error}`); this.storeValue(undefined, storage, varName, cache); @@ -95,5 +98,5 @@ module.exports = { this.callNextAction(cache); }, - mod() {}, + mod() {} }; From 00cf7e4f0627f597a6be84adc4f59f43c8273d16 Mon Sep 17 00:00:00 2001 From: thekingofspace <37231416+thekingofspace@users.noreply.github.com> Date: Sun, 2 Jun 2024 21:26:09 -0700 Subject: [PATCH 07/23] Added json_read_MOD added json_write_MOD.js --- actions/json_write_MOD.js | 178 ++++++++++---------------------------- 1 file changed, 48 insertions(+), 130 deletions(-) diff --git a/actions/json_write_MOD.js b/actions/json_write_MOD.js index 7b8611c2..ca01e309 100644 --- a/actions/json_write_MOD.js +++ b/actions/json_write_MOD.js @@ -2,18 +2,17 @@ const fs = require('fs'); const path = require('path'); module.exports = { - name: 'JSON File Control', + name: 'Read JSON File', section: 'File Stuff', - fields: ['filepath', 'action', 'title', 'contentTitle', 'contentText', 'newTitle', 'oldTitle', 'deleteContentTitle'], - meta: { - version: '2.1.7', - preciseCheck: false, - author: 'DBM Mods', - authorUrl: 'https://github.com/dbm-network/mods', - }, + fields: ['filepath', 'title', 'contentTitle', 'storage', 'varName'], subtitle(data) { - return `JSON edit on ${data.filepath} with ${data.action}`; + return `Read JSON file "${data.filepath}"`; + }, + + variableStorage(data, varType) { + if (parseInt(data.storage, 10) !== varType) return; + return [data.varName, 'Unknown']; }, html() { @@ -24,161 +23,80 @@ module.exports = {
- Action - -
-
Title - +
-
+ Action + +
+
Title - +
-
+ -
- + +
`; }, - init() {}, + init() { + const { glob, document } = this; + + glob.onChangeAction = function(event) { + const value = event.value; + document.getElementById('titleSection').style.display = value === 'addTitle' || value === 'addContent' || value === 'renameContent' ? 'block' : 'none'; + document.getElementById('contentSection').style.display = value === 'addContent' ? 'block' : 'none'; + document.getElementById('renameSection').style.display = value === 'renameContent' || value === 'renameTitle' ? 'block' : 'none'; + document.getElementById('deleteSection').style.display = value === 'deleteContent' ? 'block' : 'none'; + }; + + glob.onChangeAction(document.getElementById('action')); + }, async action(cache) { const data = cache.actions[cache.index]; let filepath = this.evalMessage(data.filepath, cache); - const title = this.evalMessage(data.title, cache); - const contentTitle = this.evalMessage(data.contentTitle, cache); - const storage = parseInt(data.storage, 10); - const varName = this.evalMessage(data.varName, cache); if (filepath.startsWith('./')) { filepath = path.join(__dirname, '..', filepath.substring(2)); } - let jsonData; + const action = data.action; + const title = this.evalMessage(data.title, cache); + const contentTitle = this.evalMessage(data.contentTitle, cache); + const contentText = this.evalMessage(data.contentText, cache); + const oldTitle = this.evalMessage(data.oldTitle, cache); + const newTitle = this.evalMessage(data.newTitle, cache); + const deleteContentTitle = this.evalMessage(data.deleteContentTitle, cache); + // Load JSON file + let jsonData; try { if (fs.existsSync(filepath)) { const fileData = fs.readFileSync(filepath); - if (fileData.length === 0) { - console.warn('JSON file is empty.'); - this.storeValue(undefined, storage, varName, cache); - return this.callNextAction(cache); - } jsonData = JSON.parse(fileData); } else { - throw new Error('File does not exist'); + jsonData = []; } } catch (error) { console.error(`Error reading JSON file: ${error}`); - this.storeValue(undefined, storage, varName, cache); - return this.callNextAction(cache); + jsonData = []; } - let result; - try { - const titleData = jsonData.find((item) => item.Title === title); - if (!titleData) throw new Error('Title not found'); - - if (contentTitle.includes('/')) { - const contentKeys = contentTitle.split('/'); - result = {}; - for (const key of contentKeys) { - if (titleData[key] !== undefined) { - result[key] = titleData[key]; - } + switch (action) { + case 'addTitle': + if (title) { + jsonData.push({ Title: title }); } - } else { - if (titleData[contentTitle] === undefined) throw new Error('Content Title not found'); - result = titleData[contentTitle]; - } + break; + case 'addContent': + let target = jsonData.find(item => item.Title === title); + if (!target) { + target = { Title: title }; + jsonData.push(target); + } + if (contentTitle.includes('/')) { + const keys = contentTitle.split('/'); + keys.reduce((obj, key, index) => { + if (index === keys.length - 1) { + obj[key] = isNaN(contentText) ? contentText : parseFloat(contentText); + } else { + obj[key] = obj[key] || {}; + } + return obj[key]; + }, target); + } else { + target[contentTitle] = isNaN(contentText) ? contentText : parseFloat(contentText); + } + break; + case 'renameContent': + jsonData.forEach(item => { + if (item.Title === title && item[contentTitle]) { + item[newTitle] = item[contentTitle]; + delete item[contentTitle]; + } + }); + break; + case 'renameTitle': + jsonData.forEach(item => { + if (item.Title === oldTitle) { + item.Title = newTitle; + } + }); + break; + case 'deleteContent': + jsonData.forEach(item => { + if (item.Title === title) { + if (deleteContentTitle.includes('/')) { + const keys = deleteContentTitle.split('/'); + keys.reduce((obj, key, index) => { + if (index === keys.length - 1) { + delete obj[key]; + } else { + return obj[key]; + } + }, item); + } else { + delete item[deleteContentTitle]; + } + } + }); + break; + case 'deleteTitle': + jsonData = jsonData.filter(item => item.Title !== title); + break; + } + + // Save JSON file + try { + fs.writeFileSync(filepath, JSON.stringify(jsonData, null, 2)); } catch (error) { - console.error(`Error accessing data: ${error}`); - this.storeValue(undefined, storage, varName, cache); - return this.callNextAction(cache); + console.error(`Error writing JSON file: ${error}`); } - this.storeValue(result, storage, varName, cache); this.callNextAction(cache); }, - mod() {}, + mod() {} }; From 6044bffee798ae01a3fe25cfb825ba4275b32ff4 Mon Sep 17 00:00:00 2001 From: thekingofspace <37231416+thekingofspace@users.noreply.github.com> Date: Mon, 3 Jun 2024 07:29:12 -0700 Subject: [PATCH 11/23] Fixed prettier issues Fixed linting issues inside json write Fixed issue with canvas paint not using cases --- actions/json_write_MOD.js | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/actions/json_write_MOD.js b/actions/json_write_MOD.js index 7e510811..682462b5 100644 --- a/actions/json_write_MOD.js +++ b/actions/json_write_MOD.js @@ -63,11 +63,13 @@ module.exports = { init() { const { glob, document } = this; - glob.onChangeAction = function(event) { + glob.onChangeAction = function onChangeAction(event) { const value = event.value; - document.getElementById('titleSection').style.display = value === 'addTitle' || value === 'addContent' || value === 'renameContent' ? 'block' : 'none'; + document.getElementById('titleSection').style.display = + value === 'addTitle' || value === 'addContent' || value === 'renameContent' ? 'block' : 'none'; document.getElementById('contentSection').style.display = value === 'addContent' ? 'block' : 'none'; - document.getElementById('renameSection').style.display = value === 'renameContent' || value === 'renameTitle' ? 'block' : 'none'; + document.getElementById('renameSection').style.display = + value === 'renameContent' || value === 'renameTitle' ? 'block' : 'none'; document.getElementById('deleteSection').style.display = value === 'deleteContent' ? 'block' : 'none'; }; @@ -104,6 +106,8 @@ module.exports = { jsonData = []; } + let target; + switch (action) { case 'addTitle': if (title) { @@ -111,14 +115,14 @@ module.exports = { } break; case 'addContent': - let target = jsonData.find(item => item.Title === title); + target = jsonData.find((item) => item.Title === title); if (!target) { target = { Title: title }; jsonData.push(target); } if (contentTitle.includes('/')) { const keys = contentTitle.split('/'); - keys.reduce((obj, key, index) => { + keys.reduce(function addNestedContent(obj, key, index) { if (index === keys.length - 1) { obj[key] = isNaN(contentText) ? contentText : parseFloat(contentText); } else { @@ -131,7 +135,7 @@ module.exports = { } break; case 'renameContent': - jsonData.forEach(item => { + jsonData.forEach((item) => { if (item.Title === title && item[contentTitle]) { item[newTitle] = item[contentTitle]; delete item[contentTitle]; @@ -139,23 +143,24 @@ module.exports = { }); break; case 'renameTitle': - jsonData.forEach(item => { + jsonData.forEach((item) => { if (item.Title === oldTitle) { item.Title = newTitle; } }); break; case 'deleteContent': - jsonData.forEach(item => { + jsonData.forEach((item) => { if (item.Title === title) { if (deleteContentTitle.includes('/')) { const keys = deleteContentTitle.split('/'); - keys.reduce((obj, key, index) => { + keys.reduce(function deleteNestedContent(obj, key, index) { if (index === keys.length - 1) { delete obj[key]; } else { return obj[key]; } + return obj; }, item); } else { delete item[deleteContentTitle]; @@ -164,7 +169,7 @@ module.exports = { }); break; case 'deleteTitle': - jsonData = jsonData.filter(item => item.Title !== title); + jsonData = jsonData.filter((item) => item.Title !== title); break; } @@ -178,5 +183,5 @@ module.exports = { this.callNextAction(cache); }, - mod() {} + mod() {}, }; From a744bcbcf3a9145ceea7003ad20e5af8eb7420fe Mon Sep 17 00:00:00 2001 From: thekingofspace <37231416+thekingofspace@users.noreply.github.com> Date: Tue, 4 Jun 2024 04:41:41 -0700 Subject: [PATCH 12/23] Added json random --- actions/json_random_MOD.js | 99 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 actions/json_random_MOD.js diff --git a/actions/json_random_MOD.js b/actions/json_random_MOD.js new file mode 100644 index 00000000..38587f8e --- /dev/null +++ b/actions/json_random_MOD.js @@ -0,0 +1,99 @@ +const fs = require('fs'); +const path = require('path'); + +module.exports = { + name: 'Pick Random JSON Item', + section: 'File Stuff', + fields: ['filepath', 'title', 'storage', 'varName'], + + subtitle(data) { + return `Pick random item from JSON file "${data.filepath}"`; + }, + + variableStorage(data, varType) { + if (parseInt(data.storage, 10) !== varType) return; + return [data.varName, 'Text']; + }, + + html() { + return ` +
+
+ File Path + +
+
+ Title + +
+
+ +
+
+ `; + }, + + init() {}, + + async action(cache) { + const data = cache.actions[cache.index]; + let filepath = this.evalMessage(data.filepath, cache); + const title = this.evalMessage(data.title, cache); + const storage = parseInt(data.storage, 10); + const varName = this.evalMessage(data.varName, cache); + + if (filepath.startsWith('./')) { + filepath = path.join(__dirname, '..', filepath.substring(2)); + } + + let jsonData; + + try { + if (fs.existsSync(filepath)) { + const fileData = fs.readFileSync(filepath); + if (fileData.length === 0) { + console.warn('JSON file is empty.'); + this.storeValue(undefined, storage, varName, cache); + return this.callNextAction(cache); + } + jsonData = JSON.parse(fileData); + } else { + throw new Error('File does not exist'); + } + } catch (error) { + console.error(`Error reading JSON file: ${error}`); + this.storeValue(undefined, storage, varName, cache); + return this.callNextAction(cache); + } + + let result; + + try { + if (title) { + const titleData = jsonData.find((item) => item.Title === title); + if (!titleData) throw new Error('Title not found'); + + const keys = Object.keys(titleData).filter((key) => key !== 'Title'); + if (keys.length === 0) throw new Error('No items found under specified title'); + + const randomKey = keys[Math.floor(Math.random() * keys.length)]; + result = randomKey; + } else { + const items = jsonData.flatMap((item) => Object.keys(item).filter((key) => key !== 'Title')); + if (items.length === 0) throw new Error('No items found in JSON'); + + const randomItem = items[Math.floor(Math.random() * items.length)]; + result = randomItem; + } + } catch (error) { + console.error(`Error accessing data: ${error}`); + this.storeValue(undefined, storage, varName, cache); + return this.callNextAction(cache); + } + + this.storeValue(result, storage, varName, cache); + this.callNextAction(cache); + }, + + mod() {}, +}; From a3e1010a0a6c66fe5879808a899bc235bb30e993 Mon Sep 17 00:00:00 2001 From: thekingofspace <37231416+thekingofspace@users.noreply.github.com> Date: Thu, 6 Jun 2024 05:08:46 -0700 Subject: [PATCH 13/23] **Changelog** * Fixed json_random_MOD.js meta data * Fixed json_read_MOD.js meta data * Added json_check_MOD.json --- actions/json_check_MOD.js | 127 +++++++++++++++++++++++++++++++++++++ actions/json_random_MOD.js | 6 ++ actions/json_read_MOD.js | 6 ++ 3 files changed, 139 insertions(+) create mode 100644 actions/json_check_MOD.js diff --git a/actions/json_check_MOD.js b/actions/json_check_MOD.js new file mode 100644 index 00000000..12f30159 --- /dev/null +++ b/actions/json_check_MOD.js @@ -0,0 +1,127 @@ +const fs = require('fs'); +const path = require('path'); + +module.exports = { + name: 'Check JSON File', + + section: 'File Stuff', + + subtitle(data) { + return `Check JSON file "${data.filepath}"`; + }, + + meta: { + version: '2.1.7', + preciseCheck: false, + author: 'DBM Mods', + authorUrl: 'https://github.com/dbm-network/mods', + }, + + fields: ['filepath', 'checkType', 'title', 'contentTitle', 'branch'], + + html() { + // Removed 'isEvent' and 'data' + return ` +
+ File Path + +
+
+ Check Type
+ +
+ + + `; + }, + + init() { + const { glob, document } = this; + + glob.onCheckTypeChanged = function handleCheckTypeChange(event) { + // Named function + const titleSection = document.getElementById('titleSection'); + const contentTitleSection = document.getElementById('contentTitleSection'); + switch (event.value) { + case '0': + titleSection.style.display = 'none'; + contentTitleSection.style.display = 'none'; + break; + case '1': + titleSection.style.display = null; + contentTitleSection.style.display = 'none'; + break; + case '2': + titleSection.style.display = null; + contentTitleSection.style.display = null; + break; + } + }; + + glob.onCheckTypeChanged(document.getElementById('checkType')); + }, + + async action(cache) { + const data = cache.actions[cache.index]; + let filepath = this.evalMessage(data.filepath, cache); + const checkType = parseInt(data.checkType, 10); + const title = this.evalMessage(data.title, cache); + const contentTitle = this.evalMessage(data.contentTitle, cache); + + if (filepath.startsWith('./')) { + filepath = path.join(__dirname, '..', filepath.substring(2)); + } + + let jsonData; + + try { + if (fs.existsSync(filepath)) { + const fileData = fs.readFileSync(filepath); + if (fileData.length === 0) throw new Error('JSON file is empty.'); + jsonData = JSON.parse(fileData); + } else { + throw new Error('File does not exist'); + } + } catch (error) { + console.error(`Error reading JSON file: ${error}`); + this.executeResults(false, data.branch, cache); + return; + } + + let result = false; + + try { + switch (checkType) { + case 0: + result = true; + break; + case 1: { + result = jsonData.some((item) => item.Title === title); + break; + } + case 2: { + const titleData = jsonData.find((item) => item.Title === title); + if (!titleData) throw new Error('Title not found'); + result = contentTitle in titleData; + break; + } + } + } catch (error) { + console.error(`Error checking JSON data: ${error}`); + } + + this.executeResults(result, data.branch, cache); + }, + + mod() {}, +}; diff --git a/actions/json_random_MOD.js b/actions/json_random_MOD.js index 38587f8e..df6f63cd 100644 --- a/actions/json_random_MOD.js +++ b/actions/json_random_MOD.js @@ -5,6 +5,12 @@ module.exports = { name: 'Pick Random JSON Item', section: 'File Stuff', fields: ['filepath', 'title', 'storage', 'varName'], + meta: { + version: '2.1.7', + preciseCheck: false, + author: 'DBM Mods', + authorUrl: 'https://github.com/dbm-network/mods', + }, subtitle(data) { return `Pick random item from JSON file "${data.filepath}"`; diff --git a/actions/json_read_MOD.js b/actions/json_read_MOD.js index dd85f0f0..c0c21207 100644 --- a/actions/json_read_MOD.js +++ b/actions/json_read_MOD.js @@ -5,6 +5,12 @@ module.exports = { name: 'Read JSON File', section: 'File Stuff', fields: ['filepath', 'title', 'contentTitle', 'storage', 'varName'], + meta: { + version: '2.1.7', + preciseCheck: false, + author: 'DBM Mods', + authorUrl: 'https://github.com/dbm-network/mods', + }, subtitle(data) { return `Read JSON file "${data.filepath}"`; From f4c7c7c415b8b725abe719450c9c087ed74ab377 Mon Sep 17 00:00:00 2001 From: thekingofspace <37231416+thekingofspace@users.noreply.github.com> Date: Thu, 6 Jun 2024 06:38:22 -0700 Subject: [PATCH 14/23] **Changelog** * Fixed json_random_MOD.js meta data * Fixed json_read_MOD.js meta data * Added json_check_MOD.json --- actions/json_check_MOD.js | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/actions/json_check_MOD.js b/actions/json_check_MOD.js index 12f30159..634b5690 100644 --- a/actions/json_check_MOD.js +++ b/actions/json_check_MOD.js @@ -12,15 +12,15 @@ module.exports = { meta: { version: '2.1.7', - preciseCheck: false, - author: 'DBM Mods', - authorUrl: 'https://github.com/dbm-network/mods', + preciseCheck: true, + author: 'ChatGPT', + authorUrl: null, + downloadUrl: null }, fields: ['filepath', 'checkType', 'title', 'contentTitle', 'branch'], - html() { - // Removed 'isEvent' and 'data' + html(isEvent, data) { return `
File Path @@ -34,11 +34,11 @@ module.exports = {
-