diff --git a/src/main/java/electrosphere/main/Main.java b/src/main/java/electrosphere/main/Main.java index cec856d..6fe4155 100644 --- a/src/main/java/electrosphere/main/Main.java +++ b/src/main/java/electrosphere/main/Main.java @@ -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(); diff --git a/src/main/java/electrosphere/main/client/ClientSynchronizationManager.java b/src/main/java/electrosphere/main/client/ClientSynchronizationManager.java index 47ec75e..42625d6 100644 --- a/src/main/java/electrosphere/main/client/ClientSynchronizationManager.java +++ b/src/main/java/electrosphere/main/client/ClientSynchronizationManager.java @@ -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 ); diff --git a/src/main/java/electrosphere/main/core/btree/BehaviorTree.java b/src/main/java/electrosphere/main/core/btree/BehaviorTree.java index 9d768c6..e077f9b 100644 --- a/src/main/java/electrosphere/main/core/btree/BehaviorTree.java +++ b/src/main/java/electrosphere/main/core/btree/BehaviorTree.java @@ -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; diff --git a/src/main/java/electrosphere/main/core/statics/btreeenum/BTreeIdEnum.java b/src/main/java/electrosphere/main/core/statics/btreeenum/BTreeIdEnum.java index 3728ccf..e9315ee 100644 --- a/src/main/java/electrosphere/main/core/statics/btreeenum/BTreeIdEnum.java +++ b/src/main/java/electrosphere/main/core/statics/btreeenum/BTreeIdEnum.java @@ -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); diff --git a/src/main/java/electrosphere/main/core/statics/fieldenum/FieldIdEnum.java b/src/main/java/electrosphere/main/core/statics/fieldenum/FieldIdEnum.java index 956d314..0077dcd 100644 --- a/src/main/java/electrosphere/main/core/statics/fieldenum/FieldIdEnum.java +++ b/src/main/java/electrosphere/main/core/statics/fieldenum/FieldIdEnum.java @@ -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); diff --git a/src/main/java/electrosphere/main/source/VirtualClass.java b/src/main/java/electrosphere/main/source/VirtualClass.java index 6035b65..e700669 100644 --- a/src/main/java/electrosphere/main/source/VirtualClass.java +++ b/src/main/java/electrosphere/main/source/VirtualClass.java @@ -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; } /** diff --git a/src/main/java/electrosphere/main/targets/TargetFile.java b/src/main/java/electrosphere/main/targets/TargetFile.java index dbfa5d6..69f5806 100644 --- a/src/main/java/electrosphere/main/targets/TargetFile.java +++ b/src/main/java/electrosphere/main/targets/TargetFile.java @@ -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; + } + }