From d06f6ab17d896d412a6d6ab6419cfcc934bdbb41 Mon Sep 17 00:00:00 2001 From: austin Date: Wed, 31 Jul 2024 17:33:47 -0400 Subject: [PATCH] optional start/interrupt methods on client btrees --- .../core/btree/methods/ClientInterrupt.java | 57 +++++++++++++++++++ .../main/core/btree/methods/ClientStart.java | 57 +++++++++++++++++++ .../main/project/parsers/BTreeParser.java | 20 +++++++ src/main/resources/client/AttachBTree.java | 1 - src/main/resources/client/InterruptBTree.java | 15 +++++ src/main/resources/client/StartBTree.java | 15 +++++ src/main/resources/server/AttachBTree.java | 1 - 7 files changed, 164 insertions(+), 2 deletions(-) create mode 100644 src/main/java/electrosphere/main/core/btree/methods/ClientInterrupt.java create mode 100644 src/main/java/electrosphere/main/core/btree/methods/ClientStart.java create mode 100644 src/main/resources/client/InterruptBTree.java create mode 100644 src/main/resources/client/StartBTree.java diff --git a/src/main/java/electrosphere/main/core/btree/methods/ClientInterrupt.java b/src/main/java/electrosphere/main/core/btree/methods/ClientInterrupt.java new file mode 100644 index 0000000..a0ea393 --- /dev/null +++ b/src/main/java/electrosphere/main/core/btree/methods/ClientInterrupt.java @@ -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 getImports(ProjectStructure projectStructure) { + List rVal = Arrays.asList(new String[]{ + "electrosphere.net.parser.net.message.SynchronizationMessage", + "electrosphere.net.synchronization.BehaviorTreeIdEnums", + }); + return rVal; + } + + @Override + public boolean shouldOverwrite() { + return true; + } + +} diff --git a/src/main/java/electrosphere/main/core/btree/methods/ClientStart.java b/src/main/java/electrosphere/main/core/btree/methods/ClientStart.java new file mode 100644 index 0000000..70e6eab --- /dev/null +++ b/src/main/java/electrosphere/main/core/btree/methods/ClientStart.java @@ -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 getImports(ProjectStructure projectStructure) { + List rVal = Arrays.asList(new String[]{ + "electrosphere.net.parser.net.message.SynchronizationMessage", + "electrosphere.net.synchronization.BehaviorTreeIdEnums", + }); + return rVal; + } + + @Override + public boolean shouldOverwrite() { + return true; + } + +} diff --git a/src/main/java/electrosphere/main/project/parsers/BTreeParser.java b/src/main/java/electrosphere/main/project/parsers/BTreeParser.java index 3384632..1e9d8cb 100644 --- a/src/main/java/electrosphere/main/project/parsers/BTreeParser.java +++ b/src/main/java/electrosphere/main/project/parsers/BTreeParser.java @@ -13,6 +13,8 @@ import org.jboss.forge.roaster.model.source.JavaClassSource; import electrosphere.main.core.btree.BehaviorTree; import electrosphere.main.core.btree.methods.ClientAttach; 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.Fetch; 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 Fetch(bTreeName, target.getSource().getName())); + addOptionalMethods(mainAnnotation,rVal); + // // // ADD IMPORTS HERE @@ -104,6 +108,22 @@ public class BTreeParser { 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 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 */ diff --git a/src/main/resources/client/AttachBTree.java b/src/main/resources/client/AttachBTree.java index 844806d..76e36c6 100644 --- a/src/main/resources/client/AttachBTree.java +++ b/src/main/resources/client/AttachBTree.java @@ -1,6 +1,5 @@ /** *

(initially) Automatically generated

- *

More parameters can be safely added to this method

*

* Attaches this tree to the entity. *

diff --git a/src/main/resources/client/InterruptBTree.java b/src/main/resources/client/InterruptBTree.java new file mode 100644 index 0000000..5b5ec46 --- /dev/null +++ b/src/main/resources/client/InterruptBTree.java @@ -0,0 +1,15 @@ +/** + *

Automatically generated

+ *

+ * Requests that the server start this btree + *

+ */ +public void interrupt(){ + Globals.clientConnection.queueOutgoingMessage( + SynchronizationMessage.constructClientRequestBTreeActionMessage( + Globals.clientSceneWrapper.mapClientToServerId(parent.getId()), + BehaviorTreeIdEnums.BTREE_CLIENTGROUNDMOVEMENTTREE_ID, + 1 + ) + ); +} \ No newline at end of file diff --git a/src/main/resources/client/StartBTree.java b/src/main/resources/client/StartBTree.java new file mode 100644 index 0000000..59524e7 --- /dev/null +++ b/src/main/resources/client/StartBTree.java @@ -0,0 +1,15 @@ +/** + *

Automatically generated

+ *

+ * Requests that the server start this btree + *

+ */ +public void start(){ + Globals.clientConnection.queueOutgoingMessage( + SynchronizationMessage.constructClientRequestBTreeActionMessage( + Globals.clientSceneWrapper.mapClientToServerId(parent.getId()), + BehaviorTreeIdEnums.BTREE_CLIENTGROUNDMOVEMENTTREE_ID, + 0 + ) + ); +} \ No newline at end of file diff --git a/src/main/resources/server/AttachBTree.java b/src/main/resources/server/AttachBTree.java index dfd5a8b..1ec0da3 100644 --- a/src/main/resources/server/AttachBTree.java +++ b/src/main/resources/server/AttachBTree.java @@ -1,6 +1,5 @@ /** *

(initially) Automatically generated

- *

More parameters can be safely added to this method

*

* Attaches this tree to the entity. *