Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f9b2987
create CI to build & upload .jar file
azrdev Aug 1, 2023
ab9a5e2
CI: remove broken dependency report, add upload of jar to releases
azrdev Aug 1, 2023
986faae
maven/pom.xml: fix build, creating .jar with all dependencies included
Aug 1, 2023
763a71a
fix crash (NPE) due to missing localization file
Aug 1, 2023
c83833f
add README
Aug 1, 2023
fb19865
java: print filename on parse error
Aug 1, 2023
d54fb06
generate antlr parser from grammar with maven, remove generated files…
Aug 1, 2023
02b5968
fix d54fb06 -- use global method instead of (now missing) method in g…
Aug 1, 2023
ebf5eec
java: improve parser error reporting
Aug 1, 2023
b686428
java: add dummy implementation of some stellaris~3.8 features
Aug 1, 2023
fc89edc
maven: match antlr runtime version with antlr generating
Aug 1, 2023
c8486aa
fix b686428 -- DefaultParser.SCRIPTED expects some format in modifiers
Aug 1, 2023
a6d66ed
grammar: support token 'optimize_memory'
Aug 1, 2023
9874f1a
grammar: support operator '!='
Aug 1, 2023
bc32a29
grammar: support assignment with syntax `key = value:alt1|alt2|...|`
Aug 1, 2023
b8f35dc
grammar: support `script = path/with/slashes`
Aug 2, 2023
6aa16b9
java: more dummy implementations of new Modifiers
Aug 2, 2023
42b451d
show files for parser errors from VanillaConfigParser invocations
Aug 2, 2023
1263046
java: dummy implementation of `factor = value:alt1|alt2|...|` syntax
Aug 2, 2023
d8a4c64
java: exclude all README files
Aug 2, 2023
ce217fa
grammar: try to support number as map-key
Aug 2, 2023
673495a
java: fix i18n NPE crash
Aug 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .github/workflows/maven-build-jar.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Java CI with Maven

on:
- push

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: maven

- name: Build with Maven
run: mvn -B package

- name: Upload built jar as CI artifact
uses: actions/upload-artifact@v3
with:
name: jar
path: target/*.jar

- name: From tags, create GH release and attach built jar
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: target/*.jar
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# stellaris tech tree parser
[![Java CI with Maven](https://github.com/azrdev/stellaris-technology-parser/actions/workflows/maven-build-jar.yml/badge.svg)](https://github.com/azrdev/stellaris-technology-parser/actions/workflows/maven-build-jar.yml)

Usage:
1. install a JDK and maven
2. build the project using `mvn package` resulting in `target/stellaris-1.0.0-SNAPSHOT.jar`, or use the .jar built by GitHub Actions
3. open a shell, change to a directory in which `files/` contains your Stellaris installation (e.g. `ln -Ts files ~/.steam/steam/steamapps/common/Stellaris`)
4. Run `java -jar /path/to/your/target/stellaris-1.0.0-SNAPSHOT.jar`
5. Collect the generated `*.json` files and `index.html` and publish to a webserver, e.g. add to https://github.com/turanar/stellaris-tech-tree/
Empty file removed files/common/.gitkeep
Empty file.
Empty file removed files/localisation/.gitkeep
Empty file.
45 changes: 43 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,26 @@

<build>
<plugins>
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.7.1</version>
<executions>
<execution>
<goals>
<goal>antlr4</goal>
</goals>
<configuration>
<visitor>true</visitor>
<arguments>
<argument>-package</argument>
<argument>net.turanar.stellaris.antlr</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand All @@ -55,6 +75,27 @@
<target>1.8</target>
</configuration>
</plugin>
</plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.4.RELEASE</version>
<configuration>
<mainClass>${start-class}</mainClass>
</configuration>
</plugin>

</plugins>

</build>
</project>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.0</version>
<relativePath/>
</parent>

<properties>
<start-class>net.turanar.stellaris.App</start-class>
</properties>
</project>
14 changes: 10 additions & 4 deletions Stellaris.g4 → src/main/antlr4/Stellaris.g4
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ file
;

map
: '{' (pair)* '}'
: '{' (pair | 'optimize_memory' )* '}'
;

pair
: BAREWORD SPECIFIER value
| NUMBER SPECIFIER value
;

var
Expand All @@ -20,13 +21,18 @@ array
: '{' value+ '}'
;

valueSpec
: BAREWORD ':' BAREWORD (( '|' BAREWORD )* '|')?
;

value
: NUMBER
| BOOLEAN
| DATE
| STRING
| VARIABLE
| BAREWORD
| valueSpec
| map
| array
;
Expand All @@ -43,7 +49,7 @@ VARIABLE
;

SPECIFIER
: '=' | '<>' | '>' | '<' | '<=' | '>=' ;
: '=' | '!=' | '<>' | '>' | '<' | '<=' | '>=' ;

NUMBER
: '-'?[0-9]+'%'
Expand All @@ -55,7 +61,7 @@ DATE
: [0-9]+'.'[0-9]+'.'[0-9]+;

BAREWORD
: [A-Za-z][@A-Za-z_0-9.%-]*
: [A-Za-z][@A-Za-z_0-9.%/-]*
;

STRING
Expand All @@ -68,4 +74,4 @@ WS

LINE_COMMENT
: '#'~[\r\n]* -> channel(HIDDEN)
;
;
43 changes: 34 additions & 9 deletions src/main/java/net/turanar/stellaris/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import org.yaml.snakeyaml.Yaml;

import java.io.IOException;
import java.lang.RuntimeException;
import java.util.HashMap;
import java.util.Collections;
import java.util.Map;
import static net.turanar.stellaris.Global.*;

Expand All @@ -24,11 +26,21 @@ public Map<String,String> variables() throws IOException {
HashMap<String,String> retval = new HashMap<>();

parse("files/common/scripted_variables", "txt", p -> {
factory.getParser(p).file().var().forEach(v -> retval.put(v.VARIABLE().getText(), v.NUMBER().getText()));
try {
factory.getParser(p).file().var().forEach(v -> retval.put(v.VARIABLE().getText(), v.NUMBER().getText()));
}
catch (RuntimeException e) {
throw new RuntimeException("Error parsing file " + p.toString(), e);
}
});

parse("files/common/technology", "txt", p -> {
factory.getParser(p).file().var().forEach(v -> retval.put(v.VARIABLE().getText(), v.NUMBER().getText()));
try {
factory.getParser(p).file().var().forEach(v -> retval.put(v.VARIABLE().getText(), v.NUMBER().getText()));
}
catch (RuntimeException e) {
throw new RuntimeException("Error parsing file " + p.toString(), e);
}
});

return retval;
Expand All @@ -39,12 +51,20 @@ public Map<String,String> localisation() throws IOException {
Map<String,String> retval = new HashMap<>();

parse("files/localisation/english", "yml", path -> {
Yaml yaml = new Yaml();
Iterable<Object> data = yaml.loadAll(new StellarisYamlReader(path));
Map<String,Map<Object,Object>> map = (Map<String,Map<Object,Object>>)data.iterator().next();
map.get("l_english").forEach((k, v) -> {
retval.put(k.toString().toLowerCase(), v.toString());
});
try {
Yaml yaml = new Yaml();
Iterable<Object> data = yaml.loadAll(new StellarisYamlReader(path));
Map<String,Map<Object,Object>> map = (Map<String,Map<Object,Object>>)data.iterator().next();
Map english_l10n = map.getOrDefault("l_english", Collections.emptyMap());
if (english_l10n != null) {
english_l10n.forEach((k, v) -> {
retval.put(k.toString().toLowerCase(), v.toString());
});
};
}
catch (RuntimeException e) {
throw new RuntimeException("Error parsing file " + path.toString(), e);
}
});

return retval;
Expand All @@ -55,7 +75,12 @@ public Map<String, StellarisParser.PairContext> scriptedTriggers() throws IOExce
Map<String, StellarisParser.PairContext> retval = new HashMap<>();

parse("files/common/scripted_triggers", "txt", path -> {
factory.getParser(path).file().pair().forEach(pair -> retval.put(pair.key(), pair));
try {
factory.getParser(path).file().pair().forEach(pair -> retval.put(key(pair), pair));
}
catch (RuntimeException e) {
throw new RuntimeException("Error parsing file " + path.toString(), e);
}
});

return retval;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/net/turanar/stellaris/Global.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public void init(Map<String,String> GLOBAL_VARIABLES, Map<String,String> GLOBAL_
}

public static String i18n(String key) {
if(key == null) return null;
String retval = GLOBAL_STRINGS.get(key.toLowerCase());
if(retval == null) return key;
if(retval.contains("$")) {
Expand Down Expand Up @@ -74,6 +75,10 @@ public static String gs(StellarisParser.ValueContext value) {
return null;
}

public static String key(StellarisParser.PairContext pair) {
return pair.BAREWORD().getText();
}

public static String variable(String key) {
return GLOBAL_VARIABLES.get(key);
}
Expand Down
13 changes: 0 additions & 13 deletions src/main/java/net/turanar/stellaris/antlr/Stellaris.tokens

This file was deleted.

111 changes: 0 additions & 111 deletions src/main/java/net/turanar/stellaris/antlr/StellarisBaseListener.java

This file was deleted.

Loading