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 button to import JSON from clipboard #188

Merged
Merged
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
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
Loading