scripting work
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2024-07-10 15:27:05 -04:00
parent 8a0b2d001b
commit 94c19d7990
13 changed files with 214 additions and 44 deletions

View File

@ -0,0 +1,13 @@
import { Scene } from "/Scripts/types/scene";
/**
* The main scene interface
*/
const TestScene1: Scene = {
}
/**
* The scene to export
*/
export default TestScene1

View File

@ -1 +0,0 @@
console.log("Loaded testscene1");

View File

@ -0,0 +1,22 @@
import { ClientInventory, onEquipItem, onMoveItemContainer, onUnequipItem } from "/Scripts/client/entity/inventory";
import { Namespace } from "/Scripts/types/namespace";
/**
* The client namespace type
*/
export interface NamespaceClient extends Namespace {
inventory: ClientInventory,
}
/**
* The client namespace (should contain all client callbacks, data, etc)
*/
export const Client: NamespaceClient = {
inventory: {
onMoveItemContainer: onMoveItemContainer,
onEquipItem: onEquipItem,
onUnequipItem: onUnequipItem,
},
}

View File

@ -0,0 +1,30 @@
/**
* Called every time an item is moved to a container
*/
export const onMoveItemContainer: Array<Function> = [ ]
/**
* Called every time an item is equipped
*/
export const onEquipItem: Array<Function> = [ ]
/**
* Called every time an item is unequipped
*/
export const onUnequipItem: Array<Function> = [ ]
/**
* Called every time the server commands the client to move items to another container
*/
export const onServerMoveItemContainer: Array<Function> = [ ]
/**
* Callbacks that fire every time the player's entity does specific actions
*/
export interface ClientInventory {
onMoveItemContainer: Array<Function>,
onEquipItem: Array<Function>,
onUnequipItem: Array<Function>,
}

View File

@ -22,6 +22,7 @@ const require = (path) => {
return REQUIRE_CACHE[normalizedFilePath].exports return REQUIRE_CACHE[normalizedFilePath].exports
} else if(!!COMPILER_fileMap[normalizedFilePath]?.content) { } else if(!!COMPILER_fileMap[normalizedFilePath]?.content) {
const code = COMPILER_fileMap[normalizedFilePath].moduleContent const code = COMPILER_fileMap[normalizedFilePath].moduleContent
loggerScripts.DEBUG('Module code ' + JSON.stringify(code))
let exports = new Function(code)() let exports = new Function(code)()
//create module object //create module object
const module = { const module = {
@ -35,9 +36,12 @@ const require = (path) => {
const errorMsg = "FAILED TO REQUIRE FILE " + normalizedFilePath const errorMsg = "FAILED TO REQUIRE FILE " + normalizedFilePath
loggerScripts.WARNING(errorMsg) loggerScripts.WARNING(errorMsg)
loggerScripts.WARNING('Module value:') loggerScripts.WARNING('Module value:')
loggerScripts.WARNING(Object.keys(REQUIRE_CACHE?.[normalizedFilePath]) + '') const cacheValue = REQUIRE_CACHE?.[normalizedFilePath]
loggerScripts.WARNING(Object.keys(cacheValue ? cacheValue : {}) + '')
loggerScripts.WARNING('Require cache contents:') loggerScripts.WARNING('Require cache contents:')
loggerScripts.WARNING(Object.keys(REQUIRE_CACHE) + '') loggerScripts.WARNING(Object.keys(REQUIRE_CACHE) + '')
loggerScripts.WARNING('File cache contents:')
loggerScripts.WARNING(Object.keys(COMPILER_fileMap) + '')
throw new Error(errorMsg) throw new Error(errorMsg)
} }
} }

View File

@ -1,11 +1,18 @@
import { Host } from '/engine/engine-interface' import { Engine } from '/Scripts/engine/engine-interface'
import { loggerScripts } from '/compiler/host_access' import { loggerScripts } from '/Scripts/compiler/host_access'
import { Client, NamespaceClient } from '/Scripts/client/client'
let host: Host //the core engine
let engine: Engine
/** /**
* Called when the script engine first initializes * Called when the script engine first initializes
*/ */
export const ENGINE_onInit = () => { export const ENGINE_onInit = () => {
loggerScripts.INFO('Script Engine Init') loggerScripts.INFO('Script Engine Beginning Initialization')
//load namespaces
let client: NamespaceClient = Client
loggerScripts.INFO('Script Engine Initialized')
} }

View File

@ -3,7 +3,7 @@
/** /**
* The host context that contains all core engine functions * The host context that contains all core engine functions
*/ */
export interface Host { export interface Engine {
classes: any, //the host's view of the scripting engine classes: any, //the host's view of the scripting engine
singletons: any, //the singletons available to the script engine singletons: any, //the singletons available to the script engine
} }

View File

@ -0,0 +1,55 @@
import { Scene } from "/Scripts/types/scene";
/**
* A hook that runs a function when a signal is fired in the engine
*/
export interface Hook {
/**
* The signal that triggers this hook in particular
*/
signal: any,
/**
* The function to call when the signal is fired
*/
callback: Function,
}
/**
* The scope that the hook is firing from
*/
export enum HookScope {
CORE,
SCRIPT,
SCENE_CLIENT,
SCENE_SERVER,
}
/**
* A hook that is tracked by the manager
*/
export interface TrackedHook extends Hook {
/**
* The scope that this hook was defined at
*/
scope: HookScope,
/**
* The scene that added the hook
*/
scene?: Scene,
}
/**
* Manages hooks for the engine
*/
export class HookManager {
}

View File

@ -0,0 +1,5 @@
/**
* A namespace
*/
export type Namespace = Record<string,any>

View File

@ -0,0 +1,44 @@
import { Hook } from "/Scripts/types/hook";
import { Namespace } from "/Scripts/types/namespace";
/**
* A value that is synchronized between client and server
*/
export function SynchronizedType() {
//called when the synchronized type is evaluated
return function (target: any, propertyKey: string, descriptor: PropertyDescriptor){
//called when
}
}
/**
* The namespace of a given scene
*/
export interface Scene extends Namespace {
/**
* Called when the current instance scene is first loaded
*/
onLoad?: Function
/**
* Called when the current instance of the scene is unloaded
*/
onUnload?: Function
/**
* Called when the current instance of the scene is saved -- either periodically or when the scene is being stored to disk
*/
onSave?: Function
/**
* Values that are synchronized between the client and server. They are also stored to disk when the scene saves
*/
persistentValues?: Record<string,any>
/**
* The hooks that are provided by this scene
*/
hooks?: Array<Hook>
}

View File

@ -1,35 +1,13 @@
+ spawn into the world
+ there is a sword lying on the ground
Demo experience: + when you grab the sword, a tutorial popup appears to tell you how to use in
- Load into world fire a script on a hook
- pick up a katana hook for grabbing an item
- popup appears telling you controls to swing it + on clearing the tutorial, continue the game+ when the sword is equipped, create another popup to teach sword controls. it pauses the game
- Upon dismissing popup, spawn enemy with sword hook on equipping an item
- Fight enemy to the death script ability to pause and unpause game
+ when popup is accepted, spawn an rnemy with an effect
Demo requirements: enemy ai
= Assets = review effects
Fix attack animation bone rotations for hand review combat code (lifestate, damage calculation, etc)
Clean up equip state data audio fx for everything
Audio FX for everything
= Coding =
Sub menu on title screen that allows changing control mappings
- Automatically generate based on the controls arrays in controls handler
Review combat code
- Damage calculation
- Particle generation
- Revive tree
Enemy AI
Ability for private realms to have time start/stop based on the player's feedback <-- sync this up to tutorial ui via script
Scene Message Service
- Can send arbitrary events and messages
- Synchronized and unsynchronized
- Use synchronized to have client-driver ui interactions
- Variables
- Synchronized and unsynchronized

View File

@ -22,6 +22,11 @@ import electrosphere.util.MathUtils;
*/ */
public class ScriptEngine { public class ScriptEngine {
//the default namespaces for
public static String SCRIPT_NAMESPACE_ENGINE = "engine"; //namespace for the engine functions exposed to the script engine
public static String SCRIPT_NAMESPACE_SCRIPT = "script"; //namespace for the core typescript functionsw
public static String SCRIPT_NAMESPACE_SCENE = "scene"; //namespace for the current scene
//the graal context //the graal context
Context context; Context context;
@ -51,6 +56,12 @@ public class ScriptEngine {
"Scripts/compiler/host_access.js", "Scripts/compiler/host_access.js",
}; };
//folders that should be loaded once we have bootstrapped the compiler
static final String[] foldersToLoadOnInit = new String[]{
"Scripts/engine",
"Scripts/client",
};
//The classes that will be provided to the scripting engine //The classes that will be provided to the scripting engine
//https://stackoverflow.com/a/65942034 //https://stackoverflow.com/a/65942034
static final Object[][] staticClasses = new Object[][]{ static final Object[][] staticClasses = new Object[][]{
@ -92,7 +103,9 @@ public class ScriptEngine {
defineHostMembers(); defineHostMembers();
//register engine files //register engine files
registerScriptDirectory("Scripts/engine",FileUtils.getAssetFile("Scripts/engine")); for(String folderToRegister : foldersToLoadOnInit){
registerScriptDirectory(folderToRegister,FileUtils.getAssetFile(folderToRegister));
}
//compile //compile
compile(); compile();

View File

@ -2,7 +2,7 @@
"compilerOptions": { "compilerOptions": {
"paths" : { "paths" : {
"/*" : [ "/*" : [
"./assets/Scripts/*" "./assets/*"
], ],
} }
} }