refactoring generating methods for behavior tree
This commit is contained in:
parent
e0b914b9b8
commit
8e1559c764
@ -6,6 +6,7 @@ import java.util.List;
|
|||||||
import electrosphere.main.client.ClientSynchronizationManager;
|
import electrosphere.main.client.ClientSynchronizationManager;
|
||||||
import electrosphere.main.core.statics.btreeenum.BTreeIdEnum;
|
import electrosphere.main.core.statics.btreeenum.BTreeIdEnum;
|
||||||
import electrosphere.main.core.statics.fieldenum.FieldIdEnum;
|
import electrosphere.main.core.statics.fieldenum.FieldIdEnum;
|
||||||
|
import electrosphere.main.project.ProjectStructure;
|
||||||
import electrosphere.main.source.VirtualClass;
|
import electrosphere.main.source.VirtualClass;
|
||||||
import electrosphere.main.targets.TargetFile;
|
import electrosphere.main.targets.TargetFile;
|
||||||
|
|
||||||
@ -70,4 +71,22 @@ public class VirtualProject {
|
|||||||
return this.clientSynchronizationManager;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -132,20 +132,6 @@ public class BehaviorTree extends VirtualClass {
|
|||||||
return rVal;
|
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
|
* Gets the detatch method's name
|
||||||
* @return The detatch method's name
|
* @return The detatch method's name
|
||||||
@ -156,19 +142,6 @@ public class BehaviorTree extends VirtualClass {
|
|||||||
return rVal;
|
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
|
* Gets the fetch method's name
|
||||||
* @return The name
|
* @return The name
|
||||||
|
|||||||
@ -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;
|
package electrosphere.main.core.syncfield;
|
||||||
|
|
||||||
import electrosphere.main.core.btree.BehaviorTree;
|
import electrosphere.main.core.btree.BehaviorTree;
|
||||||
import electrosphere.main.project.ProjectStructure;
|
|
||||||
import electrosphere.main.targets.TargetFile;
|
import electrosphere.main.targets.TargetFile;
|
||||||
import electrosphere.main.util.TemplateInjectionUtils;
|
|
||||||
import electrosphere.main.util.Utilities;
|
import electrosphere.main.util.Utilities;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -41,22 +39,20 @@ public class SynchronizedField {
|
|||||||
this.targetFile = targetFile;
|
this.targetFile = targetFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the name of the getter method for this field
|
||||||
|
* @return The name of the getter method
|
||||||
|
*/
|
||||||
public String getGetterName(){
|
public String getGetterName(){
|
||||||
String rVal = "";
|
String rVal = "";
|
||||||
rVal = "get" + Utilities.camelCase(fieldName);
|
rVal = "get" + Utilities.camelCase(fieldName);
|
||||||
return rVal;
|
return rVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getServerGetterContent(){
|
/**
|
||||||
String rVal = TemplateInjectionUtils.getFragmentWithReplacement("/server/Getter.java", fieldName, Utilities.camelCase(fieldName), typeName);
|
* Gets the name of the setter method for this field
|
||||||
return rVal;
|
* @return The name of the setter method
|
||||||
}
|
*/
|
||||||
|
|
||||||
public String getClientGetterContent(){
|
|
||||||
String rVal = TemplateInjectionUtils.getFragmentWithReplacement("/client/Getter.java", fieldName, Utilities.camelCase(fieldName), typeName);
|
|
||||||
return rVal;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getSetterName(){
|
public String getSetterName(){
|
||||||
String rVal = "";
|
String rVal = "";
|
||||||
rVal = "set" + Utilities.camelCase(fieldName);
|
rVal = "set" + Utilities.camelCase(fieldName);
|
||||||
@ -71,47 +67,6 @@ public class SynchronizedField {
|
|||||||
this.parent = tree;
|
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
|
* Gets the id of this field
|
||||||
* @return The id
|
* @return The id
|
||||||
|
|||||||
@ -123,4 +123,12 @@ public class SynchronizedType {
|
|||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the available values
|
||||||
|
* @return The available values
|
||||||
|
*/
|
||||||
|
public List<String> getValues(){
|
||||||
|
return this.values;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,6 +57,7 @@ public class ProjectStructure {
|
|||||||
* Main code generation routine
|
* Main code generation routine
|
||||||
*/
|
*/
|
||||||
public void generate(){
|
public void generate(){
|
||||||
|
this.virtualProject.generate(this);
|
||||||
//generate in-class functions for btrees
|
//generate in-class functions for btrees
|
||||||
for(BehaviorTree tree : this.getBehaviorTrees()){
|
for(BehaviorTree tree : this.getBehaviorTrees()){
|
||||||
if(Main.LOG){
|
if(Main.LOG){
|
||||||
@ -67,13 +68,13 @@ public class ProjectStructure {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
for(SynchronizedField field : tree.getSynchronizedFields()){
|
// for(SynchronizedField field : tree.getSynchronizedFields()){
|
||||||
ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), field.getGetterName(), field.getServerGetterContent());
|
// // ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), field.getGetterName(), field.getServerGetterContent());
|
||||||
ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), field.getSetterName(), field.getServerSetterContent(this));
|
// // ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), field.getSetterName(), field.getServerSetterContent(this));
|
||||||
}
|
// }
|
||||||
//attach + detatch methods
|
//attach + detatch methods
|
||||||
ClassSourceUtils.addMethodIfAbsent(this, tree.getTargetFile(), tree.getAttachMethodName(), tree.getAttachMethodContent());
|
// ClassSourceUtils.addMethodIfAbsent(this, tree.getTargetFile(), tree.getAttachMethodName(), tree.getAttachMethodContent());
|
||||||
ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), tree.getDetachMethodName(), tree.getDetachMethodContent());
|
// ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), tree.getDetachMethodName(), tree.getDetachMethodContent());
|
||||||
//imports
|
//imports
|
||||||
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.engine.Globals");
|
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.engine.Globals");
|
||||||
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.server.datacell.utils.DataCellSearchUtils");
|
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.server.datacell.utils.DataCellSearchUtils");
|
||||||
@ -88,13 +89,13 @@ public class ProjectStructure {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
for(SynchronizedField field : tree.getSynchronizedFields()){
|
// for(SynchronizedField field : tree.getSynchronizedFields()){
|
||||||
ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), field.getGetterName(), field.getClientGetterContent());
|
// // ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), field.getGetterName(), field.getClientGetterContent());
|
||||||
ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), field.getSetterName(), field.getClientSetterContent(this));
|
// // ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), field.getSetterName(), field.getClientSetterContent(this));
|
||||||
}
|
// }
|
||||||
//attach + detatch methods
|
//attach + detatch methods
|
||||||
ClassSourceUtils.addMethodIfAbsent(this, tree.getTargetFile(), tree.getAttachMethodName(), tree.getAttachMethodContent());
|
// ClassSourceUtils.addMethodIfAbsent(this, tree.getTargetFile(), tree.getAttachMethodName(), tree.getAttachMethodContent());
|
||||||
ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), tree.getDetachMethodName(), tree.getDetachMethodContent());
|
// ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), tree.getDetachMethodName(), tree.getDetachMethodContent());
|
||||||
//imports
|
//imports
|
||||||
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.engine.Globals"); // for client scene wrapper
|
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.Entity");
|
||||||
@ -105,22 +106,22 @@ public class ProjectStructure {
|
|||||||
|
|
||||||
|
|
||||||
//private constructor
|
//private constructor
|
||||||
ClassSourceUtils.addMethodIfAbsent(this, tree.getTargetFile(), tree.getConstructorMethodName(), tree.getConstructorMethodContent());
|
// ClassSourceUtils.addMethodIfAbsent(this, tree.getTargetFile(), tree.getConstructorMethodName(), tree.getConstructorMethodContent());
|
||||||
//guarantee entity fetch method
|
//guarantee entity fetch method
|
||||||
ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), tree.getEntityFetchMethodName(), tree.getEntityFetchMethodContent());
|
// ClassSourceUtils.addOrReplaceMethod(this, tree.getTargetFile(), tree.getEntityFetchMethodName(), tree.getEntityFetchMethodContent());
|
||||||
//guarantee imports of required files (btree enum, etc)
|
//guarantee imports of required files (btree enum, etc)
|
||||||
ClassSourceUtils.importClass(this, tree.getTargetFile(), this.virtualProject.getBTreeIdEnum().getQualifiedPath(this));
|
ClassSourceUtils.importClass(this, tree.getTargetFile(), this.virtualProject.getBTreeIdEnum().getQualifiedPath(this));
|
||||||
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.entity.EntityDataStrings");
|
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.entity.EntityDataStrings");
|
||||||
}
|
}
|
||||||
//generate enums for all synchronized types
|
//generate enums for all synchronized types
|
||||||
for(SynchronizedType type : this.mainParser.getSynchronizedTypes()){
|
// for(SynchronizedType type : this.mainParser.getSynchronizedTypes()){
|
||||||
ClassSourceUtils.addOrReplaceMethod(this, type.getTargetFile(), type.getToShortConversionMethodName(), type.getToShortConversionMethodContent());
|
// ClassSourceUtils.addOrReplaceMethod(this, type.getTargetFile(), type.getToShortConversionMethodName(), type.getToShortConversionMethodContent());
|
||||||
ClassSourceUtils.addOrReplaceMethod(this, type.getTargetFile(), type.getFromShortConversionMethodName(), type.getFromShortConversionMethodContent());
|
// ClassSourceUtils.addOrReplaceMethod(this, type.getTargetFile(), type.getFromShortConversionMethodName(), type.getFromShortConversionMethodContent());
|
||||||
}
|
// }
|
||||||
this.virtualProject.getBTreeIdEnum().generate(this);
|
// this.virtualProject.getBTreeIdEnum().generate(this);
|
||||||
this.virtualProject.getFieldIdEnum().generate(this);
|
// this.virtualProject.getFieldIdEnum().generate(this);
|
||||||
//client sync manager
|
// //client sync manager
|
||||||
this.virtualProject.getClientSynchronizationManager().generate(this);
|
// 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 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.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;
|
import electrosphere.main.targets.TargetFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -60,6 +66,22 @@ public class BTreeParser {
|
|||||||
target
|
target
|
||||||
);
|
);
|
||||||
behaviorTrees.add(rVal);
|
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.VirtualProject;
|
||||||
import electrosphere.main.core.btree.BehaviorTree;
|
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.SynchronizedField;
|
||||||
import electrosphere.main.core.syncfield.SynchronizedType;
|
import electrosphere.main.core.syncfield.SynchronizedType;
|
||||||
import electrosphere.main.targets.TargetFile;
|
import electrosphere.main.targets.TargetFile;
|
||||||
@ -47,7 +51,7 @@ public class MainParser {
|
|||||||
BehaviorTree bTree = this.bTreeParser.parse(target);
|
BehaviorTree bTree = this.bTreeParser.parse(target);
|
||||||
List<SynchronizedType> types = this.enumParser.parse(target, typeIterator);
|
List<SynchronizedType> types = this.enumParser.parse(target, typeIterator);
|
||||||
List<SynchronizedField> fields = this.fieldParser.parse(target);
|
List<SynchronizedField> fields = this.fieldParser.parse(target);
|
||||||
linkData(bTree, fields, types);
|
linkData(rVal, bTree, fields, types);
|
||||||
|
|
||||||
//
|
//
|
||||||
//specific cases
|
//specific cases
|
||||||
@ -63,16 +67,27 @@ public class MainParser {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Links all the values gathered from a behavior tree file
|
* Links all the values gathered from a behavior tree file
|
||||||
|
* @param rVal The virtual project
|
||||||
* @param tree The tree
|
* @param tree The tree
|
||||||
* @param fields The list of fields
|
* @param fields The list of fields
|
||||||
* @param types The list of types
|
* @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){
|
if(tree != null){
|
||||||
|
rVal.addClass(tree);
|
||||||
//link fields
|
//link fields
|
||||||
for(SynchronizedField field : fields){
|
for(SynchronizedField field : fields){
|
||||||
field.setParent(tree);
|
field.setParent(tree);
|
||||||
tree.addSynchronizedField(field);
|
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;
|
package electrosphere.main.source;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import electrosphere.main.project.ProjectStructure;
|
import electrosphere.main.project.ProjectStructure;
|
||||||
@ -23,17 +24,17 @@ public abstract class VirtualClass {
|
|||||||
/**
|
/**
|
||||||
* All the imports in this virtual class
|
* All the imports in this virtual class
|
||||||
*/
|
*/
|
||||||
List<String> imports;
|
List<String> imports = new LinkedList<String>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All the fields in this class
|
* All the fields in this class
|
||||||
*/
|
*/
|
||||||
List<VirtualField> fields;
|
List<VirtualField> fields = new LinkedList<VirtualField>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All the methods in this class
|
* All the methods in this class
|
||||||
*/
|
*/
|
||||||
List<VirtualMethod> methods;
|
List<VirtualMethod> methods = new LinkedList<VirtualMethod>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
@ -90,7 +91,20 @@ public abstract class VirtualClass {
|
|||||||
* @param structure The project
|
* @param structure The project
|
||||||
*/
|
*/
|
||||||
public void updateFile(ProjectStructure structure){
|
public void updateFile(ProjectStructure structure){
|
||||||
throw new UnsupportedOperationException("Not yet implemented!");
|
for(VirtualMethod method : this.methods){
|
||||||
|
System.out.println("Replace " + method.getName(structure));
|
||||||
|
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!");
|
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 java.util.List;
|
||||||
|
|
||||||
|
import electrosphere.main.project.ProjectStructure;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a method in a class
|
* Represents a method in a class
|
||||||
*/
|
*/
|
||||||
@ -9,21 +11,30 @@ public interface VirtualMethod {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the name of the method
|
* Gets the name of the method
|
||||||
|
* @param projectStructure The project structure
|
||||||
* @return The name of the method
|
* @return The name of the method
|
||||||
*/
|
*/
|
||||||
public String getName();
|
public String getName(ProjectStructure projectStructure);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the content of this method
|
* Gets the content of this method
|
||||||
|
* @param projectStructure The project structure
|
||||||
* @return The content
|
* @return The content
|
||||||
*/
|
*/
|
||||||
public String getContent();
|
public String getContent(ProjectStructure projectStructure);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the list of imports required for this method
|
* Gets the list of imports required for this method
|
||||||
|
* @param projectStructure The project structure
|
||||||
* @return The list of imports
|
* @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