Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a few items for user #1027

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions actions/CanvasCreatePrimitive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
module.exports = {
name: 'Canvas Create Shape',
section: 'Image Editing',
meta: {
version: '2.1.7',
author: 'DBM mods',
},

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 `
<div>
<div>
<span class="dbminputlabel">Shape Type</span>
<select id="shapeType" class="round">
<option value="0" selected>Circle</option>
<option value="1">Rectangle</option>
<!-- Add more options for different shapes -->
</select>
</div>
</div>
<br><br>

<div>
<div>
<span class="dbminputlabel">Width (px)</span>
<input id="width" class="round" type="text"><br>
</div>
<div>
<span class="dbminputlabel">Height (px)</span>
<input id="height" class="round" type="text"><br>
</div>
</div>
<br><br>

<div>
<div>
<span class="dbminputlabel">Color</span>
<input id="color" class="round" type="text" placeholder="Insert Color Hex code here"><br>
</div>
</div>
<br><br>

<store-in-variable dropdownLabel="Store In" selectId="storage" variableContainerId="varNameContainer" variableInputId="varName"></store-in-variable>
`;
},

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);

Check failure on line 73 in actions/CanvasCreatePrimitive.js

View workflow job for this annotation

GitHub Actions / ESLint

'color' is never reassigned. Use 'const' instead

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() {},
};
89 changes: 89 additions & 0 deletions actions/check_content_title_MOD.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
module.exports = {

Check failure on line 1 in actions/check_content_title_MOD.js

View workflow job for this annotation

GitHub Actions / ESLint

Delete `␍`
name: 'Check if JSON Content Title Exists',

Check failure on line 2 in actions/check_content_title_MOD.js

View workflow job for this annotation

GitHub Actions / ESLint

Delete `␍`
section: 'Json Data',

Check failure on line 3 in actions/check_content_title_MOD.js

View workflow job for this annotation

GitHub Actions / ESLint

Delete `␍`
meta: {

Check failure on line 4 in actions/check_content_title_MOD.js

View workflow job for this annotation

GitHub Actions / ESLint

Delete `␍`
version: '2.1.7',

Check failure on line 5 in actions/check_content_title_MOD.js

View workflow job for this annotation

GitHub Actions / ESLint

Delete `␍`
author: 'DBM Mods',

Check failure on line 6 in actions/check_content_title_MOD.js

View workflow job for this annotation

GitHub Actions / ESLint

Delete `␍`
},

Check failure on line 7 in actions/check_content_title_MOD.js

View workflow job for this annotation

GitHub Actions / ESLint

Delete `␍`

Check failure on line 8 in actions/check_content_title_MOD.js

View workflow job for this annotation

GitHub Actions / ESLint

Delete `␍`
subtitle(data) {

Check failure on line 9 in actions/check_content_title_MOD.js

View workflow job for this annotation

GitHub Actions / ESLint

Delete `␍`
return `Check if Content Title "${data.contentTitle}" exists in Title "${data.title}" of JSON File "${data.filePath}"`;
},

fields: ['filePath', 'title', 'contentTitle', 'branch'],

html(isEvent, data) {

Check warning on line 15 in actions/check_content_title_MOD.js

View workflow job for this annotation

GitHub Actions / ESLint

'isEvent' is defined but never used

Check warning on line 15 in actions/check_content_title_MOD.js

View workflow job for this annotation

GitHub Actions / ESLint

'data' is defined but never used
return `
<div>
<span class="dbminputlabel">JSON File Path</span>
<input id="filePath" class="round" type="text">
</div>

<br>

<div>
<span class="dbminputlabel">Title to Check</span>
<input id="title" class="round" type="text">
</div>

<br>

<div>
<span class="dbminputlabel">Content Title to Check</span>
<input id="contentTitle" class="round" type="text">
</div>

<br><br>

<hr class="subtlebar" style="margin-top: 8px; margin-bottom: 8px;">

<br>

<conditional-input id="branch" style="padding-top: 8px;"></conditional-input>`;
},

init() {},

action(cache) {
const data = cache.actions[cache.index];
const filePath = this.evalMessage(data.filePath, cache);
const titleToCheck = this.evalMessage(data.title, cache);
const contentTitleToCheck = this.evalMessage(data.contentTitle, cache);

let jsonData;
try {
jsonData = require(filePath);
} catch (error) {
console.error(`Error reading JSON file: ${error.message}`);
}

let result = false;

if (jsonData && jsonData[titleToCheck] && this.checkNestedContent(jsonData[titleToCheck], contentTitleToCheck)) {
result = true;
}

this.executeResults(result, data.branch ?? data, cache);
},

checkNestedContent(obj, contentTitle) {
const titles = contentTitle.split('/');
let currentObj = obj;

for (const title of titles) {
if (!currentObj.hasOwnProperty(title)) {
return false;
}
currentObj = currentObj[title];
}

return true;
},

modInit(data) {
this.prepareActions(data.branch?.iftrueActions);
this.prepareActions(data.branch?.iffalseActions);
},

mod() {},
};
61 changes: 61 additions & 0 deletions actions/check_title_MOD.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
module.exports = {
name: 'Check if JSON Title Exists',
section: 'Json Data',
meta: {
version: '2.1.7',
author: 'DBM Mods',
},

subtitle(data) {
return `Check if JSON Title "${data.title}" exists in File Path "${data.filePath}"`;
},

fields: ['filePath', 'title', 'branch'],

html(isEvent, data) {

Check warning on line 15 in actions/check_title_MOD.js

View workflow job for this annotation

GitHub Actions / ESLint

'isEvent' is defined but never used

Check warning on line 15 in actions/check_title_MOD.js

View workflow job for this annotation

GitHub Actions / ESLint

'data' is defined but never used
return `
<div>
<span class="dbminputlabel">File Path</span>
<input id="filePath" class="round" type="text">
</div>

<br><br><br>

<div>
<span class="dbminputlabel">Title to Check</span>
<input id="title" class="round" type="text">
</div>

<br><br><br>

<hr class="subtlebar">

<br>

<conditional-input id="branch" style="padding-top: 8px;"></conditional-input>`;
},

init() {},

action(cache) {
const data = cache.actions[cache.index];
const filePath = this.evalMessage(data.filePath, cache);
const titleToCheck = this.evalMessage(data.title, cache);
let result = false;

try {
const fileContent = fs.readFileSync(filePath, 'utf8');
const jsonData = JSON.parse(fileContent);

if (jsonData && jsonData instanceof Object) {
result = jsonData.hasOwnProperty(titleToCheck);
}
} catch (error) {
console.error(`Error reading or parsing JSON file: ${error}`);
}

this.executeResults(result, data.branch ?? data, cache);
},

mod() {},
};
51 changes: 51 additions & 0 deletions actions/if_color_exists_MOD.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
module.exports = {
name: 'Check if Hex Color Code Exists',
section: 'Color Stuff',
meta: {
version: '2.1.7',
author: 'DBM Mods',
},

subtitle(data, presets) {
return `Check if Hex Color Code is Valid: ${presets.getConditionsText(data)}`;
},

fields: ['colorCode', 'branch'],

html() {
return `
<div style="float: left; width: 60%">
<span class="dbminputlabel">Hex Color Code</span>
<input id="colorCode" class="round" type="text" placeholder="Enter hex color code">
</div>
<br><br><br>

<conditional-input id="branch" style="padding-top: 8px;"></conditional-input>`;
},

init() {},

async action(cache) {
const data = cache.actions[cache.index];
const colorCode = this.evalMessage(data.colorCode, cache);
let result;

if (isValidHexColorCode(colorCode)) result = true;
else result = false;
Comment on lines +33 to +34
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a separate function to check if its valid isn't necessary if its only used once. You can still separate the regex variable for readability but I would recommend the following snippet of code.

const result = /^#(?:[0-9a-fA-F]{3}){1,2}$/.test(colorCode);


this.executeResults(result, data?.branch ?? data, cache);
},

modInit(data) {
this.prepareActions(data.branch?.iftrueActions);
this.prepareActions(data.branch?.iffalseActions);
},

mod() {},
};

function isValidHexColorCode(hexColorCode) {
// Regular expression to check if the provided input is a valid hex color code
const hexColorRegex = /^#(?:[0-9a-fA-F]{3}){1,2}$/;
return hexColorRegex.test(hexColorCode);
}
Loading
Loading