Skip to content

Commit

Permalink
feat: support bundle, set constants
Browse files Browse the repository at this point in the history
  • Loading branch information
Sharlottes committed Nov 7, 2023
1 parent 50a5e3a commit 3a07fee
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 9 deletions.
5 changes: 5 additions & 0 deletions assets/bundles/bundle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mlogwatcher.setting.title=MlogWatcher Setting
mlogwatcher.setting.mlogLabel=current mlog target path
mlogwatcher.setting.mlogSelectButton=Change watcher target
mlogwatcher.setting.fileChooserTitle=select target file to watch changes
mlogwatcher.setting.extensionInputLabel=file extension to search:
5 changes: 5 additions & 0 deletions assets/bundles/bundle_ko.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
mlogwatcher.setting.title=MlogWatcher 설정
mlogwatcher.setting.mlogLabel=현재 mlog 대상 경로
mlogwatcher.setting.mlogSelectButton=mlog 대상 경로 바꾸기
mlogwatcher.setting.fileChooserTitle=변경을 지켜볼 대상 파일을 선택하세요
mlogwatcher.setting.extensionInputLabel=검색할 파일 확장자 이름:
15 changes: 15 additions & 0 deletions src/mlogwatcher/Constants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package mlogwatcher;

public class Constants {
static class Bundles {
public static final String settingTitle = "@mlogwatcher.setting.title";
public static final String settingMlogPathLabel = "@mlogwatcher.setting.mlogLabel";
public static final String settingMlogSelectButton = "@mlogwatcher.setting.mlogSelectButton";
public static final String settingFileChooserTitle = "@mlogwatcher.setting.fileChooserTitle";
public static final String settingExtensionInputLabel = "@mlogwatcher.setting.extensionInputLabel";
}

static class Settings {
public static final String mlogPath = "mlogwatcher-mlog-path";
}
}
3 changes: 2 additions & 1 deletion src/mlogwatcher/FileWatcher.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mlogwatcher;

import arc.Core;
import arc.func.Cons;
import arc.util.Log;
import arc.util.Nullable;

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

Expand Down
2 changes: 1 addition & 1 deletion src/mlogwatcher/ProcessorUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static void InsertLogic() {
return;
}

String mlogPath = Core.settings.getString("mlogwatcher-mlog-path");
String mlogPath = Core.settings.getString(Constants.Settings.mlogPath);
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
14 changes: 7 additions & 7 deletions src/mlogwatcher/Setting.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,29 @@

public class Setting {
public static void init(){
Label label = new Label(Core.settings.getString("mlogwatcher-mlog-path", "[lightgray]none[]"));
Label label = new Label(Core.settings.getString(Constants.Settings.mlogPath, "[lightgray]@none[]"));
label.setFontScale(0.75f);

TextField field = new TextField();
field.setText("mlog");
field.setFilter((f, c) -> c != ' ' && c != '.');
field.setMessageText("no ext");

Dialog dialog = new BaseDialog("MlogWatcher Setting");
Dialog dialog = new BaseDialog(Constants.Bundles.settingTitle);
dialog.addCloseButton();
dialog.cont.center();
dialog.cont.add("current mlog target path").row();
dialog.cont.add(Constants.Bundles.settingMlogPathLabel).row();
dialog.cont.add(label).row();
dialog.cont.button("Change watcher target", () -> {
Vars.platform.showFileChooser(true, "open target file to watch", field.getText(), fi -> {
dialog.cont.button(Constants.Bundles.settingMlogSelectButton, () -> {
Vars.platform.showFileChooser(true, Constants.Bundles.settingFileChooserTitle, field.getText(), fi -> {
label.setText(fi.absolutePath());
Core.settings.put("mlogwatcher-mlog-path", fi.absolutePath());
Core.settings.put(Constants.Settings.mlogPath, fi.absolutePath());
FileWatcher.stopWatcherThread();
FileWatcher.startWatcherThread();
});
}).width(280f).height(60f).pad(16f).row();
dialog.cont.table(fieldTable -> {
fieldTable.add("file extension to search: ");
fieldTable.add(Constants.Bundles.settingExtensionInputLabel);
fieldTable.add(field);
});

Expand Down

0 comments on commit 3a07fee

Please sign in to comment.