Skip to content

Commit

Permalink
translation & repl & fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Weathercold committed Feb 11, 2023
1 parent 89718b2 commit 38620f9
Show file tree
Hide file tree
Showing 27 changed files with 485 additions and 204 deletions.
4 changes: 3 additions & 1 deletion .clj-kondo/config.edn
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{:lint-as {logging.core.setting/defsetting clojure.core/defonce}}
{:lint-as {logging.core.setting/defsetting clojure.core/defonce
logging.util.macros/if-let' clojure.core/let
logging.util.macros/when-let' clojure.core/let}}
7 changes: 5 additions & 2 deletions .idea/extra-logging.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions .idea/runConfigurations/Desktop.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions .idea/runConfigurations/Desktop_build.xml

This file was deleted.

19 changes: 4 additions & 15 deletions .idea/runConfigurations/Foo.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 6 additions & 8 deletions .idea/runConfigurations/REPL.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 4 additions & 15 deletions .idea/runConfigurations/Vanilla.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 18 additions & 5 deletions assets/bundles/bundle.properties
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
# suppress inspection "UnusedProperty" for whole file

extra-logging.displayname = Extra Logging
extra-logging.basicSettings = Basic Settings
extra-logging.advancedSettings = Advanced Settings
extra-logging.footranslation = Translation is disabled because Foo has its own implementation (yes, also by me). Use that instead.
extra-logging.author = [royal]Weather[][white]cold[]
extra-logging.footranslation = Translation is disabled because you have enabled Foo's implementation (yes, also by me). You can only enable one at the same time.
extra-logging.headlesstranslation = Translation doesn't work in headless mode.

extra-logging.command.tl.description = Translate the message to the target language
extra-logging.command.tl.description = \
With zero arity, translates last message in chat.\n\
With one arity [message], translates [lightgray]message[] to English.\n\
With two arity [lang] [message], translates [lightgray]message[] to the language whose code is [lightgray]lang[].

category.extra-meta = Meta
setting.extra-enablemetadebugging.name = Enable meta debugging
setting.extra-enablemetadebugging.description = You might want to disable this as this mod's debug messages are pretty verbose.
setting.extra-metacolor.name = Meta color

category.extra-logging = Logging
Expand All @@ -30,12 +33,22 @@ $l = Level\n\
$m = Message
setting.extra-timeformat.name = Time format

category.extra-repl = Clojure REPL
setting.extra-enablerepl.name = Enable REPL
setting.extra-enablerepl.description = \
Run a Clojure REPL using nREPL.\n\
REPL stands for read-eval-print-loop. It evaluates code from input, similar to the built-in js console.\n\
Currently, you need a client like Cursive or Calva to connect.\n\
Requires restart
setting.extra-repladdress.name = Server address
setting.extra-replport.name = Server port

category.extra-eventlogging = Event Logging
setting.extra-enableeventlogging.name = Enable event logging
setting.extra-enableeventlogging.description = Requires restart
setting.extra-listeningevents.name = Listening events
setting.extra-listeningevents.description = Requires restart
setting.extra-eventloglevel.name = Event log level

category.extra-translation = Translation
setting.extra-enabletranslation.name = Enable chat translation
setting.extra-enabletranslation.description = Requires restart
10 changes: 6 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
let
android-sdk = android.sdk.x86_64-linux (sdkPkgs: with sdkPkgs; [
cmdline-tools-latest
build-tools-32-0-0
build-tools-33-0-1
emulator
# platform-tools
platforms-android-32
platform-tools
platforms-android-33
]);
in
{
Expand All @@ -31,7 +31,9 @@
shellHook = ''
export JAVA_HOME=${temurin-bin} \
ANDROID_SDK_ROOT=${android-sdk}/share/android-sdk \
PATH=$JAVA_HOME/bin:$ANDROID_SDK_ROOT/build-tools/32.0.0:$PATH
PATH=$JAVA_HOME/bin:$ANDROID_SDK_ROOT/build-tools/33.0.1:$PATH
mkdir ~/Android 2>/dev/null
ln -snf $ANDROID_SDK_ROOT ~/Android/Sdk
'';
};
};
Expand Down
15 changes: 10 additions & 5 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
(defproject extra-logging "2.0.0-alpha"
(defproject extra-logging "2.0.0-beta"
:description "Extra Logging"
:url "http://github.com/Weathercold/extra-logging"
:license {:name "GPL-3.0-or-later"
:url "https://www.gnu.org/licenses/gpl-3.0.txt"}

:repositories [["jitpack" "https://www.jitpack.io"]]
:dependencies [[org.clojure/clojure "1.11.1"]]
:profiles {:provided {:dependencies [[com.github.Anuken.MindustryJitpack/core "v141.2"]
:dependencies [[org.clojure/clojure "1.11.1"]
[org.clojure/data.json "2.4.0"]
[org.flatland/ordered "1.15.10"]
[http-kit "2.7.0-alpha1"]
[nrepl "1.1.0-alpha1"]]
:profiles {:user {:plugins [[lein-kibit "0.1.8"]]}
:provided {:dependencies [[com.github.Anuken.MindustryJitpack/core "v141.2"]
[com.github.Anuken.Arc/arc-core "v141.2"]
;; This is for task linting, you can remove this
[leiningen "2.10.0"]]}}
Expand All @@ -31,5 +36,5 @@
:aot :all
:omit-source true)

;; Uncomment for JIT
;;:jar-exclusions [#"\.java"])
;; Uncomment for JIT
;;:jar-exclusions [#"\.java"])
34 changes: 34 additions & 0 deletions src/clojure/logging/core.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
(ns logging.core
(:require (logging.core [events-log :as events-log]
[log-handler :as log-handler]
[repl :as repl]
[settings :as settings]
[translating :as tl])
[logging.ui.fragments.chat-fragment :as chat-fragment]
[logging.util.lambdas :refer [cons1]]
[logging.util.log :refer [debug]])
(:import (arc Events)
(arc.util CommandHandler)
(mindustry.game EventType$DisposeEvent)))

(defn -main []
(settings/refresh!)
(log-handler/-main)
(debug "Creating mod")
(repl/-main)
(events-log/-main)
(Events/on EventType$DisposeEvent (cons1 (fn [_] (shutdown-agents)))))

(defn -init []
(debug "Initializing")
(settings/-init)
(tl/-init)
(chat-fragment/-init))

(defn -load-content [] (debug "Loading content"))

(defn -register-client-commands [^CommandHandler handler]
(debug "Registering commands")
(tl/-register-client-commands handler))

(defn -register-server-commands [^CommandHandler _] (debug "Registering commands"))
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(ns logging.core.events
(ns logging.core.events-log
(:require [clojure.string :as str]
[logging.core.setting :refer [defsetting]]
[logging.util.lambdas :refer [cons1]]
Expand Down
57 changes: 30 additions & 27 deletions src/clojure/logging/core/log_handler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
(java.time LocalTime)
(java.time.format DateTimeFormatter)
(mindustry Vars)
(mindustry.game EventType$ClientLoadEvent)))
(mindustry.game EventType$ClientLoadEvent EventType$FileTreeInitEvent)))

(def level->code (zipmap (Log$LogLevel/values)
["&lc" "&lb" "&ly" "&lr" "&lw"]))
(def level->tag (zipmap (Log$LogLevel/values)
["[green]" "[royal]" "[yellow]" "[scarlet]" "[lightgray]"]))
(def level->icon (zipmap (Log$LogLevel/values)
["D", "I", "W", "E", "/"]))

(def client-loaded (ref false))
(def log-buffer (ref [] :validator #(or (= @client-loaded false) (empty? %))))

(defsetting log-level "extra-loglevel" 0 #(nth (Log$LogLevel/values) %))
(defsetting colored-terminal "extra-coloredterminal" true)
(defsetting terminal-format "extra-terminalformat" "&lw[$t]&fr &fb$L[$l]&fr $m&fr")
Expand All @@ -35,32 +35,35 @@
(cons1 (fn [_] (err "Time format invalid" e)))))
DateTimeFormatter/ISO_LOCAL_TIME)))

(defn -main []
(set! Log/logger
(reify Log$LogHandler
(log [_ lvl s]
(let [timestamp (.format ^DateTimeFormatter @time-formatter (LocalTime/now))
term-msg (-> @terminal-format
(str/replace "$t" timestamp)
(str/replace "$L" (level->code lvl))
(str/replace "$l" (level->icon lvl))
(str/replace "$m" s)
(#(if @colored-terminal
(-> % color/str-code->escseq color/str-tag->escseq)
(color/remove-colors %))))
cons-msg (-> @console-format
(str/replace "$t" timestamp)
(str/replace "$L" (level->tag lvl))
(str/replace "$l" (level->icon lvl))
(str/replace "$m" s)
color/str-escseq->tag
color/str-code->tag)]
(println term-msg)
(when-not Vars/headless
(if @client-loaded
(.. Vars/ui -consolefrag (addMessage cons-msg))
(dosync (alter log-buffer conj cons-msg))))))))
(def instance
(reify Log$LogHandler
(log [_ lvl s]
(let [timestamp (.format ^DateTimeFormatter @time-formatter (LocalTime/now))
term-msg (-> @terminal-format
(str/replace "$t" timestamp)
(str/replace "$L" (level->code lvl))
(str/replace "$l" (level->icon lvl))
(str/replace "$m" s)
(#(if @colored-terminal
(-> % color/str-code->escseq color/str-tag->escseq)
(color/remove-colors %))))
cons-msg (-> @console-format
(str/replace "$t" timestamp)
(str/replace "$L" (level->tag lvl))
(str/replace "$l" (level->icon lvl))
(str/replace "$m" s)
color/str-escseq->tag
color/str-code->tag)]
(println term-msg)
(when-not Vars/headless
(if @client-loaded
(.. Vars/ui -consolefrag (addMessage cons-msg))
(dosync (alter log-buffer conj cons-msg))))))))

(defn -main []
(set! Log/logger instance)
(Events/on EventType$FileTreeInitEvent
(cons1 (fn [_] (set! Log/logger instance))))
(Events/on EventType$ClientLoadEvent
(cons1 (fn [_]
(run! #(.. Vars/ui -consolefrag (addMessage %))
Expand Down
Loading

0 comments on commit 38620f9

Please sign in to comment.