-
Notifications
You must be signed in to change notification settings - Fork 202
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
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
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() {}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
module.exports = { | ||
name: 'Check if JSON Content Title Exists', | ||
section: 'Json Data', | ||
meta: { | ||
version: '2.1.7', | ||
author: 'DBM Mods', | ||
}, | ||
|
||
subtitle(data) { | ||
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 GitHub Actions / ESLint
|
||
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() {}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 GitHub Actions / ESLint
|
||
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() {}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
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); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.