Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Scripted PIDS Preset #20

Merged
merged 40 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
491a3d8
[HEAVY WIP] JS PIDS Scripting, see desc
Kenny-Hui Oct 19, 2024
22592ff
Support multiple PIDS
Kenny-Hui Oct 19, 2024
7cf377e
Support multiple scripts
Kenny-Hui Oct 20, 2024
aabb1f1
Add arrivals info
Kenny-Hui Oct 20, 2024
6a5b414
Cleanup
Kenny-Hui Oct 20, 2024
ac35885
Bump dependencies
Kenny-Hui Oct 25, 2024
96cf014
PIDS Texture Rendering
Kenny-Hui Oct 25, 2024
f86e698
Fix print function & arrivals not updating
Kenny-Hui Oct 25, 2024
a10bcc1
Default to mtr font for rendering text
Kenny-Hui Oct 25, 2024
a48c77d
Accept RGB color instead of ARGB
Kenny-Hui Oct 27, 2024
10b578a
Change construction & draw method
Kenny-Hui Oct 27, 2024
3ba1d38
Add UV parameter
Kenny-Hui Oct 27, 2024
f160560
Add the ability to include script
Kenny-Hui Oct 27, 2024
c8a0de5
Implement idRelative
Kenny-Hui Oct 27, 2024
2ae468d
Build on 1.16.5
Kenny-Hui Oct 31, 2024
043bbd7
Add MinecraftClient.worldIsThundering
Kenny-Hui Nov 1, 2024
232b1e9
Round down clock
Kenny-Hui Nov 1, 2024
d5039ef
Add pids_util
Kenny-Hui Nov 1, 2024
9280f85
Allow setting MC font
Kenny-Hui Nov 1, 2024
752859e
Shadow Rhino
Kenny-Hui Nov 2, 2024
2b05f21
Add custom thumbnail support to PIDS Preset
Kenny-Hui Nov 2, 2024
18c21b2
Update if preset changed
Kenny-Hui Nov 2, 2024
6944bb9
Add pids.station()
Kenny-Hui Nov 3, 2024
05b3506
Some refactor
Kenny-Hui Nov 3, 2024
6c86efc
Add helper function to arrival
Kenny-Hui Nov 3, 2024
d1c70ca
Add NTE compatibility method
Kenny-Hui Nov 3, 2024
2554bc9
More resource methods
Kenny-Hui Nov 3, 2024
95c6760
Consistent with naming
Kenny-Hui Nov 3, 2024
5a6a9a3
Fix build
Kenny-Hui Nov 3, 2024
e84a82c
Fix build
Kenny-Hui Nov 3, 2024
1151496
Use ImporterTopLevel
Kenny-Hui Nov 3, 2024
06b3f0a
Call dispose on reload
Kenny-Hui Nov 3, 2024
148ef7c
Refactoring
Kenny-Hui Nov 4, 2024
1cfde0d
Fix build
Kenny-Hui Nov 4, 2024
2289e53
More refactoring
Kenny-Hui Nov 4, 2024
97f1514
Show source script
Kenny-Hui Nov 4, 2024
e082875
Fix build
Kenny-Hui Nov 4, 2024
4c1d8c7
Fix build
Kenny-Hui Nov 4, 2024
70135e6
Fix cycleString not being static
Kenny-Hui Nov 5, 2024
3a2201d
Change more stuff
Kenny-Hui Nov 5, 2024
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
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ jobs:
- name: Make Gradle wrapper executable
run: chmod +x ./gradlew
- name: Setup Forge files
run: ./gradlew forge:setupFiles -Pminecraft_version="${{ matrix.minecraft }}"
run: ./gradlew setupFiles -Pminecraft_version="${{ matrix.minecraft }}"
- name: Build with Gradle
run: |
NOW=$(date '+%Y-%m-%d-%H.%M')
./gradlew :rhino:setupRhino
./gradlew build -Pminecraft_version="${{ matrix.minecraft }}" -Partifact_date=".artifact_$NOW"
- name: Upload Artifacts to GitHub
uses: actions/upload-artifact@v4
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ jobs:
- name: Make Gradle wrapper executable
run: chmod +x ./gradlew
- name: Setup Forge files
run: ./gradlew forge:setupFiles -Pminecraft_version="${{ matrix.minecraft }}"
run: ./gradlew setupFiles -Pminecraft_version="${{ matrix.minecraft }}"
- name: Build with Gradle
run: ./gradlew build -Pminecraft_version="${{ matrix.minecraft }}"
run: |
./gradlew :rhino:setupRhino
./gradlew build -Pminecraft_version="${{ matrix.minecraft }}"
- name: Create release
uses: softprops/action-gh-release@v2
with:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ fabric/run/

# forge
forge/src/main/java/**/mod
forge/src/main/java/**/mtrscripting
forge/src/main/java/net/londonunderground/mod
forge/src/main/resources/assets
forge/src/main/resources/data
forge/run
rhino/src/main/java
#forge/src/main/resources/META-INF

# java
Expand Down
48 changes: 47 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id "io.github.pacifistmc.forgix" version "1.+"
id 'com.gradleup.shadow' version '8.3.4' apply false
}

forgix {
Expand All @@ -18,25 +19,36 @@ forgix {
}
}

subprojects {
configure(subprojects.findAll {it.name != 'rhino'}) {
apply plugin: "java"
apply plugin: 'com.gradleup.shadow'

group project.maven_group
version "${rootProject.properties.mod_version}+${rootProject.properties.minecraft_version}"

configurations {
shadowImplementation
implementation.extendsFrom shadowImplementation
}

base {
archivesName = "${rootProject.archives_base_name}-${project.properties.loader_name}"
}

dependencies {
implementation 'com.google.code.findbugs:jsr305:+'
shadowImplementation project(":rhino")
}

repositories {
flatDir { dirs "../libs" }
maven { url "https://jitpack.io" }
}

shadowJar {
configurations = [project.configurations.shadowImplementation]
}

def mc_ver = rootProject.properties.minecraft_version
def mc_major = mc_ver.split("\\.")[0]
def mc_main = mc_ver.split("\\.")[1]
Expand Down Expand Up @@ -103,6 +115,40 @@ subprojects {
}
}

compileJava.dependsOn(":rhino:checkRhino")
build.finalizedBy(mergeJars)
assemble.finalizedBy(mergeJars)
}

tasks.register("setupFiles") {
var sourceModloader = "fabric"

doLast {
for(var targetModloader : ["forge"]) {
delete fileTree("${targetModloader}/src/main/java/com/lx862/jcm/mod")
delete fileTree("${targetModloader}/src/main/java/com/lx862/mtrscripting")
delete fileTree("${targetModloader}/src/main/resources/assets")
delete fileTree("${targetModloader}/src/main/resources/data")

copy {
from "${sourceModloader}/src/main/java/com/lx862/jcm/mod"
into "${targetModloader}/src/main/java/com/lx862/jcm/mod"
}

copy {
from "${sourceModloader}/src/main/java/com/lx862/mtrscripting"
into "${targetModloader}/src/main/java/com/lx862/mtrscripting"
}

copy {
from "${sourceModloader}/src/main/resources/assets"
into "${targetModloader}/src/main/resources/assets"
}

copy {
from "${sourceModloader}/src/main/resources/data"
into "${targetModloader}/src/main/resources/data"
}
}
}
}
8 changes: 7 additions & 1 deletion fabric/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.7-SNAPSHOT'
id 'fabric-loom' version '1.8-SNAPSHOT'
}

loom {
Expand Down Expand Up @@ -51,4 +51,10 @@ jar {
from("LICENSE") {
rename { "${it}_${base.archivesName.get()}"}
}
}

remapJar {
dependsOn(shadowJar)
mustRunAfter(shadowJar)
inputFile = file(shadowJar.archivePath)
}
2 changes: 1 addition & 1 deletion fabric/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Fabric Properties
# check these on https://fabricmc.net/develop
fabric_loader_version=0.16.2
fabric_loader_version=0.16.7
loader_name=fabric

yarn_mappings_1.20.4=1.20.4+build.3
Expand Down
4 changes: 3 additions & 1 deletion fabric/src/main/java/com/lx862/jcm/mod/JCMClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import com.lx862.jcm.mod.config.ClientConfig;
import com.lx862.jcm.mod.registry.JCMRegistryClient;
import com.lx862.jcm.mod.render.gui.screen.ClientConfigScreen;
import com.lx862.mtrscripting.scripting.ScriptManager;
import org.mtr.mapping.holder.Screen;
import org.mtr.mapping.holder.ScreenAbstractMapping;

public class JCMClient {
private static ClientConfig config = new ClientConfig();
public static final ScriptManager scriptManager = new ScriptManager();
private static final ClientConfig config = new ClientConfig();

public static void initializeClient() {
config.read();
Expand Down
37 changes: 34 additions & 3 deletions fabric/src/main/java/com/lx862/jcm/mod/data/pids/PIDSManager.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
package com.lx862.jcm.mod.data.pids;

import com.google.gson.JsonObject;
import com.lx862.jcm.mod.data.pids.preset.CustomComponentPIDSPreset;
import com.lx862.jcm.mod.Constants;
import com.lx862.mtrscripting.api.ScriptingAPI;
import com.lx862.jcm.mod.data.pids.preset.JsonPIDSPreset;
import com.lx862.jcm.mod.data.pids.preset.PIDSPresetBase;
import com.lx862.jcm.mod.data.pids.preset.ScriptPIDSPreset;
import com.lx862.jcm.mod.data.pids.scripting.TextWrapper;
import com.lx862.jcm.mod.data.pids.scripting.TextureWrapper;
import com.lx862.jcm.mod.data.pids.scripting.util.MTRUtil;
import com.lx862.jcm.mod.data.pids.scripting.util.TextUtil;
import com.lx862.jcm.mod.util.JCMLogger;
import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap;
import org.mtr.mod.Keys;
import org.mtr.mod.client.MinecraftClientData;
import vendor.com.lx862.jcm.org.mozilla.javascript.NativeJavaClass;

import java.util.List;
import java.util.stream.Collectors;
Expand All @@ -22,8 +31,8 @@ public static void loadJson(JsonObject customResourceJson) {
presetId = jsonObject.get("id").getAsString();
PIDSPresetBase preset;

if(jsonObject.has("file")) {
preset = CustomComponentPIDSPreset.parse(jsonObject);
if(jsonObject.has("scripts")) {
preset = ScriptPIDSPreset.parse(jsonObject);
} else {
preset = JsonPIDSPreset.parse(e.getAsJsonObject());
}
Expand All @@ -40,6 +49,28 @@ public static void loadJson(JsonObject customResourceJson) {
});
}

public static void registerScripting() {
String mtrModVersion = null;
try {
mtrModVersion = (String) Keys.class.getField("MOD_VERSION").get(null);
} catch (ReflectiveOperationException ignored) {
}
ScriptingAPI.registerAddonVersion("mtr", mtrModVersion);
ScriptingAPI.registerAddonVersion("jcm", Constants.MOD_VERSION);

ScriptingAPI.onParseScript((contextName, context, scriptable) -> {
// On behalf of MTR
scriptable.put("MTRUtil", scriptable, new NativeJavaClass(scriptable, MTRUtil.class));
scriptable.put("MTRClientData", scriptable, new NativeJavaClass(scriptable, MinecraftClientData.class));
scriptable.put("TextUtil", scriptable, new NativeJavaClass(scriptable, TextUtil.class));

if(contextName.equals("PIDS")) {
scriptable.put("Text", scriptable, new NativeJavaClass(scriptable, TextWrapper.class));
scriptable.put("Texture", scriptable, new NativeJavaClass(scriptable, TextureWrapper.class));
}
});
}

public static PIDSPresetBase getPreset(String id, PIDSPresetBase defaultPreset) {
return presetList.getOrDefault(id, defaultPreset);
}
Expand Down

This file was deleted.

Loading