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
|
||||
*/
|
||||
const TestScene1: Scene = {
|
||||
|
||||
persistentValues: undefined,
|
||||
hooks: [],
|
||||
signalHookMap: undefined,
|
||||
sceneHooks: []
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { engine } from "/Scripts/engine/engine-init";
|
||||
import { Engine } from "/Scripts/types/engine";
|
||||
import { Scene } from "/Scripts/types/scene";
|
||||
import { Vector } from "/Scripts/types/spatial";
|
||||
|
||||
@ -26,7 +27,7 @@ class TestScene1 extends Scene {
|
||||
*/
|
||||
{
|
||||
signal: "equipItem",
|
||||
callback: (entityId: number) => {
|
||||
callback: (engine: Engine) => {
|
||||
// throw tutorial message
|
||||
engine.classes.simulation.static.setFramestep(0)
|
||||
engine.classes.tutorialUtils.static.showTutorialHint(
|
||||
@ -44,7 +45,7 @@ class TestScene1 extends Scene {
|
||||
*/
|
||||
{
|
||||
signal: "entityGroundMove",
|
||||
callback: (entityId: number, newPos: Vector) => {
|
||||
callback: (engine: Engine, newPos: Vector) => {
|
||||
// console.log("Entity moved " + entityId + " to " + Vector.toString(newPos))
|
||||
}
|
||||
},
|
||||
@ -54,7 +55,7 @@ class TestScene1 extends Scene {
|
||||
*/
|
||||
{
|
||||
signal: "itemPickup",
|
||||
callback: (entityId: number, inWorldItemEntityId: number, inInventoryItemEntityId: number) => {
|
||||
callback: (engine: Engine, inWorldItemEntityId: number, inInventoryItemEntityId: number) => {
|
||||
// throw tutorial message
|
||||
engine.classes.simulation.static.setFramestep(0)
|
||||
engine.classes.tutorialUtils.static.showTutorialHint(
|
||||
|
||||
@ -2,7 +2,9 @@ package electrosphere.script;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.ProcessBuilder.Redirect;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
@ -288,50 +290,45 @@ public class ScriptContext {
|
||||
|
||||
/**
|
||||
* Compiles the project
|
||||
* @return true if the process successfully forked, false otherwise
|
||||
*/
|
||||
protected void compileOutsideContext(){
|
||||
protected boolean compileOutsideContext(){
|
||||
ScriptFileChecksumMap checksumMap = this.parent.getChecksumMap();
|
||||
//actually compile
|
||||
this.invokeMemberFunction("COMPILER", "run");
|
||||
Process process;
|
||||
try {
|
||||
Process process = Runtime.getRuntime().exec("tsc");
|
||||
process.wait();
|
||||
ProcessBuilder builder = new ProcessBuilder();
|
||||
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) {
|
||||
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
|
||||
for(String key : fileMap.getMemberKeys()){
|
||||
Value fileData = fileMap.getMember(key);
|
||||
String content = fileData.getMember("content").asString();
|
||||
String cacheFilePath = ScriptEngine.TS_SOURCE_CACHE_DIR + key;
|
||||
File toWriteFile = new File(cacheFilePath);
|
||||
|
||||
//make sure all containing folders exist
|
||||
try {
|
||||
Files.createDirectories(toWriteFile.getParentFile().toPath());
|
||||
} catch (IOException e) {
|
||||
LoggerInterface.loggerFileIO.ERROR(e);
|
||||
}
|
||||
|
||||
//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);
|
||||
}
|
||||
try {
|
||||
Files.walk(new File(".cache/tscache/src").toPath()).forEach((Path currPath) -> {
|
||||
if(!currPath.toFile().isDirectory()){
|
||||
String pathRaw = currPath.toString();
|
||||
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() + "");
|
||||
}
|
||||
});
|
||||
} catch (IOException e) {
|
||||
throw new Error("Failed to walk typescript cache dir!");
|
||||
}
|
||||
//write out cache map file
|
||||
this.parent.writeChecksumMap();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -178,7 +178,9 @@ public class ScriptEngine extends SignalServiceImpl {
|
||||
|
||||
//compile
|
||||
if(!readCache){
|
||||
scriptContext.compileInContext();
|
||||
if(!scriptContext.compileOutsideContext()){
|
||||
scriptContext.compileInContext();
|
||||
}
|
||||
}
|
||||
|
||||
//post init logic
|
||||
|
||||
Loading…
Reference in New Issue
Block a user