Skip to content

Commit

Permalink
Interface Export
Browse files Browse the repository at this point in the history
Library Changes
Interface Export
  • Loading branch information
TheblueMan003 committed Nov 8, 2022
1 parent 437ede6 commit 7865a22
Show file tree
Hide file tree
Showing 47 changed files with 563 additions and 95,884 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified .vs/BluePhoenix/v17/.suo
Binary file not shown.
Binary file added .vs/BluePhoenix/v17/HierarchyCache.v1.txt
Binary file not shown.
9 changes: 9 additions & 0 deletions JSharp/BluePhoenix.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@
<Compile Include="GameruleForm.Designer.cs">
<DependentUpon>GameruleForm.cs</DependentUpon>
</Compile>
<Compile Include="GUI\NPCEditor.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="GUI\NPCEditor.Designer.cs">
<DependentUpon>NPCEditor.cs</DependentUpon>
</Compile>
<Compile Include="ImageGenerator.cs" />
<Compile Include="Inspector.cs">
<SubType>Form</SubType>
Expand Down Expand Up @@ -302,6 +308,9 @@
<EmbeddedResource Include="GameruleForm.resx">
<DependentUpon>GameruleForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="GUI\NPCEditor.resx">
<DependentUpon>NPCEditor.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Inspector.resx">
<DependentUpon>Inspector.cs</DependentUpon>
</EmbeddedResource>
Expand Down
225 changes: 143 additions & 82 deletions JSharp/Compiler.cs

Large diffs are not rendered by default.

191 changes: 124 additions & 67 deletions JSharp/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using static JSharp.Compiler.Function;

namespace JSharp
{
Expand All @@ -32,6 +33,7 @@ public partial class Form1 : Form
public ProjectVersion projectVersion = new ProjectVersion();
public Compiler.CompilerSetting compilerSetting = new Compiler.CompilerSetting();

private CompilerCore core;
public string projectDescription;

private string previous = "load";
Expand Down Expand Up @@ -974,7 +976,8 @@ public static void SafeCopy(string src, string dest)
}
public int SafeWriteFile(string fileName, string content)
{
string filePath = fileName.Substring(0, fileName.LastIndexOf('/'));
var filedir = fileName.Replace("\\", "/");
string filePath = filedir.Substring(0, filedir.LastIndexOf('/'));
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
Expand Down Expand Up @@ -1018,61 +1021,67 @@ public void Compile(bool showForm = false)
{
this.showForm = showForm;
projectVersion.Build();
compileFile = new List<Compiler.File>();
GetCompileFiles();
if (CompileThread != null && CompileThread.IsAlive)
CompileThread.Abort();

recallFile();
CompileThread = new Thread(CompileThreaded);
CompileThread.Priority = ThreadPriority.Highest;
CompileThread.Start();
}
}

foreach (string f in codeOrder)
{
compileFile.Add(new Compiler.File(f, code[f].content.Replace('\t' + "", "")));
}

bool rp = WasRPChanged();
private void GetCompileFiles()
{
compileFile = new List<Compiler.File>();

string rpdir = Path.GetDirectoryName(projectPath) + "/resourcespack";
if (Directory.Exists(rpdir) && rp)
recallFile();

foreach (string f in codeOrder)
{
compileFile.Add(new Compiler.File(f, code[f].content.Replace('\t' + "", "")));
}

bool rp = WasRPChanged();

string rpdir = Path.GetDirectoryName(projectPath) + "/resourcespack";
if (currentDataPack != null && Directory.Exists(Path.GetDirectoryName(currentDataPack) + "/"))
{
foreach (var file in Directory.GetFiles(Path.GetDirectoryName(currentDataPack) + "/", "*.bpi", SearchOption.AllDirectories))
{
foreach (var file in Directory.GetFiles(rpdir, "*.bps", SearchOption.AllDirectories))
if (Path.GetFileName(file) != Path.GetFileName(currentDataPack) + ".bpi")
{
var f = new Compiler.File(file.Replace(rpdir, ""), File.ReadAllText(file).Replace('\t' + "", ""));
f.resourcespack = true;
compileFile.Add(f);
var f = new Compiler.File("outside", File.ReadAllText(file).Replace('\t' + "", ""));
compileFile.Insert(0, f);
}
}

compileResource = new List<Compiler.File>();
foreach (string f in resourceOrder)
}
if (Directory.Exists(rpdir) && rp)
{
foreach (var file in Directory.GetFiles(rpdir, "*.bps", SearchOption.AllDirectories))
{
compileResource.Add(new Compiler.File(f, resources[f].content.Replace('\t' + "", "")));
var f = new Compiler.File(file.Replace(rpdir, ""), File.ReadAllText(file).Replace('\t' + "", ""));
f.resourcespack = true;
compileFile.Add(f);
}
if (CompileThread != null && CompileThread.IsAlive)
CompileThread.Abort();
}

CompileThread = new Thread(CompileThreaded);
CompileThread.Priority = ThreadPriority.Highest;
CompileThread.Start();
compileResource = new List<Compiler.File>();
foreach (string f in resourceOrder)
{
compileResource.Add(new Compiler.File(f, resources[f].content.Replace('\t' + "", "")));
}
}

public void GetCallStackTrace()
{
if (isCompiling == 0)
{
this.showForm = true;
projectVersion.Build();
compileFile = new List<Compiler.File>();

recallFile();

foreach (string f in codeOrder)
{
compileFile.Add(new Compiler.File(f, code[f].content.Replace('\t' + "", "")));
}
GetCompileFiles();

compileResource = new List<Compiler.File>();
foreach (string f in resourceOrder)
{
compileResource.Add(new Compiler.File(f, resources[f].content.Replace('\t' + "", "")));
}
if (CompileThread != null && CompileThread.IsAlive)
CompileThread.Abort();
CompileThread = new Thread(GetCallStackTraceThreaded);
Expand All @@ -1085,7 +1094,7 @@ public void CompileThreaded()
try
{
isCompiling = 1;
CompilerCore core;

if (compilerSetting.CompilerCoreName == "java") { core = new CompilerCoreJava(); }
else if (compilerSetting.CompilerCoreName == "bedrock") { core = new CompilerCoreBedrock(); }
else { throw new Exception("Unknown Compiler Core"); }
Expand Down Expand Up @@ -1309,6 +1318,10 @@ public void ExportDataPack(string path, string rpPath)
JsonConvert.SerializeObject(new DataPackMeta(projectName + " - " + projectDescription,
compilerSetting.packformat)));

if (compilerSetting.exportInterface)
{
ExportInterface(path + ".bpi");
}
if (compilerSetting.ExportAsZip)
{
if (!path.EndsWith(".zip")) path += ".zip";
Expand All @@ -1334,37 +1347,64 @@ public void ExportDataPack(string path, string rpPath)
if (Directory.Exists(ProjectPath + "unzip")) Directory.Delete(ProjectPath + "unzip", true);
}
}
public void ExportFiles(string path)
public void ExportInterface(string path)
{
string ProjectPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "/";
List<Compiler.File> files = new List<Compiler.File>();
foreach (string f in codeOrder)
try
{
files.Add(new Compiler.File(f, code[f].content.Replace('\t' + "", "")));
}
core = new CompilerCoreJava();
string GetName(Compiler.Function f)
{
return f.gameName.Replace(":", ".").Replace("/", ".");
}
string GetArg(Compiler.Function f)
{
string str = "";
for (int i = 0; i < f.args.Count; i++)
{
str += i == 0 ? $"int ${i}" : $", int ${i}";
}
return str;
}
string GetContent(Compiler.Function f)
{
string str = "";
for (int i = 0; i < f.args.Count; i++)
{
str += $"/scoreboard players operation {f.args[i].scoreboard()} = ${i}.scoreboard\n";
}
str += $"/function {f.gameName}\n";
return str;
}

string rpdir = Path.GetDirectoryName(projectPath) + "/resourcespack";
if (Directory.Exists(rpdir) && exportRP)
{
foreach (var file in Directory.GetFiles(rpdir, "*.bps", SearchOption.AllDirectories))
var functions = Compiler.functions
.SelectMany(x => x.Value)
.Where(f => !f.isLambda && f.isPublic && !f.lazy)
.Select(f => $"def lazy {GetName(f)}({GetArg(f)}){{\n{GetContent(f)}}}\n").ToList();
if (functions.Count != 0)
{
var f = new Compiler.File(file.Replace(rpdir, ""), File.ReadAllText(file).Replace('\t' + "", ""));
f.resourcespack = true;
files.Add(f);
var text = functions.Aggregate((x, y) => x + y);

SafeWriteFile(path, $"package .\n{functions}");
}
}

List<Compiler.File> resourcesfiles = new List<Compiler.File>();
foreach (string f in resourceOrder)
catch(Exception e)
{
resourcesfiles.Add(new Compiler.File(f, resources[f].content.Replace('\t' + "", "")));

}
}
public void ExportFiles(string path)
{
string ProjectPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "/";
string rpdir = Path.GetDirectoryName(projectPath) + "/resourcespack";

GetCompileFiles();

CompilerCore core;
if (compilerSetting.CompilerCoreName == "java") { core = new CompilerCoreJava(); }
else if (compilerSetting.CompilerCoreName == "bedrock") { core = new CompilerCoreBedrock(); }
else { throw new Exception("Unknown Compiler Core"); }

List<Compiler.File> cFiles = Compiler.compile(core, projectName, files, resourcesfiles,
List<Compiler.File> cFiles = Compiler.compile(core, projectName, compileFile, compileResource,
DebugThread, compilerSetting, projectVersion,
Path.GetDirectoryName(projectPath));

Expand Down Expand Up @@ -1532,7 +1572,10 @@ public void ExportReadMe(string path)
}
public void ExportStructures(string path)
{
SyncStructure();
if (projectPath != null)
{
SyncStructure();
}

string ProjectPath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "/";
if (projectPath != null && Directory.Exists(path + "imported_dp/structure/"))
Expand Down Expand Up @@ -2777,24 +2820,38 @@ private void InvalidateRP_Click(object sender, EventArgs e)

private void button11_Click(object sender, EventArgs e)
{
compilerSetting.structuresSource = Directory.GetParent(currentDataPack).Parent.FullName + "/generated/minecraft/structures";
SyncStructure();
}

private void SyncStructure()
{
compilerSetting.structuresSource = Directory.GetParent(currentDataPack).Parent.FullName + "/generated/minecraft/structures";
if (Directory.Exists(compilerSetting.structuresSource))
try
{
var p = compilerSetting.structuresSource.Replace("\\\\", "/").Replace("\\", "/");
Directory.EnumerateFiles(compilerSetting.structuresSource, "*.*", SearchOption.AllDirectories)
.Where(x => !compilerSetting.structuresSources.ContainsKey(x) || File.GetLastWriteTime(x) != compilerSetting.structuresSources[x])
.ToList()
.ForEach(x =>
if (compilerSetting.structuresSource != null)
{
var projectDirectory = ProjectFolder() + "/structures/";
if (!Directory.Exists(projectDirectory))
Directory.CreateDirectory(projectDirectory);

if (Directory.Exists(compilerSetting.structuresSource))
{
compilerSetting.structuresSources[x] = File.GetLastWriteTime(x);
Debug($"Import Structure: {x}", Color.Yellow);
File.Copy(x, ProjectFolder() + "/structures/" + x.Replace("\\\\", "/").Replace("\\", "/").Replace(p, ""), true);
});
var p = compilerSetting.structuresSource.Replace("\\\\", "/").Replace("\\", "/");
Directory.EnumerateFiles(compilerSetting.structuresSource, "*.*", SearchOption.AllDirectories)
.Where(x => !compilerSetting.structuresSources.ContainsKey(x) || File.GetLastWriteTime(x) != compilerSetting.structuresSources[x])
.ToList()
.ForEach(x =>
{
compilerSetting.structuresSources[x] = File.GetLastWriteTime(x);
Debug($"Import Structure: {x}", Color.Yellow);
File.Copy(x, ProjectFolder() + "/structures/" + x.Replace("\\\\", "/").Replace("\\", "/").Replace(p, ""), true);
});
}
}
}
catch
{
Debug("Failled To Sync Structure", Color.Yellow);
}
}

Expand Down
8 changes: 4 additions & 4 deletions JSharp/FunctionPreview.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7865a22

Please sign in to comment.