mursion-json-cfg-parser

by Nic Fontaine

HTML

<textarea id="entry" placeholder="Paste JSON" spellcheck="false"></textarea><br><br>
<button id="btn-run">PARSE</button>
<pre id="out"></pre>

CSS

html {
  font-family: sans-serif;
  font-size: 15px;
  line-height: 1.4;
  letter-spacing: 0.1px;
}

body {
  background: #222;
  color: #ddd;
  margin: 0;
  padding: 1rem;
  max-width: 650px;
  margin-right: auto;
  margin-left: auto;
}

h2 {
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 0.5rem;
}

b {
  color: #666;
  font-size: 0.95rem;
}

textarea {
  height: 250px;
  width: 100%;
  background: #111;
  border: none;
  color: #ccc;
  padding: 0.5em;
  box-sizing: border-box;
}

button {
  width: 100%;
  padding: 0.5rem;
  margin-bottom: 0.5rem;
  background: #555;
  color: #ccc;
  border: none;
}

hr {
  border: none;
  border-bottom: 1px solid #555;
}

JavaScript

const dom = {
	out: document.getElementById("out"),
	btnRun: document.getElementById("btn-run"),
	entry: document.getElementById("entry")
}

dom.btnRun.addEventListener("click", e => {
	let cfg = JSON.parse(dom.entry.value)
  print(parse(cfg))
})

var assetsTemplate = function() {
	this.sim = {
  	environments: [],
    perspectives: [],
  	characters: [],
  	outfits: [],
  	objects: [],
  	controllers: [],
    sims: []
  }
  this.host = {
  	environments: [],
  	characters: [],
  	outfits: [],
  	objects: [],
  	controllers: [],
    sims: []
  }
}

function parse(cfg) {

	// Start assets store fresh
  var assets = new assetsTemplate()

	// Regular Sims
	if ("_regularSimulations" in cfg) {
  
    // Loop sims
    var sims = cfg["_regularSimulations"], simsLen = sims.length, i=0
    
    for (i; i<simsLen; i++) {
      let sim = sims[i]
      
      // Sim name
      assets.sim.sims.push(sim._friendlyName)
      
      // Environment
      if ("_scene" in sim) {
      	if ("_productionName" in sim["_scene"]) {
      		assets.sim.environments.push(sim["_scene"]["_productionName"])
        }
      }
      
      // Perspectives
      if ("_cameraPOI" in sim) {
      	assets.sim.perspectives.push(sim._cameraPOI)
      }
      
      // Controllers
      if ("_animatorProductionName" in sim) {
      	assets.sim.controllers.push(sim["_animatorProductionName"])
      }

      // Loop characters
      if ("_characters" in sim) {
        let characters = sim["_characters"], charsLen = characters.length, j=0
        for (j; j<charsLen; j++) {
          let char = characters[j]
          // Characters
          if ("_body" in char) {
          	if ("_productionName" in char["_body"]) {
          		assets.sim.characters.push(char["_body"]["_productionName"] + " (" + char["_friendlyName"] + ")")
            }
          }
          // Character outfit
          if ("_clothes" in char) {
          	if ("_productionName" in char["_clothes"]) {
         ...