outside-of-context tsc compilation
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
This commit is contained in:
parent
3988f256af
commit
39717cdfb2
@ -4,7 +4,10 @@ import { Scene } from "/Scripts/types/scene";
|
|||||||
* The main scene interface
|
* The main scene interface
|
||||||
*/
|
*/
|
||||||
const TestScene1: Scene = {
|
const TestScene1: Scene = {
|
||||||
|
persistentValues: undefined,
|
||||||
|
hooks: [],
|
||||||
|
signalHookMap: undefined,
|
||||||
|
sceneHooks: []
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import { engine } from "/Scripts/engine/engine-init";
|
import { engine } from "/Scripts/engine/engine-init";
|
||||||
|
import { Engine } from "/Scripts/types/engine";
|
||||||
import { Scene } from "/Scripts/types/scene";
|
import { Scene } from "/Scripts/types/scene";
|
||||||
import { Vector } from "/Scripts/types/spatial";
|
import { Vector } from "/Scripts/types/spatial";
|
||||||
|
|
||||||
@ -26,7 +27,7 @@ class TestScene1 extends Scene {
|
|||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
signal: "equipItem",
|
signal: "equipItem",
|
||||||
callback: (entityId: number) => {
|
callback: (engine: Engine) => {
|
||||||
// throw tutorial message
|
// throw tutorial message
|
||||||
engine.classes.simulation.static.setFramestep(0)
|
engine.classes.simulation.static.setFramestep(0)
|
||||||
engine.classes.tutorialUtils.static.showTutorialHint(
|
engine.classes.tutorialUtils.static.showTutorialHint(
|
||||||
@ -44,7 +45,7 @@ class TestScene1 extends Scene {
|
|||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
signal: "entityGroundMove",
|
signal: "entityGroundMove",
|
||||||
callback: (entityId: number, newPos: Vector) => {
|
callback: (engine: Engine, newPos: Vector) => {
|
||||||
// console.log("Entity moved " + entityId + " to " + Vector.toString(newPos))
|
// console.log("Entity moved " + entityId + " to " + Vector.toString(newPos))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -54,7 +55,7 @@ class TestScene1 extends Scene {
|
|||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
signal: "itemPickup",
|
signal: "itemPickup",
|
||||||
callback: (entityId: number, inWorldItemEntityId: number, inInventoryItemEntityId: number) => {
|
callback: (engine: Engine, inWorldItemEntityId: number, inInventoryItemEntityId: number) => {
|
||||||
// throw tutorial message
|
// throw tutorial message
|
||||||
engine.classes.simulation.static.setFramestep(0)
|
engine.classes.simulation.static.setFramestep(0)
|
||||||
engine.classes.tutorialUtils.static.showTutorialHint(
|
engine.classes.tutorialUtils.static.showTutorialHint(
|
||||||
|
|||||||
@ -2,7 +2,9 @@ package electrosphere.script;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.ProcessBuilder.Redirect;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
@ -288,50 +290,45 @@ public class ScriptContext {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Compiles the project
|
* Compiles the project
|
||||||
|
* @return true if the process successfully forked, false otherwise
|
||||||
*/
|
*/
|
||||||
protected void compileOutsideContext(){
|
protected boolean compileOutsideContext(){
|
||||||
ScriptFileChecksumMap checksumMap = this.parent.getChecksumMap();
|
ScriptFileChecksumMap checksumMap = this.parent.getChecksumMap();
|
||||||
//actually compile
|
//actually compile
|
||||||
this.invokeMemberFunction("COMPILER", "run");
|
Process process;
|
||||||
try {
|
try {
|
||||||
Process process = Runtime.getRuntime().exec("tsc");
|
ProcessBuilder builder = new ProcessBuilder();
|
||||||
process.wait();
|
builder.command("cmd.exe", "/c", "tsc");
|
||||||
|
builder.directory(new File(System.getProperty("user.dir")));
|
||||||
|
builder.redirectOutput(Redirect.INHERIT);
|
||||||
|
builder.redirectError(Redirect.INHERIT);
|
||||||
|
process = builder.start();
|
||||||
|
process.waitFor();
|
||||||
} catch (IOException | InterruptedException e) {
|
} catch (IOException | InterruptedException e) {
|
||||||
throw new Error("Failed to execute typescript!", e);
|
throw new Error("Failed to execute typescript!", e);
|
||||||
}
|
}
|
||||||
Value fileMap = this.topLevelValue.getMember("COMPILER").getMember("fileMap");
|
if(process.exitValue() != 0){
|
||||||
|
String message = "Failed to run external compiler! " + process.exitValue();
|
||||||
|
LoggerInterface.loggerScripts.ERROR(new Error(message));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
//register new files, update cache where appropriate
|
//register new files, update cache where appropriate
|
||||||
for(String key : fileMap.getMemberKeys()){
|
try {
|
||||||
Value fileData = fileMap.getMember(key);
|
Files.walk(new File(".cache/tscache/src").toPath()).forEach((Path currPath) -> {
|
||||||
String content = fileData.getMember("content").asString();
|
if(!currPath.toFile().isDirectory()){
|
||||||
String cacheFilePath = ScriptEngine.TS_SOURCE_CACHE_DIR + key;
|
String pathRaw = currPath.toString();
|
||||||
File toWriteFile = new File(cacheFilePath);
|
pathRaw = pathRaw.replace(".\\.cache\\tscache\\src\\", "./assets/");
|
||||||
|
File correspondingFile = new File(pathRaw.replace(".\\.cache\\tscache\\src\\", "./assets/"));
|
||||||
//make sure all containing folders exist
|
String cacheKey = pathRaw.replace("./assets", "").replace("\\", "/");
|
||||||
try {
|
checksumMap.getFileLastModifyMap().put(cacheKey, correspondingFile.lastModified() + "");
|
||||||
Files.createDirectories(toWriteFile.getParentFile().toPath());
|
}
|
||||||
} catch (IOException e) {
|
});
|
||||||
LoggerInterface.loggerFileIO.ERROR(e);
|
} catch (IOException e) {
|
||||||
}
|
throw new Error("Failed to walk typescript cache dir!");
|
||||||
|
|
||||||
//update cached timestamp
|
|
||||||
{
|
|
||||||
String pathRaw = toWriteFile.toPath() + "";
|
|
||||||
pathRaw = pathRaw.replace(".\\.cache\\tscache\\src\\", "./assets/");
|
|
||||||
File correspondingFile = new File(pathRaw.replace(".\\.cache\\tscache\\src\\", "./assets/"));
|
|
||||||
String cacheKey = pathRaw.replace("./assets", "").replace("\\", "/");
|
|
||||||
checksumMap.getFileLastModifyMap().put(cacheKey, correspondingFile.lastModified() + "");
|
|
||||||
}
|
|
||||||
|
|
||||||
//write the actual file
|
|
||||||
try {
|
|
||||||
Files.writeString(toWriteFile.toPath(), content);
|
|
||||||
} catch (IOException e) {
|
|
||||||
LoggerInterface.loggerFileIO.ERROR(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//write out cache map file
|
//write out cache map file
|
||||||
this.parent.writeChecksumMap();
|
this.parent.writeChecksumMap();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -178,7 +178,9 @@ public class ScriptEngine extends SignalServiceImpl {
|
|||||||
|
|
||||||
//compile
|
//compile
|
||||||
if(!readCache){
|
if(!readCache){
|
||||||
scriptContext.compileInContext();
|
if(!scriptContext.compileOutsideContext()){
|
||||||
|
scriptContext.compileInContext();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//post init logic
|
//post init logic
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user