more refactoring
All checks were successful
studiorailgun/highlevel-netcode-gen/pipeline/head This commit looks good
All checks were successful
studiorailgun/highlevel-netcode-gen/pipeline/head This commit looks good
This commit is contained in:
parent
53e47ba2d8
commit
18f8e62d06
@ -1,7 +1,7 @@
|
|||||||
package electrosphere.main.client;
|
package electrosphere.main.client;
|
||||||
|
|
||||||
import electrosphere.main.core.btree.BehaviorTree;
|
import electrosphere.main.core.btree.BehaviorTree;
|
||||||
import electrosphere.main.core.enums.BTreeIdEnum;
|
import electrosphere.main.core.statics.btreeenum.BTreeIdEnum;
|
||||||
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.project.ProjectStructure;
|
import electrosphere.main.project.ProjectStructure;
|
||||||
|
|||||||
34
src/main/java/electrosphere/main/core/VirtualProject.java
Normal file
34
src/main/java/electrosphere/main/core/VirtualProject.java
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
package electrosphere.main.core;
|
||||||
|
|
||||||
|
import electrosphere.main.core.statics.btreeenum.BTreeIdEnum;
|
||||||
|
import electrosphere.main.core.statics.fieldenum.FieldIdEnum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The rich data on all the classes in the project
|
||||||
|
*/
|
||||||
|
public class VirtualProject {
|
||||||
|
|
||||||
|
//The BTree id enum file
|
||||||
|
BTreeIdEnum bTreeIdEnum = new BTreeIdEnum();
|
||||||
|
|
||||||
|
//field id enum
|
||||||
|
FieldIdEnum fieldIdEnum = new FieldIdEnum();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the BTree id enum file's class
|
||||||
|
* @return The class
|
||||||
|
*/
|
||||||
|
public BTreeIdEnum getBTreeIdEnum(){
|
||||||
|
return bTreeIdEnum;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the field id enum's class
|
||||||
|
* @return The field id enum class
|
||||||
|
*/
|
||||||
|
public FieldIdEnum getFieldIdEnum(){
|
||||||
|
return this.fieldIdEnum;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -40,7 +40,6 @@ public class BehaviorTree {
|
|||||||
* @param className
|
* @param className
|
||||||
* @param correspondingTreeName
|
* @param correspondingTreeName
|
||||||
* @param isServer
|
* @param isServer
|
||||||
* @param synchronizedFields
|
|
||||||
*/
|
*/
|
||||||
public BehaviorTree(
|
public BehaviorTree(
|
||||||
int id,
|
int id,
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
package electrosphere.main.core.enums;
|
package electrosphere.main.core.statics.btreeenum;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -7,46 +7,33 @@ import com.google.common.io.Files;
|
|||||||
|
|
||||||
import electrosphere.main.core.btree.BehaviorTree;
|
import electrosphere.main.core.btree.BehaviorTree;
|
||||||
import electrosphere.main.project.ProjectStructure;
|
import electrosphere.main.project.ProjectStructure;
|
||||||
|
import electrosphere.main.source.VirtualClass;
|
||||||
import electrosphere.main.util.ClassSourceUtils;
|
import electrosphere.main.util.ClassSourceUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class that is a list of every behavior tree and its associated id
|
* A class that is a list of every behavior tree and its associated id
|
||||||
*/
|
*/
|
||||||
public class BTreeIdEnum {
|
public class BTreeIdEnum extends VirtualClass {
|
||||||
|
|
||||||
//The class name of this class
|
|
||||||
public static final String CLASSNAME = "BehaviorTreeIdEnums";
|
|
||||||
|
|
||||||
//The location of the file
|
|
||||||
public static final String LOCATION = "src/main/java/electrosphere/net/synchronization/BehaviorTreeIdEnums.java";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the qualified path for the b tree id enum
|
* Constructor
|
||||||
* @param structure The project structure
|
|
||||||
* @return The qualified path
|
|
||||||
*/
|
*/
|
||||||
public static String getQualifiedPath(ProjectStructure structure){
|
public BTreeIdEnum() {
|
||||||
File outFile = new File(structure.getRootFolder().getAbsolutePath()).toPath().resolve(LOCATION).toFile();
|
super(
|
||||||
return ClassSourceUtils.getPackageSourcePath(structure, outFile) + "." + CLASSNAME;
|
"src/main/java/electrosphere/net/synchronization/BehaviorTreeIdEnums.java",
|
||||||
}
|
"BehaviorTreeIdEnums"
|
||||||
|
);
|
||||||
/**
|
|
||||||
* Gets the import declaration for this class
|
|
||||||
* @param structure The project structure
|
|
||||||
* @return The import declaration
|
|
||||||
*/
|
|
||||||
public static String getImport(ProjectStructure structure){
|
|
||||||
return "import " + getQualifiedPath(structure) + ";";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a b tree id enum file
|
* Generates a b tree id enum file
|
||||||
* @param structure The project structure
|
* @param structure The project structure
|
||||||
*/
|
*/
|
||||||
public static void generate(ProjectStructure structure){
|
@Override
|
||||||
|
public void generate(ProjectStructure structure){
|
||||||
|
|
||||||
String source = "";
|
String source = "";
|
||||||
File outFile = new File(structure.getRootFolder().getAbsolutePath()).toPath().resolve(LOCATION).toFile();
|
File outFile = new File(structure.getRootFolder().getAbsolutePath()).toPath().resolve(this.getLocation()).toFile();
|
||||||
source = source + ClassSourceUtils.getPackageDeclaration(structure, ClassSourceUtils.getPackageSourcePath(structure, outFile));
|
source = source + ClassSourceUtils.getPackageDeclaration(structure, ClassSourceUtils.getPackageSourcePath(structure, outFile));
|
||||||
source = source + "\n";
|
source = source + "\n";
|
||||||
source = source + ClassSourceUtils.generateClassHeader("BehaviorTreeIdEnums", "List of enums for each automatically synchronized behavior tree.", true);
|
source = source + ClassSourceUtils.generateClassHeader("BehaviorTreeIdEnums", "List of enums for each automatically synchronized behavior tree.", true);
|
||||||
@ -1,4 +1,4 @@
|
|||||||
package electrosphere.main.core.enums;
|
package electrosphere.main.core.statics.fieldenum;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -7,47 +7,34 @@ import com.google.common.io.Files;
|
|||||||
|
|
||||||
import electrosphere.main.core.syncfield.SynchronizedField;
|
import electrosphere.main.core.syncfield.SynchronizedField;
|
||||||
import electrosphere.main.project.ProjectStructure;
|
import electrosphere.main.project.ProjectStructure;
|
||||||
|
import electrosphere.main.source.VirtualClass;
|
||||||
import electrosphere.main.util.ClassSourceUtils;
|
import electrosphere.main.util.ClassSourceUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class that has an enum of all fields and their associated ids
|
* A class that has an enum of all fields and their associated ids
|
||||||
*/
|
*/
|
||||||
public class FieldIdEnum {
|
public class FieldIdEnum extends VirtualClass {
|
||||||
|
|
||||||
|
|
||||||
//The class name of this class
|
|
||||||
public static final String CLASSNAME = "FieldIdEnums";
|
|
||||||
|
|
||||||
//The location of the file
|
|
||||||
public static final String LOCATION = "src/main/java/electrosphere/net/synchronization/FieldIdEnums.java";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the qualified path for the b tree id enum
|
* Constructor
|
||||||
* @param structure The project structure
|
|
||||||
* @return The qualified path
|
|
||||||
*/
|
*/
|
||||||
public static String getQualifiedPath(ProjectStructure structure){
|
public FieldIdEnum() {
|
||||||
File outFile = new File(structure.getRootFolder().getAbsolutePath()).toPath().resolve(LOCATION).toFile();
|
super(
|
||||||
return ClassSourceUtils.getPackageSourcePath(structure, outFile) + "." + CLASSNAME;
|
"src/main/java/electrosphere/net/synchronization/FieldIdEnums.java",
|
||||||
}
|
"FieldIdEnums"
|
||||||
|
);
|
||||||
/**
|
//TODO Auto-generated constructor stub
|
||||||
* Gets the import declaration for this class
|
|
||||||
* @param structure The project structure
|
|
||||||
* @return The import declaration
|
|
||||||
*/
|
|
||||||
public static String getImport(ProjectStructure structure){
|
|
||||||
return "import " + getQualifiedPath(structure) + ";";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a b tree id enum file
|
* Generates a b tree id enum file
|
||||||
* @param structure The project structure
|
* @param structure The project structure
|
||||||
*/
|
*/
|
||||||
public static void generate(ProjectStructure structure){
|
@Override
|
||||||
|
public void generate(ProjectStructure structure){
|
||||||
|
|
||||||
String source = "";
|
String source = "";
|
||||||
File outFile = new File(structure.getRootFolder().getAbsolutePath()).toPath().resolve(LOCATION).toFile();
|
File outFile = new File(structure.getRootFolder().getAbsolutePath()).toPath().resolve(this.getLocation()).toFile();
|
||||||
source = source + ClassSourceUtils.getPackageDeclaration(structure, ClassSourceUtils.getPackageSourcePath(structure, outFile));
|
source = source + ClassSourceUtils.getPackageDeclaration(structure, ClassSourceUtils.getPackageSourcePath(structure, outFile));
|
||||||
source = source + "\n";
|
source = source + "\n";
|
||||||
source = source + ClassSourceUtils.generateClassHeader("FieldIdEnums", "List of enums of all fields and their associated ids.", true);
|
source = source + ClassSourceUtils.generateClassHeader("FieldIdEnums", "List of enums of all fields and their associated ids.", true);
|
||||||
@ -6,9 +6,8 @@ import java.util.List;
|
|||||||
|
|
||||||
import electrosphere.main.Main;
|
import electrosphere.main.Main;
|
||||||
import electrosphere.main.client.ClientSynchronizationManager;
|
import electrosphere.main.client.ClientSynchronizationManager;
|
||||||
|
import electrosphere.main.core.VirtualProject;
|
||||||
import electrosphere.main.core.btree.BehaviorTree;
|
import electrosphere.main.core.btree.BehaviorTree;
|
||||||
import electrosphere.main.core.enums.BTreeIdEnum;
|
|
||||||
import electrosphere.main.core.enums.FieldIdEnum;
|
|
||||||
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.project.parsers.MainParser;
|
import electrosphere.main.project.parsers.MainParser;
|
||||||
@ -31,6 +30,11 @@ public class ProjectStructure {
|
|||||||
*/
|
*/
|
||||||
MainParser mainParser = new MainParser();
|
MainParser mainParser = new MainParser();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The virtual project
|
||||||
|
*/
|
||||||
|
VirtualProject virtualProject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param targetFiles The target files to iterate on
|
* @param targetFiles The target files to iterate on
|
||||||
@ -46,7 +50,7 @@ public class ProjectStructure {
|
|||||||
* Parses the target files in this project into rich data to generate off of
|
* Parses the target files in this project into rich data to generate off of
|
||||||
*/
|
*/
|
||||||
public void parseRichStructure(){
|
public void parseRichStructure(){
|
||||||
this.mainParser.parse(targetFiles);
|
this.virtualProject = this.mainParser.parse(targetFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -106,7 +110,7 @@ public class ProjectStructure {
|
|||||||
//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(), BTreeIdEnum.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
|
||||||
@ -114,8 +118,8 @@ public class ProjectStructure {
|
|||||||
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());
|
||||||
}
|
}
|
||||||
BTreeIdEnum.generate(this);
|
this.virtualProject.getBTreeIdEnum().generate(this);
|
||||||
FieldIdEnum.generate(this);
|
this.virtualProject.getFieldIdEnum().generate(this);
|
||||||
//client sync manager
|
//client sync manager
|
||||||
ClientSynchronizationManager.update(this, this.mainParser.getClientSynchronizationManager());
|
ClientSynchronizationManager.update(this, this.mainParser.getClientSynchronizationManager());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,9 +2,7 @@ package electrosphere.main.project.parsers;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.jboss.forge.roaster.model.source.AnnotationSource;
|
import electrosphere.main.core.VirtualProject;
|
||||||
import org.jboss.forge.roaster.model.source.JavaClassSource;
|
|
||||||
|
|
||||||
import electrosphere.main.core.btree.BehaviorTree;
|
import electrosphere.main.core.btree.BehaviorTree;
|
||||||
import electrosphere.main.core.syncfield.SynchronizedField;
|
import electrosphere.main.core.syncfield.SynchronizedField;
|
||||||
import electrosphere.main.core.syncfield.SynchronizedType;
|
import electrosphere.main.core.syncfield.SynchronizedType;
|
||||||
@ -37,19 +35,22 @@ public class MainParser {
|
|||||||
* Parses all the target files
|
* Parses all the target files
|
||||||
* @param targetFiles The list of target files
|
* @param targetFiles The list of target files
|
||||||
*/
|
*/
|
||||||
public void parse(List<TargetFile> targetFiles){
|
public VirtualProject parse(List<TargetFile> targetFiles){
|
||||||
|
VirtualProject rVal = new VirtualProject();
|
||||||
|
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// MAIN PARSING LOOP
|
||||||
|
//
|
||||||
|
//
|
||||||
int typeIterator = 0;
|
int typeIterator = 0;
|
||||||
for(TargetFile target : targetFiles){
|
for(TargetFile target : targetFiles){
|
||||||
AnnotationSource<JavaClassSource> mainAnnotation = target.getSource().getAnnotation("SynchronizedBehaviorTree");
|
|
||||||
|
|
||||||
//parse btrees
|
//parse btrees
|
||||||
if(mainAnnotation != null){
|
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(bTree, fields, types);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
//specific cases
|
//specific cases
|
||||||
@ -59,6 +60,8 @@ public class MainParser {
|
|||||||
this.clientSynchronizationManager = target;
|
this.clientSynchronizationManager = target;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return rVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -68,11 +71,12 @@ public class MainParser {
|
|||||||
* @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(BehaviorTree tree, List<SynchronizedField> fields, List<SynchronizedType> types){
|
||||||
|
if(tree != null){
|
||||||
//link fields
|
//link fields
|
||||||
for(SynchronizedField field : fields){
|
for(SynchronizedField field : fields){
|
||||||
field.setParent(tree);
|
field.setParent(tree);
|
||||||
tree.addSynchronizedField(field);
|
tree.addSynchronizedField(field);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,20 @@
|
|||||||
package electrosphere.main.source;
|
package electrosphere.main.source;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import electrosphere.main.project.ProjectStructure;
|
||||||
|
import electrosphere.main.util.ClassSourceUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the contents of a class
|
* Represents the contents of a class
|
||||||
*/
|
*/
|
||||||
public abstract class VirtualClass {
|
public abstract class VirtualClass {
|
||||||
|
|
||||||
|
//the location of the file
|
||||||
|
private String LOCATION;
|
||||||
|
//the class's name
|
||||||
|
private String CLASSNAME;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All the imports in this virtual class
|
* All the imports in this virtual class
|
||||||
@ -22,5 +31,58 @@ public abstract class VirtualClass {
|
|||||||
*/
|
*/
|
||||||
List<VirtualMethod> methods;
|
List<VirtualMethod> methods;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
* @param location The location of the file
|
||||||
|
* @param name The name of the class
|
||||||
|
*/
|
||||||
|
public VirtualClass(String location, String name){
|
||||||
|
this.LOCATION = location;
|
||||||
|
this.CLASSNAME = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the qualified path for the b tree id enum
|
||||||
|
* @param structure The project structure
|
||||||
|
* @return The qualified path
|
||||||
|
*/
|
||||||
|
public String getQualifiedPath(ProjectStructure structure){
|
||||||
|
File outFile = new File(structure.getRootFolder().getAbsolutePath()).toPath().resolve(LOCATION).toFile();
|
||||||
|
return ClassSourceUtils.getPackageSourcePath(structure, outFile) + "." + CLASSNAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the import declaration for this class
|
||||||
|
* @param structure The project structure
|
||||||
|
* @return The import declaration
|
||||||
|
*/
|
||||||
|
public String getImport(ProjectStructure structure){
|
||||||
|
return "import " + getQualifiedPath(structure) + ";";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the location of this file
|
||||||
|
* @return The location
|
||||||
|
*/
|
||||||
|
public String getLocation(){
|
||||||
|
return this.LOCATION;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates the file from scratch
|
||||||
|
* @param structure The project
|
||||||
|
*/
|
||||||
|
public void generate(ProjectStructure structure){
|
||||||
|
throw new UnsupportedOperationException("Not yet implemented!");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the existing file with the new contents of specific methods
|
||||||
|
* @param structure The project
|
||||||
|
*/
|
||||||
|
public void update(ProjectStructure structure){
|
||||||
|
throw new UnsupportedOperationException("Not yet implemented!");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
package electrosphere.main.source;
|
package electrosphere.main.source;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a method in a class
|
* Represents a method in a class
|
||||||
*/
|
*/
|
||||||
@ -18,4 +20,10 @@ public interface VirtualMethod {
|
|||||||
*/
|
*/
|
||||||
public String getContent();
|
public String getContent();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the list of imports required for this method
|
||||||
|
* @return The list of imports
|
||||||
|
*/
|
||||||
|
public List<String> getImports();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user