Skip to content

Commit

Permalink
Merge pull request #188 from ZachTheLitchKing/ImportJSONFromClipboard
Browse files Browse the repository at this point in the history
Added button to import JSON from clipboard
  • Loading branch information
sanderfrenken authored Sep 16, 2024
2 parents 9470c89 + eba66c0 commit 8323838
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ <h1>Universal LPC Spritesheet Generator</h1>
<div>
<label class="control-label">Import/Export:</label>
<button type="button" class="exportToClipboard">Export to Clipboard (JSON)</button>
<button type="button" class="importFromClipboard">Import from Clipboard (JSON)</button>
</div>
<div>
<label class="control-label">Edit:</label>
Expand Down
1 change: 1 addition & 0 deletions source_index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ <h1>Universal LPC Spritesheet Generator</h1>
<div>
<label class="control-label">Import/Export:</label>
<button type="button" class="exportToClipboard">Export to Clipboard (JSON)</button>
<button type="button" class="importFromClipboard">Import from Clipboard (JSON)</button>
</div>
<div>
<label class="control-label">Edit:</label>
Expand Down
28 changes: 28 additions & 0 deletions sources/chargen.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,17 @@ $(document).ready(function() {
document.removeChild(a);
});

$(".importFromClipboard").click(async function() {
var clipboardText = await navigator.clipboard.readText();
var spritesheet = JSON.parse(clipboardText)["layers"];
window.setTimeout(function() {
$("#resetAll").click(); //Reset first so defaults are set properly
},1,false);
window.setTimeout(function() {
setParamsFromImport(spritesheet); //wait for reset function(s) to complete then apply spritesheet
},2,false);
});

$(".exportToClipboard").click(function() {
var spritesheet = {};
Object.assign(spritesheet, itemsMeta);
Expand Down Expand Up @@ -624,6 +635,23 @@ $(document).ready(function() {
jHash.val(params);
}

function setParamsFromImport(spritesheet){
spritesheet.forEach((sprite)=>{
var custom_animation = sprite.custom_animation;
var fileName = sprite.fileName;
var name = sprite.name;
var parentName = sprite.parentName;
var variant = sprite.variant;
var zPos = sprite.zPos;
const assetType = name.replaceAll(" ", "_");
const assetVariant = variant.replaceAll(" ", "_")
const assetToSelect = parentName + "-" + assetType + "_" + assetVariant;
$(`#${assetToSelect}`).prop("checked", true);

});
setParams();
}

function getImage(imgRef) {
if (images[imgRef])
return images[imgRef];
Expand Down

0 comments on commit 8323838

Please sign in to comment.