|
| 1 | +const { Scene } = require('../index.js'); |
| 2 | +const yaml = require('js-yaml'); |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | +Scene.newF("translate", function(data, meta) { |
| 7 | + Object.assign(this, yaml.load(meta)); // load and add the scene's metadata |
| 8 | + |
| 9 | + |
| 10 | + // most of this is string formatting sorry it's so messy |
| 11 | + let stuff = data.split("--- !u"); |
| 12 | + stuff.shift(); |
| 13 | + |
| 14 | + let ids = []; |
| 15 | + |
| 16 | + stuff = stuff.map( s => { |
| 17 | + s = s.split(/(\r\n|\n|\r)/gm); |
| 18 | + let id = s.shift(); |
| 19 | + let eid = parseInt(id.split(" ")[0].replace("!", "")); |
| 20 | + let fileID = parseInt(id.split(" ")[1].replace("&", "")); |
| 21 | + ids.push({ id: id, eid: eid, fileID: fileID}); |
| 22 | + s = s.filter( thing => !(thing == "\r\n") ); |
| 23 | + return s; |
| 24 | + }); |
| 25 | + // k messy is mostly over |
| 26 | + |
| 27 | + |
| 28 | + // adds the settings as their raw thing ex: Scene.occlusionCullingSettings |
| 29 | + this.occlusionCullingSettings = this.__createChild('OcclusionCullingSettings', stuff); |
| 30 | + this.renderSettings = this.__createChild('RenderSettings', stuff); |
| 31 | + this.lightmapSettings = this.__createChild('LightmapSettings', stuff); |
| 32 | + this.navMeshSettings = this.__createChild('NavMeshSettings', stuff); |
| 33 | + |
| 34 | + |
| 35 | + // adds the settings to Scene.settings |
| 36 | + this.settings.push("occlusionCulling", this.occlusionCullingSettings); |
| 37 | + this.settings.push("rendering", this.renderSettings); |
| 38 | + this.settings.push("lightmap", this.lightmapSettings); |
| 39 | + this.settings.push("navMesh", this.navMeshSettings); |
| 40 | + |
| 41 | + |
| 42 | + // removes the data and ids of the settings stuff |
| 43 | + stuff.shift(); stuff.shift(); stuff.shift(); stuff.shift(); |
| 44 | + ids.shift(); ids.shift(); ids.shift(); ids.shift(); |
| 45 | + |
| 46 | + |
| 47 | + // nvm more messy |
| 48 | + stuff.forEach( (s, i) => { |
| 49 | + let name = s[0].replace(":", ""); // removes the : from the name of the property |
| 50 | + let { fileID } = ids[i]; // gets the file id |
| 51 | + try { |
| 52 | + let obj = this.__createChild(name, stuff); // creates a new child obj |
| 53 | + |
| 54 | + // this part is mostly just for like making sure that objects get put in Scene.objects and UnityscriptWorkspace.objects |
| 55 | + if (obj instanceof this.parent.GameObject) { this.objects.push(fileID, obj); this.parent.objects.push(fileID, obj); } |
| 56 | + if (obj instanceof this.parent.Light) { this.lights.push(fileID, obj); } |
| 57 | + |
| 58 | + // finally adds it to the children |
| 59 | + this.children.push(fileID, obj); |
| 60 | + } catch(e) {} |
| 61 | + |
| 62 | + }) |
| 63 | +}) |
0 commit comments