UNPKG

sat-sol-sim

Version:

sat-sol-sim: A stunning, interactive 3D satellite and solar system simulator featuring realistic planetary motion, satellite constellations, and comprehensive programmatic control through a powerful JavaScript API

2 lines 8.4 kB
/**sat-sol-sim v1.0.0 - Minified*/ window.SolarSystemAPI={simulation:{start:function(){return"undefined"!=typeof paused&&(paused=!1,updateUI()),this},pause:function(){return"undefined"!=typeof paused&&(paused=!0,updateUI()),this},reset:function(){return"function"==typeof resetSimulation&&resetSimulation(),this},setSpeed:function(e){if(e>=.1&&e<=3&&"undefined"!=typeof simulationSpeed){simulationSpeed=e;const t=document.getElementById("simulation-speed");t&&(t.value=e,"function"==typeof updateSimulationSpeed&&updateSimulationSpeed())}return this},getSpeed:function(){return"undefined"!=typeof simulationSpeed?simulationSpeed:1},isPaused:function(){return"undefined"!=typeof paused&&paused},getState:function(){return{paused:"undefined"!=typeof paused&&paused,speed:"undefined"!=typeof simulationSpeed?simulationSpeed:1,earthOrbitAngle:"undefined"!=typeof earthOrbitAngle?earthOrbitAngle:0,moonOrbitAngle:"undefined"!=typeof moonOrbitAngle?moonOrbitAngle:0,showOrbits:"undefined"==typeof showOrbits||showOrbits,showTrails:"undefined"!=typeof showTrails&&showTrails,negativeLighting:"undefined"!=typeof negativeLighting&&negativeLighting}}},camera:{setPreset:function(e){return"function"==typeof setCameraPreset&&setCameraPreset(e),this},getCurrentPreset:function(){return"undefined"!=typeof currentCameraPreset?currentCameraPreset:0},getPresets:function(){return"undefined"!=typeof cameraPresets?cameraPresets.map(((e,t)=>({index:t,name:e.name,description:e.description}))):[]},enableFreeMode:function(){return"function"==typeof toggleFreeMode&&"undefined"!=typeof freeMode&&!freeMode&&toggleFreeMode(),this},disableFreeMode:function(){return"function"==typeof toggleFreeMode&&"undefined"!=typeof freeMode&&freeMode&&toggleFreeMode(),this},enableFollowEarth:function(){return"function"==typeof toggleFollowEarth&&"undefined"!=typeof followEarth&&!followEarth&&toggleFollowEarth(),this},disableFollowEarth:function(){return"function"==typeof toggleFollowEarth&&"undefined"!=typeof followEarth&&followEarth&&toggleFollowEarth(),this},setPosition:function(e,t,n){return"undefined"!=typeof camera&&camera.position&&camera.position.set(e,t,n),this},getPosition:function(){return"undefined"!=typeof camera&&camera.position?{x:camera.position.x,y:camera.position.y,z:camera.position.z}:{x:0,y:0,z:0}},lookAt:function(e,t,n){return"undefined"!=typeof camera&&camera.lookAt&&camera.lookAt(e,t,n),this}},satellites:{getAll:function(){return"undefined"!=typeof satellites?satellites.map((e=>({id:e.userData.id,type:e.userData.type,status:e.userData.status,health:e.userData.health,position:e.position,class:e.userData.class}))):[]},getByType:function(e){return this.getAll().filter((t=>t.type===e))},getOperational:function(){return this.getAll().filter((e=>"operational"===e.status))},getFailed:function(){return this.getAll().filter((e=>"failed"===e.status))},failRandom:function(){return"function"==typeof randomFailure&&randomFailure(),this},highlight:function(e){return"function"==typeof highlightSatelliteClass&&highlightSatelliteClass(e),this},unhighlight:function(){return"function"==typeof unhighlightAllSatellites&&unhighlightAllSatellites(),this},setConfiguration:function(e){return Object.keys(e).forEach((t=>{const n={LEO_COMM:"leo-comm",LEO_WEATHER:"weather",MEO_NAV:"nav",GEO_COMM:"geo-comm",MILITARY:"military"}[t];if(n){const o=document.getElementById(n);o&&(o.value=e[t])}})),"function"==typeof applySatelliteConfig&&applySatelliteConfig(),this},getConfiguration:function(){return{LEO_COMM:parseInt(document.getElementById("leo-comm")?.value||0),LEO_WEATHER:parseInt(document.getElementById("weather")?.value||0),MEO_NAV:parseInt(document.getElementById("nav")?.value||0),GEO_COMM:parseInt(document.getElementById("geo-comm")?.value||0),MILITARY:parseInt(document.getElementById("military")?.value||0)}}},visuals:{showOrbits:function(){return"function"==typeof toggleOrbits&&"undefined"!=typeof showOrbits&&!showOrbits&&toggleOrbits(),this},hideOrbits:function(){return"function"==typeof toggleOrbits&&"undefined"!=typeof showOrbits&&showOrbits&&toggleOrbits(),this},showTrails:function(){return"function"==typeof toggleTrails&&"undefined"!=typeof showTrails&&!showTrails&&toggleTrails(),this},hideTrails:function(){return"function"==typeof toggleTrails&&"undefined"!=typeof showTrails&&showTrails&&toggleTrails(),this},enableNegativeMode:function(){return"function"==typeof toggleNegativeLighting&&"undefined"!=typeof negativeLighting&&!negativeLighting&&toggleNegativeLighting(),this},disableNegativeMode:function(){return"function"==typeof toggleNegativeLighting&&"undefined"!=typeof negativeLighting&&negativeLighting&&toggleNegativeLighting(),this},showUI:function(){return"function"==typeof toggleUI&&"undefined"!=typeof uiVisible&&!uiVisible&&toggleUI(),this},hideUI:function(){return"function"==typeof toggleUI&&"undefined"!=typeof uiVisible&&uiVisible&&toggleUI(),this},getVisualState:function(){return{orbits:"undefined"==typeof showOrbits||showOrbits,trails:"undefined"!=typeof showTrails&&showTrails,negative:"undefined"!=typeof negativeLighting&&negativeLighting,ui:"undefined"==typeof uiVisible||uiVisible}}},events:{callbacks:{},on:function(e,t){return this.callbacks[e]||(this.callbacks[e]=[]),this.callbacks[e].push(t),this},off:function(e,t){if(this.callbacks[e]){const n=this.callbacks[e].indexOf(t);n>-1&&this.callbacks[e].splice(n,1)}return this},emit:function(e,t){return this.callbacks[e]&&this.callbacks[e].forEach((e=>{try{e(t)}catch(e){console.error("Event callback error:",e)}})),this}},utils:{getVersion:function(){return"1.0.0"},exportConfiguration:function(){return{simulation:SolarSystemAPI.simulation.getState(),satellites:SolarSystemAPI.satellites.getConfiguration(),visuals:SolarSystemAPI.visuals.getVisualState(),camera:{preset:"undefined"!=typeof currentCameraPreset?currentCameraPreset:0,freeMode:"undefined"!=typeof freeMode&&freeMode,followEarth:"undefined"!=typeof followEarth&&followEarth,position:SolarSystemAPI.camera.getPosition()}}},importConfiguration:function(e){return e.simulation&&e.simulation.speed&&SolarSystemAPI.simulation.setSpeed(e.simulation.speed),e.satellites&&SolarSystemAPI.satellites.setConfiguration(e.satellites),e.visuals&&(SolarSystemAPI.visuals.getVisualState(),e.visuals.orbits!==visuals.orbits&&SolarSystemAPI.visuals[e.visuals.orbits?"showOrbits":"hideOrbits"](),e.visuals.trails!==visuals.trails&&SolarSystemAPI.visuals[e.visuals.trails?"showTrails":"hideTrails"](),e.visuals.negative!==visuals.negative&&SolarSystemAPI.visuals[e.visuals.negative?"enableNegativeMode":"disableNegativeMode"]()),e.camera&&void 0!==e.camera.preset&&SolarSystemAPI.camera.setPreset(e.camera.preset),this},takeScreenshot:function(){return"undefined"!=typeof renderer&&renderer.domElement?renderer.domElement.toDataURL("image/png"):null},getSystemInfo:function(){const e={version:this.getVersion(),timestamp:Date.now()};"undefined"!=typeof renderer&&(e.renderer=renderer.info),"undefined"!=typeof scene&&(e.scene={children:scene.children.length}),"undefined"!=typeof satellites&&(e.scene.satellites=satellites.length),"undefined"!=typeof planets&&(e.scene.planets=Object.keys(planets).length);return e.camera={position:SolarSystemAPI.camera.getPosition(),preset:"undefined"!=typeof currentCameraPreset?currentCameraPreset:0},e}},_initialize:function(){setTimeout((()=>{this.events.emit("initialized",{timestamp:Date.now(),version:this.utils.getVersion()})}),100),console.log(`\n🌟 Solar System API v${this.utils.getVersion()} Ready! 🌟\n\nExample usage:\nSolarSystemAPI.simulation.setSpeed(2.0);\nSolarSystemAPI.camera.setPreset(3);\nSolarSystemAPI.visuals.hideUI();\nSolarSystemAPI.satellites.highlight('LEO_COMM');\n\nAPI Modules:\n- simulation: Control playback, speed, state\n- camera: Camera presets, positioning, modes \n- satellites: Manage satellite constellations\n- visuals: Toggle orbits, trails, UI, negative mode\n- events: Subscribe to simulation events\n- utils: Export/import, screenshots, system info\n\nTry: SolarSystemAPI.utils.getSystemInfo()\n `)}};"undefined"!=typeof window&&window.addEventListener("load",(function(){setTimeout((()=>{window.SolarSystemAPI&&window.SolarSystemAPI._initialize&&window.SolarSystemAPI._initialize()}),200)}));function updateUI(){const e=document.querySelector('button[onclick="togglePause()"]');e&&"undefined"!=typeof paused&&(e.textContent=paused?"▶️ RESUME":"⏸️ PAUSE")}