diff --git a/assets/Models/creatures/person2/person2_1.glb b/assets/Models/creatures/person2/person2_1.glb index 3c861e6e..e1a86e6b 100644 Binary files a/assets/Models/creatures/person2/person2_1.glb and b/assets/Models/creatures/person2/person2_1.glb differ diff --git a/assets/Models/creatures/viewmodel.glb b/assets/Models/creatures/viewmodel.glb index f257e2d2..6ba1d2cf 100644 Binary files a/assets/Models/creatures/viewmodel.glb and b/assets/Models/creatures/viewmodel.glb differ diff --git a/docs/src/architecture/architectureindex.md b/docs/src/architecture/architectureindex.md index f5717514..9fd2a43b 100644 --- a/docs/src/architecture/architectureindex.md +++ b/docs/src/architecture/architectureindex.md @@ -11,6 +11,7 @@ - @subpage savesindex - @subpage hitboxesindex - @subpage drawcell +- @subpage scriptengine # What is this section diff --git a/docs/src/architecture/scripting/scriptengine.md b/docs/src/architecture/scripting/scriptengine.md new file mode 100644 index 00000000..124c4fb0 --- /dev/null +++ b/docs/src/architecture/scripting/scriptengine.md @@ -0,0 +1,31 @@ +@page scriptengine Script Engine + + +# Potential problems with integrating with the overall game engine +A chief problem we want to avoid is allowing people to 'escape' the scripting engine and get access to all objects in the overall engine + +# Roadmap for integrating with the overall game engine + + + + +# On adding different instances of the scripting engine +There should be a single monolithic instance of the scripting engine +All context-dependent scripts running should have their context provided + +IE, lets say I'm the client and I want to fire an event when a client-side effect completes, +I'd provide a copy of the client's scene as a part of the function call on javascript side +That way for any unforseen reason the client could still get access to the server's objects + +IE, lets say I'm a script running on a specific scene on the server, +I'd provide the specific scene to the function call + +IE, lets say I'm some script firing every time a user logs in, +I'd provide the new user object and the global server user tracking service +That way you could still drill down to individual scenes on the server if you needed to + + + + + + diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index aef7c862..cd6819bc 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -387,6 +387,20 @@ Fix items falling below the ground Fix server always rotating entity to face client camera -- should only be changing movement vector Probably some kind of tutorial text +(06/??/2024) +Start working on script engine documentation/design + +(06/27/2024) +Animations + - 2H Sword Hold (3rd person) + - 2H Sword Attack (3rd person) + - 2H Sword Block (3rd person) + - 2H Sword Hold (1st person) + - 2H Sword Attach (1st person) + - 2H Sword Block (1st person) + + + # TODO @@ -394,8 +408,6 @@ Probably some kind of tutorial text Demo requirements: = Assets = -Block animation in first person -Block animation in third person Fix attack animation bone rotations for hand Clean up equip state data Audio FX for everything diff --git a/src/main/java/electrosphere/script/ScriptEngine.java b/src/main/java/electrosphere/script/ScriptEngine.java index 40d731f9..a3569e9d 100644 --- a/src/main/java/electrosphere/script/ScriptEngine.java +++ b/src/main/java/electrosphere/script/ScriptEngine.java @@ -13,12 +13,23 @@ import org.graalvm.polyglot.Value; import electrosphere.logger.LoggerInterface; import electrosphere.util.FileUtils; +/** + * Interface for executing scripts in the game engine + */ public class ScriptEngine { + //the graal context Context context; + //the map of script filepaths to parsed, in-memory scripts Map sourceMap; + //the javascript object that stores values + Value jsBindingsObject; + + /** + * Initializes the engine + */ public void init(){ //init datastructures sourceMap = new HashMap(); @@ -28,6 +39,8 @@ public class ScriptEngine { context = Context.newBuilder("js").engine(engine).build(); //read scripts into source map readScriptsDirectory("/src/main/sql", FileUtils.getAssetFile("/src/main/sql")); + //save the js bindings object + jsBindingsObject = context.getBindings("js"); //create bindings // try { // String content = FileUtils.getAssetFileAsString("/Scripts/test.js"); @@ -40,11 +53,29 @@ public class ScriptEngine { // } } - void createBindings(){ - Value jsBindings = context.getBindings("js"); - jsBindings.putMember("name", "somescript"); + /** + * Stores a variable at the top level of the js bindings + * @param valueName The name of the variable (ie the name of the variable) + * @param value The value that is stored at that variable + */ + public void putTopLevelValue(String valueName, Object value){ + jsBindingsObject.putMember(valueName, value); } + /** + * Gets a top level value from the script engine + * @param valueName The name of the variable + * @return The value of the variable + */ + public Value getTopLevelValue(String valueName){ + return jsBindingsObject.getMember(valueName); + } + + /** + * Reads the scripts directory + * @param path The + * @param directory + */ void readScriptsDirectory(String path, File directory){ if(directory.exists() && directory.isDirectory()){ File[] children = directory.listFiles(); @@ -61,6 +92,10 @@ public class ScriptEngine { } } + /** + * Loads a script from disk + * @param path The path to the script file + */ public void loadScript(String path){ String content; try { @@ -73,11 +108,17 @@ public class ScriptEngine { } } + /** + * Runs a script + * @param path The filepath of the script + */ public void runScript(String path){ Source source = sourceMap.get(path); if(source != null){ context.eval(source); } } + + }