JSFiddle - React, Tailwind, and code Playground
by Bharat Battu
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Audiosprite-->SoundJS JSON Parsing</title>
</head>
<body>
<p>Select a JSON output file from <a href="https://github.com/tonistiigi/audiosprite" target="on_blank">audiosprite</a> to refactor for use with SoundJS 0.5.2 NEXT<br><br>(resulting SoundJS audioSprite code will appear in this page body, yours to copy and paste)</p>
<input type="file" id="fileinput" />
<script>
document.getElementById('fileinput').addEventListener('change', readSingleFile, false);
var json;
function readSingleFile(evt) {
//Retrieve the first (and only!) File from the FileList object
var f = evt.target.files[0];
if (f) {
var r = new FileReader();
r.onload = function(e) {
var contents = e.target.result;
/*
alert( "Got the file.n"
+"name: " + f.name + "n"
+"type: " + f.type + "n"
+"size: " + f.size + " bytesn"
+ "starts with: " + contents.substr(1, contents.indexOf("n"))
);
*/
//document.write(contents);
//json = e.target.result;
json = JSON.parse(e.target.result)
//console.log(json)
remakeJSON(json);
}
r.readAsText(f);
} else {
alert("Failed to load file");
}
}
</script>
</body>
<script>
function writeIt(line){
console.log(line);
//line = line.replace(/\s/g, '');
document.write(line);
document.write("<br>");
}
function remakeJSON(){
console.log('remakeJSON');
//***** OUTPUT CODE HERE
console.log(json.resources)
console.log(json.spritemap)
var n; //name
var s;// start
var e; //end
var d; //duration (end - start)
for (var key in json.spritemap) {
if (json.spritemap.hasOwnProperty(key)) {
//console.log(key + " .. start: " + json.spritemap[key].start)
n = key;
s =...