animation updates

This commit is contained in:
austin 2024-06-27 22:35:36 -04:00
parent 2182cc80fa
commit a26ea92aae
6 changed files with 90 additions and 5 deletions

View File

@ -11,6 +11,7 @@
- @subpage savesindex
- @subpage hitboxesindex
- @subpage drawcell
- @subpage scriptengine
# What is this section

View File

@ -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

View File

@ -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

View File

@ -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<String,Source> sourceMap;
//the javascript object that stores values
Value jsBindingsObject;
/**
* Initializes the engine
*/
public void init(){
//init datastructures
sourceMap = new HashMap<String,Source>();
@ -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);
}
}
}