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

This commit is contained in:
austin 2024-07-31 15:17:58 -04:00
parent ecab7952b7
commit e0b914b9b8
7 changed files with 58 additions and 18 deletions

View File

@ -3,6 +3,7 @@ package electrosphere.main;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
@ -100,9 +101,12 @@ public class Main {
content.contains("@SynchronizedBehaviorTree") ||
isHardCodedAlwaysParse(currentFile.getName())
){
//get relative path
Path relativePath = topLevelFolder.toPath().relativize(currentFile.toPath());
String relativePathString = "src/main/java/electrosphere/" + relativePath.toString();
//parse
JavaClassSource source = parseJavaFile(content);
rVal.add(new TargetFile(currentFile.getAbsolutePath(), content, currentFile.getName(), source));
rVal.add(new TargetFile(currentFile.getAbsolutePath(), relativePathString, content, currentFile.getName(), source));
}
} catch (IOException e){
e.printStackTrace();

View File

@ -24,7 +24,7 @@ public class ClientSynchronizationManager extends VirtualClass {
*/
public ClientSynchronizationManager(TargetFile file) {
super(
"src/main/java/electrosphere/net/synchronization/ClientSynchronizationManager.java",
file,
"ClientSynchronizationManager",
true
);

View File

@ -4,13 +4,14 @@ import java.util.LinkedList;
import java.util.List;
import electrosphere.main.core.syncfield.SynchronizedField;
import electrosphere.main.source.VirtualClass;
import electrosphere.main.targets.TargetFile;
import electrosphere.main.util.TemplateInjectionUtils;
/**
* Represents a behavior tree in the source code
*/
public class BehaviorTree {
public class BehaviorTree extends VirtualClass {
//id assigned to the tree by this tool
int id;
@ -49,6 +50,7 @@ public class BehaviorTree {
boolean isServer,
TargetFile targetFile
){
super(targetFile,className,true);
this.id = id;
this.name = name;
this.className = className;

View File

@ -8,6 +8,7 @@ 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.targets.TargetFile;
import electrosphere.main.util.ClassSourceUtils;
/**
@ -20,7 +21,13 @@ public class BTreeIdEnum extends VirtualClass {
*/
public BTreeIdEnum() {
super(
"src/main/java/electrosphere/net/synchronization/BehaviorTreeIdEnums.java",
new TargetFile(
null,
"src/main/java/electrosphere/net/synchronization/BehaviorTreeIdEnums.java",
"",
"BehaviorTreeIdEnums",
null
),
"BehaviorTreeIdEnums",
false
);
@ -34,7 +41,7 @@ public class BTreeIdEnum extends VirtualClass {
public void createFile(ProjectStructure structure){
String source = "";
File outFile = new File(structure.getRootFolder().getAbsolutePath()).toPath().resolve(this.getLocation()).toFile();
File outFile = new File(structure.getRootFolder().getAbsolutePath()).toPath().resolve(this.getTargetFile().getRelativePath()).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

@ -8,6 +8,7 @@ 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.targets.TargetFile;
import electrosphere.main.util.ClassSourceUtils;
/**
@ -20,7 +21,13 @@ public class FieldIdEnum extends VirtualClass {
*/
public FieldIdEnum() {
super(
"src/main/java/electrosphere/net/synchronization/FieldIdEnums.java",
new TargetFile(
null,
"src/main/java/electrosphere/net/synchronization/FieldIdEnums.java",
"",
"FieldIdEnums",
null
),
"FieldIdEnums",
false
);
@ -34,7 +41,7 @@ public class FieldIdEnum extends VirtualClass {
public void createFile(ProjectStructure structure){
String source = "";
File outFile = new File(structure.getRootFolder().getAbsolutePath()).toPath().resolve(this.getLocation()).toFile();
File outFile = new File(structure.getRootFolder().getAbsolutePath()).toPath().resolve(this.getTargetFile().getRelativePath()).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

@ -4,6 +4,7 @@ import java.io.File;
import java.util.List;
import electrosphere.main.project.ProjectStructure;
import electrosphere.main.targets.TargetFile;
import electrosphere.main.util.ClassSourceUtils;
/**
@ -11,12 +12,13 @@ import electrosphere.main.util.ClassSourceUtils;
*/
public abstract class VirtualClass {
//the location of the file
private String LOCATION;
//the class's name
private String CLASSNAME;
//controls whether this class should update or generate from scratch
private boolean shouldUpdate;
//The file this type appears in
private TargetFile targetFile;
/**
* All the imports in this virtual class
@ -35,12 +37,12 @@ public abstract class VirtualClass {
/**
* Constructor
* @param location The location of the file
* @param targetFile The target file for this class
* @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, boolean shouldUpdate){
this.LOCATION = location;
public VirtualClass(TargetFile targetFile, String name, boolean shouldUpdate){
this.targetFile = targetFile;
this.CLASSNAME = name;
this.shouldUpdate = shouldUpdate;
}
@ -51,7 +53,7 @@ public abstract class VirtualClass {
* @return The qualified path
*/
public String getQualifiedPath(ProjectStructure structure){
File outFile = new File(structure.getRootFolder().getAbsolutePath()).toPath().resolve(LOCATION).toFile();
File outFile = new File(structure.getRootFolder().getAbsolutePath()).toPath().resolve(targetFile.getRelativePath()).toFile();
return ClassSourceUtils.getPackageSourcePath(structure, outFile) + "." + CLASSNAME;
}
@ -65,11 +67,10 @@ public abstract class VirtualClass {
}
/**
* Gets the location of this file
* @return The location
* Gets the target file for this class
*/
public String getLocation(){
return this.LOCATION;
public TargetFile getTargetFile(){
return this.targetFile;
}
/**

View File

@ -16,6 +16,8 @@ public class TargetFile {
//the path of the file
String path;
//The path relative to the source directory
String relativePath;
//the original content of the file
String originalContent;
//The content, with any modifications made by the netcode generator
@ -35,8 +37,9 @@ public class TargetFile {
* @param name
* @param source
*/
public TargetFile(String path, String content, String name, JavaClassSource source){
public TargetFile(String path, String relativePath, String content, String name, JavaClassSource source){
this.path = path;
this.relativePath = relativePath;
this.originalContent = content;
this.modifiedContent = new StringBuilder(content);
this.name = name;
@ -130,4 +133,20 @@ public class TargetFile {
return rVal;
}
/**
* Gets the file path of the target file
* @return The file path
*/
public String getPath(){
return this.path;
}
/**
* The path of the target file relative to the root folder of the project
* @return The relative path
*/
public String getRelativePath(){
return this.relativePath;
}
}