Skip to content

Commit

Permalink
Add members list/browser, fix state declaration, improve generation p…
Browse files Browse the repository at this point in the history
…erformance
  • Loading branch information
shrimpza committed Jul 6, 2024
1 parent 25ac009 commit ede3845
Show file tree
Hide file tree
Showing 17 changed files with 169 additions and 37 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group = 'net.shrimpworks'
version = "1.1"
version = "1.2"

mainClassName = 'net.shrimpworks.unreal.scriptbrowser.App'

Expand All @@ -20,7 +20,7 @@ repositories {
dependencies {
antlr 'org.antlr:antlr4:4.13.1'

implementation 'org.freemarker:freemarker:2.3.32'
implementation 'org.freemarker:freemarker:2.3.33'

testImplementation 'org.junit.jupiter:junit-jupiter:5.9.2'
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ replicationidentifiers : identifier ( ',' identifier )*;
body : ( statedecl | functiondecl )+;

// State parts
statedecl : ( stateparams )* STATE ('(' ')')? identifier ( configgroup )? ( EXTENDS identifier )? statebody;
statename : identifier;
statedecl : ( stateparams )* STATE ('(' ')')? statename ( configgroup )? ( EXTENDS identifier )? statebody;
statebody : '{' ( stateignore )? ( functiondecl )* statelabels '}';
stateignore : IGNORES identifier ( ',' identifier )* ';';
statelabel : identifier ':' ( statement )*;
Expand Down
25 changes: 14 additions & 11 deletions src/main/java/net/shrimpworks/unreal/scriptbrowser/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -35,8 +36,8 @@ public Progress(int total) {
public void progress(int processed, UClass current) {
int prog = (int)((processed / total) * WIDTH);
int space = WIDTH - prog;
System.err.printf("\r [%s%s] %d/%d: %-20s", "=".repeat(prog), " ".repeat(space),
processed, (int)total, current.name.substring(0, Math.min(20, current.name.length())));
System.err.printf("\r [%s%s] %d/%d: %-30s", "=".repeat(prog), " ".repeat(space),
processed, (int)total, current.name.substring(0, Math.min(30, current.name.length())));
}
}

Expand Down Expand Up @@ -64,13 +65,14 @@ public static void main(String[] args) throws IOException {
System.err.println(" - Generating source pages");
Progress p = new Progress(source.classCount());
AtomicInteger counter = new AtomicInteger();
source.packages.values().forEach(pkg -> pkg.classes.values().parallelStream()
.filter(c -> c.kind == UClass.UClassKind.CLASS)
.forEach(c -> {
p.progress(counter.incrementAndGet(), c);
Generator.src(c, srcOut);
}));
System.err.printf("\r%-80s", ""); // clear progress :/
source.packages.values().parallelStream()
.forEach(pkg -> pkg.classes.values().parallelStream()
.filter(c -> c.kind == UClass.UClassKind.CLASS)
.forEach(c -> {
p.progress(counter.incrementAndGet(), c);
Generator.src(c, srcOut);
}));
System.err.printf("\r%-90s", ""); // clear progress :/

Generator.home(source, srcOut);

Expand Down Expand Up @@ -118,12 +120,13 @@ private static void loadSources(USources sources, Path srcPath) throws IOExcepti
try (Stream<Path> paths = Files.list(srcPath)) {
System.err.printf(" - Loading classes from %s%n", srcPath);

paths.map(p -> {
paths.parallel()
.map(p -> {
if (!Files.isDirectory(p)) return null;
final UPackage pkg = new UPackage(sources, fileName(p));

try (Stream<Path> all = Files.walk(p, 3)) {
all.forEach(f -> {
all.parallel().forEach(f -> {
if (!extension(f).equalsIgnoreCase("uc")) return;

ClassInfoListener.processFile(f, pkg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public UClass(UClassKind kind, Path path, UPackage pkg, String name, String pare
}

public void addMember(UMember.UMemberKind kind, String type, String name) {
if (members.stream().anyMatch(m -> m.kind == kind && m.name.equalsIgnoreCase(name))) return;

members.add(new UMember(this, kind, type, name));
}

Expand Down Expand Up @@ -75,6 +77,25 @@ public Optional<UMember> function(String name) {
.or(() -> functions().stream().filter(v -> v.name.equalsIgnoreCase(name)).findFirst());
}

public Set<UMember> localVariables() {
return localMembers(UMember.UMemberKind.VARIABLE)
// since this is used for listing in the UI, we don't actually want to surface default and super
.stream().filter(m -> !m.name.equalsIgnoreCase("default") && !m.name.equalsIgnoreCase("super"))
.collect(Collectors.toSet());
}
public Set<UMember> localFunctions() {
return localMembers(UMember.UMemberKind.FUNCTION);
}
public Set<UMember> localStructs() {
return localMembers(UMember.UMemberKind.STRUCT);
}
public Set<UMember> localEnums() {
return localMembers(UMember.UMemberKind.ENUM);
}
public Set<UMember> localStates() {
return localMembers(UMember.UMemberKind.STATE);
}

private Set<UMember> members(UMember.UMemberKind kind) {
Set<UMember> mems = localMembers(kind);
parent().ifPresent(p -> mems.addAll(p.members(kind)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public void enterEveryRule(ParserRuleContext ctx) {
public void enterClassdecl(UnrealScriptParser.ClassdeclContext ctx) {
tokenStyle(ctx.CLASS(), "kw");
tokenStyle(ctx.classname(), "cls");
tokenAnchor(ctx.CLASS().getSymbol(), "class");
tokenStyle(ctx.parentclass(), "cls");
ctx.classparams().forEach(p -> tokenStyle(p, "kw"));
tokenStyle(ctx.EXPANDS(), "kw");
Expand Down Expand Up @@ -411,6 +412,7 @@ public void enterFunctiondecl(UnrealScriptParser.FunctiondeclContext ctx) {
@Override
public void enterReplicationblock(UnrealScriptParser.ReplicationblockContext ctx) {
tokenStyle(ctx.REPLICATION(), "kw");
tokenAnchor(ctx.REPLICATION().getSymbol(), "replication");
}

@Override
Expand All @@ -434,7 +436,17 @@ public void enterStatedecl(UnrealScriptParser.StatedeclContext ctx) {
ctx.stateparams().forEach(p -> tokenStyle(p, "kw"));
tokenStyle(ctx.STATE(), "kw");
tokenStyle(ctx.EXTENDS(), "kw");
ctx.identifier().forEach(i -> tokenStyle(i, "cls"));
tokenStyle(ctx.statename(), "cls");
tokenStyle(ctx.identifier(), "cls");
tokenAnchor(ctx.statename(), ctx.statename().getText());
}

@Override
public void enterStateignore(UnrealScriptParser.StateignoreContext ctx) {
ctx.identifier().forEach(i -> {
clazz.function(i.getText())
.ifPresent(v -> memberLink(i, v));
});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public void exitStatebody(UnrealScriptParser.StatebodyContext ctx) {

@Override
public void enterStatedecl(UnrealScriptParser.StatedeclContext ctx) {
if (!inState) return;
ctx.identifier().forEach(i -> clazz.addMember(UClass.UMember.UMemberKind.STATE, null, i.getText()));
// if (!inState) return;
clazz.addMember(UClass.UMember.UMemberKind.STATE, null, ctx.statename().identifier().getText());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

public class Generator {

private static final Configuration TPL_CONFIG = new Configuration(Configuration.VERSION_2_3_31);
private static final Configuration TPL_CONFIG = new Configuration(Configuration.VERSION_2_3_32);

static {
TPL_CONFIG.setClassForTemplateLoading(Generator.class, "");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,56 @@

<body>
<article id="script">
<section id="members">
<div class="title">Shortcuts</div>
<div class="group">
<div><a href="#class">Declaration</a></div>
<div id="replication-jump"><a href="#replication">Replication</a></div>
<div id="default-jump"><a href="#default">Default Properties</a></div>
</div>

<#list clazz.localVariables?sort_by("name")>
<div class="title">Variables</div>
<div class="group">
<#items as m>
<div><a href="#${m.name?c_lower_case}">${m.name}</a></div>
</#items>
</div>
</#list>
<#list clazz.localEnums?sort_by("name")>
<div class="title">Enums</div>
<div class="group">
<#items as m>
<div><a href="#${m.name?c_lower_case}">${m.name}</a></div>
</#items>
</div>
</#list>
<#list clazz.localStructs?sort_by("name")>
<div class="title">Structs</div>
<div class="group">
<#items as m>
<div><a href="#${m.name?c_lower_case}">${m.name}</a></div>
</#items>
</div>
</#list>
<#list clazz.localFunctions?sort_by("name")>
<div class="title">Functions</div>
<div class="group">
<#items as m>
<div><a href="#${m.name?c_lower_case}">${m.name}</a></div>
</#items>
</div>
</#list>
<#list clazz.localStates?sort_by("name")>
<div class="title">States</div>
<div class="group">
<#items as m>
<div><a href="#${m.name?c_lower_case}">${m.name}</a></div>
</#items>
</div>
</#list>
</section>

<section id="lines">
<#list 1..lines as line><div>${line?c}</div></#list>
</section>
Expand Down Expand Up @@ -54,7 +104,17 @@
console.log("unknown message event ", m.data.event, m.data)
}
}
})
});
if (!document.getElementById("replication")) {
const j = document.getElementById("replication-jump");
j.parentNode.removeChild(j);
}
if (!document.getElementById("default")) {
const j = document.getElementById("default-jump");
j.parentNode.removeChild(j);
}
})
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
--source-bg: #272822;
--secondary-bg: #3c3f41;
--lines-color: #6e6f6c;
--lines-gb: var(--source-bg);
--lines-bg: var(--source-bg);
--comment: #74715e;
--directive: var(--comment);
--operator: #f92772;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
--source-bg: #fafafe;
--secondary-bg: #f5fbfc;
--lines-color: #a9a9a9;
--lines-gb: var(--source-bg);
--lines-bg: var(--source-bg);
--comment: #009933;
--directive: #cc0000;
--operator: var(--source-color);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
--source-bg: #002a35;
--secondary-bg: #053542;
--lines-color: gray;
--lines-gb: var(--secondary-bg);
--lines-bg: var(--secondary-bg);
--comment: #657b83;
--directive: var(--comment);
--operator: #cb4b16;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
--source-bg: #fdf6e3;
--secondary-bg: #eee8d5;
--lines-color: gray;
--lines-gb: var(--secondary-bg);
--lines-bg: var(--secondary-bg);
--comment: #839496;
--directive: var(--comment);
--operator: #cb4b16;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
--source-bg: white;
--secondary-bg: #e9e9e9;
--lines-color: gray;
--lines-gb: #e9e9e9;
--lines-bg: #e9e9e9;
--members-color: var(--lines-color);
--members-bg: var(--lines-bg);
--members-link-color: var(--color);
--comment: gray;
--directive: darkgreen;
--operator: brown;
Expand Down Expand Up @@ -51,7 +54,7 @@ header {
padding-left: 10px;

background-color: var(--source-bg);
border-left: 50px solid var(--lines-gb);
border-left: 50px solid var(--lines-bg);
}

/* Source tree and class filtering */
Expand Down Expand Up @@ -236,8 +239,8 @@ header h1 {

#script {
display: grid;
grid-template: "lines source";
grid-template-columns: 50px 1fr;
grid-template: "members lines source";
grid-template-columns: 250px 50px 1fr;
grid-gap: 10px;

width: 100vw;
Expand All @@ -248,6 +251,35 @@ header h1 {
font-size: 1.1em;
}

#members {
grid-area: members;
position: fixed;
height: 100%;
overflow: scroll;
width: 250px;
padding: 5px;

font-size: 1em;
line-height: 1.3em;

color: var(--members-color);
background-color: var(--members-bg);
}

#members a {
color: var(--members-link-color);
text-decoration: none;
}

#members .title {
font-weight: bold;
}

#members .group {
font-family: monospace;
padding: 5px 0 10px 10px;
}

#lines {
grid-area: lines;
min-height: 100%;
Expand All @@ -259,7 +291,7 @@ header h1 {
line-height: 1.4em;

color: var(--lines-color);
background-color: var(--lines-gb);
background-color: var(--lines-bg);
}

#script pre {
Expand Down
Loading

0 comments on commit ede3845

Please sign in to comment.