Skip to content

Commit

Permalink
style: mlogjswatcher -> MlogWatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharlottes committed Nov 7, 2023
1 parent a5bf40a commit 141eebc
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ jobs:
- name: Upload Build Artifact
uses: actions/upload-artifact@v2.2.1
with:
name: mlogjswatcher built by action
name: MlogWatcher built by action
path: build/libs/[!raw-]*.jar
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
# mlogjswatcher
# MlogWatcher

the Mindustry mod for Logic JavaScript Compiler watch mode.

## Principle
This mode watches for changes to a specific mlog file (any file compiled by [mlogjs](https://mlogjs.github.io/mlogjs).
This mod watches for changes to a specific `.mlog` file (the custom file extension which contains mlog).
When a new compilation is made, the file being watched changes, and the mode detects this and injects the file contents into the selected logic processor.

## MlogJSWatchTemplate

I recommend using [mlogJSTemplate](https://github.com/Sharlottes/mlogJsWatchTemplate) as the development environment.
This template repository is also ready for watch mode: if you edit and save `script.ts`, it will automatically compile.
so if you use it with this mod, you have a complete continuous development flow!

## Config

Because of the principle described above, you must first select the path to the file to be watched before using it.

![image](https://github.com/Sharlottes/mlogJsWatcher/assets/60801210/7a061cde-f4be-476f-909d-8de18c87f3b2)
![image](https://github.com/Sharlottes/MlogWatcher/assets/60801210/7a061cde-f4be-476f-909d-8de18c87f3b2)

## How to use it

just select the processor. that's all!
The processor injector compresses and injects code remotely into the selected processor, so you don't need to enter the canvas or anything like that.

![java_jcWgh8Mx2d](https://github.com/Sharlottes/mlogJsWatcher/assets/60801210/023853dd-ae84-491a-8460-acfbac18716a)
![java_jcWgh8Mx2d](https://github.com/Sharlottes/MlogWatcher/assets/60801210/023853dd-ae84-491a-8460-acfbac18716a)

if you click the block which isn't the processor, the processor will be unselected.

## Demo

https://github.com/Sharlottes/mlogJsWatcher/assets/60801210/09305ce7-0775-45a1-9072-dd4728e5d442
https://github.com/Sharlottes/MlogWatcher/assets/60801210/09305ce7-0775-45a1-9072-dd4728e5d442

## MlogJSWatchTemplate

If you are using [mlogjs](https://mlogjs.github.io/mlogjs), I recommend using [mlogJSTemplate](https://github.com/Sharlottes/mlogJsWatchTemplate) as the development environment.
This template repository is also ready for watch mode: if you edit and save `script.ts`, it will automatically compile.
so if you use it with this mod, you have a complete continuous development flow!
12 changes: 6 additions & 6 deletions assets/mod.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "mlogjswatcher",
"displayName": "MLogJsWatcher",
"name": "mlogwatcher",
"displayName": "MLogWatcher",
"author": "Sharlottes",
"description": "the mlogjs watcher mod",
"subtitle": "for mlogjs",
"version": "0.1v",
"main": "mlogjswatcher.MlogJsWatcher",
"description": "the mlog watcher mod",
"subtitle": "for mlog",
"version": "0.1.1v",
"main": "mlogwatcher.MlogWatcher",
"minGameVersion": "146",
"dependencies": [],
"hidden": true,
Expand Down
6 changes: 3 additions & 3 deletions build.bat
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
@rem put this project path into PATH_FROM
setlocal
set PATH_FROM=C:\Users\user\Documents\GitHub\mlogJsWatcher
set PATH_FROM=C:\Users\user\Documents\GitHub\MlogWatcher
@rem put your mindustry local path into PATH_TO
setlocal
set PATH_TO=C:\Users\user\AppData\Roaming\Mindustry

if exist %PATH_TO%\mods\MLogJsWatcherDesktop.jar del %PATH_TO%\mods\MLogJsWatcherDesktop.jar
xcopy %PATH_FROM%\build\libs\MLogJsWatcherDesktop.jar %PATH_TO%\mods\ /k /y
if exist %PATH_TO%\mods\MlogWatcherDesktop.jar del %PATH_TO%\mods\MlogWatcherDesktop.jar
xcopy %PATH_FROM%\build\libs\MlogWatcherDesktop.jar %PATH_TO%\mods\ /k /y
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ sourceSets {

ext {
mindustryVersion = 'v146'
artifactFilename = "MLogJsWatcher"
artifactFilename = "MlogWatcher"
sdkRoot = System.getenv("ANDROID_HOME") ?: System.getenv("ANDROID_SDK_ROOT")
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mlogjswatcher;
package mlogwatcher;

import arc.Core;
import arc.util.Log;
Expand All @@ -11,7 +11,7 @@ public class FileWatcher {
@Nullable
private static Thread fileWatcherThread;
public static void startWatcherThread() {
fileWatcherThread = new FileWatcherThread();
fileWatcherThread = new FileWatcherThread(Core.settings.getString("mlogwatcher-mlog-path"));
fileWatcherThread.start();
}

Expand All @@ -21,19 +21,20 @@ public static void stopWatcherThread() {
}

class FileWatcherThread extends Thread {
public FileWatcherThread() {
private final String targetFilePath;

public FileWatcherThread(String targetFilePath) {
super();
setPriority(MIN_PRIORITY);
setDaemon(true);
setPriority(MIN_PRIORITY);
this.targetFilePath = targetFilePath;
}

@Override
public void run() {
super.run();
String mlogjsPath = Core.settings.getString("mlogjswatcher-mlogjs-path");

try (final WatchService watchService = FileSystems.getDefault().newWatchService()) {
FileSystems.getDefault().getPath(mlogjsPath).getParent().register(watchService, StandardWatchEventKinds.ENTRY_MODIFY);
FileSystems.getDefault().getPath(targetFilePath).getParent().register(watchService, StandardWatchEventKinds.ENTRY_MODIFY);
while (true) {
final WatchKey watchKey = watchService.take();
for (WatchEvent<?> event : watchKey.pollEvents()) {
Expand All @@ -48,9 +49,9 @@ public void run() {
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
Log.warn("mlogjs target file has been changed");
Log.warn("mlog watcher's target file has been changed");
} catch (Exception e) {
Log.warn("mlogjs file watcher restarted");
Log.warn("mlog watcher's file watcher restarted");
FileWatcher.startWatcherThread();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package mlogjswatcher;
package mlogwatcher;

import arc.Events;
import mindustry.mod.Mod;
import mindustry.game.EventType;

public class MlogJsWatcher extends Mod {
public MlogJsWatcher(){
public class MlogWatcher extends Mod {
public MlogWatcher(){
Events.on(EventType.ClientLoadEvent.class, e -> {
Setting.init();
ProcessorUpdater.init();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mlogjswatcher;
package mlogwatcher;

import arc.*;
import arc.util.*;
Expand Down Expand Up @@ -39,8 +39,8 @@ public static void InsertLogic() {
return;
}

String mlogjsPath = Core.settings.getString("mlogjswatcher-mlogjs-path");
String asmCode = Fi.get(mlogjsPath).readString().replace("\r\n", "\n");
String mlogPath = Core.settings.getString("mlogwatcher-mlog-path");
String asmCode = Fi.get(mlogPath).readString().replace("\r\n", "\n");
lastTappedLogicBuild.configure(LogicBlock.compress(asmCode, lastTappedLogicBuild.relativeConnections()));
Fx.spawn.at(lastTappedLogicBuild.x, lastTappedLogicBuild.y);
}
Expand Down
12 changes: 6 additions & 6 deletions src/mlogjswatcher/Setting.java → src/mlogwatcher/Setting.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mlogjswatcher;
package mlogwatcher;

import arc.Core;
import arc.scene.Group;
Expand All @@ -12,16 +12,16 @@

public class Setting {
public static void init(){
Dialog dialog = new BaseDialog("MlogJs Watcher Setting");
Dialog dialog = new BaseDialog("MlogWatcher Setting");
dialog.addCloseButton();
dialog.cont.center();
dialog.cont.add("current dir").row();
Label label = dialog.cont.add(Core.settings.getString("mlogjswatcher-mlogjs-path", "[lightgray]none[]")).fontScale(0.75f).get();
dialog.cont.add("current .mlog target path").row();
Label label = dialog.cont.add(Core.settings.getString("mlogwatcher-mlog-path", "[lightgray]none[]")).fontScale(0.75f).get();
dialog.row();
dialog.cont.button("Change watcher target", () -> {
Vars.platform.showFileChooser(true, "open target file to watch", "mlog", fi -> {
label.setText(fi.absolutePath());
Core.settings.put("mlogjswatcher-mlogjs-path", fi.absolutePath());
Core.settings.put("mlogwatcher-mlog-path", fi.absolutePath());
FileWatcher.stopWatcherThread();
FileWatcher.startWatcherThread();
});
Expand All @@ -30,7 +30,7 @@ public static void init(){
Vars.ui.settings.shown(() -> {
Table settingUi = (Table)((Group)((Group)(Vars.ui.settings.getChildren().get(1))).getChildren().get(0)).getChildren().get(0); //This looks so stupid lol
settingUi.row();
settingUi.button("MlogJs Watcher", Styles.cleart, dialog::show);
settingUi.button("Mlog Watcher", Styles.cleart, dialog::show);
});
}
}

0 comments on commit 141eebc

Please sign in to comment.