Compare commits
2 Commits
e0b914b9b8
...
6390c0b0c2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6390c0b0c2 | ||
|
|
8e1559c764 |
@ -0,0 +1,35 @@
|
||||
package electrosphere.main.client.syncmanager;
|
||||
|
||||
import electrosphere.main.client.syncmanager.methods.UpdateEntityState;
|
||||
import electrosphere.main.source.VirtualClass;
|
||||
import electrosphere.main.targets.TargetFile;
|
||||
|
||||
/**
|
||||
* The client synchronization manager class
|
||||
*/
|
||||
public class ClientSynchronizationManager extends VirtualClass {
|
||||
|
||||
|
||||
//The target file for the current version of this class
|
||||
TargetFile file;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public ClientSynchronizationManager(TargetFile file) {
|
||||
super(
|
||||
file,
|
||||
"ClientSynchronizationManager",
|
||||
true
|
||||
);
|
||||
this.file = file;
|
||||
|
||||
//
|
||||
//
|
||||
// ADD METHODS HERE
|
||||
//
|
||||
//
|
||||
this.addMethod(new UpdateEntityState());
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,48 +1,32 @@
|
||||
package electrosphere.main.client;
|
||||
package electrosphere.main.client.syncmanager.methods;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import electrosphere.main.core.btree.BehaviorTree;
|
||||
import electrosphere.main.core.statics.btreeenum.BTreeIdEnum;
|
||||
import electrosphere.main.core.syncfield.SynchronizedField;
|
||||
import electrosphere.main.core.syncfield.SynchronizedType;
|
||||
import electrosphere.main.project.ProjectStructure;
|
||||
import electrosphere.main.source.VirtualClass;
|
||||
import electrosphere.main.targets.TargetFile;
|
||||
import electrosphere.main.util.ClassSourceUtils;
|
||||
import electrosphere.main.source.VirtualMethod;
|
||||
import electrosphere.main.util.TemplateInjectionUtils;
|
||||
|
||||
/**
|
||||
* The client synchronization manager class
|
||||
* Updates individual entity tree states
|
||||
*/
|
||||
public class ClientSynchronizationManager extends VirtualClass {
|
||||
public class UpdateEntityState implements VirtualMethod {
|
||||
|
||||
|
||||
//The target file for the current version of this class
|
||||
TargetFile file;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public ClientSynchronizationManager(TargetFile file) {
|
||||
super(
|
||||
file,
|
||||
"ClientSynchronizationManager",
|
||||
true
|
||||
);
|
||||
this.file = file;
|
||||
@Override
|
||||
public String getName(ProjectStructure projectStructure) {
|
||||
return "updateEntityState";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates the ClientSynchronizationManager with latest data in specific functions
|
||||
* @param structure The project texture
|
||||
*/
|
||||
@Override
|
||||
public void updateFile(ProjectStructure structure){
|
||||
public String getContent(ProjectStructure projectStructure) {
|
||||
String updateCases = "";
|
||||
for(BehaviorTree serverTree : structure.getBehaviorTrees()){
|
||||
for(BehaviorTree serverTree : projectStructure.getBehaviorTrees()){
|
||||
//counterintuitively, want to only update client for server behavior tree ids
|
||||
if(serverTree.isServer()){
|
||||
BehaviorTree clientEquivalent = structure.getTree(serverTree.getCorrespondingTreeName());
|
||||
BehaviorTree clientEquivalent = projectStructure.getTree(serverTree.getCorrespondingTreeName());
|
||||
updateCases = updateCases + " case BehaviorTreeIdEnums." + BTreeIdEnum.getTreeIdEnum(serverTree) + ": {\n";
|
||||
updateCases = updateCases + " switch(message.getfieldId()){\n";
|
||||
for(SynchronizedField field : serverTree.getSynchronizedFields()){
|
||||
@ -80,7 +64,7 @@ public class ClientSynchronizationManager extends VirtualClass {
|
||||
updateCases = updateCases + " } break;\n";
|
||||
} break;
|
||||
default: {
|
||||
SynchronizedType type = structure.getType(field.getTypeName());
|
||||
SynchronizedType type = projectStructure.getType(field.getTypeName());
|
||||
String typeClass = type.getTargetFile().getSource().getName();
|
||||
updateCases = updateCases + " case FieldIdEnums." + fieldIdVariable + ":{\n";
|
||||
updateCases = updateCases + " " + treeName + " tree = " + treeName + ".get" + treeName + "(entity);\n";
|
||||
@ -92,13 +76,23 @@ public class ClientSynchronizationManager extends VirtualClass {
|
||||
updateCases = updateCases + " }\n";
|
||||
updateCases = updateCases + " } break;\n";
|
||||
|
||||
//guarantee import
|
||||
// ClassSourceUtils.importClass(structure, clientSynchronizationManager, serverTree.getTargetFile().getQualifiedPath());
|
||||
ClassSourceUtils.importClass(structure, this.file, structure.getTree(serverTree.getCorrespondingTreeName()).getTargetFile().getQualifiedPath());
|
||||
// //guarantee import
|
||||
// ClassSourceUtils.importClass(structure, this.file, structure.getTree(serverTree.getCorrespondingTreeName()).getTargetFile().getQualifiedPath());
|
||||
}
|
||||
}
|
||||
ClassSourceUtils.importClass(structure, this.file, "electrosphere.net.synchronization.FieldIdEnums");
|
||||
String fullReplacementText = TemplateInjectionUtils.getFragmentWithReplacement("/client/UpdateEntityState.java", updateCases);
|
||||
ClassSourceUtils.addOrReplaceMethod(structure, this.file, "updateEntityState", fullReplacementText);
|
||||
return fullReplacementText;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getImports(ProjectStructure projectStructure) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getImports'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldOverwrite() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@ -3,9 +3,10 @@ package electrosphere.main.core;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import electrosphere.main.client.ClientSynchronizationManager;
|
||||
import electrosphere.main.client.syncmanager.ClientSynchronizationManager;
|
||||
import electrosphere.main.core.statics.btreeenum.BTreeIdEnum;
|
||||
import electrosphere.main.core.statics.fieldenum.FieldIdEnum;
|
||||
import electrosphere.main.project.ProjectStructure;
|
||||
import electrosphere.main.source.VirtualClass;
|
||||
import electrosphere.main.targets.TargetFile;
|
||||
|
||||
@ -70,4 +71,22 @@ public class VirtualProject {
|
||||
return this.clientSynchronizationManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a virtual class to the project
|
||||
* @param virtualClass The virtual class
|
||||
*/
|
||||
public void addClass(VirtualClass virtualClass){
|
||||
this.classes.add(virtualClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the new file contents for all files in the virtual project
|
||||
* @param structure The project structure
|
||||
*/
|
||||
public void generate(ProjectStructure structure){
|
||||
for(VirtualClass virtualClass : this.classes){
|
||||
virtualClass.generate(structure);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -6,7 +6,6 @@ import java.util.List;
|
||||
import electrosphere.main.core.syncfield.SynchronizedField;
|
||||
import electrosphere.main.source.VirtualClass;
|
||||
import electrosphere.main.targets.TargetFile;
|
||||
import electrosphere.main.util.TemplateInjectionUtils;
|
||||
|
||||
/**
|
||||
* Represents a behavior tree in the source code
|
||||
@ -132,20 +131,6 @@ public class BehaviorTree extends VirtualClass {
|
||||
return rVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the content for the attach method of this behavior tree
|
||||
* @param isServer true if this is a server behavior tree, false otherwise
|
||||
* @return The attach method content
|
||||
*/
|
||||
public String getAttachMethodContent(){
|
||||
String templateSource = "/server/AttachBTree.java";
|
||||
if(!isServer){
|
||||
templateSource = "/client/AttachBTree.java";
|
||||
}
|
||||
String rVal = TemplateInjectionUtils.getFragmentWithReplacement(templateSource, this.name.toUpperCase(), "TREE_" + this.name.toUpperCase(), className);
|
||||
return rVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the detatch method's name
|
||||
* @return The detatch method's name
|
||||
@ -156,19 +141,6 @@ public class BehaviorTree extends VirtualClass {
|
||||
return rVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the content for the detatch method
|
||||
* @return The content
|
||||
*/
|
||||
public String getDetachMethodContent(){
|
||||
String templateSource = "/server/DetachBTree.java";
|
||||
if(!isServer){
|
||||
templateSource = "/client/DetachBTree.java";
|
||||
}
|
||||
String rVal = TemplateInjectionUtils.getFragmentWithReplacement(templateSource, this.name.toUpperCase());
|
||||
return rVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the fetch method's name
|
||||
* @return The name
|
||||
@ -178,15 +150,6 @@ public class BehaviorTree extends VirtualClass {
|
||||
return rVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the content for the fetch method
|
||||
* @return The content
|
||||
*/
|
||||
public String getEntityFetchMethodContent(){
|
||||
String rVal = TemplateInjectionUtils.getFragmentWithReplacement("/btree/EntityFetchMethod.java", this.className, "TREE_" + this.name.toUpperCase());
|
||||
return rVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the constructor method's name
|
||||
* @return The constructor method's name
|
||||
@ -196,15 +159,6 @@ public class BehaviorTree extends VirtualClass {
|
||||
return rVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the constructor method's content
|
||||
* @return The content
|
||||
*/
|
||||
public String getConstructorMethodContent(){
|
||||
String rVal = TemplateInjectionUtils.getFragmentWithReplacement("/btree/Constructor.java", this.className);
|
||||
return rVal;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -0,0 +1,54 @@
|
||||
package electrosphere.main.core.btree.methods;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import electrosphere.main.project.ProjectStructure;
|
||||
import electrosphere.main.source.VirtualMethod;
|
||||
import electrosphere.main.util.TemplateInjectionUtils;
|
||||
|
||||
/**
|
||||
* Attach method for the b tree
|
||||
*/
|
||||
public class ClientAttach implements VirtualMethod {
|
||||
|
||||
//The name of the btree
|
||||
String name;
|
||||
|
||||
//The classname of the btree
|
||||
String className;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param name
|
||||
* @param className
|
||||
*/
|
||||
public ClientAttach(String name, String className){
|
||||
this.name = name;
|
||||
this.className = className;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(ProjectStructure projectStructure) {
|
||||
String rVal = "";
|
||||
rVal = "attachTree";
|
||||
return rVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContent(ProjectStructure projectStructure) {
|
||||
String rVal = TemplateInjectionUtils.getFragmentWithReplacement("/client/AttachBTree.java", this.name.toUpperCase(), "TREE_" + this.name.toUpperCase(), className);
|
||||
return rVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getImports(ProjectStructure projectStructure) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getImports'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldOverwrite(){
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
package electrosphere.main.core.btree.methods;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import electrosphere.main.project.ProjectStructure;
|
||||
import electrosphere.main.source.VirtualMethod;
|
||||
import electrosphere.main.util.TemplateInjectionUtils;
|
||||
|
||||
/**
|
||||
* Client detatch method
|
||||
*/
|
||||
public class ClientDetach implements VirtualMethod {
|
||||
|
||||
//The name of the btree
|
||||
String name;
|
||||
|
||||
//The classname of the btree
|
||||
String className;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param name
|
||||
* @param className
|
||||
*/
|
||||
public ClientDetach(String name, String className){
|
||||
this.name = name;
|
||||
this.className = className;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(ProjectStructure projectStructure) {
|
||||
String rVal = "";
|
||||
rVal = "detachTree";
|
||||
return rVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContent(ProjectStructure projectStructure) {
|
||||
String rVal = TemplateInjectionUtils.getFragmentWithReplacement("/client/DetachBTree.java", this.name.toUpperCase());
|
||||
return rVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getImports(ProjectStructure projectStructure) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getImports'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldOverwrite(){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,61 @@
|
||||
package electrosphere.main.core.btree.methods;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import electrosphere.main.core.btree.BehaviorTree;
|
||||
import electrosphere.main.project.ProjectStructure;
|
||||
import electrosphere.main.source.VirtualMethod;
|
||||
import electrosphere.main.util.TemplateInjectionUtils;
|
||||
import electrosphere.main.util.Utilities;
|
||||
|
||||
/**
|
||||
* A getter for a client field
|
||||
*/
|
||||
public class ClientFieldGetter implements VirtualMethod {
|
||||
|
||||
//the name of the field
|
||||
String fieldName;
|
||||
|
||||
//the name of the type of the field
|
||||
String typeName;
|
||||
|
||||
//The parent behavior tree
|
||||
BehaviorTree parent;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param tree The parent behavior tree
|
||||
* @param typeName The name of the type of the field
|
||||
* @param fieldName The name of the field
|
||||
*/
|
||||
public ClientFieldGetter(BehaviorTree tree, String typeName, String fieldName){
|
||||
this.parent = tree;
|
||||
this.typeName = typeName;
|
||||
this.fieldName = fieldName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(ProjectStructure projectStructure) {
|
||||
String rVal = "";
|
||||
rVal = "get" + Utilities.camelCase(fieldName);
|
||||
return rVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContent(ProjectStructure projectStructure) {
|
||||
String rVal = TemplateInjectionUtils.getFragmentWithReplacement("/client/Getter.java", fieldName, Utilities.camelCase(fieldName), typeName);
|
||||
return rVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getImports(ProjectStructure projectStructure) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getImports'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldOverwrite(){
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,61 @@
|
||||
package electrosphere.main.core.btree.methods;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import electrosphere.main.core.btree.BehaviorTree;
|
||||
import electrosphere.main.project.ProjectStructure;
|
||||
import electrosphere.main.source.VirtualMethod;
|
||||
import electrosphere.main.util.TemplateInjectionUtils;
|
||||
import electrosphere.main.util.Utilities;
|
||||
|
||||
/**
|
||||
* A setter on the client
|
||||
*/
|
||||
public class ClientFieldSetter implements VirtualMethod {
|
||||
|
||||
//the name of the field
|
||||
String fieldName;
|
||||
|
||||
//the name of the type of the field
|
||||
String typeName;
|
||||
|
||||
//The parent behavior tree
|
||||
BehaviorTree parent;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param tree The parent behavior tree
|
||||
* @param typeName The name of the type of the field
|
||||
* @param fieldName The name of the field
|
||||
*/
|
||||
public ClientFieldSetter(BehaviorTree tree, String typeName, String fieldName){
|
||||
this.parent = tree;
|
||||
this.typeName = typeName;
|
||||
this.fieldName = fieldName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(ProjectStructure projectStructure) {
|
||||
String rVal = "";
|
||||
rVal = "set" + Utilities.camelCase(fieldName);
|
||||
return rVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContent(ProjectStructure projectStructure) {
|
||||
String rVal = TemplateInjectionUtils.getFragmentWithReplacement("/client/Setter.java", fieldName, Utilities.camelCase(fieldName), typeName);
|
||||
return rVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getImports(ProjectStructure projectStructure) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getImports'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldOverwrite(){
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
package electrosphere.main.core.btree.methods;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import electrosphere.main.project.ProjectStructure;
|
||||
import electrosphere.main.source.VirtualMethod;
|
||||
import electrosphere.main.util.TemplateInjectionUtils;
|
||||
|
||||
/**
|
||||
* Private constructor method
|
||||
*/
|
||||
public class Constructor implements VirtualMethod {
|
||||
|
||||
//The name of the btree
|
||||
String name;
|
||||
|
||||
//The classname of the btree
|
||||
String className;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param name
|
||||
* @param className
|
||||
*/
|
||||
public Constructor(String name, String className){
|
||||
this.name = name;
|
||||
this.className = className;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(ProjectStructure projectStructure) {
|
||||
String rVal = className;
|
||||
return rVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContent(ProjectStructure projectStructure) {
|
||||
String rVal = TemplateInjectionUtils.getFragmentWithReplacement("/btree/Constructor.java", this.className);
|
||||
return rVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getImports(ProjectStructure projectStructure) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getImports'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldOverwrite(){
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,53 @@
|
||||
package electrosphere.main.core.btree.methods;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import electrosphere.main.project.ProjectStructure;
|
||||
import electrosphere.main.source.VirtualMethod;
|
||||
import electrosphere.main.util.TemplateInjectionUtils;
|
||||
|
||||
/**
|
||||
* Fetch btree from entity method
|
||||
*/
|
||||
public class Fetch implements VirtualMethod {
|
||||
|
||||
//The name of the btree
|
||||
String name;
|
||||
|
||||
//The classname of the btree
|
||||
String className;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param name
|
||||
* @param className
|
||||
*/
|
||||
public Fetch(String name, String className){
|
||||
this.name = name;
|
||||
this.className = className;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(ProjectStructure projectStructure) {
|
||||
String rVal = "get" + className;
|
||||
return rVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContent(ProjectStructure projectStructure) {
|
||||
String rVal = TemplateInjectionUtils.getFragmentWithReplacement("/btree/EntityFetchMethod.java", this.className, "TREE_" + this.name.toUpperCase());
|
||||
return rVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getImports(ProjectStructure projectStructure) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getImports'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldOverwrite(){
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,59 @@
|
||||
package electrosphere.main.core.btree.methods;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import electrosphere.main.core.syncfield.SynchronizedType;
|
||||
import electrosphere.main.project.ProjectStructure;
|
||||
import electrosphere.main.source.VirtualMethod;
|
||||
import electrosphere.main.util.TemplateInjectionUtils;
|
||||
import electrosphere.main.util.Utilities;
|
||||
|
||||
/**
|
||||
* Converts an enum into a short
|
||||
*/
|
||||
public class FromTypeConversion implements VirtualMethod {
|
||||
|
||||
//The synchronized type we're converting in this function
|
||||
SynchronizedType type;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param type The synchronized type
|
||||
*/
|
||||
public FromTypeConversion(SynchronizedType type){
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(ProjectStructure projectStructure) {
|
||||
return "get" + Utilities.camelCase(type.getName()) + "EnumAsShort";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContent(ProjectStructure projectStructure) {
|
||||
//get enum switch array
|
||||
String enumSwitchArray = "";
|
||||
int i = 0;
|
||||
for(String value : this.type.getValues()){
|
||||
enumSwitchArray = enumSwitchArray + " case " + value + ":\n";
|
||||
enumSwitchArray = enumSwitchArray + " return " + i + ";\n";
|
||||
i++;
|
||||
}
|
||||
//chop off last newline
|
||||
enumSwitchArray = enumSwitchArray.substring(0, enumSwitchArray.length() - 1);
|
||||
String rVal = TemplateInjectionUtils.getFragmentWithReplacement("/enum/EnumToShort.java", this.type.getName(), this.type.getName(), enumSwitchArray);
|
||||
return rVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getImports(ProjectStructure projectStructure) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getImports'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldOverwrite(){
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
package electrosphere.main.core.btree.methods;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import electrosphere.main.project.ProjectStructure;
|
||||
import electrosphere.main.source.VirtualMethod;
|
||||
import electrosphere.main.util.TemplateInjectionUtils;
|
||||
|
||||
/**
|
||||
* Attach method for server btree
|
||||
*/
|
||||
public class ServerAttach implements VirtualMethod {
|
||||
|
||||
//The name of the btree
|
||||
String name;
|
||||
|
||||
//The classname of the btree
|
||||
String className;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param name
|
||||
* @param className
|
||||
*/
|
||||
public ServerAttach(String name, String className){
|
||||
this.name = name;
|
||||
this.className = className;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(ProjectStructure projectStructure) {
|
||||
String rVal = "";
|
||||
rVal = "attachTree";
|
||||
return rVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContent(ProjectStructure projectStructure) {
|
||||
String rVal = TemplateInjectionUtils.getFragmentWithReplacement("/server/AttachBTree.java", this.name.toUpperCase(), "TREE_" + this.name.toUpperCase(), className);
|
||||
return rVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getImports(ProjectStructure projectStructure) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getImports'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldOverwrite(){
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,54 @@
|
||||
package electrosphere.main.core.btree.methods;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import electrosphere.main.project.ProjectStructure;
|
||||
import electrosphere.main.source.VirtualMethod;
|
||||
import electrosphere.main.util.TemplateInjectionUtils;
|
||||
|
||||
/**
|
||||
* Server detach method
|
||||
*/
|
||||
public class ServerDetach implements VirtualMethod {
|
||||
|
||||
//The name of the btree
|
||||
String name;
|
||||
|
||||
//The classname of the btree
|
||||
String className;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param name
|
||||
* @param className
|
||||
*/
|
||||
public ServerDetach(String name, String className){
|
||||
this.name = name;
|
||||
this.className = className;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(ProjectStructure projectStructure) {
|
||||
String rVal = "";
|
||||
rVal = "detachTree";
|
||||
return rVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContent(ProjectStructure projectStructure) {
|
||||
String rVal = TemplateInjectionUtils.getFragmentWithReplacement("/server/DetachBTree.java", this.name.toUpperCase());
|
||||
return rVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getImports(ProjectStructure projectStructure) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getImports'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldOverwrite(){
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,59 @@
|
||||
package electrosphere.main.core.btree.methods;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import electrosphere.main.core.btree.BehaviorTree;
|
||||
import electrosphere.main.project.ProjectStructure;
|
||||
import electrosphere.main.source.VirtualMethod;
|
||||
import electrosphere.main.util.TemplateInjectionUtils;
|
||||
import electrosphere.main.util.Utilities;
|
||||
|
||||
/**
|
||||
* A server getter for a field
|
||||
*/
|
||||
public class ServerFieldGetter implements VirtualMethod {
|
||||
//the name of the field
|
||||
String fieldName;
|
||||
|
||||
//the name of the type of the field
|
||||
String typeName;
|
||||
|
||||
//The parent behavior tree
|
||||
BehaviorTree parent;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param tree The parent behavior tree
|
||||
* @param typeName The name of the type of the field
|
||||
* @param fieldName The name of the field
|
||||
*/
|
||||
public ServerFieldGetter(BehaviorTree tree, String typeName, String fieldName){
|
||||
this.parent = tree;
|
||||
this.typeName = typeName;
|
||||
this.fieldName = fieldName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(ProjectStructure projectStructure) {
|
||||
String rVal = "";
|
||||
rVal = "get" + Utilities.camelCase(fieldName);
|
||||
return rVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContent(ProjectStructure projectStructure) {
|
||||
String rVal = TemplateInjectionUtils.getFragmentWithReplacement("/server/Getter.java", fieldName, Utilities.camelCase(fieldName), typeName);
|
||||
return rVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getImports(ProjectStructure projectStructure) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getImports'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldOverwrite(){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,91 @@
|
||||
package electrosphere.main.core.btree.methods;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import electrosphere.main.core.btree.BehaviorTree;
|
||||
import electrosphere.main.core.syncfield.SynchronizedType;
|
||||
import electrosphere.main.project.ProjectStructure;
|
||||
import electrosphere.main.source.VirtualMethod;
|
||||
import electrosphere.main.util.TemplateInjectionUtils;
|
||||
import electrosphere.main.util.Utilities;
|
||||
|
||||
/**
|
||||
* A server setter
|
||||
*/
|
||||
public class ServerFieldSetter implements VirtualMethod {
|
||||
|
||||
//the name of the field
|
||||
String fieldName;
|
||||
|
||||
//the name of the type of the field
|
||||
String typeName;
|
||||
|
||||
//The parent behavior tree
|
||||
BehaviorTree parent;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param tree The parent behavior tree
|
||||
* @param typeName The name of the type of the field
|
||||
* @param fieldName The name of the field
|
||||
*/
|
||||
public ServerFieldSetter(BehaviorTree tree, String typeName, String fieldName){
|
||||
this.parent = tree;
|
||||
this.typeName = typeName;
|
||||
this.fieldName = fieldName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(ProjectStructure projectStructure){
|
||||
return "set" + Utilities.camelCase(fieldName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContent(ProjectStructure projectStructure){
|
||||
String rVal = null;
|
||||
String bTreeIdVariable = "BehaviorTreeIdEnums.BTREE_" + this.parent.getName().toUpperCase() + "_ID";
|
||||
String fieldIdVariable = "FieldIdEnums.TREE_" + this.parent.getName().toUpperCase() + "_SYNCEDFIELD_" + this.fieldName.toUpperCase() + "_ID";
|
||||
switch(typeName){
|
||||
case "long": {
|
||||
String packetContentFiller = " DataCellSearchUtils.getEntityDataCell(parent).broadcastNetworkMessage(SynchronizationMessage.constructUpdateClientLongStateMessage(parent.getId(), " + bTreeIdVariable + ", " + fieldIdVariable + ", " + fieldName + "));";
|
||||
rVal = TemplateInjectionUtils.getFragmentWithReplacement("/server/Setter.java", fieldName, Utilities.camelCase(fieldName), typeName, packetContentFiller);
|
||||
} break;
|
||||
case "float": {
|
||||
String packetContentFiller = " DataCellSearchUtils.getEntityDataCell(parent).broadcastNetworkMessage(SynchronizationMessage.constructUpdateClientFloatStateMessage(parent.getId(), " + bTreeIdVariable + ", " + fieldIdVariable + ", " + fieldName + "));";
|
||||
rVal = TemplateInjectionUtils.getFragmentWithReplacement("/server/Setter.java", fieldName, Utilities.camelCase(fieldName), typeName, packetContentFiller);
|
||||
} break;
|
||||
case "double":
|
||||
{
|
||||
String packetContentFiller = " DataCellSearchUtils.getEntityDataCell(parent).broadcastNetworkMessage(SynchronizationMessage.constructUpdateClientDoubleStateMessage(parent.getId(), " + bTreeIdVariable + ", " + fieldIdVariable + ", " + fieldName + "));";
|
||||
rVal = TemplateInjectionUtils.getFragmentWithReplacement("/server/Setter.java", fieldName, Utilities.camelCase(fieldName), typeName, packetContentFiller);
|
||||
} break;
|
||||
case "int": {
|
||||
String packetContentFiller = " DataCellSearchUtils.getEntityDataCell(parent).broadcastNetworkMessage(SynchronizationMessage.constructUpdateClientIntStateMessage(parent.getId(), " + bTreeIdVariable + ", " + fieldIdVariable + ", " + fieldName + "));";
|
||||
rVal = TemplateInjectionUtils.getFragmentWithReplacement("/server/Setter.java", fieldName, Utilities.camelCase(fieldName), typeName, packetContentFiller);
|
||||
} break;
|
||||
case "String": {
|
||||
String packetContentFiller = " DataCellSearchUtils.getEntityDataCell(parent).broadcastNetworkMessage(SynchronizationMessage.constructUpdateClientStringStateMessage(parent.getId(), " + bTreeIdVariable + ", " + fieldIdVariable + ", " + fieldName + "));";
|
||||
rVal = TemplateInjectionUtils.getFragmentWithReplacement("/server/Setter.java", fieldName, Utilities.camelCase(fieldName), typeName, packetContentFiller);
|
||||
} break;
|
||||
default: {
|
||||
SynchronizedType type = projectStructure.getType(typeName);
|
||||
String packetContentFiller = " int value = " + type.getContainingClassName() + "." + type.getToShortConversionMethodName() + "(" + fieldName + ");\n";
|
||||
packetContentFiller = packetContentFiller + " DataCellSearchUtils.getEntityDataCell(parent).broadcastNetworkMessage(SynchronizationMessage.constructUpdateClientStateMessage(parent.getId(), " + bTreeIdVariable + ", " + fieldIdVariable + ", value));";
|
||||
rVal = TemplateInjectionUtils.getFragmentWithReplacement("/server/Setter.java", fieldName, Utilities.camelCase(fieldName), typeName, packetContentFiller);
|
||||
} break;
|
||||
}
|
||||
return rVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getImports(ProjectStructure projectStructure) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getImports'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldOverwrite(){
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,62 @@
|
||||
package electrosphere.main.core.btree.methods;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import electrosphere.main.core.syncfield.SynchronizedType;
|
||||
import electrosphere.main.project.ProjectStructure;
|
||||
import electrosphere.main.source.VirtualMethod;
|
||||
import electrosphere.main.util.TemplateInjectionUtils;
|
||||
import electrosphere.main.util.Utilities;
|
||||
|
||||
/**
|
||||
* Converts a short to the specified synchronized type
|
||||
*/
|
||||
public class ToTypeConversion implements VirtualMethod {
|
||||
|
||||
//The synchronized type we're converting in this function
|
||||
SynchronizedType type;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param type The synchronized type
|
||||
*/
|
||||
public ToTypeConversion(SynchronizedType type){
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName(ProjectStructure projectStructure) {
|
||||
return "get" + Utilities.camelCase(type.getName()) + "ShortAsEnum";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContent(ProjectStructure projectStructure) {
|
||||
//get enum switch array
|
||||
String enumSwitchArray = "";
|
||||
int i = 0;
|
||||
for(String value : type.getValues()){
|
||||
enumSwitchArray = enumSwitchArray + " case " + i + ":\n";
|
||||
enumSwitchArray = enumSwitchArray + " return " + this.type.getName() + "." + value + ";\n";
|
||||
i++;
|
||||
}
|
||||
//add default case
|
||||
enumSwitchArray = enumSwitchArray + " default:\n";
|
||||
enumSwitchArray = enumSwitchArray + " return " + this.type.getName() + "." + type.getValues().get(0) + ";\n";
|
||||
//chop off last newline
|
||||
enumSwitchArray = enumSwitchArray.substring(0, enumSwitchArray.length() - 1);
|
||||
String rVal = TemplateInjectionUtils.getFragmentWithReplacement("/enum/ShortToEnum.java", this.type.getName(), this.type.getName(), enumSwitchArray);
|
||||
return rVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getImports(ProjectStructure projectStructure) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getImports'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldOverwrite(){
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,9 +1,7 @@
|
||||
package electrosphere.main.core.syncfield;
|
||||
|
||||
import electrosphere.main.core.btree.BehaviorTree;
|
||||
import electrosphere.main.project.ProjectStructure;
|
||||
import electrosphere.main.targets.TargetFile;
|
||||
import electrosphere.main.util.TemplateInjectionUtils;
|
||||
import electrosphere.main.util.Utilities;
|
||||
|
||||
/**
|
||||
@ -41,22 +39,20 @@ public class SynchronizedField {
|
||||
this.targetFile = targetFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the getter method for this field
|
||||
* @return The name of the getter method
|
||||
*/
|
||||
public String getGetterName(){
|
||||
String rVal = "";
|
||||
rVal = "get" + Utilities.camelCase(fieldName);
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public String getServerGetterContent(){
|
||||
String rVal = TemplateInjectionUtils.getFragmentWithReplacement("/server/Getter.java", fieldName, Utilities.camelCase(fieldName), typeName);
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public String getClientGetterContent(){
|
||||
String rVal = TemplateInjectionUtils.getFragmentWithReplacement("/client/Getter.java", fieldName, Utilities.camelCase(fieldName), typeName);
|
||||
return rVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the setter method for this field
|
||||
* @return The name of the setter method
|
||||
*/
|
||||
public String getSetterName(){
|
||||
String rVal = "";
|
||||
rVal = "set" + Utilities.camelCase(fieldName);
|
||||
@ -71,47 +67,6 @@ public class SynchronizedField {
|
||||
this.parent = tree;
|
||||
}
|
||||
|
||||
public String getServerSetterContent(ProjectStructure structure){
|
||||
String rVal = null;
|
||||
String bTreeIdVariable = "BehaviorTreeIdEnums.BTREE_" + this.parent.getName().toUpperCase() + "_ID";
|
||||
String fieldIdVariable = "FieldIdEnums.TREE_" + this.parent.getName().toUpperCase() + "_SYNCEDFIELD_" + this.fieldName.toUpperCase() + "_ID";
|
||||
switch(typeName){
|
||||
case "long": {
|
||||
String packetContentFiller = " DataCellSearchUtils.getEntityDataCell(parent).broadcastNetworkMessage(SynchronizationMessage.constructUpdateClientLongStateMessage(parent.getId(), " + bTreeIdVariable + ", " + fieldIdVariable + ", " + fieldName + "));";
|
||||
rVal = TemplateInjectionUtils.getFragmentWithReplacement("/server/Setter.java", fieldName, Utilities.camelCase(fieldName), typeName, packetContentFiller);
|
||||
} break;
|
||||
case "float": {
|
||||
String packetContentFiller = " DataCellSearchUtils.getEntityDataCell(parent).broadcastNetworkMessage(SynchronizationMessage.constructUpdateClientFloatStateMessage(parent.getId(), " + bTreeIdVariable + ", " + fieldIdVariable + ", " + fieldName + "));";
|
||||
rVal = TemplateInjectionUtils.getFragmentWithReplacement("/server/Setter.java", fieldName, Utilities.camelCase(fieldName), typeName, packetContentFiller);
|
||||
} break;
|
||||
case "double":
|
||||
{
|
||||
String packetContentFiller = " DataCellSearchUtils.getEntityDataCell(parent).broadcastNetworkMessage(SynchronizationMessage.constructUpdateClientDoubleStateMessage(parent.getId(), " + bTreeIdVariable + ", " + fieldIdVariable + ", " + fieldName + "));";
|
||||
rVal = TemplateInjectionUtils.getFragmentWithReplacement("/server/Setter.java", fieldName, Utilities.camelCase(fieldName), typeName, packetContentFiller);
|
||||
} break;
|
||||
case "int": {
|
||||
String packetContentFiller = " DataCellSearchUtils.getEntityDataCell(parent).broadcastNetworkMessage(SynchronizationMessage.constructUpdateClientIntStateMessage(parent.getId(), " + bTreeIdVariable + ", " + fieldIdVariable + ", " + fieldName + "));";
|
||||
rVal = TemplateInjectionUtils.getFragmentWithReplacement("/server/Setter.java", fieldName, Utilities.camelCase(fieldName), typeName, packetContentFiller);
|
||||
} break;
|
||||
case "String": {
|
||||
String packetContentFiller = " DataCellSearchUtils.getEntityDataCell(parent).broadcastNetworkMessage(SynchronizationMessage.constructUpdateClientStringStateMessage(parent.getId(), " + bTreeIdVariable + ", " + fieldIdVariable + ", " + fieldName + "));";
|
||||
rVal = TemplateInjectionUtils.getFragmentWithReplacement("/server/Setter.java", fieldName, Utilities.camelCase(fieldName), typeName, packetContentFiller);
|
||||
} break;
|
||||
default: {
|
||||
SynchronizedType type = structure.getType(typeName);
|
||||
String packetContentFiller = " int value = " + type.getContainingClassName() + "." + type.getToShortConversionMethodName() + "(" + fieldName + ");\n";
|
||||
packetContentFiller = packetContentFiller + " DataCellSearchUtils.getEntityDataCell(parent).broadcastNetworkMessage(SynchronizationMessage.constructUpdateClientStateMessage(parent.getId(), " + bTreeIdVariable + ", " + fieldIdVariable + ", value));";
|
||||
rVal = TemplateInjectionUtils.getFragmentWithReplacement("/server/Setter.java", fieldName, Utilities.camelCase(fieldName), typeName, packetContentFiller);
|
||||
} break;
|
||||
}
|
||||
return rVal;
|
||||
}
|
||||
|
||||
public String getClientSetterContent(ProjectStructure structure){
|
||||
String rVal = TemplateInjectionUtils.getFragmentWithReplacement("/client/Setter.java", fieldName, Utilities.camelCase(fieldName), typeName);
|
||||
return rVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the id of this field
|
||||
* @return The id
|
||||
|
||||
@ -3,7 +3,6 @@ package electrosphere.main.core.syncfield;
|
||||
import java.util.List;
|
||||
|
||||
import electrosphere.main.targets.TargetFile;
|
||||
import electrosphere.main.util.TemplateInjectionUtils;
|
||||
import electrosphere.main.util.Utilities;
|
||||
|
||||
/**
|
||||
@ -58,25 +57,6 @@ public class SynchronizedType {
|
||||
return "get" + Utilities.camelCase(name) + "EnumAsShort";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the content of the function that converts this synchronized type TO a short
|
||||
* @return The content
|
||||
*/
|
||||
public String getToShortConversionMethodContent(){
|
||||
//get enum switch array
|
||||
String enumSwitchArray = "";
|
||||
int i = 0;
|
||||
for(String value : values){
|
||||
enumSwitchArray = enumSwitchArray + " case " + value + ":\n";
|
||||
enumSwitchArray = enumSwitchArray + " return " + i + ";\n";
|
||||
i++;
|
||||
}
|
||||
//chop off last newline
|
||||
enumSwitchArray = enumSwitchArray.substring(0, enumSwitchArray.length() - 1);
|
||||
String rVal = TemplateInjectionUtils.getFragmentWithReplacement("/enum/EnumToShort.java", this.name, this.name, enumSwitchArray);
|
||||
return rVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the function that converts this synchronized type FROM a short
|
||||
* @return The name
|
||||
@ -85,28 +65,6 @@ public class SynchronizedType {
|
||||
return "get" + Utilities.camelCase(name) + "ShortAsEnum";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the content of the function that converts this synchronized type TO a short
|
||||
* @return The content
|
||||
*/
|
||||
public String getFromShortConversionMethodContent(){
|
||||
//get enum switch array
|
||||
String enumSwitchArray = "";
|
||||
int i = 0;
|
||||
for(String value : values){
|
||||
enumSwitchArray = enumSwitchArray + " case " + i + ":\n";
|
||||
enumSwitchArray = enumSwitchArray + " return " + this.name + "." + value + ";\n";
|
||||
i++;
|
||||
}
|
||||
//add default case
|
||||
enumSwitchArray = enumSwitchArray + " default:\n";
|
||||
enumSwitchArray = enumSwitchArray + " return " + this.name + "." + values.get(0) + ";\n";
|
||||
//chop off last newline
|
||||
enumSwitchArray = enumSwitchArray.substring(0, enumSwitchArray.length() - 1);
|
||||
String rVal = TemplateInjectionUtils.getFragmentWithReplacement("/enum/ShortToEnum.java", this.name, this.name, enumSwitchArray);
|
||||
return rVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the name of the class containing the declaration of this type
|
||||
* @return
|
||||
@ -123,4 +81,12 @@ public class SynchronizedType {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the available values
|
||||
* @return The available values
|
||||
*/
|
||||
public List<String> getValues(){
|
||||
return this.values;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -4,14 +4,12 @@ import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
import electrosphere.main.Main;
|
||||
import electrosphere.main.core.VirtualProject;
|
||||
import electrosphere.main.core.btree.BehaviorTree;
|
||||
import electrosphere.main.core.syncfield.SynchronizedField;
|
||||
import electrosphere.main.core.syncfield.SynchronizedType;
|
||||
import electrosphere.main.project.parsers.MainParser;
|
||||
import electrosphere.main.targets.TargetFile;
|
||||
import electrosphere.main.util.ClassSourceUtils;
|
||||
|
||||
/**
|
||||
* Container for overall structure of the project
|
||||
@ -57,70 +55,71 @@ public class ProjectStructure {
|
||||
* Main code generation routine
|
||||
*/
|
||||
public void generate(){
|
||||
this.virtualProject.generate(this);
|
||||
//generate in-class functions for btrees
|
||||
for(BehaviorTree tree : this.getBehaviorTrees()){
|
||||
if(Main.LOG){
|
||||
System.out.println("Generating for " + tree.getClassName());
|
||||
}
|
||||
//server side getter + setter
|
||||
if(tree.isServer()){
|
||||
// for(BehaviorTree tree : this.getBehaviorTrees()){
|
||||
// if(Main.LOG){
|
||||
// System.out.println("Generating for " + tree.getClassName());
|
||||
// }
|
||||
// //server side getter + setter
|
||||
// if(tree.isServer()){
|
||||
|
||||
|
||||
|
||||
for(SynchronizedField field : tree.getSynchronizedFields()){
|
||||
ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), field.getGetterName(), field.getServerGetterContent());
|
||||
ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), field.getSetterName(), field.getServerSetterContent(this));
|
||||
}
|
||||
//attach + detatch methods
|
||||
ClassSourceUtils.addMethodIfAbsent(this, tree.getTargetFile(), tree.getAttachMethodName(), tree.getAttachMethodContent());
|
||||
ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), tree.getDetachMethodName(), tree.getDetachMethodContent());
|
||||
//imports
|
||||
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.engine.Globals");
|
||||
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.server.datacell.utils.DataCellSearchUtils");
|
||||
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.net.parser.net.message.SynchronizationMessage");
|
||||
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.server.datacell.utils.ServerBehaviorTreeUtils");
|
||||
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.entity.Entity");
|
||||
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.entity.EntityDataStrings");
|
||||
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.entity.btree.BehaviorTree");
|
||||
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.net.synchronization.BehaviorTreeIdEnums");
|
||||
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.net.synchronization.FieldIdEnums");
|
||||
} else {
|
||||
// // for(SynchronizedField field : tree.getSynchronizedFields()){
|
||||
// // // ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), field.getGetterName(), field.getServerGetterContent());
|
||||
// // // ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), field.getSetterName(), field.getServerSetterContent(this));
|
||||
// // }
|
||||
// //attach + detatch methods
|
||||
// // ClassSourceUtils.addMethodIfAbsent(this, tree.getTargetFile(), tree.getAttachMethodName(), tree.getAttachMethodContent());
|
||||
// // ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), tree.getDetachMethodName(), tree.getDetachMethodContent());
|
||||
// //imports
|
||||
// // ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.engine.Globals");
|
||||
// // ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.server.datacell.utils.DataCellSearchUtils");
|
||||
// // ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.net.parser.net.message.SynchronizationMessage");
|
||||
// // ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.server.datacell.utils.ServerBehaviorTreeUtils");
|
||||
// // ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.entity.Entity");
|
||||
// // ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.entity.EntityDataStrings");
|
||||
// // ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.entity.btree.BehaviorTree");
|
||||
// // ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.net.synchronization.BehaviorTreeIdEnums");
|
||||
// // ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.net.synchronization.FieldIdEnums");
|
||||
// } else {
|
||||
|
||||
|
||||
|
||||
for(SynchronizedField field : tree.getSynchronizedFields()){
|
||||
ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), field.getGetterName(), field.getClientGetterContent());
|
||||
ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), field.getSetterName(), field.getClientSetterContent(this));
|
||||
}
|
||||
//attach + detatch methods
|
||||
ClassSourceUtils.addMethodIfAbsent(this, tree.getTargetFile(), tree.getAttachMethodName(), tree.getAttachMethodContent());
|
||||
ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), tree.getDetachMethodName(), tree.getDetachMethodContent());
|
||||
//imports
|
||||
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.engine.Globals"); // for client scene wrapper
|
||||
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.entity.Entity");
|
||||
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.entity.EntityDataStrings");
|
||||
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.entity.btree.BehaviorTree");
|
||||
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.net.synchronization.BehaviorTreeIdEnums");
|
||||
}
|
||||
// // for(SynchronizedField field : tree.getSynchronizedFields()){
|
||||
// // // ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), field.getGetterName(), field.getClientGetterContent());
|
||||
// // // ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), field.getSetterName(), field.getClientSetterContent(this));
|
||||
// // }
|
||||
// //attach + detatch methods
|
||||
// // ClassSourceUtils.addMethodIfAbsent(this, tree.getTargetFile(), tree.getAttachMethodName(), tree.getAttachMethodContent());
|
||||
// // ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), tree.getDetachMethodName(), tree.getDetachMethodContent());
|
||||
// //imports
|
||||
// // ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.engine.Globals"); // for client scene wrapper
|
||||
// // ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.entity.Entity");
|
||||
// // ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.entity.EntityDataStrings");
|
||||
// // ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.entity.btree.BehaviorTree");
|
||||
// // ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.net.synchronization.BehaviorTreeIdEnums");
|
||||
// }
|
||||
|
||||
|
||||
//private constructor
|
||||
ClassSourceUtils.addMethodIfAbsent(this, tree.getTargetFile(), tree.getConstructorMethodName(), tree.getConstructorMethodContent());
|
||||
//guarantee entity fetch method
|
||||
ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), tree.getEntityFetchMethodName(), tree.getEntityFetchMethodContent());
|
||||
//guarantee imports of required files (btree enum, etc)
|
||||
ClassSourceUtils.importClass(this, tree.getTargetFile(), this.virtualProject.getBTreeIdEnum().getQualifiedPath(this));
|
||||
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.entity.EntityDataStrings");
|
||||
}
|
||||
//generate enums for all synchronized types
|
||||
for(SynchronizedType type : this.mainParser.getSynchronizedTypes()){
|
||||
ClassSourceUtils.addOrReplaceMethod(this, type.getTargetFile(), type.getToShortConversionMethodName(), type.getToShortConversionMethodContent());
|
||||
ClassSourceUtils.addOrReplaceMethod(this, type.getTargetFile(), type.getFromShortConversionMethodName(), type.getFromShortConversionMethodContent());
|
||||
}
|
||||
this.virtualProject.getBTreeIdEnum().generate(this);
|
||||
this.virtualProject.getFieldIdEnum().generate(this);
|
||||
//client sync manager
|
||||
this.virtualProject.getClientSynchronizationManager().generate(this);
|
||||
// //private constructor
|
||||
// // ClassSourceUtils.addMethodIfAbsent(this, tree.getTargetFile(), tree.getConstructorMethodName(), tree.getConstructorMethodContent());
|
||||
// //guarantee entity fetch method
|
||||
// // ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), tree.getEntityFetchMethodName(), tree.getEntityFetchMethodContent());
|
||||
// //guarantee imports of required files (btree enum, etc)
|
||||
// // ClassSourceUtils.importClass(this, tree.getTargetFile(), this.virtualProject.getBTreeIdEnum().getQualifiedPath(this));
|
||||
// // ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.entity.EntityDataStrings");
|
||||
// }
|
||||
// //generate enums for all synchronized types
|
||||
// // for(SynchronizedType type : this.mainParser.getSynchronizedTypes()){
|
||||
// // ClassSourceUtils.addOrReplaceMethod(this, type.getTargetFile(), type.getToShortConversionMethodName(), type.getToShortConversionMethodContent());
|
||||
// // ClassSourceUtils.addOrReplaceMethod(this, type.getTargetFile(), type.getFromShortConversionMethodName(), type.getFromShortConversionMethodContent());
|
||||
// // }
|
||||
// // this.virtualProject.getBTreeIdEnum().generate(this);
|
||||
// // this.virtualProject.getFieldIdEnum().generate(this);
|
||||
// // //client sync manager
|
||||
// // this.virtualProject.getClientSynchronizationManager().generate(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -11,6 +11,12 @@ import org.jboss.forge.roaster.model.source.FieldSource;
|
||||
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.Constructor;
|
||||
import electrosphere.main.core.btree.methods.Fetch;
|
||||
import electrosphere.main.core.btree.methods.ServerAttach;
|
||||
import electrosphere.main.core.btree.methods.ServerDetach;
|
||||
import electrosphere.main.targets.TargetFile;
|
||||
|
||||
/**
|
||||
@ -60,6 +66,22 @@ public class BTreeParser {
|
||||
target
|
||||
);
|
||||
behaviorTrees.add(rVal);
|
||||
|
||||
//
|
||||
//
|
||||
// ADD METHODS HERE
|
||||
//
|
||||
//
|
||||
if(isServer){
|
||||
rVal.addMethod(new ServerAttach(bTreeName, target.getSource().getName()));
|
||||
rVal.addMethod(new ServerDetach(bTreeName, target.getSource().getName()));
|
||||
} else {
|
||||
rVal.addMethod(new ClientAttach(bTreeName, target.getSource().getName()));
|
||||
rVal.addMethod(new ClientDetach(bTreeName, target.getSource().getName()));
|
||||
}
|
||||
|
||||
rVal.addMethod(new Constructor(bTreeName, target.getSource().getName()));
|
||||
rVal.addMethod(new Fetch(bTreeName, target.getSource().getName()));
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@ -4,6 +4,10 @@ import java.util.List;
|
||||
|
||||
import electrosphere.main.core.VirtualProject;
|
||||
import electrosphere.main.core.btree.BehaviorTree;
|
||||
import electrosphere.main.core.btree.methods.ClientFieldSetter;
|
||||
import electrosphere.main.core.btree.methods.FromTypeConversion;
|
||||
import electrosphere.main.core.btree.methods.ServerFieldSetter;
|
||||
import electrosphere.main.core.btree.methods.ToTypeConversion;
|
||||
import electrosphere.main.core.syncfield.SynchronizedField;
|
||||
import electrosphere.main.core.syncfield.SynchronizedType;
|
||||
import electrosphere.main.targets.TargetFile;
|
||||
@ -47,7 +51,7 @@ public class MainParser {
|
||||
BehaviorTree bTree = this.bTreeParser.parse(target);
|
||||
List<SynchronizedType> types = this.enumParser.parse(target, typeIterator);
|
||||
List<SynchronizedField> fields = this.fieldParser.parse(target);
|
||||
linkData(bTree, fields, types);
|
||||
linkData(rVal, bTree, fields, types);
|
||||
|
||||
//
|
||||
//specific cases
|
||||
@ -63,16 +67,27 @@ public class MainParser {
|
||||
|
||||
/**
|
||||
* Links all the values gathered from a behavior tree file
|
||||
* @param rVal The virtual project
|
||||
* @param tree The tree
|
||||
* @param fields The list of fields
|
||||
* @param types The list of types
|
||||
*/
|
||||
private void linkData(BehaviorTree tree, List<SynchronizedField> fields, List<SynchronizedType> types){
|
||||
private void linkData(VirtualProject rVal, BehaviorTree tree, List<SynchronizedField> fields, List<SynchronizedType> types){
|
||||
if(tree != null){
|
||||
rVal.addClass(tree);
|
||||
//link fields
|
||||
for(SynchronizedField field : fields){
|
||||
field.setParent(tree);
|
||||
tree.addSynchronizedField(field);
|
||||
if(tree.isServer()){
|
||||
tree.addMethod(new ServerFieldSetter(tree, field.getTypeName(), field.getFieldName()));
|
||||
} else {
|
||||
tree.addMethod(new ClientFieldSetter(tree, field.getTypeName(), field.getFieldName()));
|
||||
}
|
||||
}
|
||||
for(SynchronizedType type : types){
|
||||
tree.addMethod(new ToTypeConversion(type));
|
||||
tree.addMethod(new FromTypeConversion(type));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package electrosphere.main.source;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import electrosphere.main.project.ProjectStructure;
|
||||
@ -23,17 +24,17 @@ public abstract class VirtualClass {
|
||||
/**
|
||||
* All the imports in this virtual class
|
||||
*/
|
||||
List<String> imports;
|
||||
List<String> imports = new LinkedList<String>();
|
||||
|
||||
/**
|
||||
* All the fields in this class
|
||||
*/
|
||||
List<VirtualField> fields;
|
||||
List<VirtualField> fields = new LinkedList<VirtualField>();
|
||||
|
||||
/**
|
||||
* All the methods in this class
|
||||
*/
|
||||
List<VirtualMethod> methods;
|
||||
List<VirtualMethod> methods = new LinkedList<VirtualMethod>();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@ -78,6 +79,7 @@ public abstract class VirtualClass {
|
||||
* @param structure The project
|
||||
*/
|
||||
public void generate(ProjectStructure structure){
|
||||
System.out.println("Generating for " + this.CLASSNAME);
|
||||
if(this.shouldUpdate){
|
||||
this.updateFile(structure);
|
||||
} else {
|
||||
@ -90,7 +92,19 @@ public abstract class VirtualClass {
|
||||
* @param structure The project
|
||||
*/
|
||||
public void updateFile(ProjectStructure structure){
|
||||
throw new UnsupportedOperationException("Not yet implemented!");
|
||||
for(VirtualMethod method : this.methods){
|
||||
if(method.shouldOverwrite()){
|
||||
ClassSourceUtils.addOrReplaceMethod(structure, this.targetFile, method.getName(structure), method.getContent(structure));
|
||||
} else {
|
||||
ClassSourceUtils.addMethodIfAbsent(structure, this.targetFile, method.getName(structure), method.getContent(structure));
|
||||
}
|
||||
}
|
||||
// for(VirtualField field : this.fields){
|
||||
// throw new UnsupportedOperationException("updating fields not supported yet!");
|
||||
// }
|
||||
for(String currentImport : this.imports){
|
||||
ClassSourceUtils.importClass(structure, this.targetFile, currentImport);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -101,5 +115,13 @@ public abstract class VirtualClass {
|
||||
throw new UnsupportedOperationException("Not yet implemented!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a virtual method
|
||||
* @param method The virtual method
|
||||
*/
|
||||
public void addMethod(VirtualMethod method){
|
||||
this.methods.add(method);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -2,6 +2,8 @@ package electrosphere.main.source;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import electrosphere.main.project.ProjectStructure;
|
||||
|
||||
/**
|
||||
* Represents a method in a class
|
||||
*/
|
||||
@ -9,21 +11,30 @@ public interface VirtualMethod {
|
||||
|
||||
/**
|
||||
* Gets the name of the method
|
||||
* @param projectStructure The project structure
|
||||
* @return The name of the method
|
||||
*/
|
||||
public String getName();
|
||||
public String getName(ProjectStructure projectStructure);
|
||||
|
||||
|
||||
/**
|
||||
* Gets the content of this method
|
||||
* @param projectStructure The project structure
|
||||
* @return The content
|
||||
*/
|
||||
public String getContent();
|
||||
public String getContent(ProjectStructure projectStructure);
|
||||
|
||||
/**
|
||||
* Gets the list of imports required for this method
|
||||
* @param projectStructure The project structure
|
||||
* @return The list of imports
|
||||
*/
|
||||
public List<String> getImports();
|
||||
public List<String> getImports(ProjectStructure projectStructure);
|
||||
|
||||
/**
|
||||
* Gets whether the method should be overwritten, or just initially populated
|
||||
* @return true if should be overwritten, false if should just be initially populated
|
||||
*/
|
||||
public boolean shouldOverwrite();
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user