more refactoring
All checks were successful
studiorailgun/highlevel-netcode-gen/pipeline/head This commit looks good

This commit is contained in:
austin 2024-07-31 11:58:18 -04:00
parent 53e47ba2d8
commit 18f8e62d06
9 changed files with 161 additions and 76 deletions

View File

@ -1,7 +1,7 @@
package electrosphere.main.client;
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.SynchronizedType;
import electrosphere.main.project.ProjectStructure;

View 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;
}
}

View File

@ -40,7 +40,6 @@ public class BehaviorTree {
* @param className
* @param correspondingTreeName
* @param isServer
* @param synchronizedFields
*/
public BehaviorTree(
int id,

View File

@ -1,4 +1,4 @@
package electrosphere.main.core.enums;
package electrosphere.main.core.statics.btreeenum;
import java.io.File;
import java.io.IOException;
@ -7,46 +7,33 @@ import com.google.common.io.Files;
import electrosphere.main.core.btree.BehaviorTree;
import electrosphere.main.project.ProjectStructure;
import electrosphere.main.source.VirtualClass;
import electrosphere.main.util.ClassSourceUtils;
/**
* A class that is a list of every behavior tree and its associated id
*/
public class BTreeIdEnum {
//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";
public class BTreeIdEnum extends VirtualClass {
/**
* Gets the qualified path for the b tree id enum
* @param structure The project structure
* @return The qualified path
* Constructor
*/
public static 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 static String getImport(ProjectStructure structure){
return "import " + getQualifiedPath(structure) + ";";
public BTreeIdEnum() {
super(
"src/main/java/electrosphere/net/synchronization/BehaviorTreeIdEnums.java",
"BehaviorTreeIdEnums"
);
}
/**
* Generates a b tree id enum file
* @param structure The project structure
*/
public static void generate(ProjectStructure structure){
@Override
public void generate(ProjectStructure structure){
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 + "\n";
source = source + ClassSourceUtils.generateClassHeader("BehaviorTreeIdEnums", "List of enums for each automatically synchronized behavior tree.", true);

View File

@ -1,4 +1,4 @@
package electrosphere.main.core.enums;
package electrosphere.main.core.statics.fieldenum;
import java.io.File;
import java.io.IOException;
@ -7,47 +7,34 @@ import com.google.common.io.Files;
import electrosphere.main.core.syncfield.SynchronizedField;
import electrosphere.main.project.ProjectStructure;
import electrosphere.main.source.VirtualClass;
import electrosphere.main.util.ClassSourceUtils;
/**
* 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
* @param structure The project structure
* @return The qualified path
* Constructor
*/
public static 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 static String getImport(ProjectStructure structure){
return "import " + getQualifiedPath(structure) + ";";
public FieldIdEnum() {
super(
"src/main/java/electrosphere/net/synchronization/FieldIdEnums.java",
"FieldIdEnums"
);
//TODO Auto-generated constructor stub
}
/**
* Generates a b tree id enum file
* @param structure The project structure
*/
public static void generate(ProjectStructure structure){
@Override
public void generate(ProjectStructure structure){
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 + "\n";
source = source + ClassSourceUtils.generateClassHeader("FieldIdEnums", "List of enums of all fields and their associated ids.", true);

View File

@ -6,9 +6,8 @@ import java.util.List;
import electrosphere.main.Main;
import electrosphere.main.client.ClientSynchronizationManager;
import electrosphere.main.core.VirtualProject;
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.SynchronizedType;
import electrosphere.main.project.parsers.MainParser;
@ -31,6 +30,11 @@ public class ProjectStructure {
*/
MainParser mainParser = new MainParser();
/**
* The virtual project
*/
VirtualProject virtualProject;
/**
* Constructor
* @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
*/
public void parseRichStructure(){
this.mainParser.parse(targetFiles);
this.virtualProject = this.mainParser.parse(targetFiles);
}
@ -106,7 +110,7 @@ public class ProjectStructure {
//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(), BTreeIdEnum.getQualifiedPath(this));
ClassSourceUtils.importClass(this, tree.getTargetFile(), this.virtualProject.getBTreeIdEnum().getQualifiedPath(this));
ClassSourceUtils.importClass(this, tree.getTargetFile(), "electrosphere.entity.EntityDataStrings");
}
//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.getFromShortConversionMethodName(), type.getFromShortConversionMethodContent());
}
BTreeIdEnum.generate(this);
FieldIdEnum.generate(this);
this.virtualProject.getBTreeIdEnum().generate(this);
this.virtualProject.getFieldIdEnum().generate(this);
//client sync manager
ClientSynchronizationManager.update(this, this.mainParser.getClientSynchronizationManager());
}

View File

@ -2,9 +2,7 @@ package electrosphere.main.project.parsers;
import java.util.List;
import org.jboss.forge.roaster.model.source.AnnotationSource;
import org.jboss.forge.roaster.model.source.JavaClassSource;
import electrosphere.main.core.VirtualProject;
import electrosphere.main.core.btree.BehaviorTree;
import electrosphere.main.core.syncfield.SynchronizedField;
import electrosphere.main.core.syncfield.SynchronizedType;
@ -37,19 +35,22 @@ public class MainParser {
* Parses all the 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;
for(TargetFile target : targetFiles){
AnnotationSource<JavaClassSource> mainAnnotation = target.getSource().getAnnotation("SynchronizedBehaviorTree");
//parse btrees
if(mainAnnotation != null){
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);
}
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);
//
//specific cases
@ -59,6 +60,8 @@ public class MainParser {
this.clientSynchronizationManager = target;
}
}
return rVal;
}
/**
@ -68,11 +71,12 @@ public class MainParser {
* @param types The list of types
*/
private void linkData(BehaviorTree tree, List<SynchronizedField> fields, List<SynchronizedType> types){
//link fields
for(SynchronizedField field : fields){
field.setParent(tree);
tree.addSynchronizedField(field);
if(tree != null){
//link fields
for(SynchronizedField field : fields){
field.setParent(tree);
tree.addSynchronizedField(field);
}
}
}

View File

@ -1,11 +1,20 @@
package electrosphere.main.source;
import java.io.File;
import java.util.List;
import electrosphere.main.project.ProjectStructure;
import electrosphere.main.util.ClassSourceUtils;
/**
* Represents the contents of a class
*/
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
@ -22,5 +31,58 @@ public abstract class VirtualClass {
*/
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!");
}
}

View File

@ -1,5 +1,7 @@
package electrosphere.main.source;
import java.util.List;
/**
* Represents a method in a class
*/
@ -18,4 +20,10 @@ public interface VirtualMethod {
*/
public String getContent();
/**
* Gets the list of imports required for this method
* @return The list of imports
*/
public List<String> getImports();
}