Skip to content

Commit

Permalink
feat(script): Add Text View For Script Scope
Browse files Browse the repository at this point in the history
- Scripts in ScriptsView is now viewable/readable
  • Loading branch information
FlipperPlz committed Jul 27, 2022
1 parent 4436965 commit ad1ec08
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 10 deletions.
20 changes: 20 additions & 0 deletions Es/Models/EnforceClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

using System;
using System.Collections.Generic;
using System.Text;
using Antlr4.Runtime.Misc;
using PakExplorer.Es.Antlr;

Expand Down Expand Up @@ -57,5 +58,24 @@ public EnforceClass(EnforceParser.ClassDeclarationContext ctx) {
}

}


public override string ToString() {
var ctxBuilder = new StringBuilder();
if (ClassAnnotation is not null) ctxBuilder.Append(ClassAnnotation).Append('\n');
if (ModdedClass) ctxBuilder.Append("modded ");
if (SealedClass) ctxBuilder.Append("sealed ");
ctxBuilder.Append("class ").Append(ClassName);

if (ParentClass is not null) ctxBuilder.Append(" : ").Append(ParentClass);
ctxBuilder.Append(" {\n");
if (Variables.Count != 0) ctxBuilder.Append("//-----------------------------Variables---------------------------------\n");
Variables.ForEach(v => ctxBuilder.Append(v).Append(';').Append("\n\n"));
if (Functions.Count != 0) ctxBuilder.Append("//-----------------------------Functions---------------------------------\n");
Functions.ForEach(f => ctxBuilder.Append(f).Append("\n\n"));

ctxBuilder.Append('}');
return ctxBuilder.ToString();
}
}

24 changes: 24 additions & 0 deletions Es/Models/EnforceEnum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// *******************************************************/

using System.Collections.Generic;
using System.Text;
using Antlr4.Runtime.Misc;
using PakExplorer.Es.Antlr;

Expand Down Expand Up @@ -64,4 +65,27 @@ public EnforceEnum(EnforceParser.EnumDeclarationContext ctx) {
}
}
}

public override string ToString() {
var ctxBuilder = new StringBuilder();
if (EnumAnnotation is not null) ctxBuilder.Append(EnumAnnotation).Append('\n');
if (ModdedEnum) ctxBuilder.Append("modded ");
if (SealedEnum) ctxBuilder.Append("sealed ");
ctxBuilder.Append("enum ").Append(EnumName);
if (EnumParent is not null) ctxBuilder.Append(" : ").Append(EnumParent);
ctxBuilder.Append(" {\n\t");

var enumValues = new List<string>();
foreach (var (k, v) in EnumValues) {
var val = new StringBuilder(k);
if (v is not null) val.Append(" = ").Append(v);
enumValues.Add(val.ToString());

}

ctxBuilder.Append(string.Join(",\n\t", enumValues)).Append('\n');
ctxBuilder.Append('}');

return ctxBuilder.ToString();
}
}
20 changes: 17 additions & 3 deletions Es/Models/EnforceFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
// *******************************************************/

using System.Collections.Generic;
using System.Text;
using PakExplorer.Es.Antlr;

namespace PakExplorer.Es.Models;
Expand All @@ -22,16 +23,29 @@ public class EnforceFile {
public EnforceFile(EnforceParser.ComputationalUnitContext ctx) {
if (ctx.globalDeclaration() is { } globalDeclarations) {
foreach (var globalDeclaration in globalDeclarations) {
if(globalDeclaration.methodDeclaration() is { } method) Functions.Add(new EnforceFunction(method));
if (globalDeclaration.methodDeclaration() is { } method) Functions.Add(new EnforceFunction(method));
if (globalDeclaration.fieldDeclaration() is { } field) Variables.Add(new EnforceVariable(field));
}
}

if (ctx.typeDeclaration() is { } typeDeclarations) {
foreach (var typeDeclaration in typeDeclarations) {
if(typeDeclaration.classDeclaration() is { } clazz) Classes.Add(new EnforceClass(clazz));
if(typeDeclaration.enumDeclaration() is { } enumCtx) Enums.Add(new EnforceEnum(enumCtx));
if (typeDeclaration.classDeclaration() is { } clazz) Classes.Add(new EnforceClass(clazz));
if (typeDeclaration.enumDeclaration() is { } enumCtx) Enums.Add(new EnforceEnum(enumCtx));
}
}
}

public override string ToString() {
var ctxBuilder = new StringBuilder();
if (Variables.Count != 0) ctxBuilder.Append("//-----------------------------Variables---------------------------------\n");
Variables.ForEach(v => ctxBuilder.Append(v).Append(';').Append("\n\n"));
if (Functions.Count != 0) ctxBuilder.Append("//-----------------------------Functions---------------------------------\n");
Functions.ForEach(f => ctxBuilder.Append(f).Append("\n\n"));
if (Classes.Count != 0) ctxBuilder.Append("//------------------------------Classes----------------------------------\n");
Classes.ForEach(c => ctxBuilder.Append(c).Append("\n\n"));
if (Enums.Count != 0) ctxBuilder.Append("//-------------------------------Enums-----------------------------------\n");
Enums.ForEach(e => ctxBuilder.Append(e).Append("\n\n"));
return ctxBuilder.ToString();
}
}
11 changes: 11 additions & 0 deletions Es/Models/EnforceFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

using System;
using System.Collections.Generic;
using System.Text;
using Antlr4.Runtime.Misc;
using PakExplorer.Es.Antlr;

Expand Down Expand Up @@ -64,4 +65,14 @@ public EnforceFunction(EnforceParser.MethodDeclarationContext ctx) {
}
}


public override string ToString() {
var ctxBuilder = new StringBuilder();
if (FunctionAnnotation is not null) ctxBuilder.Append(FunctionAnnotation).Append('\n');
ctxBuilder.Append(string.Join(' ', FunctionModifiers)).Append(' ').Append(FunctionType).Append(' ');
if (IsDeconstructor) ctxBuilder.Append('~');
ctxBuilder.Append(FunctionName).Append('(').Append(string.Join(", ", FunctionParameters)).Append(") ")
.Append(FunctionBody);
return ctxBuilder.ToString();
}
}
19 changes: 19 additions & 0 deletions Es/Models/EnforceVariable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
// * permission of Ryann
// *******************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Antlr4.Runtime.Misc;
using PakExplorer.Es.Antlr;

Expand Down Expand Up @@ -162,4 +165,20 @@ public EnforceVariable(EnforceParser.LocalVariableDeclarationContext ctx) {

}


public override string ToString() {
var ctxBuilder = new StringBuilder();
if (VariableAnnotation is not null) ctxBuilder.Append(VariableAnnotation).Append('\n');
ctxBuilder.Append(string.Join(' ', VariableModifiers)).Append(' ').Append(VariableType).Append(' ');

var variableBuilder = new List<string>();
foreach (var (k, v) in Variables) {
var def = k;
if (v is not null) def += " = " + v;
variableBuilder.Add(def);
}

ctxBuilder.Append(string.Join(", ", variableBuilder));
return ctxBuilder.ToString();
}
}
24 changes: 24 additions & 0 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Win32;
using PakExplorer.Es.Models;
using PakExplorer.Pak;
using PakExplorer.Tree;
using PakExplorer.Tree.Files;
using PakExplorer.Tree.Items;
using PakExplorer.Tree.Items.Es;
using PakExplorer.Tree.Items.Es.Child;

namespace PakExplorer {
/// <summary>
Expand Down Expand Up @@ -84,6 +86,28 @@ private void Show(FileBase entry) {
}

private void ShowPakScript(object sender, RoutedPropertyChangedEventArgs<object> e) {
switch (e.NewValue) {
case EnforceScriptTreeItem esItem:
ResetView();
TextPreview.Text = esItem.Scope.ToString();
TextPreview.Visibility = Visibility.Visible;
break;
case EnforceClassTreeItem esClassItem:
ResetView();
TextPreview.Text = esClassItem.EsClazz.ToString();
TextPreview.Visibility = Visibility.Visible;
break;
case EnforceFunctionTreeItem esFunctionItem:
ResetView();
TextPreview.Text = esFunctionItem.EsFunction.ToString();
TextPreview.Visibility = Visibility.Visible;
break;
case EnforceVariableTreeItem esVariableItem:
ResetView();
TextPreview.Text = esVariableItem.EsVariable.ToString() + ';';
TextPreview.Visibility = Visibility.Visible;
break;
}
}

private void EnableScriptParsing_Click(object sender, RoutedEventArgs e) {
Expand Down
31 changes: 30 additions & 1 deletion Tree/Items/Es/Child/EnforceFunctionTreeItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@
// * permission of Ryann
// *******************************************************/

using System;
using System.Collections.Generic;
using System.Text;
using PakExplorer.Es.Models;

namespace PakExplorer.Tree.Items.Es.Child;

public class EnforceFunctionTreeItem : ITreeItem {
public readonly EnforceFunction EsFunction;
public readonly EnforceClass? EsParentClass;
public string Name { get; set; }
public EnforceFunctionTreeItem(EnforceFunction func) {
var nameBuilder = new StringBuilder("{func} ");
EsFunction = func;
EsParentClass = null;
var nameBuilder = new StringBuilder(EsFunction.IsDeconstructor ? "{deconst} " : "{func} ");
nameBuilder.Append(func.FunctionName).Append('(');

List<string> paramsToAppend = new();
Expand All @@ -29,4 +34,28 @@ public EnforceFunctionTreeItem(EnforceFunction func) {
nameBuilder.Append(string.Join(", ", paramsToAppend)).Append("): ").Append(func.FunctionType);
Name = nameBuilder.ToString();
}

public EnforceFunctionTreeItem(EnforceFunction func, EnforceClass parentClass) {
EsFunction = func;
EsParentClass = parentClass;
var nameBuilder = new StringBuilder(string.Equals(parentClass.ClassName, func.FunctionName, StringComparison.CurrentCultureIgnoreCase)
? (func.IsDeconstructor
? "{deconstructor} "
: "{constructor} ")
: "{func}");

nameBuilder.Append(func.FunctionName).Append('(');

List<string> paramsToAppend = new();

foreach (var param in func.FunctionParameters) {
for (var i = 0; i < param.Variables.Count; i++) {
paramsToAppend.Add(param.VariableType);
}
}

nameBuilder.Append(string.Join(", ", paramsToAppend)).Append("): ").Append(func.FunctionType);
Name = nameBuilder.ToString();
}

}
3 changes: 3 additions & 0 deletions Tree/Items/Es/Child/EnforceVariableTreeItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
namespace PakExplorer.Tree.Items.Es.Child;

public class EnforceVariableTreeItem : ITreeItem {
public readonly EnforceVariable EsVariable;
public string Name { get; set; }

public EnforceVariableTreeItem(EnforceVariable variable) {
EsVariable = variable;
var nameBuilder = new StringBuilder("{var} ");
nameBuilder.Append(string.Join(", ", variable.Variables.Keys)).Append(": ").Append(variable.VariableType);
Name = nameBuilder.ToString();
}


}
12 changes: 6 additions & 6 deletions Tree/Items/Es/EnforceClassTreeItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace PakExplorer.Tree.Items.Es;

public class EnforceClassTreeItem : IParentTreeItem {
private readonly EnforceClass _esClazz;
public readonly EnforceClass EsClazz;
public string Name { get; set; }

public ICollection<ITreeItem> Children {
Expand All @@ -26,15 +26,15 @@ public ICollection<ITreeItem> Children {
return col;
}
}
public IEnumerable<ITreeItem> FunctionTreeItems => _esClazz.Functions.Select(static func => new EnforceFunctionTreeItem(func));
public IEnumerable<ITreeItem> VariableTreeItems => _esClazz.Variables.Select(static var => new EnforceVariableTreeItem(var));
public IEnumerable<ITreeItem> FunctionTreeItems => EsClazz.Functions.Select( func => new EnforceFunctionTreeItem(func, EsClazz));
public IEnumerable<ITreeItem> VariableTreeItems => EsClazz.Variables.Select(static var => new EnforceVariableTreeItem(var));
public EnforceClassTreeItem(EnforceClass clazz) {
var nameBuilder = new StringBuilder("{class} ");
if (clazz.ModdedClass) nameBuilder.Append("[modded]");
if (clazz.SealedClass) nameBuilder.Append("[sealed]");
if (clazz.ModdedClass) nameBuilder.Append("[modded] ");
if (clazz.SealedClass) nameBuilder.Append("[sealed] ");
nameBuilder.Append(clazz.ClassName);
if (clazz.ParentClass is not null and not "") nameBuilder.Append(": ").Append(clazz.ParentClass);
Name = nameBuilder.ToString();
_esClazz = clazz;
EsClazz = clazz;
}
}
1 change: 1 addition & 0 deletions Tree/Items/Es/EnforceScriptTreeItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@ private void GenerateScope() {
VariableTreeItems = Scope.Variables.Select(static var => new EnforceVariableTreeItem(var)).ToList();
}

public override string ToString() => Scope.ToString();
}

0 comments on commit ad1ec08

Please sign in to comment.