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

This commit is contained in:
austin 2024-07-31 14:57:30 -04:00
parent 18f8e62d06
commit ecab7952b7
7 changed files with 90 additions and 33 deletions

View File

@ -5,26 +5,39 @@ 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.util.TemplateInjectionUtils;
public class ClientSynchronizationManager {
/**
* The client synchronization manager class
*/
public class ClientSynchronizationManager extends VirtualClass {
//The class name of this class
public static final String CLASSNAME = "ClientSynchronizationManager";
//The target file for the current version of this class
TargetFile file;
//The location of the file
public static final String LOCATION = "src/main/java/electrosphere/net/synchronization/ClientSynchronizationManager.java";
/**
* Constructor
*/
public ClientSynchronizationManager(TargetFile file) {
super(
"src/main/java/electrosphere/net/synchronization/ClientSynchronizationManager.java",
"ClientSynchronizationManager",
true
);
this.file = file;
}
/**
* Updates the ClientSynchronizationManager with latest data in specific functions
* @param structure
* @param clientSynchronizationManager
* @param structure The project texture
*/
public static void update(ProjectStructure structure, TargetFile clientSynchronizationManager){
@Override
public void updateFile(ProjectStructure structure){
String updateCases = "";
for(BehaviorTree serverTree : structure.getBehaviorTrees()){
//counterintuitively, want to only update client for server behavior tree ids
@ -81,11 +94,11 @@ public class ClientSynchronizationManager {
//guarantee import
// ClassSourceUtils.importClass(structure, clientSynchronizationManager, serverTree.getTargetFile().getQualifiedPath());
ClassSourceUtils.importClass(structure, clientSynchronizationManager, structure.getTree(serverTree.getCorrespondingTreeName()).getTargetFile().getQualifiedPath());
ClassSourceUtils.importClass(structure, this.file, structure.getTree(serverTree.getCorrespondingTreeName()).getTargetFile().getQualifiedPath());
}
}
ClassSourceUtils.importClass(structure, clientSynchronizationManager, "electrosphere.net.synchronization.FieldIdEnums");
ClassSourceUtils.importClass(structure, this.file, "electrosphere.net.synchronization.FieldIdEnums");
String fullReplacementText = TemplateInjectionUtils.getFragmentWithReplacement("/client/UpdateEntityState.java", updateCases);
ClassSourceUtils.addOrReplaceMethod(structure, clientSynchronizationManager, "updateEntityState", fullReplacementText);
ClassSourceUtils.addOrReplaceMethod(structure, this.file, "updateEntityState", fullReplacementText);
}
}

View File

@ -1,12 +1,21 @@
package electrosphere.main.core;
import java.util.LinkedList;
import java.util.List;
import electrosphere.main.client.ClientSynchronizationManager;
import electrosphere.main.core.statics.btreeenum.BTreeIdEnum;
import electrosphere.main.core.statics.fieldenum.FieldIdEnum;
import electrosphere.main.source.VirtualClass;
import electrosphere.main.targets.TargetFile;
/**
* The rich data on all the classes in the project
*/
public class VirtualProject {
//all virtual classes in this virtual project
List<VirtualClass> classes = new LinkedList<VirtualClass>();
//The BTree id enum file
BTreeIdEnum bTreeIdEnum = new BTreeIdEnum();
@ -14,6 +23,19 @@ public class VirtualProject {
//field id enum
FieldIdEnum fieldIdEnum = new FieldIdEnum();
//The client synchronization manager class
ClientSynchronizationManager clientSynchronizationManager;
/**
* Constructor
*/
public VirtualProject(){
this.classes.add(bTreeIdEnum);
this.classes.add(fieldIdEnum);
}
/**
* Gets the BTree id enum file's class
@ -31,4 +53,21 @@ public class VirtualProject {
return this.fieldIdEnum;
}
/**
* Creates the client synchronization manager
* @param file The target file
*/
public void createClientSynchronizationManager(TargetFile file){
this.clientSynchronizationManager = new ClientSynchronizationManager(file);
this.classes.add(this.clientSynchronizationManager);
}
/**
* Gets the client synchronization manager
* @return The client synchonization manager
*/
public ClientSynchronizationManager getClientSynchronizationManager(){
return this.clientSynchronizationManager;
}
}

View File

@ -21,7 +21,8 @@ public class BTreeIdEnum extends VirtualClass {
public BTreeIdEnum() {
super(
"src/main/java/electrosphere/net/synchronization/BehaviorTreeIdEnums.java",
"BehaviorTreeIdEnums"
"BehaviorTreeIdEnums",
false
);
}
@ -30,7 +31,7 @@ public class BTreeIdEnum extends VirtualClass {
* @param structure The project structure
*/
@Override
public void generate(ProjectStructure structure){
public void createFile(ProjectStructure structure){
String source = "";
File outFile = new File(structure.getRootFolder().getAbsolutePath()).toPath().resolve(this.getLocation()).toFile();

View File

@ -21,9 +21,9 @@ public class FieldIdEnum extends VirtualClass {
public FieldIdEnum() {
super(
"src/main/java/electrosphere/net/synchronization/FieldIdEnums.java",
"FieldIdEnums"
"FieldIdEnums",
false
);
//TODO Auto-generated constructor stub
}
/**
@ -31,7 +31,7 @@ public class FieldIdEnum extends VirtualClass {
* @param structure The project structure
*/
@Override
public void generate(ProjectStructure structure){
public void createFile(ProjectStructure structure){
String source = "";
File outFile = new File(structure.getRootFolder().getAbsolutePath()).toPath().resolve(this.getLocation()).toFile();

View File

@ -5,7 +5,6 @@ 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.syncfield.SynchronizedField;
@ -121,7 +120,7 @@ public class ProjectStructure {
this.virtualProject.getBTreeIdEnum().generate(this);
this.virtualProject.getFieldIdEnum().generate(this);
//client sync manager
ClientSynchronizationManager.update(this, this.mainParser.getClientSynchronizationManager());
this.virtualProject.getClientSynchronizationManager().generate(this);
}
/**

View File

@ -28,9 +28,6 @@ public class MainParser {
*/
FieldParser fieldParser = new FieldParser();
//the client synchronization manager
TargetFile clientSynchronizationManager;
/**
* Parses all the target files
* @param targetFiles The list of target files
@ -57,7 +54,7 @@ public class MainParser {
//client synchronization manager
if(target.getName().contains("ClientSynchronizationManager")){
this.clientSynchronizationManager = target;
rVal.createClientSynchronizationManager(target);
}
}
@ -133,12 +130,4 @@ public class MainParser {
return this.enumParser.getSynchronizedTypes();
}
/**
* Gets the client synchronization manager target file
* @return The target file
*/
public TargetFile getClientSynchronizationManager(){
return this.clientSynchronizationManager;
}
}

View File

@ -15,6 +15,8 @@ public abstract class VirtualClass {
private String LOCATION;
//the class's name
private String CLASSNAME;
//controls whether this class should update or generate from scratch
private boolean shouldUpdate;
/**
* All the imports in this virtual class
@ -35,10 +37,12 @@ public abstract class VirtualClass {
* Constructor
* @param location The location of the file
* @param name The name of the class
* @param shouldUpdate Controls whether the class should generate the file from scratch or update its existing file
*/
public VirtualClass(String location, String name){
public VirtualClass(String location, String name, boolean shouldUpdate){
this.LOCATION = location;
this.CLASSNAME = name;
this.shouldUpdate = shouldUpdate;
}
/**
@ -73,14 +77,26 @@ public abstract class VirtualClass {
* @param structure The project
*/
public void generate(ProjectStructure structure){
throw new UnsupportedOperationException("Not yet implemented!");
if(this.shouldUpdate){
this.updateFile(structure);
} else {
this.createFile(structure);
}
}
/**
* Updates the existing file with the new contents of specific methods
* @param structure The project
*/
public void update(ProjectStructure structure){
public void updateFile(ProjectStructure structure){
throw new UnsupportedOperationException("Not yet implemented!");
}
/**
* Creates contents for a new file that represents this class
* @param structure The project
*/
public void createFile(ProjectStructure structure){
throw new UnsupportedOperationException("Not yet implemented!");
}