optional start/interrupt methods on client btrees
All checks were successful
studiorailgun/highlevel-netcode-gen/pipeline/head This commit looks good

This commit is contained in:
austin 2024-07-31 17:33:47 -04:00
parent 24626f8f8b
commit d06f6ab17d
7 changed files with 164 additions and 2 deletions

View File

@ -0,0 +1,57 @@
package electrosphere.main.core.btree.methods;
import java.util.Arrays;
import java.util.List;
import electrosphere.main.project.ProjectStructure;
import electrosphere.main.source.VirtualMethod;
import electrosphere.main.util.TemplateInjectionUtils;
/**
* Interrupt method on client btrees
*/
public class ClientInterrupt implements VirtualMethod {
//The name of the btree
String name;
//The classname of the btree
String className;
/**
* Constructor
* @param name
* @param className
*/
public ClientInterrupt(String name, String className){
this.name = name;
this.className = className;
}
@Override
public String getName(ProjectStructure projectStructure) {
return "interrupt";
}
@Override
public String getContent(ProjectStructure projectStructure) {
//BTREE_CLIENTGROUNDMOVEMENTTREE_ID
String rVal = TemplateInjectionUtils.getFragmentWithReplacement("/client/InterruptBTree.java", "BTREE_" + this.name.toUpperCase() + "_ID", "TREE_" + this.name.toUpperCase());
return rVal;
}
@Override
public List<String> getImports(ProjectStructure projectStructure) {
List<String> rVal = Arrays.asList(new String[]{
"electrosphere.net.parser.net.message.SynchronizationMessage",
"electrosphere.net.synchronization.BehaviorTreeIdEnums",
});
return rVal;
}
@Override
public boolean shouldOverwrite() {
return true;
}
}

View File

@ -0,0 +1,57 @@
package electrosphere.main.core.btree.methods;
import java.util.Arrays;
import java.util.List;
import electrosphere.main.project.ProjectStructure;
import electrosphere.main.source.VirtualMethod;
import electrosphere.main.util.TemplateInjectionUtils;
/**
* The start method on client btrees
*/
public class ClientStart implements VirtualMethod {
//The name of the btree
String name;
//The classname of the btree
String className;
/**
* Constructor
* @param name
* @param className
*/
public ClientStart(String name, String className){
this.name = name;
this.className = className;
}
@Override
public String getName(ProjectStructure projectStructure) {
return "start";
}
@Override
public String getContent(ProjectStructure projectStructure) {
//BTREE_CLIENTGROUNDMOVEMENTTREE_ID
String rVal = TemplateInjectionUtils.getFragmentWithReplacement("/client/StartBTree.java", "BTREE_" + this.name.toUpperCase() + "_ID", "TREE_" + this.name.toUpperCase());
return rVal;
}
@Override
public List<String> getImports(ProjectStructure projectStructure) {
List<String> rVal = Arrays.asList(new String[]{
"electrosphere.net.parser.net.message.SynchronizationMessage",
"electrosphere.net.synchronization.BehaviorTreeIdEnums",
});
return rVal;
}
@Override
public boolean shouldOverwrite() {
return true;
}
}

View File

@ -13,6 +13,8 @@ import org.jboss.forge.roaster.model.source.JavaClassSource;
import electrosphere.main.core.btree.BehaviorTree; import electrosphere.main.core.btree.BehaviorTree;
import electrosphere.main.core.btree.methods.ClientAttach; import electrosphere.main.core.btree.methods.ClientAttach;
import electrosphere.main.core.btree.methods.ClientDetach; import electrosphere.main.core.btree.methods.ClientDetach;
import electrosphere.main.core.btree.methods.ClientInterrupt;
import electrosphere.main.core.btree.methods.ClientStart;
import electrosphere.main.core.btree.methods.Constructor; import electrosphere.main.core.btree.methods.Constructor;
import electrosphere.main.core.btree.methods.Fetch; import electrosphere.main.core.btree.methods.Fetch;
import electrosphere.main.core.btree.methods.ServerAttach; import electrosphere.main.core.btree.methods.ServerAttach;
@ -83,6 +85,8 @@ public class BTreeParser {
rVal.addMethod(new Constructor(bTreeName, target.getSource().getName())); rVal.addMethod(new Constructor(bTreeName, target.getSource().getName()));
rVal.addMethod(new Fetch(bTreeName, target.getSource().getName())); rVal.addMethod(new Fetch(bTreeName, target.getSource().getName()));
addOptionalMethods(mainAnnotation,rVal);
// //
// //
// ADD IMPORTS HERE // ADD IMPORTS HERE
@ -104,6 +108,22 @@ public class BTreeParser {
return rVal; return rVal;
} }
/**
* Adds methods that can optionally be requested via the main annotation
* @param mainAnnotation The main annotation
* @param tree The btree
*/
private void addOptionalMethods(AnnotationSource<JavaClassSource> mainAnnotation, BehaviorTree tree){
TargetFile targetFile = tree.getTargetFile();
if(mainAnnotation.getStringValue("genStartInt") != null){
boolean genStartInt = Boolean.parseBoolean(mainAnnotation.getStringValue("genStartInt"));
if(genStartInt){
tree.addMethod(new ClientStart(tree.getName(), targetFile.getSource().getName()));
tree.addMethod(new ClientInterrupt(tree.getName(), targetFile.getSource().getName()));
}
}
}
/** /**
* Updates the behavior tree objects with the behavior tree ids that are already defined * Updates the behavior tree objects with the behavior tree ids that are already defined
*/ */

View File

@ -1,6 +1,5 @@
/** /**
* <p> (initially) Automatically generated </p> * <p> (initially) Automatically generated </p>
* <p> More parameters can be safely added to this method</p>
* <p> * <p>
* Attaches this tree to the entity. * Attaches this tree to the entity.
* </p> * </p>

View File

@ -0,0 +1,15 @@
/**
* <p> Automatically generated </p>
* <p>
* Requests that the server start this btree
* </p>
*/
public void interrupt(){
Globals.clientConnection.queueOutgoingMessage(
SynchronizationMessage.constructClientRequestBTreeActionMessage(
Globals.clientSceneWrapper.mapClientToServerId(parent.getId()),
BehaviorTreeIdEnums.BTREE_CLIENTGROUNDMOVEMENTTREE_ID,
1
)
);
}

View File

@ -0,0 +1,15 @@
/**
* <p> Automatically generated </p>
* <p>
* Requests that the server start this btree
* </p>
*/
public void start(){
Globals.clientConnection.queueOutgoingMessage(
SynchronizationMessage.constructClientRequestBTreeActionMessage(
Globals.clientSceneWrapper.mapClientToServerId(parent.getId()),
BehaviorTreeIdEnums.BTREE_CLIENTGROUNDMOVEMENTTREE_ID,
0
)
);
}

View File

@ -1,6 +1,5 @@
/** /**
* <p> (initially) Automatically generated </p> * <p> (initially) Automatically generated </p>
* <p> More parameters can be safely added to this method</p>
* <p> * <p>
* Attaches this tree to the entity. * Attaches this tree to the entity.
* </p> * </p>