more scripting work
This commit is contained in:
parent
3682497060
commit
719999b6aa
@ -1,10 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An entity
|
|
||||||
*/
|
|
||||||
export interface Entity {
|
|
||||||
id: number,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
16
assets/Scripts/types/host/entity/entity.ts
Normal file
16
assets/Scripts/types/host/entity/entity.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An entity
|
||||||
|
*/
|
||||||
|
export interface Entity {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the id of the entity
|
||||||
|
* @returns The id
|
||||||
|
*/
|
||||||
|
getId: () => number,
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,4 +1,6 @@
|
|||||||
|
import { Entity } from "/Scripts/types/host/entity/entity";
|
||||||
import { TutorialUtils } from "/Scripts/types/host/renderer/ui/tutorial";
|
import { TutorialUtils } from "/Scripts/types/host/renderer/ui/tutorial";
|
||||||
|
import { Vector } from "/Scripts/types/spatial";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -21,6 +23,11 @@ export interface StaticClasses {
|
|||||||
*/
|
*/
|
||||||
readonly tutorialUtils?: Class<TutorialUtils>,
|
readonly tutorialUtils?: Class<TutorialUtils>,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utilities for performing actions on the server
|
||||||
|
*/
|
||||||
|
readonly serverUtils?: Class<ServerUtils>,
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,3 +57,31 @@ export interface SimulationClass {
|
|||||||
readonly setFramestep: (value: number) => void,
|
readonly setFramestep: (value: number) => void,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utilities for core functionality on the server
|
||||||
|
*/
|
||||||
|
export interface ServerUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Spawns a creature
|
||||||
|
* @param creatureType The type of creature
|
||||||
|
* @returns The entity created on the server
|
||||||
|
*/
|
||||||
|
readonly spawnCreature: (sceneInstanceId: number, creatureType: string, position: Vector) => Entity
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the position of an entity
|
||||||
|
* @param entity The entity
|
||||||
|
* @returns The position
|
||||||
|
*/
|
||||||
|
readonly getPosition: (entity: Entity) => Vector
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the position of an entity
|
||||||
|
* @param entity The entity
|
||||||
|
* @param position The position
|
||||||
|
*/
|
||||||
|
readonly setPosition: (entity: Entity, position: Vector) => void
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@ -2,6 +2,8 @@ package electrosphere.entity;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import org.graalvm.polyglot.HostAccess.Export;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An entity
|
* An entity
|
||||||
@ -29,6 +31,7 @@ public class Entity {
|
|||||||
* Gets the id of this entity
|
* Gets the id of this entity
|
||||||
* @return The id
|
* @return The id
|
||||||
*/
|
*/
|
||||||
|
@Export
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -70,12 +70,6 @@ public class ServerEntityUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// //if the server is also a client, update the drawcell manager to know to pull new chunks
|
|
||||||
// if(Globals.RUN_CLIENT){
|
|
||||||
// Globals.drawCellManager.invalidateAllCells();
|
|
||||||
// Globals.drawCellManager.setCellX(Globals.clientPlayerData.getWorldPos().x);
|
|
||||||
// Globals.drawCellManager.setCellY(Globals.clientPlayerData.getWorldPos().z);
|
|
||||||
// }
|
|
||||||
//reposition entity
|
//reposition entity
|
||||||
CollisionObjUtils.serverPositionCharacter(entity, position);
|
CollisionObjUtils.serverPositionCharacter(entity, position);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,6 +17,7 @@ import electrosphere.engine.Globals;
|
|||||||
import electrosphere.engine.Main;
|
import electrosphere.engine.Main;
|
||||||
import electrosphere.logger.LoggerInterface;
|
import electrosphere.logger.LoggerInterface;
|
||||||
import electrosphere.menu.tutorial.TutorialMenus;
|
import electrosphere.menu.tutorial.TutorialMenus;
|
||||||
|
import electrosphere.script.translation.JSServerUtils;
|
||||||
import electrosphere.util.FileUtils;
|
import electrosphere.util.FileUtils;
|
||||||
import electrosphere.util.math.MathUtils;
|
import electrosphere.util.math.MathUtils;
|
||||||
|
|
||||||
@ -85,6 +86,7 @@ public class ScriptEngine {
|
|||||||
{"mathUtils",MathUtils.class},
|
{"mathUtils",MathUtils.class},
|
||||||
{"simulation",Main.class},
|
{"simulation",Main.class},
|
||||||
{"tutorialUtils",TutorialMenus.class},
|
{"tutorialUtils",TutorialMenus.class},
|
||||||
|
{"serverUtils",JSServerUtils.class},
|
||||||
};
|
};
|
||||||
|
|
||||||
//singletons from the host that are provided to the javascript context
|
//singletons from the host that are provided to the javascript context
|
||||||
|
|||||||
@ -0,0 +1,42 @@
|
|||||||
|
package electrosphere.script.translation;
|
||||||
|
|
||||||
|
import electrosphere.entity.Entity;
|
||||||
|
import electrosphere.entity.EntityUtils;
|
||||||
|
import electrosphere.entity.ServerEntityUtils;
|
||||||
|
import electrosphere.entity.types.creature.CreatureUtils;
|
||||||
|
import electrosphere.script.access.Vector;
|
||||||
|
import electrosphere.script.utils.AccessTransforms;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Server utilities provided to the js context
|
||||||
|
*/
|
||||||
|
public class JSServerUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Spawns a creature
|
||||||
|
* @param creatureType The creature
|
||||||
|
*/
|
||||||
|
public static void spawnCreature(int sceneInstanceId, String creatureType, Vector position){
|
||||||
|
//TODO: find realm from scene id
|
||||||
|
CreatureUtils.serverSpawnBasicCreature(null, AccessTransforms.getVector(position), creatureType, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the position of an entity
|
||||||
|
* @param entity The entity
|
||||||
|
* @return The position of the entity
|
||||||
|
*/
|
||||||
|
public static Vector getPosition(Entity entity){
|
||||||
|
return AccessTransforms.getVector(EntityUtils.getPosition(entity));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the position of an entity
|
||||||
|
* @param entity The entity
|
||||||
|
* @param vector THe new position of the entity
|
||||||
|
*/
|
||||||
|
public static void setPosition(Entity entity, Vector vector){
|
||||||
|
ServerEntityUtils.repositionEntity(entity, AccessTransforms.getVector(vector));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -15,4 +15,13 @@ public class AccessTransforms {
|
|||||||
return new electrosphere.script.access.Vector(source.x, source.y, source.z);
|
return new electrosphere.script.access.Vector(source.x, source.y, source.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts an access vector into a JOML vector
|
||||||
|
* @param source The access vectpr
|
||||||
|
* @return The JOML vector
|
||||||
|
*/
|
||||||
|
public static org.joml.Vector3d getVector(electrosphere.script.access.Vector source){
|
||||||
|
return new org.joml.Vector3d(source.x,source.y,source.z);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user