diff --git a/.idea/artifacts/ModuleBasegame.xml b/.idea/artifacts/ModuleBasegame.xml
index 6e7468621..7d8d1e492 100644
--- a/.idea/artifacts/ModuleBasegame.xml
+++ b/.idea/artifacts/ModuleBasegame.xml
@@ -3,7 +3,6 @@
$PROJECT_DIR$/out/artifacts/ModuleBasegame
-
\ No newline at end of file
diff --git a/.idea/artifacts/TerrarumBuild.xml b/.idea/artifacts/TerrarumBuild.xml
index 064909a98..bea354ce0 100644
--- a/.idea/artifacts/TerrarumBuild.xml
+++ b/.idea/artifacts/TerrarumBuild.xml
@@ -6,9 +6,8 @@
-
-
+
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index 24ee1a052..f1e285986 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -4,7 +4,7 @@
-
+
diff --git a/.idea/libraries/GetCpuName_src.xml b/.idea/libraries/GetCpuName_src.xml
new file mode 100644
index 000000000..8aa28f997
--- /dev/null
+++ b/.idea/libraries/GetCpuName_src.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/KotlinJavaRuntime.xml b/.idea/libraries/KotlinJavaRuntime.xml
index 0eb1ce283..1a7265de2 100644
--- a/.idea/libraries/KotlinJavaRuntime.xml
+++ b/.idea/libraries/KotlinJavaRuntime.xml
@@ -4,15 +4,16 @@
-
-
-
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/TerranVirtualDisk.xml b/.idea/libraries/TerranVirtualDisk.xml
new file mode 100644
index 000000000..e0e61d4e9
--- /dev/null
+++ b/.idea/libraries/TerranVirtualDisk.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/TerrarumSansBitmap.xml b/.idea/libraries/TerrarumSansBitmap.xml
new file mode 100644
index 000000000..beff7c7ae
--- /dev/null
+++ b/.idea/libraries/TerrarumSansBitmap.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Terrarum_Joise.xml b/.idea/libraries/Terrarum_Joise.xml
new file mode 100644
index 000000000..93b70e811
--- /dev/null
+++ b/.idea/libraries/Terrarum_Joise.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/com_badlogicgames_gdx_gdx_1_10_0.xml b/.idea/libraries/com_badlogicgames_gdx_gdx_1_10_0.xml
new file mode 100644
index 000000000..7a8c6607d
--- /dev/null
+++ b/.idea/libraries/com_badlogicgames_gdx_gdx_1_10_0.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/com_badlogicgames_gdx_gdx_backend_lwjgl3_1_10_0.xml b/.idea/libraries/com_badlogicgames_gdx_gdx_backend_lwjgl3_1_10_0.xml
new file mode 100644
index 000000000..520d8796b
--- /dev/null
+++ b/.idea/libraries/com_badlogicgames_gdx_gdx_backend_lwjgl3_1_10_0.xml
@@ -0,0 +1,128 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/com_badlogicgames_gdx_gdx_backend_lwjgl3_1_9_10.xml b/.idea/libraries/com_badlogicgames_gdx_gdx_backend_lwjgl3_1_9_10.xml
deleted file mode 100644
index 5ddfaae09..000000000
--- a/.idea/libraries/com_badlogicgames_gdx_gdx_backend_lwjgl3_1_9_10.xml
+++ /dev/null
@@ -1,53 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/libraries/com_badlogicgames_gdx_gdx_backend_lwjgl_1_9_10.xml b/.idea/libraries/com_badlogicgames_gdx_gdx_backend_lwjgl_1_9_10.xml
deleted file mode 100644
index 4a4be9dc8..000000000
--- a/.idea/libraries/com_badlogicgames_gdx_gdx_backend_lwjgl_1_9_10.xml
+++ /dev/null
@@ -1,41 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/libraries/com_badlogicgames_gdx_gdx_controllers_desktop_1_9_10.xml b/.idea/libraries/com_badlogicgames_gdx_gdx_controllers_desktop_1_9_10.xml
deleted file mode 100644
index 4a5fbca3d..000000000
--- a/.idea/libraries/com_badlogicgames_gdx_gdx_controllers_desktop_1_9_10.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/libraries/com_badlogicgames_gdx_gdx_controllers_platform_1_9_10.xml b/.idea/libraries/com_badlogicgames_gdx_gdx_controllers_platform_1_9_10.xml
deleted file mode 100644
index df741eb04..000000000
--- a/.idea/libraries/com_badlogicgames_gdx_gdx_controllers_platform_1_9_10.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/libraries/com_badlogicgames_gdx_gdx_platform_1_9_10.xml b/.idea/libraries/com_badlogicgames_gdx_gdx_platform_1_9_10.xml
deleted file mode 100644
index cff463e6d..000000000
--- a/.idea/libraries/com_badlogicgames_gdx_gdx_platform_1_9_10.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/libraries/com_google_code_gson_gson_2_8_7.xml b/.idea/libraries/com_google_code_gson_gson_2_8_7.xml
new file mode 100644
index 000000000..ff204fce5
--- /dev/null
+++ b/.idea/libraries/com_google_code_gson_gson_2_8_7.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/commons_codec_commons_codec_1_15.xml b/.idea/libraries/commons_codec_commons_codec_1_15.xml
new file mode 100644
index 000000000..3d97194e4
--- /dev/null
+++ b/.idea/libraries/commons_codec_commons_codec_1_15.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/gdx_controllers_core_2_2_1.xml b/.idea/libraries/gdx_controllers_core_2_2_1.xml
new file mode 100644
index 000000000..bed4ed0d0
--- /dev/null
+++ b/.idea/libraries/gdx_controllers_core_2_2_1.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/gdx_controllers_desktop_2_2_1.xml b/.idea/libraries/gdx_controllers_desktop_2_2_1.xml
new file mode 100644
index 000000000..997428115
--- /dev/null
+++ b/.idea/libraries/gdx_controllers_desktop_2_2_1.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/gdx_platform_1_10_0_natives_desktop.xml b/.idea/libraries/gdx_platform_1_10_0_natives_desktop.xml
new file mode 100644
index 000000000..9938aa858
--- /dev/null
+++ b/.idea/libraries/gdx_platform_1_10_0_natives_desktop.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/graalvm_js_21_1_0_and_graalvm_js_scriptengine_21_1_0.xml b/.idea/libraries/graalvm_js_21_1_0_and_graalvm_js_scriptengine_21_1_0.xml
new file mode 100644
index 000000000..8c02e125d
--- /dev/null
+++ b/.idea/libraries/graalvm_js_21_1_0_and_graalvm_js_scriptengine_21_1_0.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/jxinput_1_0_0.xml b/.idea/libraries/jxinput_1_0_0.xml
new file mode 100644
index 000000000..fda042a40
--- /dev/null
+++ b/.idea/libraries/jxinput_1_0_0.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/lib.xml b/.idea/libraries/lib.xml
deleted file mode 100644
index 010e938cc..000000000
--- a/.idea/libraries/lib.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/libraries/org_apache_commons_commons_csv_1_8.xml b/.idea/libraries/org_apache_commons_commons_csv_1_8.xml
new file mode 100644
index 000000000..f68ca0c41
--- /dev/null
+++ b/.idea/libraries/org_apache_commons_commons_csv_1_8.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/prtree.xml b/.idea/libraries/prtree.xml
new file mode 100644
index 000000000..32114945c
--- /dev/null
+++ b/.idea/libraries/prtree.xml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index df5a15f37..972207dae 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -38,7 +38,7 @@
-
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
index f25caf36b..4a174c960 100644
--- a/.idea/modules.xml
+++ b/.idea/modules.xml
@@ -1,9 +1,12 @@
+
+
+
-
+
\ No newline at end of file
diff --git a/config_colemak.json b/config_colemak.json
index 09f68c662..bde3817d3 100644
--- a/config_colemak.json
+++ b/config_colemak.json
@@ -34,12 +34,12 @@
-0.044
],
"gamepadlabelstyle": "msxbone",
- "config_keyup":34,
- "config_keyleft":46,
- "config_keydown":47,
- "config_keyright":48,
+ "config_keyup":33,
+ "config_keyleft":47,
+ "config_keydown":32,
+ "config_keyright":34,
"config_keyinventory":45,
- "config_keyinteract":44,
+ "config_keyinteract":46,
"config_keymovementaux": 29,
"config_keyclose": 31,
"config_keyzoom": 54,
diff --git a/ingamemodule_basegame/ingamemodule_basegame.iml b/ingamemodule_basegame/ingamemodule_basegame.iml
index 0f01dd760..cd8dbc66b 100644
--- a/ingamemodule_basegame/ingamemodule_basegame.iml
+++ b/ingamemodule_basegame/ingamemodule_basegame.iml
@@ -7,11 +7,25 @@
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/lib/Concentus-1.0-SNAPSHOT.jar b/lib/Concentus-1.0-SNAPSHOT.jar
deleted file mode 100644
index 30cbf5b44..000000000
Binary files a/lib/Concentus-1.0-SNAPSHOT.jar and /dev/null differ
diff --git a/lib/commons-codec-1.10-javadoc.jar b/lib/commons-codec-1.10-javadoc.jar
deleted file mode 100644
index 2f372ecfb..000000000
Binary files a/lib/commons-codec-1.10-javadoc.jar and /dev/null differ
diff --git a/lib/commons-codec-1.10.jar b/lib/commons-codec-1.10.jar
deleted file mode 100644
index 1d7417c40..000000000
Binary files a/lib/commons-codec-1.10.jar and /dev/null differ
diff --git a/lib/commons-codec-1.15-javadoc.jar b/lib/commons-codec-1.15-javadoc.jar
new file mode 100644
index 000000000..3fee18e35
Binary files /dev/null and b/lib/commons-codec-1.15-javadoc.jar differ
diff --git a/lib/commons-codec-1.15-sources.jar b/lib/commons-codec-1.15-sources.jar
new file mode 100644
index 000000000..5291685e6
Binary files /dev/null and b/lib/commons-codec-1.15-sources.jar differ
diff --git a/lib/commons-codec-1.15.jar b/lib/commons-codec-1.15.jar
new file mode 100644
index 000000000..f14985ac9
Binary files /dev/null and b/lib/commons-codec-1.15.jar differ
diff --git a/lib/commons-csv-1.2.jar b/lib/commons-csv-1.2.jar
deleted file mode 100644
index 1b26424fd..000000000
Binary files a/lib/commons-csv-1.2.jar and /dev/null differ
diff --git a/lib/commons-csv-1.8-javadoc.jar b/lib/commons-csv-1.8-javadoc.jar
new file mode 100644
index 000000000..87ba1524e
Binary files /dev/null and b/lib/commons-csv-1.8-javadoc.jar differ
diff --git a/lib/commons-csv-1.8-sources.jar b/lib/commons-csv-1.8-sources.jar
new file mode 100644
index 000000000..a1a417823
Binary files /dev/null and b/lib/commons-csv-1.8-sources.jar differ
diff --git a/lib/commons-csv-1.8.jar b/lib/commons-csv-1.8.jar
new file mode 100644
index 000000000..127c5a209
Binary files /dev/null and b/lib/commons-csv-1.8.jar differ
diff --git a/lib/commons-csv-javadoc.jar b/lib/commons-csv-javadoc.jar
deleted file mode 100644
index fadf3b9ec..000000000
Binary files a/lib/commons-csv-javadoc.jar and /dev/null differ
diff --git a/lib/gdx-1.10.0-javadoc.jar b/lib/gdx-1.10.0-javadoc.jar
new file mode 100644
index 000000000..e371794c3
Binary files /dev/null and b/lib/gdx-1.10.0-javadoc.jar differ
diff --git a/lib/gdx-1.10.0-sources.jar b/lib/gdx-1.10.0-sources.jar
new file mode 100644
index 000000000..90f2677ed
Binary files /dev/null and b/lib/gdx-1.10.0-sources.jar differ
diff --git a/lib/gdx-1.10.0.jar b/lib/gdx-1.10.0.jar
new file mode 100644
index 000000000..d40d51795
Binary files /dev/null and b/lib/gdx-1.10.0.jar differ
diff --git a/lib/gdx-1.9.10-javadoc.jar b/lib/gdx-1.9.10-javadoc.jar
deleted file mode 100644
index 1b78b67e0..000000000
Binary files a/lib/gdx-1.9.10-javadoc.jar and /dev/null differ
diff --git a/lib/gdx-1.9.10-sources.jar b/lib/gdx-1.9.10-sources.jar
deleted file mode 100644
index e8a37a7b2..000000000
Binary files a/lib/gdx-1.9.10-sources.jar and /dev/null differ
diff --git a/lib/gdx-1.9.10.jar b/lib/gdx-1.9.10.jar
deleted file mode 100644
index 49772bda1..000000000
Binary files a/lib/gdx-1.9.10.jar and /dev/null differ
diff --git a/lib/gdx-backend-lwjgl-1.9.10-javadoc.jar b/lib/gdx-backend-lwjgl-1.9.10-javadoc.jar
deleted file mode 100644
index b3bc0b49a..000000000
Binary files a/lib/gdx-backend-lwjgl-1.9.10-javadoc.jar and /dev/null differ
diff --git a/lib/gdx-backend-lwjgl-1.9.10-sources.jar b/lib/gdx-backend-lwjgl-1.9.10-sources.jar
deleted file mode 100644
index 040a4b643..000000000
Binary files a/lib/gdx-backend-lwjgl-1.9.10-sources.jar and /dev/null differ
diff --git a/lib/gdx-backend-lwjgl-1.9.10.jar b/lib/gdx-backend-lwjgl-1.9.10.jar
deleted file mode 100644
index 6b9069ab7..000000000
Binary files a/lib/gdx-backend-lwjgl-1.9.10.jar and /dev/null differ
diff --git a/lib/gdx-backend-lwjgl3-1.10.0-javadoc.jar b/lib/gdx-backend-lwjgl3-1.10.0-javadoc.jar
new file mode 100644
index 000000000..488eed8a8
Binary files /dev/null and b/lib/gdx-backend-lwjgl3-1.10.0-javadoc.jar differ
diff --git a/lib/gdx-backend-lwjgl3-1.10.0-sources.jar b/lib/gdx-backend-lwjgl3-1.10.0-sources.jar
new file mode 100644
index 000000000..412affa04
Binary files /dev/null and b/lib/gdx-backend-lwjgl3-1.10.0-sources.jar differ
diff --git a/lib/gdx-backend-lwjgl3-1.10.0.jar b/lib/gdx-backend-lwjgl3-1.10.0.jar
new file mode 100644
index 000000000..69bd2d769
Binary files /dev/null and b/lib/gdx-backend-lwjgl3-1.10.0.jar differ
diff --git a/lib/gdx-backend-lwjgl3-1.9.10-javadoc.jar b/lib/gdx-backend-lwjgl3-1.9.10-javadoc.jar
deleted file mode 100644
index 750110b8d..000000000
Binary files a/lib/gdx-backend-lwjgl3-1.9.10-javadoc.jar and /dev/null differ
diff --git a/lib/gdx-backend-lwjgl3-1.9.10-sources.jar b/lib/gdx-backend-lwjgl3-1.9.10-sources.jar
deleted file mode 100644
index 25714aba1..000000000
Binary files a/lib/gdx-backend-lwjgl3-1.9.10-sources.jar and /dev/null differ
diff --git a/lib/gdx-backend-lwjgl3-1.9.10.jar b/lib/gdx-backend-lwjgl3-1.9.10.jar
deleted file mode 100644
index 0551d679c..000000000
Binary files a/lib/gdx-backend-lwjgl3-1.9.10.jar and /dev/null differ
diff --git a/lib/gdx-controllers-1.9.10-javadoc.jar b/lib/gdx-controllers-1.9.10-javadoc.jar
deleted file mode 100644
index 571d8dc46..000000000
Binary files a/lib/gdx-controllers-1.9.10-javadoc.jar and /dev/null differ
diff --git a/lib/gdx-controllers-1.9.10-sources.jar b/lib/gdx-controllers-1.9.10-sources.jar
deleted file mode 100644
index ce8cff539..000000000
Binary files a/lib/gdx-controllers-1.9.10-sources.jar and /dev/null differ
diff --git a/lib/gdx-controllers-1.9.10.jar b/lib/gdx-controllers-1.9.10.jar
deleted file mode 100644
index ddafb7555..000000000
Binary files a/lib/gdx-controllers-1.9.10.jar and /dev/null differ
diff --git a/lib/gdx-controllers-core-2.2.1-javadoc.jar b/lib/gdx-controllers-core-2.2.1-javadoc.jar
new file mode 100644
index 000000000..ef0b94fc9
Binary files /dev/null and b/lib/gdx-controllers-core-2.2.1-javadoc.jar differ
diff --git a/lib/gdx-controllers-core-2.2.1-sources.jar b/lib/gdx-controllers-core-2.2.1-sources.jar
new file mode 100644
index 000000000..af28c30ab
Binary files /dev/null and b/lib/gdx-controllers-core-2.2.1-sources.jar differ
diff --git a/lib/gdx-controllers-core-2.2.1.jar b/lib/gdx-controllers-core-2.2.1.jar
new file mode 100644
index 000000000..b31783389
Binary files /dev/null and b/lib/gdx-controllers-core-2.2.1.jar differ
diff --git a/lib/gdx-controllers-desktop-1.9.10-javadoc.jar b/lib/gdx-controllers-desktop-1.9.10-javadoc.jar
deleted file mode 100644
index 9fc8c8fdd..000000000
Binary files a/lib/gdx-controllers-desktop-1.9.10-javadoc.jar and /dev/null differ
diff --git a/lib/gdx-controllers-desktop-1.9.10-sources.jar b/lib/gdx-controllers-desktop-1.9.10-sources.jar
deleted file mode 100644
index b53be70ce..000000000
Binary files a/lib/gdx-controllers-desktop-1.9.10-sources.jar and /dev/null differ
diff --git a/lib/gdx-controllers-desktop-1.9.10.jar b/lib/gdx-controllers-desktop-1.9.10.jar
deleted file mode 100644
index 8e0deafe1..000000000
Binary files a/lib/gdx-controllers-desktop-1.9.10.jar and /dev/null differ
diff --git a/lib/gdx-controllers-desktop-2.2.1-javadoc.jar b/lib/gdx-controllers-desktop-2.2.1-javadoc.jar
new file mode 100644
index 000000000..22b7dde77
Binary files /dev/null and b/lib/gdx-controllers-desktop-2.2.1-javadoc.jar differ
diff --git a/lib/gdx-controllers-desktop-2.2.1-sources.jar b/lib/gdx-controllers-desktop-2.2.1-sources.jar
new file mode 100644
index 000000000..bd7d3ab03
Binary files /dev/null and b/lib/gdx-controllers-desktop-2.2.1-sources.jar differ
diff --git a/lib/gdx-controllers-desktop-2.2.1.jar b/lib/gdx-controllers-desktop-2.2.1.jar
new file mode 100644
index 000000000..23c510213
Binary files /dev/null and b/lib/gdx-controllers-desktop-2.2.1.jar differ
diff --git a/lib/gdx-controllers-desktop-natives.jar b/lib/gdx-controllers-desktop-natives.jar
deleted file mode 100644
index 7856f2afd..000000000
Binary files a/lib/gdx-controllers-desktop-natives.jar and /dev/null differ
diff --git a/lib/gdx-controllers-platform-1.9.10.jar b/lib/gdx-controllers-platform-1.9.10.jar
deleted file mode 100644
index 60f82f01e..000000000
Binary files a/lib/gdx-controllers-platform-1.9.10.jar and /dev/null differ
diff --git a/lib/gdx-natives.jar b/lib/gdx-natives.jar
deleted file mode 100644
index 9ee91721f..000000000
Binary files a/lib/gdx-natives.jar and /dev/null differ
diff --git a/lib/gdx-platform-1.10.0-natives-desktop.jar b/lib/gdx-platform-1.10.0-natives-desktop.jar
new file mode 100644
index 000000000..d5d8a907d
Binary files /dev/null and b/lib/gdx-platform-1.10.0-natives-desktop.jar differ
diff --git a/lib/gdx-platform-1.10.0.jar b/lib/gdx-platform-1.10.0.jar
new file mode 100644
index 000000000..761e6ac1d
Binary files /dev/null and b/lib/gdx-platform-1.10.0.jar differ
diff --git a/lib/gdx-platform-1.9.10.jar b/lib/gdx-platform-1.9.10.jar
deleted file mode 100644
index 51fb6e50e..000000000
Binary files a/lib/gdx-platform-1.9.10.jar and /dev/null differ
diff --git a/lib/graal-sdk-21.1.0-javadoc.jar b/lib/graal-sdk-21.1.0-javadoc.jar
new file mode 100644
index 000000000..72baa0ea1
Binary files /dev/null and b/lib/graal-sdk-21.1.0-javadoc.jar differ
diff --git a/lib/graal-sdk-21.1.0-sources.jar b/lib/graal-sdk-21.1.0-sources.jar
new file mode 100644
index 000000000..0865d52b1
Binary files /dev/null and b/lib/graal-sdk-21.1.0-sources.jar differ
diff --git a/lib/graal-sdk-21.1.0.jar b/lib/graal-sdk-21.1.0.jar
new file mode 100644
index 000000000..f90e5c0d2
Binary files /dev/null and b/lib/graal-sdk-21.1.0.jar differ
diff --git a/lib/gson-2.8.5-javadoc.jar b/lib/gson-2.8.5-javadoc.jar
deleted file mode 100644
index e74a1d24c..000000000
Binary files a/lib/gson-2.8.5-javadoc.jar and /dev/null differ
diff --git a/lib/gson-2.8.5.jar b/lib/gson-2.8.5.jar
deleted file mode 100644
index 0d5baf3fa..000000000
Binary files a/lib/gson-2.8.5.jar and /dev/null differ
diff --git a/lib/gson-2.8.7-javadoc.jar b/lib/gson-2.8.7-javadoc.jar
new file mode 100644
index 000000000..7b2ba6406
Binary files /dev/null and b/lib/gson-2.8.7-javadoc.jar differ
diff --git a/lib/gson-2.8.5-sources.jar b/lib/gson-2.8.7-sources.jar
similarity index 59%
rename from lib/gson-2.8.5-sources.jar
rename to lib/gson-2.8.7-sources.jar
index a64f4e732..116bf95b5 100644
Binary files a/lib/gson-2.8.5-sources.jar and b/lib/gson-2.8.7-sources.jar differ
diff --git a/lib/gson-2.8.7.jar b/lib/gson-2.8.7.jar
new file mode 100644
index 000000000..215e82328
Binary files /dev/null and b/lib/gson-2.8.7.jar differ
diff --git a/lib/icu4j-68.2-javadoc.jar b/lib/icu4j-68.2-javadoc.jar
new file mode 100644
index 000000000..51e45f3d3
Binary files /dev/null and b/lib/icu4j-68.2-javadoc.jar differ
diff --git a/lib/icu4j-68.2-sources.jar b/lib/icu4j-68.2-sources.jar
new file mode 100644
index 000000000..ae61996aa
Binary files /dev/null and b/lib/icu4j-68.2-sources.jar differ
diff --git a/lib/icu4j-68.2.jar b/lib/icu4j-68.2.jar
new file mode 100644
index 000000000..b0674fb1c
Binary files /dev/null and b/lib/icu4j-68.2.jar differ
diff --git a/lib/jlayer-1.0.1-gdx-javadoc.jar b/lib/jlayer-1.0.1-gdx-javadoc.jar
old mode 100644
new mode 100755
diff --git a/lib/jlayer-1.0.1-gdx-sources.jar b/lib/jlayer-1.0.1-gdx-sources.jar
old mode 100644
new mode 100755
diff --git a/lib/jlayer-1.0.1-gdx.jar b/lib/jlayer-1.0.1-gdx.jar
old mode 100644
new mode 100755
diff --git a/lib/jorbis-0.0.17-javadoc.jar b/lib/jorbis-0.0.17-javadoc.jar
old mode 100644
new mode 100755
diff --git a/lib/jorbis-0.0.17-sources.jar b/lib/jorbis-0.0.17-sources.jar
old mode 100644
new mode 100755
diff --git a/lib/jorbis-0.0.17.jar b/lib/jorbis-0.0.17.jar
old mode 100644
new mode 100755
diff --git a/lib/js-21.1.0-edit.jar b/lib/js-21.1.0-edit.jar
new file mode 100644
index 000000000..fc332a05c
Binary files /dev/null and b/lib/js-21.1.0-edit.jar differ
diff --git a/lib/js-21.1.0-javadoc.jar b/lib/js-21.1.0-javadoc.jar
new file mode 100644
index 000000000..209dae43e
Binary files /dev/null and b/lib/js-21.1.0-javadoc.jar differ
diff --git a/lib/js-21.1.0-sources.jar b/lib/js-21.1.0-sources.jar
new file mode 100644
index 000000000..27e81e1ca
Binary files /dev/null and b/lib/js-21.1.0-sources.jar differ
diff --git a/lib/js-scriptengine-21.1.0-javadoc.jar b/lib/js-scriptengine-21.1.0-javadoc.jar
new file mode 100644
index 000000000..c1c4a2470
Binary files /dev/null and b/lib/js-scriptengine-21.1.0-javadoc.jar differ
diff --git a/lib/js-scriptengine-21.1.0-sources.jar b/lib/js-scriptengine-21.1.0-sources.jar
new file mode 100644
index 000000000..179906ad7
Binary files /dev/null and b/lib/js-scriptengine-21.1.0-sources.jar differ
diff --git a/lib/js-scriptengine-21.1.0.jar b/lib/js-scriptengine-21.1.0.jar
new file mode 100644
index 000000000..b03ca7a62
Binary files /dev/null and b/lib/js-scriptengine-21.1.0.jar differ
diff --git a/lib/lwjgl-2.9.3-javadoc.jar b/lib/lwjgl-2.9.3-javadoc.jar
deleted file mode 100644
index 5825101ff..000000000
Binary files a/lib/lwjgl-2.9.3-javadoc.jar and /dev/null differ
diff --git a/lib/lwjgl-2.9.3-sources.jar b/lib/lwjgl-2.9.3-sources.jar
deleted file mode 100644
index ff15768f9..000000000
Binary files a/lib/lwjgl-2.9.3-sources.jar and /dev/null differ
diff --git a/lib/lwjgl-2.9.3.jar b/lib/lwjgl-2.9.3.jar
deleted file mode 100644
index 82294e160..000000000
Binary files a/lib/lwjgl-2.9.3.jar and /dev/null differ
diff --git a/lib/lwjgl-3.2.1-javadoc.jar b/lib/lwjgl-3.2.1-javadoc.jar
deleted file mode 100644
index 7e8c11eba..000000000
Binary files a/lib/lwjgl-3.2.1-javadoc.jar and /dev/null differ
diff --git a/lib/lwjgl-3.2.1-natives-linux.jar b/lib/lwjgl-3.2.1-natives-linux.jar
deleted file mode 100644
index 78f0c2e44..000000000
Binary files a/lib/lwjgl-3.2.1-natives-linux.jar and /dev/null differ
diff --git a/lib/lwjgl-3.2.1-natives-macos.jar b/lib/lwjgl-3.2.1-natives-macos.jar
deleted file mode 100644
index 6d4034754..000000000
Binary files a/lib/lwjgl-3.2.1-natives-macos.jar and /dev/null differ
diff --git a/lib/lwjgl-3.2.1-natives-windows.jar b/lib/lwjgl-3.2.1-natives-windows.jar
deleted file mode 100644
index 07e7a7f06..000000000
Binary files a/lib/lwjgl-3.2.1-natives-windows.jar and /dev/null differ
diff --git a/lib/lwjgl-3.2.1-sources.jar b/lib/lwjgl-3.2.1-sources.jar
deleted file mode 100644
index 56c5939d7..000000000
Binary files a/lib/lwjgl-3.2.1-sources.jar and /dev/null differ
diff --git a/lib/lwjgl-3.2.1.jar b/lib/lwjgl-3.2.1.jar
deleted file mode 100644
index fb904a112..000000000
Binary files a/lib/lwjgl-3.2.1.jar and /dev/null differ
diff --git a/lib/lwjgl-3.2.3-javadoc.jar b/lib/lwjgl-3.2.3-javadoc.jar
new file mode 100644
index 000000000..6751cba7c
Binary files /dev/null and b/lib/lwjgl-3.2.3-javadoc.jar differ
diff --git a/lib/lwjgl-3.2.3-natives-linux-arm32.jar b/lib/lwjgl-3.2.3-natives-linux-arm32.jar
new file mode 100644
index 000000000..25a176a18
Binary files /dev/null and b/lib/lwjgl-3.2.3-natives-linux-arm32.jar differ
diff --git a/lib/lwjgl-3.2.3-natives-linux-arm64.jar b/lib/lwjgl-3.2.3-natives-linux-arm64.jar
new file mode 100644
index 000000000..c32df86e4
Binary files /dev/null and b/lib/lwjgl-3.2.3-natives-linux-arm64.jar differ
diff --git a/lib/lwjgl-3.2.3-natives-linux.jar b/lib/lwjgl-3.2.3-natives-linux.jar
new file mode 100644
index 000000000..f6509cf5d
Binary files /dev/null and b/lib/lwjgl-3.2.3-natives-linux.jar differ
diff --git a/lib/lwjgl-3.2.3-natives-macos.jar b/lib/lwjgl-3.2.3-natives-macos.jar
new file mode 100644
index 000000000..a7f9872ad
Binary files /dev/null and b/lib/lwjgl-3.2.3-natives-macos.jar differ
diff --git a/lib/lwjgl-3.2.3-natives-windows-x86.jar b/lib/lwjgl-3.2.3-natives-windows-x86.jar
new file mode 100644
index 000000000..82fbbd02c
Binary files /dev/null and b/lib/lwjgl-3.2.3-natives-windows-x86.jar differ
diff --git a/lib/lwjgl-3.2.3-natives-windows.jar b/lib/lwjgl-3.2.3-natives-windows.jar
new file mode 100644
index 000000000..78a762000
Binary files /dev/null and b/lib/lwjgl-3.2.3-natives-windows.jar differ
diff --git a/lib/lwjgl-3.2.3-sources.jar b/lib/lwjgl-3.2.3-sources.jar
new file mode 100644
index 000000000..1360c5096
Binary files /dev/null and b/lib/lwjgl-3.2.3-sources.jar differ
diff --git a/lib/lwjgl-3.2.3.jar b/lib/lwjgl-3.2.3.jar
new file mode 100644
index 000000000..e2f71fbda
Binary files /dev/null and b/lib/lwjgl-3.2.3.jar differ
diff --git a/lib/lwjgl-glfw-3.2.1-natives-linux.jar b/lib/lwjgl-glfw-3.2.1-natives-linux.jar
deleted file mode 100644
index cb647937a..000000000
Binary files a/lib/lwjgl-glfw-3.2.1-natives-linux.jar and /dev/null differ
diff --git a/lib/lwjgl-glfw-3.2.1-natives-macos.jar b/lib/lwjgl-glfw-3.2.1-natives-macos.jar
deleted file mode 100644
index 56af31fc8..000000000
Binary files a/lib/lwjgl-glfw-3.2.1-natives-macos.jar and /dev/null differ
diff --git a/lib/lwjgl-glfw-3.2.1-natives-windows.jar b/lib/lwjgl-glfw-3.2.1-natives-windows.jar
deleted file mode 100644
index 971a1f89b..000000000
Binary files a/lib/lwjgl-glfw-3.2.1-natives-windows.jar and /dev/null differ
diff --git a/lib/lwjgl-glfw-3.2.1-sources.jar b/lib/lwjgl-glfw-3.2.1-sources.jar
deleted file mode 100644
index d7da4c6bd..000000000
Binary files a/lib/lwjgl-glfw-3.2.1-sources.jar and /dev/null differ
diff --git a/lib/lwjgl-glfw-3.2.1.jar b/lib/lwjgl-glfw-3.2.1.jar
deleted file mode 100644
index e3f673bca..000000000
Binary files a/lib/lwjgl-glfw-3.2.1.jar and /dev/null differ
diff --git a/lib/lwjgl-glfw-3.2.1-javadoc.jar b/lib/lwjgl-glfw-3.2.3-javadoc.jar
similarity index 56%
rename from lib/lwjgl-glfw-3.2.1-javadoc.jar
rename to lib/lwjgl-glfw-3.2.3-javadoc.jar
index 1edfb0c24..5e328ce90 100644
Binary files a/lib/lwjgl-glfw-3.2.1-javadoc.jar and b/lib/lwjgl-glfw-3.2.3-javadoc.jar differ
diff --git a/lib/lwjgl-glfw-3.2.3-natives-linux-arm32.jar b/lib/lwjgl-glfw-3.2.3-natives-linux-arm32.jar
new file mode 100644
index 000000000..54441cd9d
Binary files /dev/null and b/lib/lwjgl-glfw-3.2.3-natives-linux-arm32.jar differ
diff --git a/lib/lwjgl-glfw-3.2.3-natives-linux-arm64.jar b/lib/lwjgl-glfw-3.2.3-natives-linux-arm64.jar
new file mode 100644
index 000000000..9f5bbf365
Binary files /dev/null and b/lib/lwjgl-glfw-3.2.3-natives-linux-arm64.jar differ
diff --git a/lib/lwjgl-glfw-3.2.3-natives-linux.jar b/lib/lwjgl-glfw-3.2.3-natives-linux.jar
new file mode 100644
index 000000000..2f48c4978
Binary files /dev/null and b/lib/lwjgl-glfw-3.2.3-natives-linux.jar differ
diff --git a/lib/lwjgl-glfw-3.2.3-natives-macos.jar b/lib/lwjgl-glfw-3.2.3-natives-macos.jar
new file mode 100644
index 000000000..148ea4174
Binary files /dev/null and b/lib/lwjgl-glfw-3.2.3-natives-macos.jar differ
diff --git a/lib/lwjgl-glfw-3.2.3-natives-windows-x86.jar b/lib/lwjgl-glfw-3.2.3-natives-windows-x86.jar
new file mode 100644
index 000000000..0b6172111
Binary files /dev/null and b/lib/lwjgl-glfw-3.2.3-natives-windows-x86.jar differ
diff --git a/lib/lwjgl-glfw-3.2.3-natives-windows.jar b/lib/lwjgl-glfw-3.2.3-natives-windows.jar
new file mode 100644
index 000000000..ba29a1482
Binary files /dev/null and b/lib/lwjgl-glfw-3.2.3-natives-windows.jar differ
diff --git a/lib/lwjgl-glfw-3.2.3-sources.jar b/lib/lwjgl-glfw-3.2.3-sources.jar
new file mode 100644
index 000000000..3f11673de
Binary files /dev/null and b/lib/lwjgl-glfw-3.2.3-sources.jar differ
diff --git a/lib/lwjgl-glfw-3.2.3.jar b/lib/lwjgl-glfw-3.2.3.jar
new file mode 100644
index 000000000..5408c4d92
Binary files /dev/null and b/lib/lwjgl-glfw-3.2.3.jar differ
diff --git a/lib/lwjgl-jemalloc-3.2.1-natives-linux.jar b/lib/lwjgl-jemalloc-3.2.1-natives-linux.jar
deleted file mode 100644
index ea94bc326..000000000
Binary files a/lib/lwjgl-jemalloc-3.2.1-natives-linux.jar and /dev/null differ
diff --git a/lib/lwjgl-jemalloc-3.2.1-natives-macos.jar b/lib/lwjgl-jemalloc-3.2.1-natives-macos.jar
deleted file mode 100644
index 68986219b..000000000
Binary files a/lib/lwjgl-jemalloc-3.2.1-natives-macos.jar and /dev/null differ
diff --git a/lib/lwjgl-jemalloc-3.2.1-natives-windows.jar b/lib/lwjgl-jemalloc-3.2.1-natives-windows.jar
deleted file mode 100644
index a53de780f..000000000
Binary files a/lib/lwjgl-jemalloc-3.2.1-natives-windows.jar and /dev/null differ
diff --git a/lib/lwjgl-jemalloc-3.2.1-sources.jar b/lib/lwjgl-jemalloc-3.2.1-sources.jar
deleted file mode 100644
index e294e12dc..000000000
Binary files a/lib/lwjgl-jemalloc-3.2.1-sources.jar and /dev/null differ
diff --git a/lib/lwjgl-jemalloc-3.2.1.jar b/lib/lwjgl-jemalloc-3.2.1.jar
deleted file mode 100644
index af8c715ac..000000000
Binary files a/lib/lwjgl-jemalloc-3.2.1.jar and /dev/null differ
diff --git a/lib/lwjgl-jemalloc-3.2.1-javadoc.jar b/lib/lwjgl-jemalloc-3.2.3-javadoc.jar
similarity index 79%
rename from lib/lwjgl-jemalloc-3.2.1-javadoc.jar
rename to lib/lwjgl-jemalloc-3.2.3-javadoc.jar
index d0996f282..adb48bcef 100644
Binary files a/lib/lwjgl-jemalloc-3.2.1-javadoc.jar and b/lib/lwjgl-jemalloc-3.2.3-javadoc.jar differ
diff --git a/lib/lwjgl-jemalloc-3.2.3-natives-linux-arm32.jar b/lib/lwjgl-jemalloc-3.2.3-natives-linux-arm32.jar
new file mode 100644
index 000000000..c95a2513c
Binary files /dev/null and b/lib/lwjgl-jemalloc-3.2.3-natives-linux-arm32.jar differ
diff --git a/lib/lwjgl-jemalloc-3.2.3-natives-linux-arm64.jar b/lib/lwjgl-jemalloc-3.2.3-natives-linux-arm64.jar
new file mode 100644
index 000000000..dbc114372
Binary files /dev/null and b/lib/lwjgl-jemalloc-3.2.3-natives-linux-arm64.jar differ
diff --git a/lib/lwjgl-jemalloc-3.2.3-natives-linux.jar b/lib/lwjgl-jemalloc-3.2.3-natives-linux.jar
new file mode 100644
index 000000000..396941dfc
Binary files /dev/null and b/lib/lwjgl-jemalloc-3.2.3-natives-linux.jar differ
diff --git a/lib/lwjgl-jemalloc-3.2.3-natives-macos.jar b/lib/lwjgl-jemalloc-3.2.3-natives-macos.jar
new file mode 100644
index 000000000..ad4ede746
Binary files /dev/null and b/lib/lwjgl-jemalloc-3.2.3-natives-macos.jar differ
diff --git a/lib/lwjgl-jemalloc-3.2.3-natives-windows-x86.jar b/lib/lwjgl-jemalloc-3.2.3-natives-windows-x86.jar
new file mode 100644
index 000000000..2fd051c44
Binary files /dev/null and b/lib/lwjgl-jemalloc-3.2.3-natives-windows-x86.jar differ
diff --git a/lib/lwjgl-jemalloc-3.2.3-natives-windows.jar b/lib/lwjgl-jemalloc-3.2.3-natives-windows.jar
new file mode 100644
index 000000000..a6526486a
Binary files /dev/null and b/lib/lwjgl-jemalloc-3.2.3-natives-windows.jar differ
diff --git a/lib/lwjgl-jemalloc-3.2.3-sources.jar b/lib/lwjgl-jemalloc-3.2.3-sources.jar
new file mode 100644
index 000000000..fa7056896
Binary files /dev/null and b/lib/lwjgl-jemalloc-3.2.3-sources.jar differ
diff --git a/lib/lwjgl-jemalloc-3.2.3.jar b/lib/lwjgl-jemalloc-3.2.3.jar
new file mode 100644
index 000000000..07029fc00
Binary files /dev/null and b/lib/lwjgl-jemalloc-3.2.3.jar differ
diff --git a/lib/lwjgl-openal-3.2.1-natives-linux.jar b/lib/lwjgl-openal-3.2.1-natives-linux.jar
deleted file mode 100644
index 3a403c84a..000000000
Binary files a/lib/lwjgl-openal-3.2.1-natives-linux.jar and /dev/null differ
diff --git a/lib/lwjgl-openal-3.2.1-natives-macos.jar b/lib/lwjgl-openal-3.2.1-natives-macos.jar
deleted file mode 100644
index f94268f9a..000000000
Binary files a/lib/lwjgl-openal-3.2.1-natives-macos.jar and /dev/null differ
diff --git a/lib/lwjgl-openal-3.2.1-natives-windows.jar b/lib/lwjgl-openal-3.2.1-natives-windows.jar
deleted file mode 100644
index 500d3c17a..000000000
Binary files a/lib/lwjgl-openal-3.2.1-natives-windows.jar and /dev/null differ
diff --git a/lib/lwjgl-openal-3.2.1-sources.jar b/lib/lwjgl-openal-3.2.1-sources.jar
deleted file mode 100644
index 0d9c560f2..000000000
Binary files a/lib/lwjgl-openal-3.2.1-sources.jar and /dev/null differ
diff --git a/lib/lwjgl-openal-3.2.1.jar b/lib/lwjgl-openal-3.2.1.jar
deleted file mode 100644
index 777a8b018..000000000
Binary files a/lib/lwjgl-openal-3.2.1.jar and /dev/null differ
diff --git a/lib/lwjgl-openal-3.2.1-javadoc.jar b/lib/lwjgl-openal-3.2.3-javadoc.jar
similarity index 70%
rename from lib/lwjgl-openal-3.2.1-javadoc.jar
rename to lib/lwjgl-openal-3.2.3-javadoc.jar
index c43c78e88..7152d1533 100644
Binary files a/lib/lwjgl-openal-3.2.1-javadoc.jar and b/lib/lwjgl-openal-3.2.3-javadoc.jar differ
diff --git a/lib/lwjgl-openal-3.2.3-natives-linux-arm32.jar b/lib/lwjgl-openal-3.2.3-natives-linux-arm32.jar
new file mode 100644
index 000000000..fce5eb9dd
Binary files /dev/null and b/lib/lwjgl-openal-3.2.3-natives-linux-arm32.jar differ
diff --git a/lib/lwjgl-openal-3.2.3-natives-linux-arm64.jar b/lib/lwjgl-openal-3.2.3-natives-linux-arm64.jar
new file mode 100644
index 000000000..65ebedb5e
Binary files /dev/null and b/lib/lwjgl-openal-3.2.3-natives-linux-arm64.jar differ
diff --git a/lib/lwjgl-openal-3.2.3-natives-linux.jar b/lib/lwjgl-openal-3.2.3-natives-linux.jar
new file mode 100644
index 000000000..383bf3fa2
Binary files /dev/null and b/lib/lwjgl-openal-3.2.3-natives-linux.jar differ
diff --git a/lib/lwjgl-openal-3.2.3-natives-macos.jar b/lib/lwjgl-openal-3.2.3-natives-macos.jar
new file mode 100644
index 000000000..f690b9241
Binary files /dev/null and b/lib/lwjgl-openal-3.2.3-natives-macos.jar differ
diff --git a/lib/lwjgl-openal-3.2.3-natives-windows-x86.jar b/lib/lwjgl-openal-3.2.3-natives-windows-x86.jar
new file mode 100644
index 000000000..34633e605
Binary files /dev/null and b/lib/lwjgl-openal-3.2.3-natives-windows-x86.jar differ
diff --git a/lib/lwjgl-openal-3.2.3-natives-windows.jar b/lib/lwjgl-openal-3.2.3-natives-windows.jar
new file mode 100644
index 000000000..56adadf21
Binary files /dev/null and b/lib/lwjgl-openal-3.2.3-natives-windows.jar differ
diff --git a/lib/lwjgl-openal-3.2.3-sources.jar b/lib/lwjgl-openal-3.2.3-sources.jar
new file mode 100644
index 000000000..6ca1e29fd
Binary files /dev/null and b/lib/lwjgl-openal-3.2.3-sources.jar differ
diff --git a/lib/lwjgl-openal-3.2.3.jar b/lib/lwjgl-openal-3.2.3.jar
new file mode 100644
index 000000000..8f5f39d9d
Binary files /dev/null and b/lib/lwjgl-openal-3.2.3.jar differ
diff --git a/lib/lwjgl-opengl-3.2.1-javadoc.jar b/lib/lwjgl-opengl-3.2.1-javadoc.jar
deleted file mode 100644
index 59cc0cb70..000000000
Binary files a/lib/lwjgl-opengl-3.2.1-javadoc.jar and /dev/null differ
diff --git a/lib/lwjgl-opengl-3.2.1-natives-linux.jar b/lib/lwjgl-opengl-3.2.1-natives-linux.jar
deleted file mode 100644
index 2efffb3d9..000000000
Binary files a/lib/lwjgl-opengl-3.2.1-natives-linux.jar and /dev/null differ
diff --git a/lib/lwjgl-opengl-3.2.1-natives-macos.jar b/lib/lwjgl-opengl-3.2.1-natives-macos.jar
deleted file mode 100644
index 22a328ee3..000000000
Binary files a/lib/lwjgl-opengl-3.2.1-natives-macos.jar and /dev/null differ
diff --git a/lib/lwjgl-opengl-3.2.1-natives-windows.jar b/lib/lwjgl-opengl-3.2.1-natives-windows.jar
deleted file mode 100644
index fd2cf29b8..000000000
Binary files a/lib/lwjgl-opengl-3.2.1-natives-windows.jar and /dev/null differ
diff --git a/lib/lwjgl-opengl-3.2.1.jar b/lib/lwjgl-opengl-3.2.1.jar
deleted file mode 100644
index 7e727ad69..000000000
Binary files a/lib/lwjgl-opengl-3.2.1.jar and /dev/null differ
diff --git a/lib/lwjgl-opengl-3.2.3-javadoc.jar b/lib/lwjgl-opengl-3.2.3-javadoc.jar
new file mode 100644
index 000000000..5e5ba8302
Binary files /dev/null and b/lib/lwjgl-opengl-3.2.3-javadoc.jar differ
diff --git a/lib/lwjgl-opengl-3.2.3-natives-linux-arm32.jar b/lib/lwjgl-opengl-3.2.3-natives-linux-arm32.jar
new file mode 100644
index 000000000..cebb76767
Binary files /dev/null and b/lib/lwjgl-opengl-3.2.3-natives-linux-arm32.jar differ
diff --git a/lib/lwjgl-opengl-3.2.3-natives-linux-arm64.jar b/lib/lwjgl-opengl-3.2.3-natives-linux-arm64.jar
new file mode 100644
index 000000000..6aa076935
Binary files /dev/null and b/lib/lwjgl-opengl-3.2.3-natives-linux-arm64.jar differ
diff --git a/lib/lwjgl-opengl-3.2.3-natives-linux.jar b/lib/lwjgl-opengl-3.2.3-natives-linux.jar
new file mode 100644
index 000000000..bbe45383c
Binary files /dev/null and b/lib/lwjgl-opengl-3.2.3-natives-linux.jar differ
diff --git a/lib/lwjgl-opengl-3.2.3-natives-macos.jar b/lib/lwjgl-opengl-3.2.3-natives-macos.jar
new file mode 100644
index 000000000..084072e41
Binary files /dev/null and b/lib/lwjgl-opengl-3.2.3-natives-macos.jar differ
diff --git a/lib/lwjgl-opengl-3.2.3-natives-windows-x86.jar b/lib/lwjgl-opengl-3.2.3-natives-windows-x86.jar
new file mode 100644
index 000000000..c7da8fe91
Binary files /dev/null and b/lib/lwjgl-opengl-3.2.3-natives-windows-x86.jar differ
diff --git a/lib/lwjgl-opengl-3.2.3-natives-windows.jar b/lib/lwjgl-opengl-3.2.3-natives-windows.jar
new file mode 100644
index 000000000..977cfcb12
Binary files /dev/null and b/lib/lwjgl-opengl-3.2.3-natives-windows.jar differ
diff --git a/lib/lwjgl-opengl-3.2.1-sources.jar b/lib/lwjgl-opengl-3.2.3-sources.jar
similarity index 56%
rename from lib/lwjgl-opengl-3.2.1-sources.jar
rename to lib/lwjgl-opengl-3.2.3-sources.jar
index e657ad5d6..17ff783ec 100644
Binary files a/lib/lwjgl-opengl-3.2.1-sources.jar and b/lib/lwjgl-opengl-3.2.3-sources.jar differ
diff --git a/lib/lwjgl-opengl-3.2.3.jar b/lib/lwjgl-opengl-3.2.3.jar
new file mode 100644
index 000000000..b7dcfa363
Binary files /dev/null and b/lib/lwjgl-opengl-3.2.3.jar differ
diff --git a/lib/lwjgl-platform-2.9.3-natives-linux.jar b/lib/lwjgl-platform-2.9.3-natives-linux.jar
deleted file mode 100644
index 60693bde1..000000000
Binary files a/lib/lwjgl-platform-2.9.3-natives-linux.jar and /dev/null differ
diff --git a/lib/lwjgl-platform-2.9.3-natives-osx.jar b/lib/lwjgl-platform-2.9.3-natives-osx.jar
deleted file mode 100644
index 5f6dcbe4a..000000000
Binary files a/lib/lwjgl-platform-2.9.3-natives-osx.jar and /dev/null differ
diff --git a/lib/lwjgl-platform-2.9.3-natives-windows.jar b/lib/lwjgl-platform-2.9.3-natives-windows.jar
deleted file mode 100644
index c931e737b..000000000
Binary files a/lib/lwjgl-platform-2.9.3-natives-windows.jar and /dev/null differ
diff --git a/lib/lwjgl_util-2.9.3-javadoc.jar b/lib/lwjgl_util-2.9.3-javadoc.jar
deleted file mode 100644
index 5db8ffbcb..000000000
Binary files a/lib/lwjgl_util-2.9.3-javadoc.jar and /dev/null differ
diff --git a/lib/lwjgl_util-2.9.3-sources.jar b/lib/lwjgl_util-2.9.3-sources.jar
deleted file mode 100644
index 1bea4c3f5..000000000
Binary files a/lib/lwjgl_util-2.9.3-sources.jar and /dev/null differ
diff --git a/lib/lwjgl_util-2.9.3.jar b/lib/lwjgl_util-2.9.3.jar
deleted file mode 100644
index 97911ab10..000000000
Binary files a/lib/lwjgl_util-2.9.3.jar and /dev/null differ
diff --git a/lib/regex-21.1.0-edit.jar b/lib/regex-21.1.0-edit.jar
new file mode 100644
index 000000000..f407e05d1
Binary files /dev/null and b/lib/regex-21.1.0-edit.jar differ
diff --git a/lib/regex-21.1.0-javadoc.jar b/lib/regex-21.1.0-javadoc.jar
new file mode 100644
index 000000000..8b8495d11
Binary files /dev/null and b/lib/regex-21.1.0-javadoc.jar differ
diff --git a/lib/regex-21.1.0-sources.jar b/lib/regex-21.1.0-sources.jar
new file mode 100644
index 000000000..77aeda5e0
Binary files /dev/null and b/lib/regex-21.1.0-sources.jar differ
diff --git a/lib/truffle-api-21.1.0-javadoc.jar b/lib/truffle-api-21.1.0-javadoc.jar
new file mode 100644
index 000000000..5a083501c
Binary files /dev/null and b/lib/truffle-api-21.1.0-javadoc.jar differ
diff --git a/lib/truffle-api-21.1.0-sources.jar b/lib/truffle-api-21.1.0-sources.jar
new file mode 100644
index 000000000..19ca21fcc
Binary files /dev/null and b/lib/truffle-api-21.1.0-sources.jar differ
diff --git a/lib/truffle-api-21.1.0.jar b/lib/truffle-api-21.1.0.jar
new file mode 100644
index 000000000..77ba08277
Binary files /dev/null and b/lib/truffle-api-21.1.0.jar differ
diff --git a/src/module-info.java.wtf b/src/module-info.java.wtf
index 6d6af58ec..b9d1df39e 100644
--- a/src/module-info.java.wtf
+++ b/src/module-info.java.wtf
@@ -1,4 +1,4 @@
-module terrarum {
+module terrarum.terrarum {
// java
requires java.desktop;
requires java.logging;
@@ -6,11 +6,14 @@ module terrarum {
// kotlin
requires kotlin.stdlib;
+ requires kotlin.test;
// gdx
requires gdx;
- requires gdx.backend.lwjgl;
- requires gdx.controllers;
+ requires gdx.platform;
+ requires gdx.backend.lwjgl3;
+ requires gdx.controllers.core;
+ requires gdx.controllers.desktop;
// terrarum
requires TerrarumSansBitmap;
@@ -19,8 +22,8 @@ module terrarum {
// etc
requires GetCpuName;
- requires jxinput;
- requires gson;
- requires commons.codec;
+ requires com.google.gson;
+ requires org.apache.commons.codec;
requires commons.csv;
+ requires jxinput;
}
\ No newline at end of file
diff --git a/src/net/torvald/colourutil/CIEXYZUtil.kt b/src/net/torvald/colourutil/CIEXYZUtil.kt
index 5825a3de2..4a3b631d2 100644
--- a/src/net/torvald/colourutil/CIEXYZUtil.kt
+++ b/src/net/torvald/colourutil/CIEXYZUtil.kt
@@ -238,7 +238,7 @@ data class CIEXYZ(var X: Float = 0f, var Y: Float = 0f, var Z: Float = 0f, var a
data class CIEYXY(val yy: Float = 0f, var x: Float = 0f, var y: Float = 0f, var alpha: Float = 1f) {
init {
if (yy < 0f || x < 0f || y < 0f)
- throw IllegalArgumentException("Value range error - parametres of YXY cannot be negative: ($yy, $x, $y)")
+ throw IllegalArgumentException("Value range error - parameters of YXY cannot be negative: ($yy, $x, $y)")
}
}
diff --git a/src/net/torvald/parametricsky/Application.kt b/src/net/torvald/parametricsky/Application.kt
index a5747faa0..4692e31c9 100644
--- a/src/net/torvald/parametricsky/Application.kt
+++ b/src/net/torvald/parametricsky/Application.kt
@@ -3,8 +3,8 @@ package net.torvald.parametricsky
import com.badlogic.gdx.Game
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Screen
-import com.badlogic.gdx.backends.lwjgl.LwjglApplication
-import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.Pixmap
import com.badlogic.gdx.graphics.Texture
@@ -284,10 +284,8 @@ class Application : Game() {
fun main(args: Array) {
- val config = LwjglApplicationConfiguration()
- config.width = WIDTH
- config.height = HEIGHT
- config.foregroundFPS = 0
+ val config = Lwjgl3ApplicationConfiguration()
+ config.setWindowedMode(WIDTH, HEIGHT)
- LwjglApplication(Application(), config)
+ Lwjgl3Application(Application(), config)
}
\ No newline at end of file
diff --git a/src/net/torvald/spriteassembler/SpriteAssemblerApp.kt b/src/net/torvald/spriteassembler/SpriteAssemblerApp.kt
index f3aaff476..2633a7b71 100644
--- a/src/net/torvald/spriteassembler/SpriteAssemblerApp.kt
+++ b/src/net/torvald/spriteassembler/SpriteAssemblerApp.kt
@@ -2,8 +2,8 @@ package net.torvald.spriteassembler
import com.badlogic.gdx.Game
import com.badlogic.gdx.Gdx
-import com.badlogic.gdx.backends.lwjgl.LwjglApplication
-import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.Pixmap
import com.badlogic.gdx.graphics.Texture
@@ -309,15 +309,14 @@ class SpriteAssemblerPreview: Game() {
}
fun main(args: Array) {
- val appConfig = LwjglApplicationConfiguration()
- appConfig.resizable = false
- appConfig.width = 512
- appConfig.height = 1024
- appConfig.foregroundFPS = 5
- appConfig.backgroundFPS = 5
+ val appConfig = Lwjgl3ApplicationConfiguration()
+ appConfig.setWindowedMode(512, 1024)
+ appConfig.setIdleFPS(5)
+ appConfig.setForegroundFPS(5)
+ appConfig.setResizable(false)
val gdxWindow = SpriteAssemblerPreview()
- LwjglApplication(gdxWindow, appConfig)
+ Lwjgl3Application(gdxWindow, appConfig)
SpriteAssemblerApp(gdxWindow)
}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/AppLoader.java b/src/net/torvald/terrarum/AppLoader.java
index 3e9b17bf5..9b571bfc5 100644
--- a/src/net/torvald/terrarum/AppLoader.java
+++ b/src/net/torvald/terrarum/AppLoader.java
@@ -2,8 +2,8 @@ package net.torvald.terrarum;
import com.badlogic.gdx.*;
import com.badlogic.gdx.audio.AudioDevice;
-import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
-import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
import com.badlogic.gdx.controllers.Controllers;
import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
@@ -40,6 +40,7 @@ import net.torvald.util.ArrayListMap;
import java.io.File;
import java.io.IOException;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Random;
@@ -94,7 +95,7 @@ public class AppLoader implements ApplicationListener {
* @param appConfig LWJGL(2) Application Configuration
* @param injectScreen GDX Screen you want to run
*/
- public AppLoader(LwjglApplicationConfiguration appConfig, Screen injectScreen) {
+ public AppLoader(Lwjgl3ApplicationConfiguration appConfig, Screen injectScreen) {
AppLoader.injectScreen = injectScreen;
AppLoader.appConfig = appConfig;
}
@@ -102,9 +103,9 @@ public class AppLoader implements ApplicationListener {
/**
* Initialise the application with default game screen
*
- * @param appConfig LWJGL(2) Application Configuration
+ * @param appConfig LWJGL3 Application Configuration
*/
- public AppLoader(LwjglApplicationConfiguration appConfig) {
+ public AppLoader(Lwjgl3ApplicationConfiguration appConfig) {
AppLoader.appConfig = appConfig;
}
@@ -148,14 +149,6 @@ public class AppLoader implements ApplicationListener {
public static final int GLOBAL_FRAMERATE_LIMIT = 300;
- public static final float TV_SAFE_GRAPHICS = 0.05f; // as per EBU recommendation (https://tech.ebu.ch/docs/r/r095.pdf)
- public static final float TV_SAFE_ACTION = 0.035f; // as per EBU recommendation (https://tech.ebu.ch/docs/r/r095.pdf)
-
- public static int getTvSafeGraphicsWidth() { return Math.round(screenW * TV_SAFE_GRAPHICS); }
- public static int getTvSafeGraphicsHeight() { return Math.round(screenH * TV_SAFE_GRAPHICS); }
- public static int getTvSafeActionWidth() { return Math.round(screenW * TV_SAFE_ACTION); }
- public static int getTvSafeActionHeight() { return Math.round(screenH * TV_SAFE_ACTION); }
-
/**
* These languages won't distinguish regional differences (e.g. enUS and enUK, frFR and frCA)
*/
@@ -192,7 +185,8 @@ public class AppLoader implements ApplicationListener {
private static boolean resizeRequested = false;
private static Point2i resizeReqSize;
- public static LwjglApplicationConfiguration appConfig;
+ public static Lwjgl3ApplicationConfiguration appConfig;
+ public static TerrarumScreenSize screenSize;
public static GameFontBase fontGame;
public static TinyAlphNum fontSmallNumbers;
@@ -209,10 +203,6 @@ public class AppLoader implements ApplicationListener {
public static ArrayListMap debugTimers = new ArrayListMap();
- public static final int defaultW = 1280;
- public static final int defaultH = 720;
- public static final int minimumW = 1080;
- public static final int minimumH = 720;
public static final String FONT_DIR = "assets/graphics/fonts/terrarum-sans-bitmap";
@@ -238,15 +228,6 @@ public class AppLoader implements ApplicationListener {
private static Screen currenScreen;
private static LoadScreenBase currentSetLoadScreen;
- public static int screenW = 0;
- public static int screenH = 0;
- public static float screenWf = 0f;
- public static float screenHf = 0f;
- public static int halfScreenW = 0;
- public static int halfScreenH = 0;
- public static float halfScreenWf = 0f;
- public static float halfScreenHf = 0f;
- public static float aspectRatio = 0f;
public static Texture textureWhiteSquare;
public static Texture textureWhiteCircle;
@@ -315,35 +296,37 @@ public class AppLoader implements ApplicationListener {
ShaderProgram.pedantic = false;
- LwjglApplicationConfiguration appConfig = new LwjglApplicationConfiguration();
- appConfig.useGL30 = false; // https://stackoverflow.com/questions/46753218/libgdx-should-i-use-gl30
- appConfig.vSyncEnabled = getConfigBoolean("usevsync");
- appConfig.resizable = false;//true;
- appConfig.width = getConfigInt("screenwidth");
- if (appConfig.width % 2 == 1) appConfig.width -= 1;
- if (appConfig.width < minimumW) appConfig.width = minimumW;
- appConfig.height = getConfigInt("screenheight");
- if (appConfig.height % 2 == 1) appConfig.height -= 1;
- if (appConfig.height < minimumH) appConfig.height = minimumH;
- appConfig.backgroundFPS = Math.min(GLOBAL_FRAMERATE_LIMIT, getConfigInt("displayfps"));
- appConfig.foregroundFPS = Math.min(GLOBAL_FRAMERATE_LIMIT, getConfigInt("displayfps"));
- appConfig.title = GAME_NAME;
- appConfig.forceExit = true; // it seems KDE 5 likes this one better...
- // (Plasma freezes upon app exit. with forceExit = true, it's only frozen for a minute; with forceExit = false, it's indefinite)
- appConfig.samples = 4; // force the AA on, if the graphics driver didn't do already
+ screenSize = new TerrarumScreenSize(getConfigInt("screenwidth"), getConfigInt("screenheight"));
+ int width = screenSize.getScreenW();
+ int height = screenSize.getScreenH();
- if (appConfig.backgroundFPS <= 0) appConfig.backgroundFPS = GLOBAL_FRAMERATE_LIMIT;
- if (appConfig.foregroundFPS <= 0) appConfig.foregroundFPS = GLOBAL_FRAMERATE_LIMIT;
+ Lwjgl3ApplicationConfiguration appConfig = new Lwjgl3ApplicationConfiguration();
+ //appConfig.useGL30 = false; // https://stackoverflow.com/questions/46753218/libgdx-should-i-use-gl30
+ appConfig.useVsync(getConfigBoolean("usevsync"));
+ appConfig.setResizable(false);
+ appConfig.setWindowedMode(width, height);
+ int fps = Math.min(GLOBAL_FRAMERATE_LIMIT, getConfigInt("displayfps"));
+ if (fps <= 0) fps = GLOBAL_FRAMERATE_LIMIT;
+ appConfig.setIdleFPS(fps);
+ appConfig.setForegroundFPS(fps);
+ appConfig.setTitle(GAME_NAME);
+ //appConfig.forceExit = true; // it seems KDE 5 likes this one better...
+ // (Plasma freezes upon app exit. with forceExit = true, it's only frozen for a minute; with forceExit = false, it's indefinite)
+ //appConfig.samples = 4; // force the AA on, if the graphics driver didn't do already
// load app icon
int[] appIconSizes = new int[]{256,128,64,32,16};
+ ArrayList appIconPaths = new ArrayList<>();
for (int size : appIconSizes) {
String name = "assets/appicon" + size + ".png";
if (new File("./" + name).exists()) {
- appConfig.addIcon(name, Files.FileType.Internal);
+ appIconPaths.add("./" + name);
}
}
+ Object[] iconPathsTemp = appIconPaths.toArray();
+ appConfig.setWindowIcon(Arrays.copyOf(iconPathsTemp, iconPathsTemp.length, String[].class));
+
//if (args.length == 1 && args[0].equals("isdev=true")) {
IS_DEVELOPMENT_BUILD = true;
// safe area box
@@ -356,7 +339,7 @@ public class AppLoader implements ApplicationListener {
// set some more configuration vars
MULTITHREAD = THREAD_COUNT >= 3 && getConfigBoolean("multithread");
- new LwjglApplication(new AppLoader(appConfig), appConfig);
+ new Lwjgl3Application(new AppLoader(appConfig), appConfig);
}
@Override
@@ -390,12 +373,12 @@ public class AppLoader implements ApplicationListener {
// set basis of draw
logoBatch = new SpriteBatch();
- camera = new OrthographicCamera(((float) appConfig.width), ((float) appConfig.height));
+ camera = new OrthographicCamera((screenSize.getScreenWf()), (screenSize.getScreenHf()));
batch = new SpriteBatch();
shapeRender = new ShapeRenderer();
- initViewPort(appConfig.width, appConfig.height);
+ initViewPort(screenSize.getScreenW(), screenSize.getScreenH());
// logo here :p
logo = new TextureRegion(new Texture(Gdx.files.internal("assets/graphics/logo_placeholder.tga")));
@@ -417,7 +400,7 @@ public class AppLoader implements ApplicationListener {
VertexAttribute.ColorUnpacked(),
VertexAttribute.TexCoords(0)
);
- updateFullscreenQuad(appConfig.width, appConfig.height);
+ updateFullscreenQuad(screenSize.getScreenW(), screenSize.getScreenH());
// set up renderer info variables
@@ -562,7 +545,7 @@ public class AppLoader implements ApplicationListener {
screenshotRequested = false;
try {
- Pixmap p = ScreenUtils.getFrameBufferPixmap(0, 0, appConfig.width, appConfig.height);
+ Pixmap p = ScreenUtils.getFrameBufferPixmap(0, 0, screenSize.getScreenW(), screenSize.getScreenH());
PixmapIO2.writeTGA(Gdx.files.absolute(defaultDir+"/Screenshot-"+String.valueOf(System.currentTimeMillis())+".tga"), p, true);
p.dispose();
@@ -592,8 +575,8 @@ public class AppLoader implements ApplicationListener {
setCameraPosition(0f, 0f);
int safetyTextLen = fontGame.getWidth(Lang.INSTANCE.get("APP_WARNING_HEALTH_AND_SAFETY"));
- int logoPosX = (appConfig.width - logo.getRegionWidth() - safetyTextLen) >>> 1;
- int logoPosY = Math.round(appConfig.height / 15f);
+ int logoPosX = (screenSize.getScreenW() - logo.getRegionWidth() - safetyTextLen) >>> 1;
+ int logoPosY = Math.round(screenSize.getScreenH() / 15f);
int textY = logoPosY + logo.getRegionHeight() - 16;
// draw logo reflection
@@ -605,8 +588,8 @@ public class AppLoader implements ApplicationListener {
logoBatch.draw(logo, logoPosX, logoPosY + logo.getRegionHeight());
}
else {
- logoBatch.draw(logo, (appConfig.width - logo.getRegionWidth()) / 2f,
- (appConfig.height - logo.getRegionHeight() * 2) / 2f + logo.getRegionHeight()
+ logoBatch.draw(logo, (screenSize.getScreenW() - logo.getRegionWidth()) / 2f,
+ (screenSize.getScreenH() - logo.getRegionHeight() * 2) / 2f + logo.getRegionHeight()
);
}
@@ -631,8 +614,8 @@ public class AppLoader implements ApplicationListener {
String s = Lang.INSTANCE.get("APP_CHINESE_HEALTHY_GAME_MSG_" + i);
fontGame.draw(logoBatch, s,
- (appConfig.width - fontGame.getWidth(s)) >>> 1,
- Math.round(appConfig.height * 12f / 15f + fontGame.getLineHeight() * (i - 1))
+ (screenSize.getScreenW() - fontGame.getWidth(s)) >>> 1,
+ Math.round(screenSize.getScreenH() * 12f / 15f + fontGame.getLineHeight() * (i - 1))
);
}
}
@@ -640,15 +623,15 @@ public class AppLoader implements ApplicationListener {
logoBatch.setColor(new Color(0x282828ff));
Texture tex1 = CommonResourcePool.INSTANCE.getAsTexture("title_health1");
Texture tex2 = CommonResourcePool.INSTANCE.getAsTexture("title_health2");
- int virtualHeight = appConfig.height - logoPosY - logo.getRegionHeight() / 4;
- int virtualHeightOffset = appConfig.height - virtualHeight;
- logoBatch.draw(tex1, (appConfig.width - tex1.getWidth()) >>> 1, virtualHeightOffset + (virtualHeight >>> 1) - 16, tex1.getWidth(), -tex1.getHeight());
- logoBatch.draw(tex2, (appConfig.width - tex2.getWidth()) >>> 1, virtualHeightOffset + (virtualHeight >>> 1) + 16 + tex2.getHeight(), tex2.getWidth(), -tex2.getHeight());
+ int virtualHeight = screenSize.getScreenH() - logoPosY - logo.getRegionHeight() / 4;
+ int virtualHeightOffset = screenSize.getScreenH() - virtualHeight;
+ logoBatch.draw(tex1, (screenSize.getScreenW() - tex1.getWidth()) >>> 1, virtualHeightOffset + (virtualHeight >>> 1) - 16, tex1.getWidth(), -tex1.getHeight());
+ logoBatch.draw(tex2, (screenSize.getScreenW() - tex2.getWidth()) >>> 1, virtualHeightOffset + (virtualHeight >>> 1) + 16 + tex2.getHeight(), tex2.getWidth(), -tex2.getHeight());
}
else {
- logoBatch.draw(logo, (appConfig.width - logo.getRegionWidth()) / 2f,
- (appConfig.height - logo.getRegionHeight() * 2) / 2f
+ logoBatch.draw(logo, (screenSize.getScreenW() - logo.getRegionWidth()) / 2f,
+ (screenSize.getScreenH() - logo.getRegionHeight() * 2) / 2f
);
}
@@ -662,45 +645,30 @@ public class AppLoader implements ApplicationListener {
//initViewPort(width, height);
- screenW = width;
- screenH = height;
+ screenSize.setDimension(width, height);
- if (currenScreen != null) currenScreen.resize(screenW, screenH);
+ if (currenScreen != null) currenScreen.resize(screenSize.getScreenW(), screenSize.getScreenH());
+ updateFullscreenQuad(screenSize.getScreenW(), screenSize.getScreenH());
if (renderFBO == null ||
- (renderFBO.getWidth() != screenW ||
- renderFBO.getHeight() != screenH)
+ (renderFBO.getWidth() != screenSize.getScreenW() ||
+ renderFBO.getHeight() != screenSize.getScreenH())
) {
renderFBO = new FrameBuffer(
Pixmap.Format.RGBA8888,
- screenW,
- screenH,
+ screenSize.getScreenW(),
+ screenSize.getScreenH(),
false
);
}
- appConfig.width = screenW;
- appConfig.height = screenH;
-
- halfScreenW = screenW / 2;
- halfScreenH = screenH / 2;
-
- screenWf = (float) screenW;
- screenHf = (float) screenH;
- halfScreenWf = (float) halfScreenW;
- halfScreenHf = (float) halfScreenH;
-
- aspectRatio = screenWf / screenHf;
-
- updateFullscreenQuad(screenW, screenH);
-
printdbg(this, "Resize end");
}
public static void resizeScreen(int width, int height) {
resizeRequested = true;
- resizeReqSize = new Point2i(Math.max(width, minimumW), Math.max(height, minimumH));
+ resizeReqSize = new Point2i(width, height);
}
@Override
@@ -798,7 +766,7 @@ public class AppLoader implements ApplicationListener {
currenScreen = screen;
currenScreen.show();
- currenScreen.resize(appConfig.width, appConfig.height);
+ currenScreen.resize(screenSize.getScreenW(), screenSize.getScreenH());
System.gc();
@@ -847,7 +815,7 @@ public class AppLoader implements ApplicationListener {
private void setCameraPosition(float newX, float newY) {
- camera.position.set((-newX + appConfig.width / 2), (-newY + appConfig.height / 2), 0f); // deliberate integer division
+ camera.position.set((-newX + screenSize.getScreenW() / 2), (-newY + screenSize.getScreenH() / 2), 0f); // deliberate integer division
camera.update();
logoBatch.setProjectionMatrix(camera.combined);
}
diff --git a/src/net/torvald/terrarum/ColorLimiterTest.kt b/src/net/torvald/terrarum/ColorLimiterTest.kt
index a4e182f43..b225f28d9 100644
--- a/src/net/torvald/terrarum/ColorLimiterTest.kt
+++ b/src/net/torvald/terrarum/ColorLimiterTest.kt
@@ -2,8 +2,8 @@ package net.torvald.terrarum
import com.badlogic.gdx.ApplicationAdapter
import com.badlogic.gdx.Gdx
-import com.badlogic.gdx.backends.lwjgl.LwjglApplication
-import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.GL20
import com.badlogic.gdx.graphics.Texture
@@ -18,14 +18,11 @@ import net.torvald.terrarumsansbitmap.gdx.GameFontBase
*/
fun main(args: Array) { // LWJGL 3 won't work? java.lang.VerifyError
- val config = LwjglApplicationConfiguration()
- //config.useGL30 = true
- config.vSyncEnabled = false
- config.resizable = false
- config.width = 1072
- config.height = 742
- config.foregroundFPS = 9999
- LwjglApplication(ColorLimiterTest, config)
+ val config = Lwjgl3ApplicationConfiguration()
+ config.useVsync(false)
+ config.setResizable(false)
+ config.setWindowedMode(1072, 742)
+ Lwjgl3Application(ColorLimiterTest, config)
}
object ColorLimiterTest : ApplicationAdapter() {
diff --git a/src/net/torvald/terrarum/DefaultConfig.kt b/src/net/torvald/terrarum/DefaultConfig.kt
index edf75b16d..34d7db48d 100644
--- a/src/net/torvald/terrarum/DefaultConfig.kt
+++ b/src/net/torvald/terrarum/DefaultConfig.kt
@@ -4,7 +4,6 @@ import com.badlogic.gdx.Input
import com.google.gson.JsonArray
import com.google.gson.JsonObject
import net.torvald.terrarum.blockproperties.Block
-import net.torvald.terrarum.blockproperties.BlockCodex
/**
* Keys must be all lowercase
@@ -17,8 +16,8 @@ object DefaultConfig {
jsonObject.addProperty("displayfps", 0) // 0: no limit, non-zero: limit
jsonObject.addProperty("usevsync", false)
- jsonObject.addProperty("screenwidth", AppLoader.defaultW)
- jsonObject.addProperty("screenheight", AppLoader.defaultH)
+ jsonObject.addProperty("screenwidth", TerrarumScreenSize.defaultW)
+ jsonObject.addProperty("screenheight", TerrarumScreenSize.defaultH)
//jsonObject.addProperty("imtooyoungtodie", false) // no perma-death
diff --git a/src/net/torvald/terrarum/GlslTilingTest.kt b/src/net/torvald/terrarum/GlslTilingTest.kt
index 3303ff711..c64aae925 100644
--- a/src/net/torvald/terrarum/GlslTilingTest.kt
+++ b/src/net/torvald/terrarum/GlslTilingTest.kt
@@ -2,8 +2,8 @@ package net.torvald.terrarum
import com.badlogic.gdx.ApplicationAdapter
import com.badlogic.gdx.Gdx
-import com.badlogic.gdx.backends.lwjgl.LwjglApplication
-import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration
import com.badlogic.gdx.graphics.*
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.glutils.ShaderProgram
@@ -15,14 +15,11 @@ import net.torvald.terrarumsansbitmap.gdx.GameFontBase
* Created by minjaesong on 2017-08-25.
*/
fun main(args: Array) { // LWJGL 3 won't work? java.lang.VerifyError
- val config = LwjglApplicationConfiguration()
- //config.useGL30 = true
- config.vSyncEnabled = false
- config.resizable = false
- config.width = 1072
- config.height = 742
- config.foregroundFPS = 9999
- LwjglApplication(GlslTilingTest, config)
+ val config = Lwjgl3ApplicationConfiguration()
+ config.useVsync(false)
+ config.setResizable(false)
+ config.setWindowedMode(1072, 742)
+ Lwjgl3Application(GlslTilingTest, config)
}
object GlslTilingTest : ApplicationAdapter() {
diff --git a/src/net/torvald/terrarum/LoadScreenBase.kt b/src/net/torvald/terrarum/LoadScreenBase.kt
index 6ae264c89..a187cc49e 100644
--- a/src/net/torvald/terrarum/LoadScreenBase.kt
+++ b/src/net/torvald/terrarum/LoadScreenBase.kt
@@ -21,7 +21,7 @@ open class LoadScreenBase : ScreenAdapter(), Disposable {
internal var errorTrapped = false
internal var doContextChange = false
- var camera = OrthographicCamera(AppLoader.screenWf, AppLoader.screenHf)
+ var camera = OrthographicCamera(AppLoader.screenSize.screenWf, AppLoader.screenSize.screenHf)
override fun show() {
messages.clear()
@@ -49,7 +49,7 @@ open class LoadScreenBase : ScreenAdapter(), Disposable {
}
- initViewPort(AppLoader.screenW, AppLoader.screenH)
+ initViewPort(AppLoader.screenSize.screenW, AppLoader.screenSize.screenH)
}
fun initViewPort(width: Int, height: Int) {
@@ -77,6 +77,6 @@ open class LoadScreenBase : ScreenAdapter(), Disposable {
}
override fun resize(width: Int, height: Int) {
- initViewPort(AppLoader.screenW, AppLoader.screenH)
+ initViewPort(AppLoader.screenSize.screenW, AppLoader.screenSize.screenH)
}
}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/ModOptionsHost.kt b/src/net/torvald/terrarum/ModOptionsHost.kt
index 98a067f75..74a03a558 100644
--- a/src/net/torvald/terrarum/ModOptionsHost.kt
+++ b/src/net/torvald/terrarum/ModOptionsHost.kt
@@ -12,8 +12,8 @@ class ModOptionsHost : UICanvas() {
private val moduleAreaHMargin = 48
private val moduleAreaBorder = 8
- override var width = AppLoader.screenW - UIRemoCon.remoConWidth - moduleAreaHMargin
- override var height = AppLoader.screenH - moduleAreaHMargin * 2
+ override var width = AppLoader.screenSize.screenW - UIRemoCon.remoConWidth - moduleAreaHMargin
+ override var height = AppLoader.screenSize.screenH - moduleAreaHMargin * 2
override fun updateUI(delta: Float) {
}
diff --git a/src/net/torvald/terrarum/MusicComposerApp.java b/src/net/torvald/terrarum/MusicComposerApp.java
index 062815d09..66a29d1d0 100644
--- a/src/net/torvald/terrarum/MusicComposerApp.java
+++ b/src/net/torvald/terrarum/MusicComposerApp.java
@@ -2,8 +2,8 @@ package net.torvald.terrarum;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Files;
-import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
-import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
import com.badlogic.gdx.graphics.Texture;
import net.torvald.terrarumsansbitmap.gdx.GameFontBase;
@@ -14,37 +14,22 @@ import java.io.File;
*/
public class MusicComposerApp extends ApplicationAdapter {
- public static LwjglApplicationConfiguration appConfig;
+ public static Lwjgl3ApplicationConfiguration appConfig;
public static GameFontBase fontGame;
- public MusicComposerApp(LwjglApplicationConfiguration appConfig) {
+ public MusicComposerApp(Lwjgl3ApplicationConfiguration appConfig) {
this.appConfig = appConfig;
}
public void main(String[] args) {
- LwjglApplicationConfiguration appConfig = new LwjglApplicationConfiguration();
- appConfig.useGL30 = true; // utilising some GL trickeries, need this to be TRUE
- appConfig.resizable = false;//true;
- //appConfig.width = 1110; // photographic ratio (1.5:1)
- //appConfig.height = 740; // photographic ratio (1.5:1)
- appConfig.width = 1000;;;
- appConfig.height = 666;
- appConfig.backgroundFPS = 9999;
- appConfig.foregroundFPS = 9999;
- appConfig.title = "Speelklok";
- appConfig.forceExit = false;
+ Lwjgl3ApplicationConfiguration appConfig = new Lwjgl3ApplicationConfiguration();
- // load app icon
- int[] appIconSizes = new int[]{256,128,64,32,16};
- for (int size : appIconSizes) {
- String name = "assets/appicon" + size + ".png";
- if (new File("./" + name).exists()) {
- appConfig.addIcon(name, Files.FileType.Internal);
- }
- }
+ appConfig.setResizable(false);
+ appConfig.setWindowedMode(1280, 720);
+ appConfig.setTitle("Speelklok");
- new LwjglApplication(new MusicComposerApp(appConfig), appConfig);
+ new Lwjgl3Application(new MusicComposerApp(appConfig), appConfig);
}
@Override
diff --git a/src/net/torvald/terrarum/OpusDecodeTest.kt b/src/net/torvald/terrarum/OpusDecodeTest.kt
index 0a15c2563..088898a2a 100644
--- a/src/net/torvald/terrarum/OpusDecodeTest.kt
+++ b/src/net/torvald/terrarum/OpusDecodeTest.kt
@@ -1,18 +1,18 @@
package net.torvald.terrarum
import com.badlogic.gdx.ApplicationAdapter
-import com.badlogic.gdx.backends.lwjgl.LwjglApplication
-import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration
import com.badlogic.gdx.graphics.Color
-import com.glester.jopus.JOpusBufferFile
fun main(args: Array) {
-
-
- val config = LwjglApplicationConfiguration()
- LwjglApplication(OpusDecodeTest, config)
+ val config = Lwjgl3ApplicationConfiguration()
+ config.useVsync(false)
+ config.setResizable(false)
+ config.setWindowedMode(1072, 742)
+ Lwjgl3Application(OpusDecodeTest, config)
}
/**
@@ -21,8 +21,6 @@ fun main(args: Array) {
object OpusDecodeTest : ApplicationAdapter() {
- private lateinit var opusFile: JOpusBufferFile
-
override fun create() {
}
diff --git a/src/net/torvald/terrarum/PostProcessor.kt b/src/net/torvald/terrarum/PostProcessor.kt
index 1398746e0..7be11cb82 100644
--- a/src/net/torvald/terrarum/PostProcessor.kt
+++ b/src/net/torvald/terrarum/PostProcessor.kt
@@ -65,13 +65,13 @@ object PostProcessor : Disposable {
debugUI.setPosition(0, 0)
batch = SpriteBatch()
- camera = OrthographicCamera(AppLoader.screenWf, AppLoader.screenHf)
+ camera = OrthographicCamera(AppLoader.screenSize.screenWf, AppLoader.screenSize.screenHf)
camera.setToOrtho(true)
batch.projectionMatrix = camera.combined
shapeRenderer = ShapeRenderer()
- Gdx.gl20.glViewport(0, 0, AppLoader.appConfig.width, AppLoader.appConfig.height)
+ Gdx.gl20.glViewport(0, 0, AppLoader.screenSize.screenW, AppLoader.screenSize.screenH)
}
@@ -93,7 +93,7 @@ object PostProcessor : Disposable {
batch.color = Color.WHITE
batch.inUse {
it.draw(functionRowHelper,
- (AppLoader.screenW - functionRowHelper.width) / 2f,
+ (AppLoader.screenSize.screenW - functionRowHelper.width) / 2f,
functionRowHelper.height.toFloat(),
functionRowHelper.width.toFloat(),
functionRowHelper.height * -1f
@@ -120,7 +120,7 @@ object PostProcessor : Disposable {
if (AppLoader.IS_DEVELOPMENT_BUILD && Terrarum.ingame != null) {
batch.inUse {
batch.color = safeAreaCol
- AppLoader.fontGame.draw(it, thisIsDebugStr, 5f, AppLoader.screenH - 24f)
+ AppLoader.fontGame.draw(it, thisIsDebugStr, 5f, AppLoader.screenSize.screenH - 24f)
}
}
}
@@ -147,37 +147,37 @@ object PostProcessor : Disposable {
}
private fun drawSafeArea() {
- val tvSafeAreaW = AppLoader.getTvSafeGraphicsWidth().toFloat()
- val tvSafeAreaH = AppLoader.getTvSafeGraphicsHeight().toFloat()
- val tvSafeArea2W = AppLoader.getTvSafeActionWidth().toFloat()
- val tvSafeArea2H = AppLoader.getTvSafeActionHeight().toFloat()
+ val tvSafeAreaW = AppLoader.screenSize.tvSafeGraphicsWidth.toFloat()
+ val tvSafeAreaH = AppLoader.screenSize.tvSafeGraphicsHeight.toFloat()
+ val tvSafeArea2W = AppLoader.screenSize.tvSafeActionWidth.toFloat()
+ val tvSafeArea2H = AppLoader.screenSize.tvSafeActionHeight.toFloat()
shapeRenderer.inUse(ShapeRenderer.ShapeType.Line) {
// centre ind
shapeRenderer.color = safeAreaCol2
- shapeRenderer.line(0f, 0f, AppLoader.screenWf, AppLoader.screenHf)
- shapeRenderer.line(0f, AppLoader.screenHf, AppLoader.screenWf, 0f)
+ shapeRenderer.line(0f, 0f, AppLoader.screenSize.screenWf, AppLoader.screenSize.screenHf)
+ shapeRenderer.line(0f, AppLoader.screenSize.screenHf, AppLoader.screenSize.screenWf, 0f)
// safe action area
shapeRenderer.color = safeAreaCol2
shapeRenderer.rect(
- tvSafeArea2W, tvSafeArea2H, AppLoader.screenW - 2 * tvSafeArea2W, AppLoader.screenH - 2 * tvSafeArea2H
+ tvSafeArea2W, tvSafeArea2H, AppLoader.screenSize.screenW - 2 * tvSafeArea2W, AppLoader.screenSize.screenH - 2 * tvSafeArea2H
)
// safe graphics area
shapeRenderer.color = safeAreaCol
shapeRenderer.rect(
- tvSafeAreaW, tvSafeAreaH, AppLoader.screenW - 2 * tvSafeAreaW, AppLoader.screenH - 2 * tvSafeAreaH
+ tvSafeAreaW, tvSafeAreaH, AppLoader.screenSize.screenW - 2 * tvSafeAreaW, AppLoader.screenSize.screenH - 2 * tvSafeAreaH
)
// default res ind
shapeRenderer.color = defaultResCol
shapeRenderer.rect(
- (AppLoader.screenW - AppLoader.minimumW).div(2).toFloat(),
- (AppLoader.screenH - AppLoader.minimumH).div(2).toFloat(),
- AppLoader.minimumW.toFloat(),
- AppLoader.minimumH.toFloat()
+ (AppLoader.screenSize.screenW - TerrarumScreenSize.minimumW).div(2).toFloat(),
+ (AppLoader.screenSize.screenH - TerrarumScreenSize.minimumH).div(2).toFloat(),
+ TerrarumScreenSize.minimumW.toFloat(),
+ TerrarumScreenSize.minimumH.toFloat()
)
}
@@ -192,14 +192,14 @@ object PostProcessor : Disposable {
batch.color = defaultResCol
AppLoader.fontSmallNumbers.draw(
batch, defaultResStr,
- (AppLoader.screenW - AppLoader.minimumW).div(2).toFloat(),
- (AppLoader.screenH - AppLoader.minimumH).div(2).toFloat()
+ (AppLoader.screenSize.screenW - TerrarumScreenSize.minimumW).div(2).toFloat(),
+ (AppLoader.screenSize.screenH - TerrarumScreenSize.minimumH).div(2).toFloat()
)
batch.color = currentResCol
AppLoader.fontSmallNumbers.draw(
batch, currentResStr,
- AppLoader.screenW - 80f,
+ AppLoader.screenSize.screenW - 80f,
0f
)
}
@@ -213,8 +213,8 @@ object PostProcessor : Disposable {
}
}
- private val defaultResStr = "${AppLoader.minimumW}x${AppLoader.minimumH}"
- private val currentResStr = "${AppLoader.screenW}x${AppLoader.screenH}"
+ private val defaultResStr = "${TerrarumScreenSize.minimumW}x${TerrarumScreenSize.minimumH}"
+ private val currentResStr = "${AppLoader.screenSize.screenW}x${AppLoader.screenSize.screenH}"
private val safeAreaStr = "TV Safe Area"
private val versionStr = "Version ${AppLoader.getVERSION_STRING()}"
private val thisIsDebugStr = "${AppLoader.GAME_NAME} Develoment Build $versionStr"
diff --git a/src/net/torvald/terrarum/SanicLoadScreen.kt b/src/net/torvald/terrarum/SanicLoadScreen.kt
index a6df9ee7e..30df1a4dd 100644
--- a/src/net/torvald/terrarum/SanicLoadScreen.kt
+++ b/src/net/torvald/terrarum/SanicLoadScreen.kt
@@ -1,16 +1,13 @@
package net.torvald.terrarum
import com.badlogic.gdx.Gdx
-import com.badlogic.gdx.ScreenAdapter
import com.badlogic.gdx.graphics.Color
-import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.Pixmap
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.glutils.FrameBuffer
import com.jme3.math.FastMath
import net.torvald.terrarum.langpack.Lang
import net.torvald.terrarum.modulebasegame.TerrarumIngame
-import net.torvald.util.CircularArray
/**
* Created by minjaesong on 2017-07-13.
@@ -24,7 +21,7 @@ object SanicLoadScreen : LoadScreenBase() {
private var arrowObjPos = 0f // 0 means at starting position, regardless of screen position
private var arrowObjGlideOffsetX = 0f
private var arrowObjGlideSize = 0f
- private val arrowGlideSpeed: Float; get() = AppLoader.screenW * 2f // pixels per sec
+ private val arrowGlideSpeed: Float; get() = AppLoader.screenSize.screenW * 2f // pixels per sec
private lateinit var arrowObjTex: Texture
private var glideTimer = 0f
private var glideDispY = 0f
@@ -63,7 +60,7 @@ object SanicLoadScreen : LoadScreenBase() {
}
- val textX: Float; get() = (AppLoader.screenW * 0.72f).floor()
+ val textX: Float; get() = (AppLoader.screenSize.screenW * 0.72f).floor()
private var genuineSonic = false // the "NOW LOADING..." won't appear unless the arrow first run passes it (it's totally not a GenuineIntel tho)
@@ -75,8 +72,8 @@ object SanicLoadScreen : LoadScreenBase() {
val delta = Gdx.graphics.rawDeltaTime
- glideDispY = AppLoader.screenH - 100f - AppLoader.fontGame.lineHeight
- arrowObjGlideSize = arrowObjTex.width + 2f * AppLoader.screenW
+ glideDispY = AppLoader.screenSize.screenH - 100f - AppLoader.fontGame.lineHeight
+ arrowObjGlideSize = arrowObjTex.width + 2f * AppLoader.screenSize.screenW
@@ -137,14 +134,14 @@ object SanicLoadScreen : LoadScreenBase() {
AppLoader.batch.inUse {
- initViewPort(AppLoader.screenW, AppLoader.screenH) // dunno, no render without this
+ initViewPort(AppLoader.screenSize.screenW, AppLoader.screenSize.screenH) // dunno, no render without this
it.projectionMatrix = camera.combined
blendNormal(AppLoader.batch)
// almost black background
it.color = Color(0x181818ff)
- it.fillRect(0f, 0f, AppLoader.screenWf, AppLoader.screenHf)
+ it.fillRect(0f, 0f, AppLoader.screenSize.screenWf, AppLoader.screenSize.screenHf)
it.color = Color.WHITE
@@ -187,14 +184,14 @@ object SanicLoadScreen : LoadScreenBase() {
// message backgrounds
it.color = messageBackgroundColour
- it.fillRect(0f, 60f, AppLoader.screenWf, 40f + (messages.size) * AppLoader.fontGame.lineHeight)
+ it.fillRect(0f, 60f, AppLoader.screenSize.screenWf, 40f + (messages.size) * AppLoader.fontGame.lineHeight)
// log messages
it.color = messageForegroundColour
messages.forEachIndexed { i, s ->
AppLoader.fontGame.draw(it,
s,
- AppLoader.getTvSafeGraphicsWidth() + 16f,
+ AppLoader.screenSize.tvSafeGraphicsWidth + 16f,
80f + (messages.size - i - 1) * AppLoader.fontGame.lineHeight
)
}
@@ -204,7 +201,7 @@ object SanicLoadScreen : LoadScreenBase() {
AppLoader.batch.inUse {
// recycling part of the draw code //
- initViewPort(AppLoader.screenW, AppLoader.screenH) // dunno, no render without this
+ initViewPort(AppLoader.screenSize.screenW, AppLoader.screenSize.screenH) // dunno, no render without this
it.projectionMatrix = camera.combined
blendNormal(AppLoader.batch)
@@ -212,14 +209,14 @@ object SanicLoadScreen : LoadScreenBase() {
// message backgrounds
it.color = messageBackgroundColour
- it.fillRect(0f, 60f, AppLoader.screenWf, 40f + (messages.size) * AppLoader.fontGame.lineHeight)
+ it.fillRect(0f, 60f, AppLoader.screenSize.screenWf, 40f + (messages.size) * AppLoader.fontGame.lineHeight)
// log messages
it.color = messageForegroundColour
messages.forEachIndexed { i, s ->
AppLoader.fontGame.draw(it,
s,
- AppLoader.getTvSafeGraphicsWidth() + 16f,
+ AppLoader.screenSize.tvSafeGraphicsWidth + 16f,
80f + (messages.size - i - 1) * AppLoader.fontGame.lineHeight
)
}
diff --git a/src/net/torvald/terrarum/ShitOnGlsl.kt b/src/net/torvald/terrarum/ShitOnGlsl.kt
index c0011aa35..8f00d9821 100644
--- a/src/net/torvald/terrarum/ShitOnGlsl.kt
+++ b/src/net/torvald/terrarum/ShitOnGlsl.kt
@@ -2,8 +2,8 @@ package net.torvald.terrarum
import com.badlogic.gdx.ApplicationAdapter
import com.badlogic.gdx.Gdx
-import com.badlogic.gdx.backends.lwjgl.LwjglApplication
-import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration
import com.badlogic.gdx.graphics.*
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.glutils.ShaderProgram
@@ -14,14 +14,11 @@ import net.torvald.terrarumsansbitmap.gdx.GameFontBase
* Created by minjaesong on 2017-08-11.
*/
fun main(args: Array) { // LWJGL 3 won't work? java.lang.VerifyError
- val config = LwjglApplicationConfiguration()
- //config.useGL30 = true
- config.vSyncEnabled = false
- config.resizable = false
- config.width = 1072
- config.height = 742
- config.foregroundFPS = 9999
- LwjglApplication(ShitOnGlsl, config)
+ val config = Lwjgl3ApplicationConfiguration()
+ config.useVsync(false)
+ config.setResizable(false)
+ config.setWindowedMode(1072, 742)
+ Lwjgl3Application(ShitOnGlsl, config)
}
object ShitOnGlsl : ApplicationAdapter() {
diff --git a/src/net/torvald/terrarum/Terrarum.kt b/src/net/torvald/terrarum/Terrarum.kt
index 23e187679..2434b4824 100644
--- a/src/net/torvald/terrarum/Terrarum.kt
+++ b/src/net/torvald/terrarum/Terrarum.kt
@@ -335,7 +335,7 @@ inline fun FrameBuffer.inAction(camera: OrthographicCamera?, batch: SpriteBatch?
//this.end()
FrameBufferManager.end()
- camera?.setToOrtho(true, AppLoader.screenWf, AppLoader.screenHf)
+ camera?.setToOrtho(true, AppLoader.screenSize.screenWf, AppLoader.screenSize.screenHf)
camera?.update()
batch?.projectionMatrix = camera?.combined
}
diff --git a/src/net/torvald/terrarum/TerrarumScreenSize.kt b/src/net/torvald/terrarum/TerrarumScreenSize.kt
new file mode 100644
index 000000000..a11734210
--- /dev/null
+++ b/src/net/torvald/terrarum/TerrarumScreenSize.kt
@@ -0,0 +1,48 @@
+package net.torvald.terrarum
+
+class TerrarumScreenSize(scrw: Int = defaultW, scrh: Int = defaultH) {
+
+ companion object {
+ const val minimumW = 1080
+ const val minimumH = 720
+ const val defaultW = 1280
+ const val defaultH = 720
+
+ const val TV_SAFE_GRAPHICS = 0.05f // as per EBU recommendation (https://tech.ebu.ch/docs/r/r095.pdf)
+ const val TV_SAFE_ACTION = 0.035f // as per EBU recommendation (https://tech.ebu.ch/docs/r/r095.pdf)
+ }
+
+ var screenW: Int = 0; private set
+ var screenH: Int = 0; private set
+ var screenWf: Float = 0f; private set
+ var screenHf: Float = 0f; private set
+ var halfScreenW: Int = 0; private set
+ var halfScreenH: Int = 0; private set
+ var halfScreenWf: Float = 0f; private set
+ var halfScreenHf: Float = 0f; private set
+ var aspectRatio: Float = 0f; private set
+
+
+
+ val tvSafeGraphicsWidth: Int; get() = Math.round(screenW * TV_SAFE_GRAPHICS)
+ val tvSafeGraphicsHeight: Int; get() = Math.round(screenH * TV_SAFE_GRAPHICS)
+ val tvSafeActionWidth: Int; get() = Math.round(screenW * TV_SAFE_ACTION)
+ val tvSafeActionHeight: Int; get() = Math.round(screenH * TV_SAFE_ACTION)
+
+ init {
+ setDimension(maxOf(minimumW, scrw), maxOf(minimumH, scrh))
+ }
+
+ fun setDimension(scrw: Int, scrh: Int) {
+ screenW = scrw and 0x7FFFFFFE
+ screenH = scrh and 0x7FFFFFFE
+ screenWf = scrw.toFloat()
+ screenHf = scrh.toFloat()
+ halfScreenW = screenW / 2
+ halfScreenH = screenH / 2
+ halfScreenWf = screenWf / 2f
+ halfScreenHf = screenHf / 2f
+ aspectRatio = screenWf / screenHf
+ }
+
+}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/TestTestTest.kt b/src/net/torvald/terrarum/TestTestTest.kt
index 5786fd886..ccfe86b7f 100644
--- a/src/net/torvald/terrarum/TestTestTest.kt
+++ b/src/net/torvald/terrarum/TestTestTest.kt
@@ -3,8 +3,8 @@ package net.torvald.terrarum
import com.badlogic.gdx.ApplicationAdapter
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Screen
-import com.badlogic.gdx.backends.lwjgl.LwjglApplication
-import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration
import com.badlogic.gdx.graphics.*
import com.badlogic.gdx.graphics.g2d.BitmapFont
import com.badlogic.gdx.graphics.g2d.SpriteBatch
@@ -45,7 +45,7 @@ class TestTestTest(val batch: SpriteBatch) : Screen {
fun enter() {
// init view port
- camera = OrthographicCamera(AppLoader.screenWf, AppLoader.screenHf)
+ camera = OrthographicCamera(AppLoader.screenSize.screenWf, AppLoader.screenSize.screenHf)
img = Texture("assets/test_texture.tga")
@@ -57,14 +57,14 @@ class TestTestTest(val batch: SpriteBatch) : Screen {
blurFboA = FrameBuffer(Pixmap.Format.RGBA8888, img.width, img.height, false)
blurFboB = FrameBuffer(Pixmap.Format.RGBA8888, img.width, img.height, false)
- worldFbo = FrameBuffer(Pixmap.Format.RGBA8888, AppLoader.screenW, AppLoader.screenH, false)
+ worldFbo = FrameBuffer(Pixmap.Format.RGBA8888, AppLoader.screenSize.screenW, AppLoader.screenSize.screenH, false)
//blurShader.begin()
//blurShader.setUniformf("iResolution", img.width.toFloat(), img.height.toFloat(), 0f)
//blurShader.end()
- initViewPort(AppLoader.screenW, AppLoader.screenH)
+ initViewPort(AppLoader.screenSize.screenW, AppLoader.screenSize.screenH)
}
override fun render(delta: Float) {
@@ -135,7 +135,7 @@ class TestTestTest(val batch: SpriteBatch) : Screen {
batch.inUse {
batch.shader = null
- camera.position.set(AppLoader.screenW / 2f - 50f, AppLoader.screenH / 2f - 50f, 0f)
+ camera.position.set(AppLoader.screenSize.screenW / 2f - 50f, AppLoader.screenSize.screenH / 2f - 50f, 0f)
camera.update()
batch.projectionMatrix = camera.combined
@@ -147,11 +147,11 @@ class TestTestTest(val batch: SpriteBatch) : Screen {
}
- camera.setToOrtho(true, AppLoader.screenWf, AppLoader.screenHf)
+ camera.setToOrtho(true, AppLoader.screenSize.screenWf, AppLoader.screenSize.screenHf)
batch.projectionMatrix = camera.combined
batch.inUse {
- camera.position.set(AppLoader.screenW / 2f, AppLoader.screenH / 2f, 0f)
+ camera.position.set(AppLoader.screenSize.screenW / 2f, AppLoader.screenSize.screenH / 2f, 0f)
camera.update()
batch.projectionMatrix = camera.combined
@@ -168,7 +168,7 @@ class TestTestTest(val batch: SpriteBatch) : Screen {
}
override fun show() {
- initViewPort(AppLoader.screenW, AppLoader.screenH)
+ initViewPort(AppLoader.screenSize.screenW, AppLoader.screenSize.screenH)
}
override fun pause() {
@@ -216,12 +216,9 @@ object TestTestMain : ApplicationAdapter() {
}
fun main(args: Array) { // LWJGL 3 won't work? java.lang.VerifyError
- val config = LwjglApplicationConfiguration()
- //config.useGL30 = true
- config.vSyncEnabled = false
- config.resizable = false
- config.width = 1072
- config.height = 742
- config.foregroundFPS = 9999
- LwjglApplication(TestTestMain, config)
+ val config = Lwjgl3ApplicationConfiguration()
+ config.useVsync(false)
+ config.setResizable(false)
+ config.setWindowedMode(1072, 742)
+ Lwjgl3Application(TestTestMain, config)
}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/TexRegionTilingTest.kt b/src/net/torvald/terrarum/TexRegionTilingTest.kt
index 9b857cb7a..9c42031d2 100644
--- a/src/net/torvald/terrarum/TexRegionTilingTest.kt
+++ b/src/net/torvald/terrarum/TexRegionTilingTest.kt
@@ -2,8 +2,8 @@ package net.torvald.terrarum
import com.badlogic.gdx.ApplicationAdapter
import com.badlogic.gdx.Gdx
-import com.badlogic.gdx.backends.lwjgl.LwjglApplication
-import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration
import com.badlogic.gdx.graphics.GL20
import com.badlogic.gdx.graphics.Pixmap
import com.badlogic.gdx.graphics.Texture
@@ -19,14 +19,11 @@ import java.util.zip.GZIPInputStream
*/
fun main(args: Array) { // LWJGL 3 won't work? java.lang.VerifyError
- val config = LwjglApplicationConfiguration()
- //config.useGL30 = true
- config.vSyncEnabled = false
- config.resizable = false
- config.width = 1072
- config.height = 742
- config.foregroundFPS = 9999
- LwjglApplication(TexRegionTilingTest, config)
+ val config = Lwjgl3ApplicationConfiguration()
+ config.useVsync(false)
+ config.setResizable(false)
+ config.setWindowedMode(1072, 742)
+ Lwjgl3Application(TexRegionTilingTest, config)
}
object TexRegionTilingTest : ApplicationAdapter() {
diff --git a/src/net/torvald/terrarum/TitleScreen.kt b/src/net/torvald/terrarum/TitleScreen.kt
index 2abd0113a..2bd04271a 100644
--- a/src/net/torvald/terrarum/TitleScreen.kt
+++ b/src/net/torvald/terrarum/TitleScreen.kt
@@ -5,9 +5,7 @@ import com.badlogic.gdx.InputAdapter
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.Pixmap
-import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.SpriteBatch
-import com.badlogic.gdx.graphics.g2d.TextureRegion
import com.badlogic.gdx.graphics.glutils.FrameBuffer
import com.jme3.math.FastMath
import net.torvald.random.HQRNG
@@ -38,7 +36,7 @@ class TitleScreen(batch: SpriteBatch) : IngameInstance(batch) {
// todo register titlescreen as the ingame, similar in a way that the buildingmaker did
- var camera = OrthographicCamera(AppLoader.screenWf, AppLoader.screenHf)
+ var camera = OrthographicCamera(AppLoader.screenSize.screenWf, AppLoader.screenSize.screenHf)
// invert Y
@@ -170,13 +168,13 @@ class TitleScreen(batch: SpriteBatch) : IngameInstance(batch) {
override fun show() {
printdbg(this, "show() called")
- initViewPort(AppLoader.screenW, AppLoader.screenH)
+ initViewPort(AppLoader.screenSize.screenW, AppLoader.screenSize.screenH)
Gdx.input.inputProcessor = TitleScreenController(this)
- worldFBO = FrameBuffer(Pixmap.Format.RGBA8888, AppLoader.screenW, AppLoader.screenH, false)
+ worldFBO = FrameBuffer(Pixmap.Format.RGBA8888, AppLoader.screenSize.screenW, AppLoader.screenSize.screenH, false)
loadThingsWhileIntroIsVisible()
@@ -235,7 +233,7 @@ class TitleScreen(batch: SpriteBatch) : IngameInstance(batch) {
Gdx.graphics.setTitle(TerrarumIngame.getCanonicalTitle())
- //camera.setToOrtho(true, AppLoader.screenWf, AppLoader.screenHf)
+ //camera.setToOrtho(true, AppLoader.terrarumAppConfig.screenWf, AppLoader.terrarumAppConfig.screenHf)
// render world
gdxClearAndSetBlend(.64f, .754f, .84f, 1f)
@@ -272,14 +270,14 @@ class TitleScreen(batch: SpriteBatch) : IngameInstance(batch) {
COPYTING.forEachIndexed { index, s ->
val textWidth = AppLoader.fontGame.getWidth(s)
AppLoader.fontGame.draw(batch, s,
- (AppLoader.screenW - textWidth - 1f).toInt().toFloat(),
- (AppLoader.screenH - AppLoader.fontGame.lineHeight * (COPYTING.size - index) - 1f).toInt().toFloat()
+ (AppLoader.screenSize.screenW - textWidth - 1f).toInt().toFloat(),
+ (AppLoader.screenSize.screenH - AppLoader.fontGame.lineHeight * (COPYTING.size - index) - 1f).toInt().toFloat()
)
}
AppLoader.fontGame.draw(batch, "${AppLoader.GAME_NAME} ${AppLoader.getVERSION_STRING()}",
1f.toInt().toFloat(),
- (AppLoader.screenH - AppLoader.fontGame.lineHeight - 1f).toInt().toFloat()
+ (AppLoader.screenSize.screenH - AppLoader.fontGame.lineHeight - 1f).toInt().toFloat()
)
}
@@ -296,11 +294,11 @@ class TitleScreen(batch: SpriteBatch) : IngameInstance(batch) {
printStackTrace(this)
// Set up viewport when window is resized
- initViewPort(AppLoader.screenW, AppLoader.screenH)
+ initViewPort(AppLoader.screenSize.screenW, AppLoader.screenSize.screenH)
// resize UI by re-creating it (!!)
- uiMenu.resize(AppLoader.screenW, AppLoader.screenH)
+ uiMenu.resize(AppLoader.screenSize.screenW, AppLoader.screenSize.screenH)
// TODO I forgot what the fuck kind of hack I was talking about
//uiMenu.setPosition(0, UITitleRemoConRoot.menubarOffY)
uiMenu.setPosition(0, 0) // shitty hack. Could be:
@@ -308,7 +306,7 @@ class TitleScreen(batch: SpriteBatch) : IngameInstance(batch) {
// 2: The UI is coded shit
- IngameRenderer.resize(AppLoader.screenW, AppLoader.screenH)
+ IngameRenderer.resize(AppLoader.screenSize.screenW, AppLoader.screenSize.screenH)
printdbg(this, "resize() exit")
}
@@ -342,8 +340,8 @@ class TitleScreen(batch: SpriteBatch) : IngameInstance(batch) {
return true
}
- override fun scrolled(amount: Int): Boolean {
- screen.uiContainer.forEach { it?.scrolled(amount) }
+ override fun scrolled(amountX: Float, amountY: Float): Boolean {
+ screen.uiContainer.forEach { it?.scrolled(amountX, amountY) }
return true
}
diff --git a/src/net/torvald/terrarum/blockstats/BlockStats.kt b/src/net/torvald/terrarum/blockstats/BlockStats.kt
index 0702ad760..15b86e704 100644
--- a/src/net/torvald/terrarum/blockstats/BlockStats.kt
+++ b/src/net/torvald/terrarum/blockstats/BlockStats.kt
@@ -4,7 +4,6 @@ import com.jme3.math.FastMath
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.gameitem.ItemID
-import net.torvald.terrarum.gameworld.GameWorld
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.worlddrawer.BlocksDrawer
import net.torvald.terrarum.worlddrawer.CreateTileAtlas
@@ -31,8 +30,8 @@ object BlockStats {
val player = (Terrarum.ingame!! as TerrarumIngame).actorNowPlaying
if (player == null) return
- val renderWidth = FastMath.ceil(AppLoader.screenWf)
- val renderHeight = FastMath.ceil(AppLoader.screenHf)
+ val renderWidth = FastMath.ceil(AppLoader.screenSize.screenWf)
+ val renderHeight = FastMath.ceil(AppLoader.screenSize.screenHf)
val noZoomCameraX = Math.round(FastMath.clamp(
player.hitbox.centeredX.toFloat() - renderWidth / 2, TSIZE.toFloat(), map.width * TSIZE - renderWidth - TSIZE.toFloat()))
diff --git a/src/net/torvald/terrarum/console/ResizeScreen.kt b/src/net/torvald/terrarum/console/ResizeScreen.kt
index ce3f07e35..c141dde8a 100644
--- a/src/net/torvald/terrarum/console/ResizeScreen.kt
+++ b/src/net/torvald/terrarum/console/ResizeScreen.kt
@@ -1,6 +1,7 @@
package net.torvald.terrarum.console
import net.torvald.terrarum.AppLoader
+import net.torvald.terrarum.TerrarumScreenSize
object ResizeScreen: ConsoleCommand {
override fun execute(args: Array) {
@@ -11,7 +12,7 @@ object ResizeScreen: ConsoleCommand {
when (args[1]) {
"720p" -> AppLoader.resizeScreen(1280,720)
"1080p" -> AppLoader.resizeScreen(1920,1080)
- "default" -> AppLoader.resizeScreen(AppLoader.defaultW, AppLoader.defaultH)
+ "default" -> AppLoader.resizeScreen(TerrarumScreenSize.defaultW, TerrarumScreenSize.defaultH)
else -> { printUsage(); return }
}
}
@@ -19,11 +20,11 @@ object ResizeScreen: ConsoleCommand {
printUsage(); return
}
- Echo("Screen resized to ${AppLoader.screenW}x${AppLoader.screenH}")
+ Echo("Screen resized to ${AppLoader.screenSize.screenW}x${AppLoader.screenSize.screenH}")
}
override fun printUsage() {
- Echo("Usage: resize [width] [height]. Minimum size is ${AppLoader.minimumW}x${AppLoader.minimumH}")
+ Echo("Usage: resize [width] [height]. Minimum size is ${TerrarumScreenSize.minimumW}x${TerrarumScreenSize.minimumH}")
Echo("Reserved keywords: 720p, 1080p, default")
}
}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/controller/GdxControllerAdapter.kt b/src/net/torvald/terrarum/controller/GdxControllerAdapter.kt
index a1f466ace..3254a1bff 100644
--- a/src/net/torvald/terrarum/controller/GdxControllerAdapter.kt
+++ b/src/net/torvald/terrarum/controller/GdxControllerAdapter.kt
@@ -1,7 +1,7 @@
package net.torvald.terrarum.controller
import com.badlogic.gdx.controllers.Controller
-import com.badlogic.gdx.controllers.PovDirection
+import net.torvald.terrarum.toInt
/**
* Created by minjaesong on 2019-02-09.
@@ -16,18 +16,11 @@ class GdxControllerAdapter(val c: Controller): TerrarumController {
return c.getAxis(index)
}
- override fun getPov(): Int {
- return when(c.getPov(0)) {
- PovDirection.north -> TerrarumController.POV_N
- PovDirection.northEast -> TerrarumController.POV_NE
- PovDirection.northWest -> TerrarumController.POV_NW
- PovDirection.east -> TerrarumController.POV_E
- PovDirection.west -> TerrarumController.POV_W
- PovDirection.south -> TerrarumController.POV_S
- PovDirection.southEast -> TerrarumController.POV_SE
- PovDirection.southWest -> TerrarumController.POV_SW
- else -> 0
- }
+ override fun getDpad(): Int {
+ return (c.getButton(c.mapping.buttonDpadLeft).toInt()) or
+ (c.getButton(c.mapping.buttonDpadDown).toInt() shl 1) or
+ (c.getButton(c.mapping.buttonDpadRight).toInt() shl 2) or
+ (c.getButton(c.mapping.buttonDpadUp).toInt() shl 3)
}
override fun getName(): String {
diff --git a/src/net/torvald/terrarum/controller/TerrarumController.kt b/src/net/torvald/terrarum/controller/TerrarumController.kt
index 16fcdf365..aced53db5 100644
--- a/src/net/torvald/terrarum/controller/TerrarumController.kt
+++ b/src/net/torvald/terrarum/controller/TerrarumController.kt
@@ -70,7 +70,7 @@ interface TerrarumController {
* 6 2 3
* ```
*/
- fun getPov(): Int
+ fun getDpad(): Int
fun getName(): String
/**
diff --git a/src/net/torvald/terrarum/controller/XinputControllerAdapter.kt b/src/net/torvald/terrarum/controller/XinputControllerAdapter.kt
index 0a84a45da..337dae058 100644
--- a/src/net/torvald/terrarum/controller/XinputControllerAdapter.kt
+++ b/src/net/torvald/terrarum/controller/XinputControllerAdapter.kt
@@ -53,7 +53,7 @@ class XinputControllerAdapter(val c: XInputDevice): TerrarumController {
return -1f
}
- override fun getPov(): Int {
+ override fun getDpad(): Int {
if (c.poll()) {
val axes = c.components.axes
diff --git a/src/net/torvald/terrarum/gameactors/ai/AILuaAPI.kt b/src/net/torvald/terrarum/gameactors/ai/AILuaAPI.kt
deleted file mode 100644
index 0d174b648..000000000
--- a/src/net/torvald/terrarum/gameactors/ai/AILuaAPI.kt
+++ /dev/null
@@ -1,398 +0,0 @@
-package net.torvald.terrarum.gameactors.ai
-
-import org.luaj.vm2.LuaTable
-import org.luaj.vm2.LuaValue
-
-/**
- * Created by minjaesong on 2016-10-24.
- */
-/*internal class AILuaAPI(g: Globals, actor: ActorWBMovable) {
-
- // FIXME when actor jumps, the actor releases left/right stick
-
- init {
- if (actor !is AIControlled)
- throw IllegalArgumentException("The actor is not AIControlled! $actor")
-
- // load functions and set up constants
- g["ai"] = LuaValue.tableOf()
-
- g["ai"]["getSelfActorInfo"] = GetSelfActorInfo(actor)
-
- g["ai"]["getNearestActor"] = GetNearestActor()
- g["ai"]["getNearestPlayer"] = GetNearestPlayer()
-
- g["ai"]["getX"] = GetX(actor)
- g["ai"]["getY"] = GetY(actor)
- g["ai"]["moveUp"] = MoveUp(actor)
- g["ai"]["moveDown"] = MoveDown(actor)
- g["ai"]["moveLeft"] = MoveLeft(actor)
- g["ai"]["moveRight"] = MoveRight(actor)
- g["ai"]["moveTo"] = MoveTo(actor)
- g["ai"]["jump"] = Jump(actor)
-
- g["ai"]["getNearbyTiles"] = GetNearbyTiles(actor)
- g["ai"]["getFloorsHeight"] = GetFloorsHeight(actor)
- g["ai"]["getCeilingsHeight"] = GetCeilingsHeight(actor)
- g["ai"]["getLedgesHeight"] = GetLedgesHeight(actor)
-
- g["game"] = LuaValue.tableOf()
- g["game"]["version"] = GameVersion()
- g["game"]["versionRaw"] = GameVersionRaw()
- }
-
- companion object {
- /**
- * Reads arbitrary ActorWBMovable and returns its information as Lua table
- */
- fun composeActorObject(actor: ActorWBMovable): LuaTable {
- val t: LuaTable = LuaTable()
- val moveDelta = actor.externalV + actor.controllerV
-
- t["name"] = actor.actorValue.getAsString(AVKey.NAME).toLua()
- t["startX"] = actor.hitbox.centeredX.toLua()
- t["startY"] = actor.hitbox.centeredY.toLua()
-
- t["veloX"] = moveDelta.x.toLua()
- t["veloY"] = moveDelta.y.toLua()
-
- t["width"] = actor.hitbox.width.toLua()
- t["height"] = actor.hitbox.height.toLua()
-
- t["mass"] = actor.mass.toLua()
-
- t["collisionType"] = actor.collisionType.toLua()
-
- t["strength"] = actor.avStrength.toLua()
-
-
- return t
- }
-
- operator fun LuaTable.set(index: Int, value: Int) { this[index] = value.toLua() }
- }
-
- class GetSelfActorInfo(val actor: ActorWBMovable) : ZeroArgFunction() {
- override fun call(): LuaValue {
- return composeActorObject(actor)
- }
- }
-
- /** ai.getNearestActor(nullable any criterion, nullable number range) */
- class GetNearestActor() : LuaFunction() {
- override fun call(): LuaValue {
- return LuaValue.NONE
- }
-
- override fun call(crit: LuaValue): LuaValue {
- return LuaValue.NONE
- }
-
- override fun call(crit: LuaValue, range: LuaValue): LuaValue {
- return LuaValue.NONE
- }
- }
-
- /** ai.getNearestPlayer(nullable any criterion, nullable number range) */
- class GetNearestPlayer() : LuaFunction() {
- override fun call(): LuaValue {
- return LuaValue.NONE
- }
-
- override fun call(crit: LuaValue): LuaValue {
- return LuaValue.NONE
- }
-
- override fun call(crit: LuaValue, range: LuaValue): LuaValue {
- return LuaValue.NONE
- }
- }
-
- class GetX(val actor: ActorWBMovable) : ZeroArgFunction() {
- override fun call(): LuaValue {
- return LuaValue.valueOf(actor.hitbox.centeredX)
- }
- }
-
- class GetY(val actor: ActorWBMovable) : ZeroArgFunction() {
- override fun call(): LuaValue {
- return LuaValue.valueOf(actor.hitbox.centeredY)
- }
- }
-
- class MoveLeft(val actor: AIControlled) : LuaFunction() {
- override fun call(): LuaValue { // hard key press
- actor.moveLeft()
- return LuaValue.NONE
- }
-
- /** @param amount [0.0 - 1.0] */
- override fun call(amount: LuaValue): LuaValue { // stick tilt
- actor.moveLeft(amount.checkdouble().toFloat())
- return LuaValue.NONE
- }
- }
-
- class MoveRight(val actor: AIControlled) : LuaFunction() {
- override fun call(): LuaValue { // hard key press
- actor.moveRight()
- return LuaValue.NONE
- }
-
- /** @param amount [0.0 - 1.0] */
- override fun call(amount: LuaValue): LuaValue { // stick tilt
- actor.moveRight(amount.checkdouble().toFloat())
- return LuaValue.NONE
- }
- }
-
- class MoveUp(val actor: AIControlled) : LuaFunction() {
- override fun call(): LuaValue { // hard key press
- actor.moveUp()
- return LuaValue.NONE
- }
-
- /** @param amount [0.0 - 1.0] */
- override fun call(amount: LuaValue): LuaValue { // stick tilt
- actor.moveUp(amount.checkdouble().toFloat())
- return LuaValue.NONE
- }
- }
-
- class MoveDown(val actor: AIControlled) : LuaFunction() {
- override fun call(): LuaValue { // hard key press
- actor.moveDown()
- return LuaValue.NONE
- }
-
- /** @param amount [0.0 - 1.0] */
- override fun call(amount: LuaValue): LuaValue { // stick tilt
- actor.moveDown(amount.checkdouble().toFloat())
- return LuaValue.NONE
- }
- }
-
- class MoveTo(val actor: AIControlled) : LuaFunction() {
- override fun call(bearing: LuaValue): LuaValue {
- actor.moveTo(bearing.checkdouble())
- return LuaValue.NONE
- }
-
- override fun call(toX: LuaValue, toY: LuaValue): LuaValue {
- actor.moveTo(toX.checkdouble(), toY.checkdouble())
- return LuaValue.NONE
- }
- }
-
- class Jump(val actor: AIControlled) : LuaFunction() {
- override fun call(): LuaValue {
- actor.moveJump()
- return LuaValue.NONE
- }
-
- /** @param amount [0.0 - 1.0] */
- override fun call(amount: LuaValue): LuaValue { // stick tilt
- actor.moveJump(amount.checkdouble().toFloat())
- return LuaValue.NONE
- }
- }
-
- class GetNearbyTiles(val actor: ActorWBMovable) : OneArgFunction() {
- /** @param radius
- *
- * 3 will return 7x7 array, 0 will return 1x1, 1 will return 3x3
- *
- * Index: [-3: y][-3: x] ... [0: y][0: x] ... [3: y][3: x] for radius 3
- * Return value: bitset (int 0-7)
- * 1 -- solidity
- * 2 -- liquidity
- * 3 -- gravity
- */
- override fun call(arg: LuaValue): LuaValue {
- val radius = arg.checkint()
-
- if (radius < 0) {
- return LuaValue.NONE
- }
- else if (radius > 8) {
- throw IllegalArgumentException("Radius too large -- must be 8 or less")
- }
- else {
- val luatable = LuaTable()
- val feetTilePos = actor.feetPosTile
- for (y in feetTilePos[1] - radius..feetTilePos[1] + radius) {
- luatable[y - feetTilePos[1]] = LuaTable()
-
- for (x in feetTilePos[0] - radius..feetTilePos[0] + radius) {
- val tile = BlockCodex[(Terrarum.ingame!!.world).getTileFromTerrain(x, y) ?: Block.NULL]
- val solidity = tile.isSolid.toInt()
- val liquidity = tile.isFluid.toInt()
- val gravity = tile.maxSupport.toInt()
- val tileFlag: Int = gravity.shl(2) + liquidity.shl(1) + solidity
-
- luatable[y - feetTilePos[1]][x - feetTilePos[0]] = tileFlag.toLua()
- }
- }
-
- return luatable
- }
- }
- }
-
- class GetFloorsHeight(val actor: ActorWBMovable) : OneArgFunction() {
- /** @param radius
- *
- * 3 will return len:7 array, 0 will return len:1, 1 will return len:3
- *
- * Index: [-3] .. [0] .. [3] for radius
- * Return value: floor height
- * 0: body tile (legs area)
- * 1: tile you can stand on
- * 2+: tiles down there
- */
- override fun call(arg: LuaValue): LuaValue {
- val radius = arg.checkint()
-
- val searchDownLimit = 12
-
- if (radius < 0) {
- return LuaValue.NONE
- }
- else if (radius > 8) {
- throw IllegalArgumentException("Radius too large -- must be 8 or less")
- }
- else {
- val luatable = LuaTable()
- val feetTilePos = actor.feetPosTile
- for (x in feetTilePos[0] - radius..feetTilePos[0] + radius) {
- // search down
- var searchDownCounter = 0
- while (true) {
- val tile = (Terrarum.ingame!!.world).getTileFromTerrain(x, feetTilePos[1] + searchDownCounter) ?: Block.STONE
- if (BlockCodex[tile].isSolid || searchDownCounter >= searchDownLimit) {
- luatable[x - feetTilePos[0]] = searchDownCounter
- break
- }
- searchDownCounter++
- }
- }
-
- return luatable
- }
- }
- }
-
- class GetCeilingsHeight(val actor: ActorWBMovable) : OneArgFunction() {
- /** @param arg radius
- *
- * 3 will return 7x7 array, 0 will return 1x1, 1 will return 3x3
- *
- * Index: [-3] .. [0] .. [3] for radius
- * Return value: floor height
- * 0: body tile (legs area)
- * 1: body tile (may be vary depend on the size of the actor)
- * 2+: tiles up there
- */
- override fun call(arg: LuaValue): LuaValue {
- val radius = arg.checkint()
-
- val searchUpLimit = 12
-
- if (radius < 0) {
- return LuaValue.NONE
- }
- else if (radius > 8) {
- throw IllegalArgumentException("Radius too large -- must be 8 or less")
- }
- else {
- val luatable = LuaTable()
- val feetTilePos = actor.feetPosTile
- for (x in feetTilePos[0] - radius..feetTilePos[0] + radius) {
- // search up
- var searchUpCounter = 0
- while (true) {
- val tile = (Terrarum.ingame!!.world).getTileFromTerrain(x, feetTilePos[1] - searchUpCounter) ?: Block.STONE
- if (BlockCodex[tile].isSolid || searchUpCounter >= searchUpLimit) {
- luatable[x - feetTilePos[0]] = searchUpCounter
- break
- }
- searchUpCounter++
- }
- }
-
- return luatable
- }
- }
- }
-
- class GetLedgesHeight(val actor: ActorWBMovable) : OneArgFunction() {
- /** @param arg radius
- * ==
- * <- (non-solid found)
- * ==
- * ==
- * ==
- * == @ -> ledge height: 4
- * =================
- */
- override fun call(arg: LuaValue): LuaValue {
- val radius = arg.checkint()
-
- val searchUpLimit = 12
-
- if (radius < 0) {
- return LuaValue.NONE
- }
- else if (radius > 8) {
- throw IllegalArgumentException("Radius too large -- must be 8 or less")
- }
- else {
- val luatable = LuaTable()
- val feetTilePos = actor.feetPosTile
- for (x in feetTilePos[0] - radius..feetTilePos[0] + radius) {
- // search up
- var searchUpCounter = 0
- while (true) {
- val tile = (Terrarum.ingame!!.world).getTileFromTerrain(x, feetTilePos[1] - searchUpCounter) ?: Block.STONE
- if (!BlockCodex[tile].isSolid || searchUpCounter >= searchUpLimit) {
- luatable[x - feetTilePos[0]] = searchUpCounter
- break
- }
- searchUpCounter++
- }
- }
-
- return luatable
- }
- }
- }
-
-
-
-
- class GameVersion : ZeroArgFunction() {
- override fun call(): LuaValue {
- return AppLoader.getVERSION_STRING().toLua()
- }
- }
-
- class GameVersionRaw : ZeroArgFunction() {
- override fun call(): LuaValue {
- return AppLoader.VERSION_RAW.toLua()
- }
- }
-}*/
-
-fun Double.toLua() = LuaValue.valueOf(this)
-fun Int.toLua() = LuaValue.valueOf(this)
-fun String.toLua() = LuaValue.valueOf(this)
-fun Boolean.toLua() = LuaValue.valueOf(this)
-fun Double?.toLua() = if (this == null) LuaValue.NIL else this.toLua()
-fun Int?.toLua() = if (this == null) LuaValue.NIL else this.toLua()
-fun String?.toLua() = if (this == null) LuaValue.NIL else this.toLua()
-fun Boolean?.toLua() = if (this == null) LuaValue.NIL else this.toLua()
-fun luaTableOf(vararg luaValues: LuaValue): LuaTable {
- val t = LuaTable.tableOf()
- luaValues.forEachIndexed { index, luaValue -> t[index + 1] = luaValue }
- return t
-}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/gameactors/ai/LuaAIWrapper.kt b/src/net/torvald/terrarum/gameactors/ai/LuaAIWrapper.kt
deleted file mode 100644
index e82cdd775..000000000
--- a/src/net/torvald/terrarum/gameactors/ai/LuaAIWrapper.kt
+++ /dev/null
@@ -1,112 +0,0 @@
-package net.torvald.terrarum.gameactors.ai
-
-import net.torvald.terrarum.gameactors.Actor
-import org.luaj.vm2.Globals
-import org.luaj.vm2.LuaError
-import org.luaj.vm2.LuaInteger
-import org.luaj.vm2.LuaValue
-import org.luaj.vm2.lib.jse.JsePlatform
-import java.io.InputStreamReader
-import java.io.Reader
-
-/**
- * Created by minjaesong on 2017-02-04.
- */
-/*class LuaAIWrapper(private val scriptPath: String) : ActorAI {
-
- protected val luag: Globals = JsePlatform.standardGlobals()
-
- /**
- * Initialised in init block.
- * Use lua function "update(delta)" to step the AI.
- */
- protected lateinit var luaInstance: LuaValue
-
- private lateinit var aiLuaAPI: AILuaAPI
-
- private lateinit var targetActor: Actor
-
- /**
- * The initialiser
- *
- * Use ```(p.ai as LuaAIWrapper).attachActor(p)```
- */
- fun attachActor(actor: Actor) {
- targetActor = actor
-
- luag["io"] = LuaValue.NIL
- luag["os"] = LuaValue.NIL
- luag["luajava"] = LuaValue.NIL
- aiLuaAPI = AILuaAPI(luag, targetActor)
- // load the script and execute it (initialises target script)
- val inputStream = javaClass.getResourceAsStream(scriptPath)
- luaInstance = luag.load(InputStreamReader(inputStream), scriptPath.split(Regex("[\\/]")).last())
- luaInstance.call()
- }
-
- override fun update(actor: Actor, delta: Float) {
- // run "update()" function in the script
- luag.get("update").call(delta.toLua())
- }
-
- lateinit var currentExecutionThread: Thread
- var threadRun = false
-
- fun runCommand(reader: Reader, filename: String) {
- if (!threadRun && !targetActor.flagDespawn) {
- currentExecutionThread = Thread(ThreadRunCommand(luag, reader, filename))
- currentExecutionThread.start()
- threadRun = true
- }
- }
-
- fun runCommand(script: String) {
- if (!threadRun && !targetActor.flagDespawn) {
- currentExecutionThread = Thread(ThreadRunCommand(luag, script, ""))
- currentExecutionThread.start()
- threadRun = true
- }
- }
-
- class ThreadRunCommand : Runnable {
-
- val mode: Int
- val arg1: Any
- val arg2: String
- val lua: Globals
-
- constructor(luaInstance: Globals, line: String, env: String) {
- mode = 0
- arg1 = line
- arg2 = env
- lua = luaInstance
- }
-
- constructor(luaInstance: Globals, reader: Reader, filename: String) {
- mode = 1
- arg1 = reader
- arg2 = filename
- lua = luaInstance
- }
-
- override fun run() {
- try {
- val chunk: LuaValue
- if (mode == 0)
- chunk = lua.load(arg1 as String, arg2)
- else if (mode == 1)
- chunk = lua.load(arg1 as Reader, arg2)
- else
- throw IllegalArgumentException("Unsupported mode: $mode")
-
-
- chunk.call()
- }
- catch (e: LuaError) {
- e.printStackTrace(System.err)
- }
- }
- }
-
- fun Float.toLua(): LuaValue = LuaInteger.valueOf(this.toDouble())
-}*/
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/gameactors/ai/scripts/PokemonNPCAI.lua b/src/net/torvald/terrarum/gameactors/ai/scripts/PokemonNPCAI.lua
deleted file mode 100644
index 235208264..000000000
--- a/src/net/torvald/terrarum/gameactors/ai/scripts/PokemonNPCAI.lua
+++ /dev/null
@@ -1,83 +0,0 @@
---
--- Created by minjaesong on 2017-01-06.
---
-timeCounter = 0
-countMax = 0
-moveMode = math.random() >= 0.5 and "left" or "right"
-currentMode = "move"
-jumpheight = 6 -- lol
-
-function generateCountMax()
- local function generateTurn()
- return 4600 + 1250 * math.random()
- end
-
- local function generateWalk()
- return 1645 + 402 * math.random()
- end
-
- return (currentMode == "move") and generateWalk() or generateTurn()
-end
-
-function moveToDirection(delta)
- local pits = ai.getFloorsHeight(2)
- local ledges = ai.getLedgesHeight(1)
-
- if moveMode == "left" then
- if pits[-1] == 1 then
- ai.moveLeft(0.8)
- if ledges[-1] <= jumpheight then -- no futile jumps
- ai.jump()
- end
- else
- ai.moveLeft(0.5)
- end
- elseif moveMode == "right" then
- if pits[1] == 1 then
- ai.moveRight(0.8)
- if ledges[1] <= jumpheight then -- no futile jumps
- ai.jump()
- end
- else
- ai.moveRight(0.5)
- end
- end
-
- timeCounter = timeCounter + delta
-end
-
-function toggleCurrentMode()
- currentMode = (currentMode == "move") and "turn" or "move"
-end
-
-function toggleMoveMode()
- moveMode = (moveMode == "left") and "right" or "left"
-end
-
--------------------------------------------------------------------------------
-
-countMax = generateCountMax()
-
-function toggleCondition()
- local floorsheight = ai.getFloorsHeight(1)
- return timeCounter >= countMax or
- -- avoid great falls
- (timeCounter > 150 and (floorsheight[-1] > jumpheight or floorsheight[1] > jumpheight))
-end
-
-function update(delta)
- if currentMode == "move" then
- moveToDirection(delta)
- else
- timeCounter = timeCounter + delta -- no countup when jumping
- end
-
- if toggleCondition() then
- timeCounter = 0
- toggleCurrentMode()
- countMax = generateCountMax()
- if currentMode == "turn" then
- toggleMoveMode()
- end
- end
-end
diff --git a/src/net/torvald/terrarum/gamecontroller/IngameController.kt b/src/net/torvald/terrarum/gamecontroller/IngameController.kt
index 8cb9852e6..0e2261b14 100644
--- a/src/net/torvald/terrarum/gamecontroller/IngameController.kt
+++ b/src/net/torvald/terrarum/gamecontroller/IngameController.kt
@@ -4,8 +4,10 @@ import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input
import com.badlogic.gdx.InputAdapter
import com.badlogic.gdx.controllers.Controllers
+import com.badlogic.gdx.utils.GdxRuntimeException
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.AppLoader.printdbg
+import net.torvald.terrarum.AppLoader.printdbgerr
import net.torvald.terrarum.controller.TerrarumController
import net.torvald.terrarum.floorInt
import net.torvald.terrarum.gameactors.AVKey
@@ -44,8 +46,14 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
get() = (mouseY / CreateTileAtlas.TILE_SIZE).floorInt()
init {
- if (Controllers.getControllers().size == 0) {
- printdbg(this, "Controller not found")
+ try {
+ if (Controllers.getControllers().size == 0) {
+ printdbg(this, "Controller not found")
+ }
+ }
+ catch (e: GdxRuntimeException) {
+ printdbg(this, e.message)
+ e.stackTrace.forEach { printdbgerr(this, "\t$it") }
}
}
@@ -191,18 +199,18 @@ class IngameController(val terrarumIngame: TerrarumIngame) : InputAdapter() {
return true
}
- override fun scrolled(amount: Int): Boolean {
+ override fun scrolled(amountX: Float, amountY: Float): Boolean {
if (!terrarumIngame.paused) {
// quickslot by wheel
if (terrarumIngame.actorNowPlaying != null) {
terrarumIngame.actorNowPlaying!!.actorValue.set(
AVKey.__PLAYER_QUICKSLOTSEL,
- (terrarumIngame.actorNowPlaying!!.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL)!! - amount) fmod terrarumIngame.actorNowPlaying!!.inventory.quickSlot.size
+ (terrarumIngame.actorNowPlaying!!.actorValue.getAsInt(AVKey.__PLAYER_QUICKSLOTSEL)!! - amountY.toInt()) fmod terrarumIngame.actorNowPlaying!!.inventory.quickSlot.size
)
}
}
- terrarumIngame.uiContainer.forEach { it?.scrolled(amount) }
+ terrarumIngame.uiContainer.forEach { it?.scrolled(amountX, amountY) }
return true
}
diff --git a/src/net/torvald/terrarum/itemproperties/ItemEffectsLuaAPI.kt b/src/net/torvald/terrarum/itemproperties/ItemEffectsLuaAPI.kt
deleted file mode 100644
index e38f64b5b..000000000
--- a/src/net/torvald/terrarum/itemproperties/ItemEffectsLuaAPI.kt
+++ /dev/null
@@ -1,57 +0,0 @@
-package net.torvald.terrarum.itemproperties
-
-import net.torvald.terrarum.Terrarum
-import net.torvald.terrarum.gameactors.ai.toLua
-import org.luaj.vm2.Globals
-import org.luaj.vm2.LuaTable
-import org.luaj.vm2.LuaValue
-import org.luaj.vm2.lib.ThreeArgFunction
-import org.luaj.vm2.lib.ZeroArgFunction
-
-/**
- * Created by minjaesong on 2017-04-16.
- */
-class ItemEffectsLuaAPI(g: Globals) {
-
- init {
- g["getMouseTile"] = GetMouseTile()
- g["getMousePos"] = GetMousePos()
-
-
-
- g["world"] = LuaTable()
-
- g["world"]["strikeEarth"] = StrikeEarth()
- g["world"]["strikeWall"] = StrikeWall()
-
-
-
- g["actor"] = LuaTable()
- }
-
-
- class GetMouseTile : ZeroArgFunction() {
- override fun call(): LuaValue {
- return LuaValue.tableOf(arrayOf(Terrarum.mouseTileX.toLua(), Terrarum.mouseTileY.toLua()))
- }
- }
- class GetMousePos : ZeroArgFunction() {
- override fun call(): LuaValue {
- return LuaValue.tableOf(arrayOf(Terrarum.mouseX.toLua(), Terrarum.mouseY.toLua()))
- }
- }
-
- class StrikeEarth : ThreeArgFunction() {
- override fun call(x: LuaValue, y: LuaValue, power: LuaValue): LuaValue {
- (Terrarum.ingame!!.world).inflictTerrainDamage(x.checkint(), y.checkint(), power.checkdouble())
- return LuaValue.NONE
- }
- }
- class StrikeWall : ThreeArgFunction() {
- override fun call(x: LuaValue, y: LuaValue, power: LuaValue): LuaValue {
- (Terrarum.ingame!!.world).inflictWallDamage(x.checkint(), y.checkint(), power.checkdouble())
- return LuaValue.NONE
- }
- }
-
-}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt b/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt
index ef9e91f28..a4c0a77ed 100644
--- a/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt
+++ b/src/net/torvald/terrarum/modulebasegame/BuildingMaker.kt
@@ -8,7 +8,6 @@ import com.badlogic.gdx.graphics.g2d.TextureRegion
import net.torvald.gdx.graphics.Cvec
import net.torvald.terrarum.*
import net.torvald.terrarum.blockproperties.Block
-import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.blockproperties.BlockPropUtil
import net.torvald.terrarum.gameactors.*
import net.torvald.terrarum.gameitem.ItemID
@@ -20,18 +19,8 @@ import net.torvald.terrarum.modulebasegame.ui.UIBuildingMakerBlockChooser
import net.torvald.terrarum.modulebasegame.ui.UIBuildingMakerPenMenu
import net.torvald.terrarum.modulebasegame.ui.UIPaletteSelector
import net.torvald.terrarum.modulebasegame.weather.WeatherMixer
-import net.torvald.terrarum.realestate.LandUtil
-import net.torvald.terrarum.serialise.WriteLayerDataZip.FILE_FOOTER
-import net.torvald.terrarum.serialise.WriteLayerDataZip.PAYLOAD_FOOTER
-import net.torvald.terrarum.serialise.WriteLayerDataZip.PAYLOAD_HEADER
-import net.torvald.terrarum.serialise.toLittle
-import net.torvald.terrarum.serialise.toLittleShort
-import net.torvald.terrarum.serialise.toULittle48
-import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UINSMenu
import net.torvald.terrarum.worlddrawer.WorldCamera
-import java.io.File
-import java.io.FileOutputStream
/**
* Created by minjaesong on 2018-07-06.
@@ -295,11 +284,11 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
uiToolbox.isVisible = true
uiToolbox.invocationArgument = arrayOf(this)
- uiPaletteSelector.setPosition(AppLoader.screenW - uiPaletteSelector.width, 0)
+ uiPaletteSelector.setPosition(AppLoader.screenSize.screenW - uiPaletteSelector.width, 0)
uiPaletteSelector.isVisible = true
notifier.setPosition(
- (AppLoader.screenW - notifier.width) / 2, AppLoader.screenH - notifier.height)
+ (AppLoader.screenSize.screenW - notifier.width) / 2, AppLoader.screenSize.screenH - notifier.height)
actorNowPlaying?.setPosition(512 * 16.0, 149 * 16.0)
@@ -379,8 +368,8 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
// position the menu to where the cursor is
uiPenMenu.posX = Terrarum.mouseScreenX - uiPenMenu.width / 2
uiPenMenu.posY = Terrarum.mouseScreenY - uiPenMenu.height / 2
- uiPenMenu.posX = uiPenMenu.posX.coerceIn(0, AppLoader.screenW - uiPenMenu.width)
- uiPenMenu.posY = uiPenMenu.posY.coerceIn(0, AppLoader.screenH - uiPenMenu.height)
+ uiPenMenu.posX = uiPenMenu.posX.coerceIn(0, AppLoader.screenSize.screenW - uiPenMenu.width)
+ uiPenMenu.posY = uiPenMenu.posY.coerceIn(0, AppLoader.screenSize.screenH - uiPenMenu.height)
// actually open
uiPenMenu.setAsOpen()
@@ -398,10 +387,10 @@ class BuildingMaker(batch: SpriteBatch) : IngameInstance(batch) {
}
override fun resize(width: Int, height: Int) {
- IngameRenderer.resize(AppLoader.screenW, AppLoader.screenH)
+ IngameRenderer.resize(AppLoader.screenSize.screenW, AppLoader.screenSize.screenH)
uiToolbox.setPosition(0, 0)
notifier.setPosition(
- (AppLoader.screenW - notifier.width) / 2, AppLoader.screenH - notifier.height)
+ (AppLoader.screenSize.screenW - notifier.width) / 2, AppLoader.screenSize.screenH - notifier.height)
println("[BuildingMaker] Resize event")
}
@@ -518,8 +507,8 @@ class BuildingMakerController(val screen: BuildingMaker) : InputAdapter() {
return true
}
- override fun scrolled(amount: Int): Boolean {
- screen.uiContainer.forEach { it?.scrolled(amount) }
+ override fun scrolled(amountX: Float, amountY: Float): Boolean {
+ screen.uiContainer.forEach { it?.scrolled(amountX, amountY) }
return true
}
@@ -563,12 +552,12 @@ class MovableWorldCamera(val parent: BuildingMaker) : ActorHumanoid(0, physProp
// TODO resize-aware
private var coerceInStart = Point2d(
- (AppLoader.screenW - hitbox.width) / 2.0,
- (AppLoader.screenH - hitbox.height) / 2.0
+ (AppLoader.screenSize.screenW - hitbox.width) / 2.0,
+ (AppLoader.screenSize.screenH - hitbox.height) / 2.0
)
private var coerceInEnd = Point2d(
- parent.world.width * TILE_SIZE - (AppLoader.screenW - hitbox.width) / 2.0,
- parent.world.height * TILE_SIZE - (AppLoader.screenH - hitbox.height) / 2.0
+ parent.world.width * TILE_SIZE - (AppLoader.screenSize.screenW - hitbox.width) / 2.0,
+ parent.world.height * TILE_SIZE - (AppLoader.screenSize.screenH - hitbox.height) / 2.0
)
override fun update(delta: Float) {
diff --git a/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt b/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt
index 77310cd47..7e080f734 100644
--- a/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt
+++ b/src/net/torvald/terrarum/modulebasegame/IngameRenderer.kt
@@ -56,8 +56,8 @@ object IngameRenderer : Disposable {
val shaderAtoGrey: ShaderProgram
val shaderPassthru = SpriteBatch.createDefaultShader()
- private val WIDTH = AppLoader.screenW
- private val HEIGHT = AppLoader.screenH
+ private val WIDTH = AppLoader.screenSize.screenW
+ private val HEIGHT = AppLoader.screenSize.screenH
private val WIDTHF = WIDTH.toFloat()
private val HEIGHTF = HEIGHT.toFloat()
@@ -608,7 +608,7 @@ object IngameRenderer : Disposable {
* Camera will be moved so that (newX, newY) would be sit on the top-left edge.
*/
private fun setCameraPosition(newX: Float, newY: Float) {
- camera.position.set((-newX + AppLoader.halfScreenW).round(), (-newY + AppLoader.halfScreenH).round(), 0f)
+ camera.position.set((-newX + AppLoader.screenSize.halfScreenW).round(), (-newY + AppLoader.screenSize.halfScreenH).round(), 0f)
camera.update()
batch.projectionMatrix = camera.combined
}
diff --git a/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt b/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt
index 910b99309..9edef018b 100644
--- a/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt
+++ b/src/net/torvald/terrarum/modulebasegame/TerrarumIngame.kt
@@ -4,7 +4,6 @@ import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.g2d.SpriteBatch
-import com.badlogic.gdx.utils.GdxRuntimeException
import net.torvald.EMDASH
import net.torvald.terrarum.*
import net.torvald.terrarum.AppLoader.printdbg
@@ -83,7 +82,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
companion object {
/** Sets camera position so that (0,0) would be top-left of the screen, (width, height) be bottom-right. */
fun setCameraPosition(batch: SpriteBatch, camera: Camera, newX: Float, newY: Float) {
- camera.position.set((-newX + AppLoader.halfScreenW).round(), (-newY + AppLoader.halfScreenH).round(), 0f)
+ camera.position.set((-newX + AppLoader.screenSize.halfScreenW).round(), (-newY + AppLoader.screenSize.halfScreenH).round(), 0f)
camera.update()
batch.projectionMatrix = camera.combined
}
@@ -184,7 +183,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
}
override fun show() {
- //initViewPort(AppLoader.screenW, AppLoader.screenH)
+ //initViewPort(AppLoader.terrarumAppConfig.screenW, AppLoader.terrarumAppConfig.screenH)
// gameLoadMode and gameLoadInfoPayload must be set beforehand!!
@@ -289,8 +288,8 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
/** Load rest of the game with GL context */
fun postInit() {
//setTheRealGamerFirstTime(PlayerBuilderSigrid())
- //setTheRealGamerFirstTime(PlayerBuilderTestSubject1())
- setTheRealGamerFirstTime(PlayerBuilderWerebeastTest())
+ setTheRealGamerFirstTime(PlayerBuilderTestSubject1())
+ //setTheRealGamerFirstTime(PlayerBuilderWerebeastTest())
@@ -314,8 +313,8 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
// init notifier
notifier = Notification()
notifier.setPosition(
- (AppLoader.screenW - notifier.width) / 2,
- AppLoader.screenH - notifier.height - AppLoader.getTvSafeGraphicsHeight()
+ (AppLoader.screenSize.screenW - notifier.width) / 2,
+ AppLoader.screenSize.screenH - notifier.height - AppLoader.screenSize.tvSafeGraphicsHeight
)
@@ -332,11 +331,11 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
// quick bar
uiQuickBar = UIQuickslotBar()
uiQuickBar.isVisible = true
- uiQuickBar.setPosition((AppLoader.screenW - uiQuickBar.width) / 2, AppLoader.getTvSafeGraphicsHeight())
+ uiQuickBar.setPosition((AppLoader.screenSize.screenW - uiQuickBar.width) / 2, AppLoader.screenSize.tvSafeGraphicsHeight)
// pie menu
uiPieMenu = UIQuickslotPie()
- uiPieMenu.setPosition(AppLoader.halfScreenW, AppLoader.halfScreenH)
+ uiPieMenu.setPosition(AppLoader.screenSize.halfScreenW, AppLoader.screenSize.halfScreenH)
// vital metre
// fill in getter functions by
@@ -351,14 +350,14 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
uiWatchTierOne = UITierOneWatch(actorNowPlaying)
uiWatchTierOne.setAsAlwaysVisible()
uiWatchTierOne.setPosition(
- ((AppLoader.screenW - AppLoader.getTvSafeActionWidth()) - (uiQuickBar.posX + uiQuickBar.width) - uiWatchTierOne.width) / 2 + (uiQuickBar.posX + uiQuickBar.width),
- AppLoader.getTvSafeGraphicsHeight() + 8
+ ((AppLoader.screenSize.screenW - AppLoader.screenSize.tvSafeActionWidth) - (uiQuickBar.posX + uiQuickBar.width) - uiWatchTierOne.width) / 2 + (uiQuickBar.posX + uiQuickBar.width),
+ AppLoader.screenSize.tvSafeGraphicsHeight + 8
)
// basic watch-style notification bar (temperature, new mail)
uiBasicInfo = UIBasicInfo(actorNowPlaying)
uiBasicInfo.setAsAlwaysVisible()
- uiBasicInfo.setPosition((uiQuickBar.posX - uiBasicInfo.width - AppLoader.getTvSafeActionWidth()) / 2 + AppLoader.getTvSafeActionWidth(), uiWatchTierOne.posY)
+ uiBasicInfo.setPosition((uiQuickBar.posX - uiBasicInfo.width - AppLoader.screenSize.tvSafeActionWidth) / 2 + AppLoader.screenSize.tvSafeActionWidth, uiWatchTierOne.posY)
uiTooltip = UITooltip()
@@ -1009,8 +1008,8 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
/**
- * @param width same as AppLoader.screenW
- * @param height same as AppLoader.screenH
+ * @param width same as AppLoader.terrarumAppConfig.screenW
+ * @param height same as AppLoader.terrarumAppConfig.screenH
* @see net.torvald.terrarum.Terrarum
*/
override fun resize(width: Int, height: Int) {
@@ -1019,7 +1018,7 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
//MegaRainGovernor.resize()
- IngameRenderer.resize(AppLoader.screenW, AppLoader.screenH)
+ IngameRenderer.resize(AppLoader.screenSize.screenW, AppLoader.screenSize.screenH)
if (gameInitialised) {
@@ -1031,23 +1030,23 @@ open class TerrarumIngame(batch: SpriteBatch) : IngameInstance(batch) {
// resize UIs
notifier.setPosition(
- (AppLoader.screenW - notifier.width) / 2, AppLoader.screenH - notifier.height)
- uiQuickBar.setPosition((AppLoader.screenW - uiQuickBar.width) / 2, AppLoader.getTvSafeGraphicsHeight())
+ (AppLoader.screenSize.screenW - notifier.width) / 2, AppLoader.screenSize.screenH - notifier.height)
+ uiQuickBar.setPosition((AppLoader.screenSize.screenW - uiQuickBar.width) / 2, AppLoader.screenSize.tvSafeGraphicsHeight)
// inventory
/*uiInventoryPlayer =
UIInventory(player,
width = 840,
- height = AppLoader.screenH - 160,
+ height = AppLoader.terrarumAppConfig.screenH - 160,
categoryWidth = 210
)*/
// basic watch-style notification bar (temperature, new mail)
- uiBasicInfo.setPosition(AppLoader.screenW - uiBasicInfo.width, 0)
+ uiBasicInfo.setPosition(AppLoader.screenSize.screenW - uiBasicInfo.width, 0)
uiWatchTierOne.setPosition(
- ((AppLoader.screenW - AppLoader.getTvSafeGraphicsWidth()) - (uiQuickBar.posX + uiQuickBar.width) - uiWatchTierOne.width) / 2 + (uiQuickBar.posX + uiQuickBar.width),
- AppLoader.getTvSafeGraphicsHeight() + 8
+ ((AppLoader.screenSize.screenW - AppLoader.screenSize.tvSafeGraphicsWidth) - (uiQuickBar.posX + uiQuickBar.width) - uiWatchTierOne.width) / 2 + (uiQuickBar.posX + uiQuickBar.width),
+ AppLoader.screenSize.tvSafeGraphicsHeight + 8
)
}
diff --git a/src/net/torvald/terrarum/modulebasegame/WorldgenLoadScreen.kt b/src/net/torvald/terrarum/modulebasegame/WorldgenLoadScreen.kt
index 54b5d7105..f3ca873d7 100644
--- a/src/net/torvald/terrarum/modulebasegame/WorldgenLoadScreen.kt
+++ b/src/net/torvald/terrarum/modulebasegame/WorldgenLoadScreen.kt
@@ -1,16 +1,11 @@
package net.torvald.terrarum.modulebasegame
-import com.badlogic.gdx.Gdx
-import com.badlogic.gdx.ScreenAdapter
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.Pixmap
import com.badlogic.gdx.graphics.Texture
import net.torvald.terrarum.*
-import net.torvald.terrarum.AppLoader.printdbg
import net.torvald.terrarum.blockproperties.BlockCodex
-import net.torvald.terrarum.blockproperties.BlockProp
import net.torvald.terrarum.gameworld.GameWorld
-import net.torvald.util.CircularArray
import kotlin.math.roundToInt
/**
@@ -39,8 +34,8 @@ class WorldgenLoadScreen(screenToBeLoaded: IngameInstance, private val worldwidt
private val COL_AIR = Color.BLACK
}
- private val previewWidth = (AppLoader.screenW * WIDTH_RATIO).roundToInt()
- private val previewHeight = (AppLoader.screenW * WIDTH_RATIO * worldheight / worldwidth).roundToInt()
+ private val previewWidth = (AppLoader.screenSize.screenW * WIDTH_RATIO).roundToInt()
+ private val previewHeight = (AppLoader.screenSize.screenW * WIDTH_RATIO * worldheight / worldwidth).roundToInt()
private lateinit var previewPixmap: Pixmap
private lateinit var previewTexture: Texture
@@ -73,15 +68,15 @@ class WorldgenLoadScreen(screenToBeLoaded: IngameInstance, private val worldwidt
AppLoader.batch.inUse {
it.color = Color.WHITE
- val previewY = (AppLoader.screenH - previewHeight.times(1.5f)).div(2f).round()
+ val previewY = (AppLoader.screenSize.screenH - previewHeight.times(1.5f)).div(2f).round()
it.draw(previewTexture,
- (AppLoader.screenW - previewWidth).div(2f).round(),
+ (AppLoader.screenSize.screenW - previewWidth).div(2f).round(),
previewY
)
val text = messages.getHeadElem() ?: ""
AppLoader.fontGame.draw(it,
text,
- (AppLoader.screenW - AppLoader.fontGame.getWidth(text)).div(2f).round(),
+ (AppLoader.screenSize.screenW - AppLoader.fontGame.getWidth(text)).div(2f).round(),
previewY + previewHeight + 98 - AppLoader.fontGame.lineHeight
)
}
diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureStorageChest.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureStorageChest.kt
index d1814de7b..3f3e4e60d 100644
--- a/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureStorageChest.kt
+++ b/src/net/torvald/terrarum/modulebasegame/gameactors/FixtureStorageChest.kt
@@ -5,7 +5,6 @@ import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.graphics.glutils.ShapeRenderer
import net.torvald.terrarum.*
-import net.torvald.terrarum.AppLoader.printdbg
import net.torvald.terrarum.gameactors.AVKey
import net.torvald.terrarum.gameitem.GameItem
import net.torvald.terrarum.langpack.Lang
@@ -13,7 +12,6 @@ import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory.Companion.CAPACITY_MODE_COUNT
import net.torvald.terrarum.modulebasegame.ui.*
import net.torvald.terrarum.modulebasegame.ui.UIInventoryCells.Companion.weightBarWidth
-import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.CELLS_HOR
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.CELLS_VRT
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.INVENTORY_CELLS_OFFSET_X
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.INVENTORY_CELLS_OFFSET_Y
@@ -61,8 +59,8 @@ internal class UIStorageChest : UICanvas(), HasInventory {
lateinit var chestInventory: FixtureInventory
lateinit var chestNameFun: () -> String
- override var width = AppLoader.screenW
- override var height = AppLoader.screenH
+ override var width = AppLoader.screenSize.screenW
+ override var height = AppLoader.screenSize.screenH
override var openCloseTime: Second = 0.0f
private val shapeRenderer = ShapeRenderer()
@@ -124,8 +122,8 @@ internal class UIStorageChest : UICanvas(), HasInventory {
catBar = UIItemInventoryCatBar(
this,
- (AppLoader.screenW - catBarWidth) / 2,
- 42 + (AppLoader.screenH - internalHeight) / 2,
+ (AppLoader.screenSize.screenW - catBarWidth) / 2,
+ 42 + (AppLoader.screenSize.screenH - internalHeight) / 2,
internalWidth,
catBarWidth,
false
@@ -192,17 +190,17 @@ internal class UIStorageChest : UICanvas(), HasInventory {
gdxSetBlendNormal()
- val gradTopStart = (AppLoader.screenH - internalHeight).div(2).toFloat()
- val gradBottomEnd = AppLoader.screenH - gradTopStart
+ val gradTopStart = (AppLoader.screenSize.screenH - internalHeight).div(2).toFloat()
+ val gradBottomEnd = AppLoader.screenSize.screenH - gradTopStart
shapeRenderer.inUse {
- shapeRenderer.rect(0f, gradTopStart, AppLoader.screenWf, gradHeight, gradStartCol, gradStartCol, gradEndCol, gradEndCol)
- shapeRenderer.rect(0f, gradBottomEnd, AppLoader.screenWf, -gradHeight, gradStartCol, gradStartCol, gradEndCol, gradEndCol)
+ shapeRenderer.rect(0f, gradTopStart, AppLoader.screenSize.screenWf, gradHeight, gradStartCol, gradStartCol, gradEndCol, gradEndCol)
+ shapeRenderer.rect(0f, gradBottomEnd, AppLoader.screenSize.screenWf, -gradHeight, gradStartCol, gradStartCol, gradEndCol, gradEndCol)
- shapeRenderer.rect(0f, gradTopStart + gradHeight, AppLoader.screenWf, internalHeight - (2 * gradHeight), gradEndCol, gradEndCol, gradEndCol, gradEndCol)
+ shapeRenderer.rect(0f, gradTopStart + gradHeight, AppLoader.screenSize.screenWf, internalHeight - (2 * gradHeight), gradEndCol, gradEndCol, gradEndCol, gradEndCol)
- shapeRenderer.rect(0f, 0f, AppLoader.screenWf, gradTopStart, gradStartCol, gradStartCol, gradStartCol, gradStartCol)
- shapeRenderer.rect(0f, AppLoader.screenHf, AppLoader.screenWf, -(AppLoader.screenHf - gradBottomEnd), gradStartCol, gradStartCol, gradStartCol, gradStartCol)
+ shapeRenderer.rect(0f, 0f, AppLoader.screenSize.screenWf, gradTopStart, gradStartCol, gradStartCol, gradStartCol, gradStartCol)
+ shapeRenderer.rect(0f, AppLoader.screenSize.screenHf, AppLoader.screenSize.screenWf, -(AppLoader.screenSize.screenHf - gradBottomEnd), gradStartCol, gradStartCol, gradStartCol, gradStartCol)
}
diff --git a/src/net/torvald/terrarum/modulebasegame/gameactors/ParticleMegaRain.kt b/src/net/torvald/terrarum/modulebasegame/gameactors/ParticleMegaRain.kt
index 855de83b2..414d48cbf 100644
--- a/src/net/torvald/terrarum/modulebasegame/gameactors/ParticleMegaRain.kt
+++ b/src/net/torvald/terrarum/modulebasegame/gameactors/ParticleMegaRain.kt
@@ -47,7 +47,7 @@ object MegaRainGovernor {
val h = body.height
bodies = Array(1024) {
- //val pixmap = Pixmap(AppLoader.screenW * 2, AppLoader.screenH / 4, Pixmap.Format.RGBA8888)
+ //val pixmap = Pixmap(AppLoader.terrarumAppConfig.screenW * 2, AppLoader.terrarumAppConfig.screenH / 4, Pixmap.Format.RGBA8888)
val pixmap = Pixmap(64, 64, Pixmap.Format.RGBA8888)
val rng = HQRNG()
diff --git a/src/net/torvald/terrarum/modulebasegame/ui/Notification.kt b/src/net/torvald/terrarum/modulebasegame/ui/Notification.kt
index 83c5ed278..52490fcdd 100644
--- a/src/net/torvald/terrarum/modulebasegame/ui/Notification.kt
+++ b/src/net/torvald/terrarum/modulebasegame/ui/Notification.kt
@@ -5,7 +5,6 @@ import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.Second
-import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.blendNormal
import net.torvald.terrarum.ui.UICanvas
@@ -62,7 +61,7 @@ class Notification : UICanvas() {
val displayedTextWidth = maxOf(240, realTextWidth)
// force the UI to the centre of the screen
- this.posX = (AppLoader.screenW - displayedTextWidth) / 2
+ this.posX = (AppLoader.screenSize.screenW - displayedTextWidth) / 2
val textHeight = message.size * AppLoader.fontGame.lineHeight
diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIBuildingMakerPenMenu.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIBuildingMakerPenMenu.kt
index be09a9a4f..639f47fee 100644
--- a/src/net/torvald/terrarum/modulebasegame/ui/UIBuildingMakerPenMenu.kt
+++ b/src/net/torvald/terrarum/modulebasegame/ui/UIBuildingMakerPenMenu.kt
@@ -70,8 +70,8 @@ class UIBuildingMakerPenMenu(val parent: BuildingMaker): UICanvas() {
{
parent.uiPalette.isVisible = true
parent.uiPalette.setPosition(Gdx.input.x - parent.uiPalette.width / 2, Gdx.input.y - parent.uiPalette.height / 2)
- parent.uiPalette.posX = parent.uiPalette.posX.coerceIn(0, AppLoader.screenW - parent.uiPalette.width)
- parent.uiPalette.posY = parent.uiPalette.posY.coerceIn(0, AppLoader.screenH - parent.uiPalette.height)
+ parent.uiPalette.posX = parent.uiPalette.posX.coerceIn(0, AppLoader.screenSize.screenW - parent.uiPalette.width)
+ parent.uiPalette.posY = parent.uiPalette.posY.coerceIn(0, AppLoader.screenSize.screenH - parent.uiPalette.height)
},
{
parent.currentPenMode = BuildingMaker.PENMODE_PENCIL_ERASE
diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIBuildingMakerToolbox.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIBuildingMakerToolbox.kt
index 3e8257327..a40171a48 100644
--- a/src/net/torvald/terrarum/modulebasegame/ui/UIBuildingMakerToolbox.kt
+++ b/src/net/torvald/terrarum/modulebasegame/ui/UIBuildingMakerToolbox.kt
@@ -52,40 +52,4 @@ class UIBuildingMakerToolbox : UICanvas() {
override fun dispose() {
toolsTexture.dispose()
}
-
- override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
- return super.mouseMoved(screenX, screenY)
- }
-
- override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
- return super.touchDragged(screenX, screenY, pointer)
- }
-
- override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
- return super.touchDown(screenX, screenY, pointer, button)
- }
-
- override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
- return super.touchUp(screenX, screenY, pointer, button)
- }
-
- override fun scrolled(amount: Int): Boolean {
- return super.scrolled(amount)
- }
-
- override fun keyDown(keycode: Int): Boolean {
- return super.keyDown(keycode)
- }
-
- override fun keyUp(keycode: Int): Boolean {
- return super.keyUp(keycode)
- }
-
- override fun keyTyped(character: Char): Boolean {
- return super.keyTyped(character)
- }
-
- override fun resize(width: Int, height: Int) {
- super.resize(width, height)
- }
}
diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UICheatDetected.kt b/src/net/torvald/terrarum/modulebasegame/ui/UICheatDetected.kt
index 45aaf4d86..c2ccde74c 100644
--- a/src/net/torvald/terrarum/modulebasegame/ui/UICheatDetected.kt
+++ b/src/net/torvald/terrarum/modulebasegame/ui/UICheatDetected.kt
@@ -16,11 +16,11 @@ import net.torvald.terrarum.ui.UICanvas
class UICheatDetected : UICanvas() {
override var width: Int
- get() = AppLoader.screenW
+ get() = AppLoader.screenSize.screenW
set(value) { throw UnsupportedOperationException() }
override var height: Int
- get() = AppLoader.screenH
+ get() = AppLoader.screenSize.screenH
set(value) { throw UnsupportedOperationException() }
override var openCloseTime: Second = 0f
diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryCells.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryCells.kt
index 0fe951c32..17f1c7303 100644
--- a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryCells.kt
+++ b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryCells.kt
@@ -6,7 +6,6 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.*
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.langpack.Lang
-import net.torvald.terrarum.modulebasegame.gameactors.ActorInventory
import net.torvald.terrarum.modulebasegame.gameactors.FixtureInventory
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.CELLS_HOR
import net.torvald.terrarum.modulebasegame.ui.UIInventoryFull.Companion.CELLS_VRT
@@ -23,8 +22,8 @@ internal class UIInventoryCells(
val full: UIInventoryFull
) : UICanvas() {
- override var width: Int = AppLoader.screenW
- override var height: Int = AppLoader.screenH
+ override var width: Int = AppLoader.screenSize.screenW
+ override var height: Int = AppLoader.screenSize.screenH
override var openCloseTime: Second = 0.0f
companion object {
@@ -56,7 +55,7 @@ internal class UIInventoryCells(
full,
full.actor.inventory,
full.actor as ActorWithBody,
- internalWidth - UIItemInventoryEquippedView.WIDTH + (AppLoader.screenW - internalWidth) / 2,
+ internalWidth - UIItemInventoryEquippedView.WIDTH + (AppLoader.screenSize.screenW - internalWidth) / 2,
INVENTORY_CELLS_OFFSET_Y,
{ rebuildList() }
)
diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryEscMenu.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryEscMenu.kt
index a5f0b4ebb..751941de2 100644
--- a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryEscMenu.kt
+++ b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryEscMenu.kt
@@ -15,8 +15,8 @@ import net.torvald.terrarum.ui.UIItemTextButtonList.Companion.DEFAULT_LINE_HEIGH
class UIInventoryEscMenu(val full: UIInventoryFull) : UICanvas() {
- override var width: Int = AppLoader.screenW
- override var height: Int = AppLoader.screenH
+ override var width: Int = AppLoader.screenSize.screenW
+ override var height: Int = AppLoader.screenSize.screenH
override var openCloseTime = 0.0f
private val gameMenu = arrayOf("MENU_LABEL_MAINMENU", "MENU_LABEL_DESKTOP", "MENU_OPTIONS_CONTROLS", "MENU_OPTIONS_SOUND", "MENU_LABEL_GRAPHICS")
@@ -24,7 +24,7 @@ class UIInventoryEscMenu(val full: UIInventoryFull) : UICanvas() {
private val gameMenuListWidth = 400
private val gameMenuButtons = UIItemTextButtonList(
this, gameMenu,
- (AppLoader.screenW - gameMenuListWidth) / 2,
+ (AppLoader.screenSize.screenW - gameMenuListWidth) / 2,
INVENTORY_CELLS_OFFSET_Y + (INVENTORY_CELLS_UI_HEIGHT - gameMenuListHeight) / 2,
gameMenuListWidth, gameMenuListHeight,
readFromLang = true,
diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt
index 6cf8d6772..b40a8019b 100644
--- a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt
+++ b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryFull.kt
@@ -25,8 +25,8 @@ class UIInventoryFull(
doNotWarnConstant: Boolean = false
) : UICanvas(toggleKeyLiteral, toggleButtonLiteral, customPositioning, doNotWarnConstant) {
- override var width: Int = AppLoader.screenW
- override var height: Int = AppLoader.screenH
+ override var width: Int = AppLoader.screenSize.screenW
+ override var height: Int = AppLoader.screenSize.screenH
override var openCloseTime: Second = 0.0f
companion object {
@@ -34,7 +34,7 @@ class UIInventoryFull(
const val REQUIRED_MARGIN: Int = 138 // hard-coded value. Don't know the details. Range: [91-146]. I chose MAX-8 because cell gap is 8
const val CELLS_HOR = 10
- val CELLS_VRT: Int; get() = (AppLoader.screenH - REQUIRED_MARGIN - 134 + UIItemInventoryItemGrid.listGap) / // 134 is another magic number
+ val CELLS_VRT: Int; get() = (AppLoader.screenSize.screenH - REQUIRED_MARGIN - 134 + UIItemInventoryItemGrid.listGap) / // 134 is another magic number
(UIItemInventoryElemSimple.height + UIItemInventoryItemGrid.listGap)
const val itemListToEquipViewGap = UIItemInventoryItemGrid.listGap // used to be 24; figured out that the extra gap does nothig
@@ -45,8 +45,8 @@ class UIInventoryFull(
val itemListHeight: Int = CELLS_VRT * UIItemInventoryElemSimple.height + (CELLS_VRT - 1) * net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.listGap
val INVENTORY_CELLS_UI_HEIGHT: Int = CELLS_VRT * UIItemInventoryElemSimple.height + (CELLS_VRT - 1) * UIItemInventoryItemGrid.listGap
- val INVENTORY_CELLS_OFFSET_X = 0 + (AppLoader.screenW - internalWidth) / 2
- val INVENTORY_CELLS_OFFSET_Y: Int = 107 + (AppLoader.screenH - internalHeight) / 2
+ val INVENTORY_CELLS_OFFSET_X = 0 + (AppLoader.screenSize.screenW - internalWidth) / 2
+ val INVENTORY_CELLS_OFFSET_Y: Int = 107 + (AppLoader.screenSize.screenH - internalHeight) / 2
val catBarWidth = 330
@@ -60,7 +60,7 @@ class UIInventoryFull(
//val REQUIRED_MARGIN: Int = 138 // hard-coded value. Don't know the details. Range: [91-146]. I chose MAX-8 because cell gap is 8
//val CELLS_HOR = 10
- //val CELLS_VRT: Int; get() = (AppLoader.screenH - REQUIRED_MARGIN - 134 + UIItemInventoryItemGrid.listGap) / // 134 is another magic number
+ //val CELLS_VRT: Int; get() = (AppLoader.terrarumAppConfig.screenH - REQUIRED_MARGIN - 134 + UIItemInventoryItemGrid.listGap) / // 134 is another magic number
// (UIItemInventoryElemSimple.height + UIItemInventoryItemGrid.listGap)
//private val itemListToEquipViewGap = UIItemInventoryItemGrid.listGap // used to be 24; figured out that the extra gap does nothig
@@ -71,8 +71,8 @@ class UIInventoryFull(
//val itemListHeight: Int = CELLS_VRT * UIItemInventoryElemSimple.height + (CELLS_VRT - 1) * net.torvald.terrarum.modulebasegame.ui.UIItemInventoryItemGrid.Companion.listGap
//val INVENTORY_CELLS_UI_HEIGHT: Int = CELLS_VRT * UIItemInventoryElemSimple.height + (CELLS_VRT - 1) * UIItemInventoryItemGrid.listGap
- //val INVENTORY_CELLS_OFFSET_X = 0 + (AppLoader.screenW - internalWidth) / 2
- //val INVENTORY_CELLS_OFFSET_Y: Int = 107 + (AppLoader.screenH - internalHeight) / 2
+ //val INVENTORY_CELLS_OFFSET_X = 0 + (AppLoader.terrarumAppConfig.screenW - internalWidth) / 2
+ //val INVENTORY_CELLS_OFFSET_Y: Int = 107 + (AppLoader.terrarumAppConfig.screenH - internalHeight) / 2
init {
handler.allowESCtoClose = true
@@ -113,8 +113,8 @@ class UIInventoryFull(
val catBar = UIItemInventoryCatBar(
this,
- (AppLoader.screenW - catBarWidth) / 2,
- 42 + (AppLoader.screenH - internalHeight) / 2,
+ (AppLoader.screenSize.screenW - catBarWidth) / 2,
+ 42 + (AppLoader.screenSize.screenH - internalHeight) / 2,
internalWidth,
catBarWidth,
true,
@@ -127,10 +127,10 @@ class UIInventoryFull(
private val transitionalEscMenu = UIInventoryEscMenu(this)
private val transitionPanel = UIItemHorizontalFadeSlide(
this,
- (AppLoader.screenW - internalWidth) / 2,
+ (AppLoader.screenSize.screenW - internalWidth) / 2,
INVENTORY_CELLS_OFFSET_Y,
- AppLoader.screenW,
- AppLoader.screenH,
+ AppLoader.screenSize.screenW,
+ AppLoader.screenSize.screenH,
1f,
transitionalMinimap, transitionalItemCells, transitionalEscMenu
)
@@ -151,9 +151,9 @@ class UIInventoryFull(
}
- internal var offsetX = ((AppLoader.screenW - internalWidth) / 2).toFloat()
+ internal var offsetX = ((AppLoader.screenSize.screenW - internalWidth) / 2).toFloat()
private set
- internal var offsetY = ((AppLoader.screenH - internalHeight) / 2).toFloat()
+ internal var offsetY = ((AppLoader.screenSize.screenH - internalHeight) / 2).toFloat()
private set
fun requestTransition(target: Int) = transitionPanel.requestTransition(target)
@@ -172,9 +172,9 @@ class UIInventoryFull(
//private val gradHeight = 48f
private val shapeRenderer = ShapeRenderer()
- internal var xEnd = (AppLoader.screenW + internalWidth).div(2).toFloat()
+ internal var xEnd = (AppLoader.screenSize.screenW + internalWidth).div(2).toFloat()
private set
- internal var yEnd = (AppLoader.screenH + internalHeight).div(2).toFloat()
+ internal var yEnd = (AppLoader.screenSize.screenH + internalHeight).div(2).toFloat()
private set
override fun renderUI(batch: SpriteBatch, camera: Camera) {
@@ -185,17 +185,17 @@ class UIInventoryFull(
gdxSetBlendNormal()
- val gradTopStart = (AppLoader.screenH - internalHeight).div(2).toFloat()
- val gradBottomEnd = AppLoader.screenH - gradTopStart
+ val gradTopStart = (AppLoader.screenSize.screenH - internalHeight).div(2).toFloat()
+ val gradBottomEnd = AppLoader.screenSize.screenH - gradTopStart
shapeRenderer.inUse {
- shapeRenderer.rect(0f, gradTopStart, AppLoader.screenWf, gradHeight, gradStartCol, gradStartCol, gradEndCol, gradEndCol)
- shapeRenderer.rect(0f, gradBottomEnd, AppLoader.screenWf, -gradHeight, gradStartCol, gradStartCol, gradEndCol, gradEndCol)
+ shapeRenderer.rect(0f, gradTopStart, AppLoader.screenSize.screenWf, gradHeight, gradStartCol, gradStartCol, gradEndCol, gradEndCol)
+ shapeRenderer.rect(0f, gradBottomEnd, AppLoader.screenSize.screenWf, -gradHeight, gradStartCol, gradStartCol, gradEndCol, gradEndCol)
- shapeRenderer.rect(0f, gradTopStart + gradHeight, AppLoader.screenWf, internalHeight - (2 * gradHeight), gradEndCol, gradEndCol, gradEndCol, gradEndCol)
+ shapeRenderer.rect(0f, gradTopStart + gradHeight, AppLoader.screenSize.screenWf, internalHeight - (2 * gradHeight), gradEndCol, gradEndCol, gradEndCol, gradEndCol)
- shapeRenderer.rect(0f, 0f, AppLoader.screenWf, gradTopStart, gradStartCol, gradStartCol, gradStartCol, gradStartCol)
- shapeRenderer.rect(0f, AppLoader.screenHf, AppLoader.screenWf, -(AppLoader.screenHf - gradBottomEnd), gradStartCol, gradStartCol, gradStartCol, gradStartCol)
+ shapeRenderer.rect(0f, 0f, AppLoader.screenSize.screenWf, gradTopStart, gradStartCol, gradStartCol, gradStartCol, gradStartCol)
+ shapeRenderer.rect(0f, AppLoader.screenSize.screenHf, AppLoader.screenSize.screenWf, -(AppLoader.screenSize.screenHf - gradBottomEnd), gradStartCol, gradStartCol, gradStartCol, gradStartCol)
}
@@ -255,11 +255,11 @@ class UIInventoryFull(
override fun resize(width: Int, height: Int) {
super.resize(width, height)
- offsetX = ((AppLoader.screenW - internalWidth) / 2).toFloat()
- offsetY = ((AppLoader.screenH - internalHeight) / 2).toFloat()
+ offsetX = ((AppLoader.screenSize.screenW - internalWidth) / 2).toFloat()
+ offsetY = ((AppLoader.screenSize.screenH - internalHeight) / 2).toFloat()
- xEnd = (AppLoader.screenW + internalWidth).div(2).toFloat()
- yEnd = (AppLoader.screenH + internalHeight).div(2).toFloat()
+ xEnd = (AppLoader.screenSize.screenW + internalWidth).div(2).toFloat()
+ yEnd = (AppLoader.screenSize.screenH + internalHeight).div(2).toFloat()
}
}
diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryMinimap.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryMinimap.kt
index 9b47bb874..dd40de7ad 100644
--- a/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryMinimap.kt
+++ b/src/net/torvald/terrarum/modulebasegame/ui/UIInventoryMinimap.kt
@@ -15,8 +15,8 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() {
private val debugvals = true
- override var width: Int = AppLoader.screenW
- override var height: Int = AppLoader.screenH
+ override var width: Int = AppLoader.screenSize.screenW
+ override var height: Int = AppLoader.screenSize.screenH
override var openCloseTime = 0.0f
private val MINIMAP_WIDTH = 800f
@@ -115,23 +115,23 @@ class UIInventoryMinimap(val full: UIInventoryFull) : UICanvas() {
batch.begin()
if (debugvals) {
- AppLoader.fontSmallNumbers.draw(batch, "$minimapPanX, $minimapPanY; x$minimapZoom", (AppLoader.screenW - MINIMAP_WIDTH) / 2, -10f + INVENTORY_CELLS_OFFSET_Y)
+ AppLoader.fontSmallNumbers.draw(batch, "$minimapPanX, $minimapPanY; x$minimapZoom", (AppLoader.screenSize.screenW - MINIMAP_WIDTH) / 2, -10f + INVENTORY_CELLS_OFFSET_Y)
}
batch.projectionMatrix = camera.combined
// 1px stroke
batch.color = Color.WHITE
- batch.fillRect((AppLoader.screenW - MINIMAP_WIDTH) / 2, -1 + INVENTORY_CELLS_OFFSET_Y.toFloat(), MINIMAP_WIDTH, 1f)
- batch.fillRect((AppLoader.screenW - MINIMAP_WIDTH) / 2, INVENTORY_CELLS_OFFSET_Y + MINIMAP_HEIGHT, MINIMAP_WIDTH, 1f)
- batch.fillRect(-1 + (AppLoader.screenW - MINIMAP_WIDTH) / 2, INVENTORY_CELLS_OFFSET_Y.toFloat(), 1f, MINIMAP_HEIGHT)
- batch.fillRect((AppLoader.screenW - MINIMAP_WIDTH) / 2 + MINIMAP_WIDTH, INVENTORY_CELLS_OFFSET_Y.toFloat(), 1f, MINIMAP_HEIGHT)
+ batch.fillRect((AppLoader.screenSize.screenW - MINIMAP_WIDTH) / 2, -1 + INVENTORY_CELLS_OFFSET_Y.toFloat(), MINIMAP_WIDTH, 1f)
+ batch.fillRect((AppLoader.screenSize.screenW - MINIMAP_WIDTH) / 2, INVENTORY_CELLS_OFFSET_Y + MINIMAP_HEIGHT, MINIMAP_WIDTH, 1f)
+ batch.fillRect(-1 + (AppLoader.screenSize.screenW - MINIMAP_WIDTH) / 2, INVENTORY_CELLS_OFFSET_Y.toFloat(), 1f, MINIMAP_HEIGHT)
+ batch.fillRect((AppLoader.screenSize.screenW - MINIMAP_WIDTH) / 2 + MINIMAP_WIDTH, INVENTORY_CELLS_OFFSET_Y.toFloat(), 1f, MINIMAP_HEIGHT)
// control hints
batch.color = Color.WHITE
AppLoader.fontGame.draw(batch, full.minimapControlHelp, full.offsetX, full.yEnd - 20)
// the minimap
- batch.draw(minimapFBO.colorBufferTexture, (AppLoader.screenW - MINIMAP_WIDTH) / 2, INVENTORY_CELLS_OFFSET_Y.toFloat())
+ batch.draw(minimapFBO.colorBufferTexture, (AppLoader.screenSize.screenW - MINIMAP_WIDTH) / 2, INVENTORY_CELLS_OFFSET_Y.toFloat())
}
override fun doOpening(delta: Float) {}
diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryItemGrid.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryItemGrid.kt
index 68fa464aa..c897a3538 100644
--- a/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryItemGrid.kt
+++ b/src/net/torvald/terrarum/modulebasegame/ui/UIItemInventoryItemGrid.kt
@@ -523,12 +523,12 @@ class UIItemInventoryItemGrid(
return true
}
- override fun scrolled(amount: Int): Boolean {
- super.scrolled(amount)
+ override fun scrolled(amountX: Float, amountY: Float): Boolean {
+ super.scrolled(amountX, amountY)
// scroll the item list (for now)
if (mouseUp) {
- scrollItemPage(amount)
+ scrollItemPage(amountX.toInt())
}
return true
diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIProxyNewBuildingMaker.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIProxyNewBuildingMaker.kt
index aa2e61e7c..df9af0c71 100644
--- a/src/net/torvald/terrarum/modulebasegame/ui/UIProxyNewBuildingMaker.kt
+++ b/src/net/torvald/terrarum/modulebasegame/ui/UIProxyNewBuildingMaker.kt
@@ -46,40 +46,4 @@ class UIProxyNewBuildingMaker : UICanvas() {
override fun dispose() {
TODO("not implemented")
}
-
- override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
- return super.mouseMoved(screenX, screenY)
- }
-
- override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
- return super.touchDragged(screenX, screenY, pointer)
- }
-
- override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
- return super.touchDown(screenX, screenY, pointer, button)
- }
-
- override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
- return super.touchUp(screenX, screenY, pointer, button)
- }
-
- override fun scrolled(amount: Int): Boolean {
- return super.scrolled(amount)
- }
-
- override fun keyDown(keycode: Int): Boolean {
- return super.keyDown(keycode)
- }
-
- override fun keyUp(keycode: Int): Boolean {
- return super.keyUp(keycode)
- }
-
- override fun keyTyped(character: Char): Boolean {
- return super.keyTyped(character)
- }
-
- override fun resize(width: Int, height: Int) {
- super.resize(width, height)
- }
}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIProxyNewRandomGame.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIProxyNewRandomGame.kt
index d269a61c7..b180c6d64 100644
--- a/src/net/torvald/terrarum/modulebasegame/ui/UIProxyNewRandomGame.kt
+++ b/src/net/torvald/terrarum/modulebasegame/ui/UIProxyNewRandomGame.kt
@@ -62,40 +62,4 @@ class UIProxyNewRandomGame : UICanvas() {
override fun dispose() {
TODO("not implemented")
}
-
- override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
- return super.mouseMoved(screenX, screenY)
- }
-
- override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
- return super.touchDragged(screenX, screenY, pointer)
- }
-
- override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
- return super.touchDown(screenX, screenY, pointer, button)
- }
-
- override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
- return super.touchUp(screenX, screenY, pointer, button)
- }
-
- override fun scrolled(amount: Int): Boolean {
- return super.scrolled(amount)
- }
-
- override fun keyDown(keycode: Int): Boolean {
- return super.keyDown(keycode)
- }
-
- override fun keyUp(keycode: Int): Boolean {
- return super.keyUp(keycode)
- }
-
- override fun keyTyped(character: Char): Boolean {
- return super.keyTyped(character)
- }
-
- override fun resize(width: Int, height: Int) {
- super.resize(width, height)
- }
}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIQuickslotBar.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIQuickslotBar.kt
index cdef3ec0c..92f837341 100644
--- a/src/net/torvald/terrarum/modulebasegame/ui/UIQuickslotBar.kt
+++ b/src/net/torvald/terrarum/modulebasegame/ui/UIQuickslotBar.kt
@@ -83,10 +83,10 @@ class UIQuickslotBar : UICanvas() {
handler.opacity = 0f
}
- override fun scrolled(amount: Int): Boolean {
+ override fun scrolled(amountX: Float, amountY: Float): Boolean {
// super.scrolled(amount) // no UIItems here
- selection = selection.plus(if (amount > 1) 1 else if (amount < -1) -1 else 0).fmod(SLOT_COUNT)
+ selection = selection.plus(if (amountX > 1) 1 else if (amountX < -1) -1 else 0).fmod(SLOT_COUNT)
return true
}
diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIQuickslotPie.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIQuickslotPie.kt
index 7c0d33ebf..6131b9efd 100644
--- a/src/net/torvald/terrarum/modulebasegame/ui/UIQuickslotPie.kt
+++ b/src/net/torvald/terrarum/modulebasegame/ui/UIQuickslotPie.kt
@@ -49,7 +49,7 @@ class UIQuickslotPie : UICanvas() {
// update controls
if (handler.isOpened || handler.isOpening) {
val cursorPos = Vector2(Terrarum.mouseScreenX.toDouble(), Terrarum.mouseScreenY.toDouble())
- val centre = Vector2(AppLoader.halfScreenW.toDouble(), AppLoader.halfScreenH.toDouble())
+ val centre = Vector2(AppLoader.screenSize.halfScreenW.toDouble(), AppLoader.screenSize.halfScreenH.toDouble())
val deg = -(centre - cursorPos).direction.toFloat()
selection = Math.round(deg * slotCount / FastMath.TWO_PI)
diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIRemoCon.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIRemoCon.kt
index c715a15dc..438e2f231 100644
--- a/src/net/torvald/terrarum/modulebasegame/ui/UIRemoCon.kt
+++ b/src/net/torvald/terrarum/modulebasegame/ui/UIRemoCon.kt
@@ -8,7 +8,6 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.AppLoader.printdbgerr
import net.torvald.terrarum.QNDTreeNode
-import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.Yaml
import net.torvald.terrarum.ui.UICanvas
import net.torvald.terrarum.ui.UIItemTextButton
@@ -221,9 +220,9 @@ open class UIRemoCon(treeRepresentation: QNDTreeNode) : UICanvas() {
return true
}
- override fun scrolled(amount: Int): Boolean {
+ override fun scrolled(amountX: Float, amountY: Float): Boolean {
screens.forEach {
- it.second.scrolled(amount) // again, underlying handler will block unnecessary renders
+ it.second.scrolled(amountX, amountY) // again, underlying handler will block unnecessary renders
}
return true
@@ -300,6 +299,6 @@ open class UIRemoCon(treeRepresentation: QNDTreeNode) : UICanvas() {
val remoConWidth = 304
fun getRemoConHeight(menu: ArrayList) = DEFAULT_LINE_HEIGHT * menu.size.plus(1)
fun getRemoConHeight(menu: Array) = DEFAULT_LINE_HEIGHT * menu.size.plus(1)
- val menubarOffY: Int; get() = AppLoader.screenH / 2 - (AppLoader.fontGame.lineHeight * 1.5).toInt()
+ val menubarOffY: Int; get() = AppLoader.screenSize.screenH / 2 - (AppLoader.fontGame.lineHeight * 1.5).toInt()
}
}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIScreenZoom.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIScreenZoom.kt
index bc5bc73a1..a90a3f336 100644
--- a/src/net/torvald/terrarum/modulebasegame/ui/UIScreenZoom.kt
+++ b/src/net/torvald/terrarum/modulebasegame/ui/UIScreenZoom.kt
@@ -6,6 +6,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.EMDASH
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.Terrarum
+import net.torvald.terrarum.TerrarumScreenSize
import net.torvald.terrarum.keyToIcon
import net.torvald.terrarum.ui.Movement
import net.torvald.terrarum.ui.UICanvas
@@ -39,8 +40,8 @@ class UIScreenZoom : UICanvas(
AppLoader.fontGame.draw(
batch, zoomText,
- (AppLoader.screenW * AppLoader.TV_SAFE_GRAPHICS + 1).toInt().toFloat(),
- (AppLoader.screenH - height - AppLoader.getTvSafeGraphicsHeight()).toFloat()
+ (AppLoader.screenSize.screenW * TerrarumScreenSize.TV_SAFE_GRAPHICS + 1).toInt().toFloat(),
+ (AppLoader.screenSize.screenH - height - AppLoader.screenSize.tvSafeGraphicsHeight).toFloat()
)
}
diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UITitleCharactersList.kt b/src/net/torvald/terrarum/modulebasegame/ui/UITitleCharactersList.kt
index 7a6bd5359..c82e4413d 100644
--- a/src/net/torvald/terrarum/modulebasegame/ui/UITitleCharactersList.kt
+++ b/src/net/torvald/terrarum/modulebasegame/ui/UITitleCharactersList.kt
@@ -19,8 +19,8 @@ class UITitleCharactersList : UICanvas() {
private val moduleAreaHMargin = 48
private val moduleAreaBorder = 8
- override var width = AppLoader.screenW - UIRemoCon.remoConWidth - moduleAreaHMargin
- override var height = AppLoader.screenH - moduleAreaHMargin * 2
+ override var width = AppLoader.screenSize.screenW - UIRemoCon.remoConWidth - moduleAreaHMargin
+ override var height = AppLoader.screenSize.screenH - moduleAreaHMargin * 2
private val moduleInfoCells = ArrayList()
// build characters list
diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UITitleLanguage.kt b/src/net/torvald/terrarum/modulebasegame/ui/UITitleLanguage.kt
index ab9458e82..fd85c0804 100644
--- a/src/net/torvald/terrarum/modulebasegame/ui/UITitleLanguage.kt
+++ b/src/net/torvald/terrarum/modulebasegame/ui/UITitleLanguage.kt
@@ -3,7 +3,6 @@ package net.torvald.terrarum.modulebasegame.ui
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.g2d.SpriteBatch
-import net.torvald.terrarum.Terrarum
import net.torvald.terrarum.AppLoader
import net.torvald.terrarum.Second
import net.torvald.terrarum.langpack.Lang
@@ -21,13 +20,13 @@ class UITitleLanguage : UICanvas() {
private val textAreaHMargin = 48
- override var width = (AppLoader.screenW * 0.75).toInt()
- override var height = AppLoader.screenH - textAreaHMargin * 2
+ override var width = (AppLoader.screenSize.screenW * 0.75).toInt()
+ override var height = AppLoader.screenSize.screenH - textAreaHMargin * 2
private val localeList = Lang.languageList.toList().sorted()
private val textArea = UIItemTextButtonList(this,
localeList.map { Lang.langpack["MENU_LANGUAGE_THIS_$it"] ?: "!ERR: $it" }.toTypedArray(),
- AppLoader.screenW - width, textAreaHMargin,
+ AppLoader.screenSize.screenW - width, textAreaHMargin,
width, height,
textAreaWidth = width,
readFromLang = false,
diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UITitleModules.kt b/src/net/torvald/terrarum/modulebasegame/ui/UITitleModules.kt
index 484fd7fe1..5deada955 100644
--- a/src/net/torvald/terrarum/modulebasegame/ui/UITitleModules.kt
+++ b/src/net/torvald/terrarum/modulebasegame/ui/UITitleModules.kt
@@ -21,8 +21,8 @@ class UITitleModules : UICanvas() {
private val moduleAreaHMargin = 48
private val moduleAreaBorder = 8
- override var width = AppLoader.screenW - UIRemoCon.remoConWidth - moduleAreaHMargin
- override var height = AppLoader.screenH - moduleAreaHMargin * 2
+ override var width = AppLoader.screenSize.screenW - UIRemoCon.remoConWidth - moduleAreaHMargin
+ override var height = AppLoader.screenSize.screenH - moduleAreaHMargin * 2
private val moduleInfoCells = ArrayList()
diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UITitleRemoConRoot.kt b/src/net/torvald/terrarum/modulebasegame/ui/UITitleRemoConRoot.kt
index 4eec19ed2..f8d5b5617 100644
--- a/src/net/torvald/terrarum/modulebasegame/ui/UITitleRemoConRoot.kt
+++ b/src/net/torvald/terrarum/modulebasegame/ui/UITitleRemoConRoot.kt
@@ -6,7 +6,7 @@ package net.torvald.terrarum.modulebasegame.ui
val remoConWidth = 240
fun getRemoConHeight(menu: ArrayList) = 36 * menu.size.plus(1)
fun getRemoConHeight(menu: Array) = 36 * menu.size.plus(1)
- val menubarOffY: Int; get() = AppLoader.screenH / 2 - (AppLoader.fontGame.lineHeight * 1.5).toInt()
+ val menubarOffY: Int; get() = AppLoader.terrarumAppConfig.screenH / 2 - (AppLoader.fontGame.lineHeight * 1.5).toInt()
}
diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UITitleWallOfText.kt b/src/net/torvald/terrarum/modulebasegame/ui/UITitleWallOfText.kt
index 05ecc57f1..763c49a25 100644
--- a/src/net/torvald/terrarum/modulebasegame/ui/UITitleWallOfText.kt
+++ b/src/net/torvald/terrarum/modulebasegame/ui/UITitleWallOfText.kt
@@ -15,8 +15,8 @@ open class UITitleWallOfText(private val text: List) : UICanvas() {
private val textAreaHMargin = 48
- override var width = AppLoader.screenW - UIRemoCon.remoConWidth - textAreaHMargin
- override var height = AppLoader.screenH - textAreaHMargin * 2
+ override var width = AppLoader.screenSize.screenW - UIRemoCon.remoConWidth - textAreaHMargin
+ override var height = AppLoader.screenSize.screenH - textAreaHMargin * 2
private val textArea = UIItemTextArea(this,
UIRemoCon.remoConWidth, textAreaHMargin,
width, height
diff --git a/src/net/torvald/terrarum/modulebasegame/ui/UIVitalMetre.kt b/src/net/torvald/terrarum/modulebasegame/ui/UIVitalMetre.kt
index f00a250cc..589365bc4 100644
--- a/src/net/torvald/terrarum/modulebasegame/ui/UIVitalMetre.kt
+++ b/src/net/torvald/terrarum/modulebasegame/ui/UIVitalMetre.kt
@@ -50,8 +50,8 @@ class UIVitalMetre(
override fun updateUI(delta: Float) {
handler.setPosition(
- AppLoader.halfScreenW,
- AppLoader.halfScreenH
+ AppLoader.screenSize.halfScreenW,
+ AppLoader.screenSize.halfScreenH
)
}
diff --git a/src/net/torvald/terrarum/modulebasegame/weather/WeatherMixer.kt b/src/net/torvald/terrarum/modulebasegame/weather/WeatherMixer.kt
index 68dc6ca08..8813fc352 100644
--- a/src/net/torvald/terrarum/modulebasegame/weather/WeatherMixer.kt
+++ b/src/net/torvald/terrarum/modulebasegame/weather/WeatherMixer.kt
@@ -99,8 +99,8 @@ internal object WeatherMixer : RNGConsumer {
val playerPosY = player.hitbox.centeredY
kotlin.repeat(7) {
val rainParticle = ParticleMegaRain(
- playerPosX + HQRNG().nextInt(AppLoader.screenW) - AppLoader.halfScreenW,
- playerPosY - AppLoader.screenH
+ playerPosX + HQRNG().nextInt(AppLoader.screenSize.screenW) - AppLoader.screenSize.halfScreenW,
+ playerPosY - AppLoader.screenSize.screenH
)
(Terrarum.ingame!! as TerrarumIngame).addParticle(rainParticle)
}
@@ -187,7 +187,7 @@ internal object WeatherMixer : RNGConsumer {
batch.shader = null
}
batch.inUse {
- it.draw(skyboxTexture, 0f, -AppLoader.halfScreenHf, AppLoader.screenWf, AppLoader.screenHf * 2f) // because of how the linear filter works, we extend the image by two
+ it.draw(skyboxTexture, 0f, -AppLoader.screenSize.halfScreenHf, AppLoader.screenSize.screenWf, AppLoader.screenSize.screenHf * 2f) // because of how the linear filter works, we extend the image by two
}
// don't use shader to just fill the whole screen... frag shader will be called a million times and it's best to not burden it
diff --git a/src/net/torvald/terrarum/modulebasegame/worldgenerator/Worldgen.kt b/src/net/torvald/terrarum/modulebasegame/worldgenerator/Worldgen.kt
index ac431f4f6..74dd31d34 100644
--- a/src/net/torvald/terrarum/modulebasegame/worldgenerator/Worldgen.kt
+++ b/src/net/torvald/terrarum/modulebasegame/worldgenerator/Worldgen.kt
@@ -53,7 +53,7 @@ abstract class Gen(val world: GameWorld, val seed: Long, val params: Any) {
data class WorldgenParams(
val seed: Long,
- // optional parametres
+ // optional parameters
val terragenParams: TerragenParams = TerragenParams(),
val biomegenParams: BiomegenParams = BiomegenParams()
)
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/common/common.lua b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/common/common.lua
deleted file mode 100644
index 7ef1ffb3d..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/common/common.lua
+++ /dev/null
@@ -1,27 +0,0 @@
-_G.parsecmd = function(str)
- local parsetable = {}
- local quotemode = false
- local wordbuffer = ""
-
- for c = 1, #str do
- local char = str:byte(c)
- if not quotemode and char == 32 then -- quotestack is empty and char is a space
- table.insert(parsetable, wordbuffer)
- wordbuffer = ""
- elseif char == 34 then -- "
- quotemode = not quotemode
- else
- wordbuffer = wordbuffer..string.char(char)
- end
- end
-
- if #wordbuffer ~= 0 then
- table.insert(parsetable, wordbuffer)
- end
-
- return parsetable
-end
-
-_G.TODO = function(str)
- error("Not implemented: "..str or "TODO", 2)
-end
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/loots/dummix/bin/cp.lua b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/loots/dummix/bin/cp.lua
deleted file mode 100644
index eae110a74..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/loots/dummix/bin/cp.lua
+++ /dev/null
@@ -1,6 +0,0 @@
-local args = {...}
-if (#args ~= 2) then
-print([[usage: cp source_file target_file
- cp source_file target_directory]])
-return end
-fs.cp(os.expandPath(args[1]), os.expandPath(args[2]))
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/loots/dummix/bin/dsh.lua b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/loots/dummix/bin/dsh.lua
deleted file mode 100644
index 3c75c4abb..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/loots/dummix/bin/dsh.lua
+++ /dev/null
@@ -1,257 +0,0 @@
-local args = {...}
-
-os.dshenv = {}
-
---[[
-DUMBSHELL: semi sh-compatible language interpreter
-
-SYNOPSIS
- dsh [option] [file]
- sh [option] [file]
-
-OPTIONS
- -c string If the -c option is present, then commands are read from
- string. If there are arguments after the string, they are
- assigned to the positional parameters, starting with $0.
-
-
-]]
-
--- returns full path. if p starts with "/", only the p is returned
-local function expandPath(p)
- return (p:byte(1) == 47) and p or os.expandPath(p)
-end
-
-local function startsFromRoot(p)
- return p:byte(1) == 47
-end
-
-local function endsWithSlash(p)
- return p:byte(#p) == 47
-end
-
---__DSHDEBUG__ = 0x51621D
-
-local function debug(msg)
- if __DSHDEBUG__ then print("DEBUG", msg) end
-end
-
-local function printErr(msg)
- print(DLE..msg)
-end
-
-local function shallowCopy(t)
- return {table.unpack(t)}
-end
-
--- BUILTINS -------------------------------------------------------------------
-
-local function cd(tArgs)
- local dir = tArgs[1]
-
- if (dir == nil or #dir < 1) then return end
-
- local oldWorkingDir = shallowCopy(os.workingDir)
-
- -- parse dir by delimeter '/'
- if (dir:byte(1) == 47) then -- if dir begins with '/'
- os.setWorkingDir(dir)
- else
- for word in string.gmatch(dir, "[^/]+") do
-
- machine.println("CD word: "..word)
-
- -- 'execute' directory
- -- Rules: '..' pops os.workingDir
- -- if dir begins with '/', re-build os.workingDir
- -- otherwise, push the 'word' to os.workingDir
- if (word == "..") then
- os.popWorkingDir()
- elseif (word == ".") then
- -- pass
- else
- os.pushWorkingDir(word)
- end
- end
- end
- -- check if the directory exists
- if not fs.isDir(os.fullWorkPath()) then
- os.errorNoSuchFileOrDir("cd: "..dir)
- os.workingDir = shallowCopy(oldWorkingDir)
- return
- end
-end
-
-local function exit(tArgs)
- exitshell = true
-end
-
-local function exec(tArgs)
- debug("EXECARGS\t"..table.concat(tArgs, ", "))
-
- if (tArgs[1] == nil or #tArgs[1] < 1) then return end
-
- local filePath = tArgs[1]
- local fullFilePath = expandPath(tArgs[1])
- local execArgs = {}
- for i, v in ipairs(tArgs) do
- if (i >= 2) then table.insert(execArgs, v) end
- end
- local execByPathFileExists = false
- local execByPathArg = ""
-
- -- do some sophisticated file-matching
- -- step 1: exact file
- if fs.isFile(fullFilePath) then
- shell.run(fullFilePath, execArgs)
- -- step 2: try appending ".lua"
- elseif fs.isFile(fullFilePath..".lua") then
- shell.run(fullFilePath..".lua", execArgs)
- -- step 3: parse os.path (just like $PATH)
- -- step 3.1: exact file; step 3.2: append ".lua"
- elseif not startsFromRoot(filePath) then
- for path in string.gmatch(os.path, "[^;]+") do
- -- check if 'path' ends with '/'
- if not endsWithSlash(path) then path = path.."/" end
-
- debug(path..filePath)
-
- if fs.isFile(path..filePath) then
- execByPathArg = path..filePath
- execByPathFileExists = true
- break
- elseif fs.isFile(path..filePath..".lua") then
- execByPathArg = path..filePath..".lua"
- execByPathFileExists = true
- break
- end
- end
- end
-
- -- step else: file not found
- if execByPathFileExists then
- shell.run(execByPathArg, execArgs)
- return EXIT_SUCCESS
- else
- if filePath:byte(1) == 46 or filePath:byte(1) == 47 then
- os.errorNoSuchFile(filePath)
- else
- os.errorCmdNotFound(filePath)
- end
- end
-
- return false
-end
-
--- SYNTAX PARSER --------------------------------------------------------------
-
--- tables with functions
-local builtins = {
- cd = cd,
- exit = exit,
- exec = exec,
- clear = term.clear
-}
-
-local function runcommand(str, recurse)
- if #str < 1 then return end
-
- local cmdFound = false
-
- -- simple cmd parse: WORD ARG1 ARG2 ARG3 ...
- local args = {}
- local command = ""
- for word in string.gmatch(str, "[^ ]+") do
- if #command < 1 then command = word -- first word will be a name of command
- else table.insert(args, word) end
- end
-
- if builtins[command] then -- try for builtins table
- builtins[command](args)
- cmdFound = true
- return true
- else
-
- -- FIXME: 'exec programname args' works, but not 'programname args'
-
- -- try for os.dshenv.aliases
- if os.dshenv.aliases[command] then
- --builtins[os.dshenv.aliases[command]](args)
- if not recurse then
- cmdFound = runcommand(os.dshenv.aliases[command], true)
- end
- else
- -- try to launch as program
- if not recurse then
- cmdFound = runcommand("exec "..str, true)
- end
- end
- end
-
- -- command not found (really)
- if not cmdFound then
- os.errorCmdNotFound(command)
- end
-end
-
--- END OF SYNTAX PARSER -------------------------------------------------------
--- INIT SHELL -----------------------------------------------------------------
-
-exitshell = false
-
--- load up aliases
-if fs.isFile("/etc/.dshrc") then
- fs.dofile("/etc/.dshrc")
- machine.println("[dummix/dsh.lua] Dsh aliases successfully loaded.")
-end
-
-
--- END OF INIT SHELL ----------------------------------------------------------
-
--- run interpreter and quit
-if (args[1]) then
- local f = fs.open(args[1], "r")
- local line = ""
- local s = ""
-
- -- treat interpreter key (#!) properly
- -- I'm assuming I was called because I'm the right one
- -- I have a full trust on "shell.run()" that it rightfully redirected to me
- --
- -- NOTE: shell redirection should only apply in interactive mode AND the input
- -- was like "./filename", or else I'm the right one. Period.
- -- (and that's how BASH works)
- repeat
- line = f.readLine()
- if line == nil then break end
- if line:sub(1,2) ~= "#!" then -- ignore line that contains hashbang
- s = s.." "..line
- end
- until line == nil
-
- f.close()
-
- runcommand(s)
-
- exitshell = true
-end
-
-
-function getPromptText()
- --return DC4..os.workingDir[#os.workingDir]..DC3.."# "..DC4 -- we're root! omgwtf
- return DC4..os.fullWorkPath()..DC3.."# "..DC4 -- we're root! omgwtf
-end
-
--- interactive mode
-local time = os.date()
-print(time)
-
-repeat
- term.setCursorBlink(true)
- io.write(getPromptText())
- local s = input.readLine()
- runcommand(s)
-until exitshell
-
-collectgarbage()
-return EXIT_SUCCESS
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/loots/dummix/bin/lessismore.lua b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/loots/dummix/bin/lessismore.lua
deleted file mode 100644
index df511f43d..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/loots/dummix/bin/lessismore.lua
+++ /dev/null
@@ -1,170 +0,0 @@
---[[
-LESS IS MORE
-
-SYNOPSIS:
- lessismore [filename]
- less [filename]
- more [filename]
-]]
-local args = {...}
-
-displayLineNo = true
-
-local prompt = function()
- term.setForeCol(3)
-
- term.emitString(" scroll ", 3, term.height())
- term.emitString(" quit", 14, term.height())
-
- term.setForeCol(1)
- term.emit(18, 1, term.height())
- term.emit(29, 2, term.height())
- term.emit(81, 13, term.height())
-
- term.setForeCol(3)
- term.setBackCol(0)
-end
-
-local function printUsage()
- print("More: no file specified.")
- print("Usage: more [filename]")
-end
-
-if args[1] == nil or #args[1] <= 0 then printUsage() return end
-filepath = os.expandPath(args[1])
-if not fs.isFile(filepath) then os.errorNoSuchFile(filepath) return end
-
-function log10(n)
- if n < 1 then return 0
- elseif n < 10 then return 1
- elseif n < 100 then return 2
- elseif n < 1000 then return 3
- elseif n < 10000 then return 4
- elseif n < 100000 then return 5
- elseif n < 1000000 then return 6
- elseif n < 10000000 then return 7
- elseif n < 100000000 then return 8
- elseif n < 1000000000 then return 9
- else return 10
- end
-end
-
-----------------
--- fetch text --
-----------------
-lines = {}
-displayHeight = term.height() - 1 -- bottom one line for prompt
-
-local file = fs.open(filepath, "r")
-local line = ""
-repeat
- line = file.readLine()
- table.insert(lines, line)
-until line == nil
-
-lineNoLen = log10(#lines)
-
------------
--- input --
------------
-local function scrollDownAction(n)
- term.clearLine() -- prevent prompt to be scrolled
- curY = curY + n
-
- -- prevent overscroll
- if (curY > #lines - displayHeight) then
- curY = #lines - displayHeight
- end
-
- term.scroll(n)
- for i = 0, n - 1 do
- drawString(curY + displayHeight - i, displayHeight - i) -- redraw newline
- end
-end
-
-local function scrollUpAction(n)
- curY = curY - n
-
- -- prevent overscroll
- if (curY < 1) then
- curY = 1
- end
-
- term.scroll(-n)
- for i = 0, n - 1 do
- drawString(curY + i, i + 1) -- redraw prev line
- end
- term.setCursor(n, term.height())
-end
-
-local function processInput()
- if input.isKeyDown(keys.q) then quit = true end
- if input.isKeyDown(keys.down) and curY < #lines - displayHeight then
- scrollDownAction(1)
- prompt()
- elseif input.isKeyDown(keys.pageDown) and curY < #lines - displayHeight then
- scrollDownAction(8)
- prompt()
- elseif input.isKeyDown(keys.up) and curY > 1 then
- scrollUpAction(1)
- term.clearLine() -- make space for prompt
- prompt()
- elseif input.isKeyDown(keys.pageUp) and curY > 1 then
- scrollUpAction(8)
- term.clearLine() -- make space for prompt
- prompt()
- end
-
- machine.sleep(50)
-end
-
--------------
--- display --
--------------
-displayWidth = term.width() - 1 - (displayLineNo and lineNoLen or 0)
-
-function drawString(lineNo, y)
- local string = (lineNo > #lines) and ""
- or lines[lineNo]:sub(curX, curX + displayWidth)
-
- if (displayLineNo) then
- local lineNoStr = DC3..string.format("%"..lineNoLen.."d", curY + y - 1)..DC4
- string = lineNoStr..string
- end
-
- local strDrawX = curX
- term.emitString(string, strDrawX, y)
-end
-
-function redrawText()
- for i = curY, #lines do
- if (i >= displayHeight + curY) then break end
- drawString(i, i - curY + 1)
- end
-end
-
-curY = 1
-curX = 1
-quit = false
-
-if term.isTeletype() then
- for _, l in ipairs(line) do
- term.print(l)
- end
- quit = true
-end
-
-
-term.clear()
-term.setCursorBlink(false)
-redrawText()
-
-repeat
- prompt()
-
- term.setCursor(1, term.height())
- processInput()
-until quit
-
-term.clearLine()
-return
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/loots/dummix/bin/ls.lua b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/loots/dummix/bin/ls.lua
deleted file mode 100644
index 83655db98..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/loots/dummix/bin/ls.lua
+++ /dev/null
@@ -1,10 +0,0 @@
-local args = {...}
-
-local dir = os.fullWorkPath()--(#args < 1) and os.fullWorkPath() or args[1]
-
-local list = fs.list("/"..dir)
-table.sort(list)
-
-for _, v in ipairs(list) do
- print(v)
-end
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/loots/dummix/bin/msh.lua b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/loots/dummix/bin/msh.lua
deleted file mode 100644
index 15ef4fde7..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/loots/dummix/bin/msh.lua
+++ /dev/null
@@ -1,76 +0,0 @@
-local args = {...}
-local _APPVERSION = 0.3
---[[
-MOONSHELL: basically just lua.lua
-
-SYNOPSIS
- msh [file]
-
-msh: Runs shell in interactive mode
-msh [file]: Try to execute file as Lua script
-
-]]
-
--- run interpreter and quit
-if (args[1]) then
- local f = fs.open(args[1], "r")
- local line = ""
- local s = ""
-
- -- treat interpreter key (#!) properly
- -- I'm assuming I was called because I'm the right one
- -- I have a full trust on "shell.run()" that it rightfully redirected to me
- repeat
- line = f.readLine()
- if line == nil then break end
- if line:sub(1,2) ~= "#!" then -- ignore line that contains hashbang
- s = s.." "..line
- end
- until line == nil
-
- f.close()
-
- xpcall(
- function() _G.runscript(s, "="..args[1]) end,
- function(err) print(DLE..err) end
- )
-
- goto terminate
-end
-
--- interactive mode. This is a copy of BOOT.lua
-run = shell.run
-
-print("Moonshell "..DC2.._APPVERSION..DC4..", running "..DC2.._VERSION..DC4)
-print("Lua is copyrighted (C) 1994-2013 Lua.org, PUC-Rio")
-print("Run run(path) to execute program on 'path'.")
-print("Run exit() to quit.")
-
-while not machine.isHalted() do
- term.setCursorBlink(true)
-
- io.write(DC3.."lua"..computer.prompt)
-
- local s = input.readLine()
-
- if s == "exit()" then break end
-
- xpcall(
- function()
- if s:byte(1) == 61 then -- print out value
- s1 = string.sub(s, 2)
- _G.runscript("print(tostring("..s1.."))\n", "=stdin")
- else
- _G.runscript(s, "=stdin")
- end
- end,
- function(err) print(DLE..err) end -- it catches logical errors
- )
-end
-
-
-
-
-::terminate::
-collectgarbage()
-return EXIT_SUCCESS
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/loots/dummix/bin/mv.lua b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/loots/dummix/bin/mv.lua
deleted file mode 100644
index ca1189fc1..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/loots/dummix/bin/mv.lua
+++ /dev/null
@@ -1,6 +0,0 @@
-local args = {...}
-if (#args ~= 2) then
-print([[usage: mv source target
- mv source ... directory]])
-return end
-fs.mv(os.expandPath(args[1]), os.expandPath(args[2]))
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/loots/dummix/boot/efi b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/loots/dummix/boot/efi
deleted file mode 100644
index 9985af219..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/loots/dummix/boot/efi
+++ /dev/null
@@ -1 +0,0 @@
-fs.dofile("/etc/_boot.lua")
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/loots/dummix/etc/.dshrc b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/loots/dummix/etc/.dshrc
deleted file mode 100644
index 2b702dee7..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/loots/dummix/etc/.dshrc
+++ /dev/null
@@ -1,8 +0,0 @@
--- dsh aliases
-os.dshenv.aliases = {
- lua = "msh",
- sh = "dsh",
- shutdown = "exit", -- should be a separate program that actually halts the system
- less = "lessismore",
- more = "lessismore"
-}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/loots/dummix/etc/_boot.lua b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/loots/dummix/etc/_boot.lua
deleted file mode 100644
index fb5504e30..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/loots/dummix/etc/_boot.lua
+++ /dev/null
@@ -1,117 +0,0 @@
---[[
- Bootloader for Operation System
-
- Created by minjaesong on 2016-09-21
-]]
-
--- check directories
-dirlist = {
- "/boot",
- "/bin", -- crucial binaries (e.g. cat, ls, sh(ell), cp, rm, mkdir), it's loosely an UNIX system
- "/usr",
- "/usr/bin", -- more utilities and binaries (e.g. less/more, nano)
- "/home", -- home directory for user
- "/home/bin", -- user-installed apps
- "/media" -- auto mounts (e.g. "/media/fd1", "/media/hdb", "/media/sda")
-}
--- just make them if they don't exist
-for _, dir in ipairs(dirlist) do
- fs.mkdir(dir)
-end
-
-
-if not _G.os then _G.os = {} end
-os.version = "0.0"
-os.EXIT_SUCCESS = 0
-os.workingDir = {"home"}
-os.path = "home/bin/;/usr/bin/;/bin/" -- infamous $path
-os.fullWorkPath = function()
- local ret = table.concat(os.workingDir, "/") -- there's nothing wrong with this.
-
- if computer.verbose then
- machine.println("workingDir size: "..#os.workingDir)
- machine.println("fullWorkPath: "..ret)
- end
- return ret
-end
-os.setWorkingDir = function(s)
- if s:byte(#s) == 47 then
- s = string.sub(s, 1, #s - 1)
- end
- if s:byte(1) == 47 then
- s = string.sub(s, 2, #s)
- end
-
- if computer.verbose then
- machine.println("renew working dir; '"..s.."'")
- end
-
- local oldWorkingDir = {table.unpack(os.workingDir)}
-
- -- renew working directory, EVEN IF s STARTS WITH '/'
- local t = {}
- for word in string.gmatch(s, "[^/]+") do
- table.insert(t, word)
- end
-
- os.workingDir = t
-
- -- check if the directory exists
- if not fs.isDir(s) then
- os.errorNoSuchFileOrDir("cd: "..s)
- os.workingDir = oldWorkingDir
- return
- end
-end
-os.pushWorkingDir = function(s)
- if (s == "..") then
- error("cannot push '..' to working directory.")
- else
- table.insert(os.workingDir, s)
-
- if computer.verbose then
- machine.println("pushing '"..s.."' to working directory.")
- end
- end
-end
-os.popWorkingDir = function()
- if (#os.workingDir > 1) then
- table.remove(os.workingDir)
- end
-end
--- @param "path/of/arbitrary"
--- @return /working/dir/path/of/arbitrary
--- input path's trailing '/' is PRESERVED.
-os.expandPath = function(p)
- -- not applicable if the path starts with /
- if p:byte(1) == 47 or p:byte(1) == 92 then
- return p
- end
-
- return os.fullWorkPath().."/"..p
-end
-os.defaultshell = "/bin/dsh.lua"
-os.clock = function() return machine.milliTime() / 1000 end -- uptime of the computer, in seconds
-
-
-function os.errorCmdNotFound(cmd)
- print(cmd..": command not found")
-end
-
-function os.errorNoSuchFile(cmd)
- print(cmd..": No such file")
-end
-
-function os.errorNoSuchFileOrDir(cmd)
- print(cmd..": No such file or directory")
-end
-function os.errorIsDir(cmd)
- print(cmd.." is a directory")
-end
-
-
--- run default shell
-fs.dofile(os.defaultshell)
-
--- quit properly
-shell.status = shell.halt
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/loots/dummix/usr/share/man/msh b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/loots/dummix/usr/share/man/msh
deleted file mode 100644
index 2aa7e18fc..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/loots/dummix/usr/share/man/msh
+++ /dev/null
@@ -1,12 +0,0 @@
-NAME
- msh - the Moonshell
-
-SYNOPSIS
- msh [file]
-
-COPYRIGHT
- See copyright information for the game you are actually playing.
-
-DESCRIPTION
- Msh is a Lua prompt that reads lua script from the user, or execute
- a file user had put as an argument.
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/loots/lunados/command.lua b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/loots/lunados/command.lua
deleted file mode 100644
index c5665e596..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/loots/lunados/command.lua
+++ /dev/null
@@ -1,58 +0,0 @@
-print("")
-print("Starting Lunados...")
-
-------------------
---- INITIALISE ---
-------------------
-
-require "common"
-
-local prompt = "> "
-
-_G.dos = {}
-_G.dos.version = "0.1"
-_G.dos.copyright = "Copyright (C) 2019 CuriousTorvald. Distributed under GNU GPL 3."
-_G.dos.currentpath = {}
-
---- appends the directory into the current path
-_G.dos.currentpath.push = function(name)
- table.insert(dos.path, name)
-end
-
---- removes the current directory from the current path and returns what has been removed
-_G.dos.currentpath.pop = function()
- return table.remove(dos.path)
-end
-
-_G.dos.envpath = "C:\\lunados\\bin;" -- must be a sting and not a table
-
-
-
-
-
-
-
-
-
-
-
-
---------------------------
---- LET THE SHOW BEGIN ---
---------------------------
-
-print("Lunados Version "..dos.version)
-print(dos.copyright)
-
---- PARSE AND RUN COMMANDS ---
-
-local exit = false
-
-while not exit do
- io.write(table.concat(dos.path, '\\'))
- io.write(prompt)
- local cmd = io.read()
- local commands = parsecmd(cmd)
-
- TODO()
-end
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/luaold/BOOT.lua b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/luaold/BOOT.lua
deleted file mode 100644
index 31cc4d715..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/luaold/BOOT.lua
+++ /dev/null
@@ -1,1057 +0,0 @@
---[[
- Must be loaded VERY FIRST!
-
- Created by minjaesong on 2016-09-13.
-
- Some codes were taken from OpenComputers, which is distributed under MIT
---]]
-
-_G._TERRARUM = true -- for multi-env programs
-
--- global functions
-_G.runscript = function(s, src, ...)
- if s:byte(1) == 0x1b then error("Bytecode execution is prohibited.") end -- exact MAGIC is 0x1b 'L' 'u' 'a'
-
- local code, reason = load(s, src)
-
- if code then
- xpcall(code(...), eprint)
- else
- print(DLE..tostring(reason)) -- it catches syntax errors
- end
-end
-
-fs.dofile = function(p, ...)
- local f = fs.open(p, "r")
- local s = f.readAll()
- f.close()
- _G.runscript(s, p, ...)
-end
-
-computer.realTime = function() return 0 end
-
--- global variables
-_G._VERSION = _VERSION.." (Lua 5.2.3)"
-_G.EMDASH = string.char(0xC4)
-_G.UNCHECKED = string.char(0x9C) -- box unchecked
-_G.CHECKED = string.char(0x9D) -- box checked
-_G.MONEY = string.char(0x9E) -- currency sign
-_G.MIDDOT = string.char(0xFA) -- middle dot sign
-_G.DC1 = string.char(17) -- black
-_G.DC2 = string.char(18) -- white
-_G.DC3 = string.char(19) -- dim grey
-_G.DC4 = string.char(20) -- light grey
-_G.DLE = string.char(16) -- default error colour
-
-_G.bell = function(patn) term.bell(patn or ".") end
-_G.beep = _G.bell
-
-if totalMemory() == 0 then
- bell "==="
- print("no RAM installed")
- __haltsystemexplicit__()
- return
-end
-
-local hookInterval = 100
-local deadline = math.huge
-local hitDeadline = false
-local function checkDeadline()
- if computer.realTime() > deadline then
- debug.sethook(coroutine.running(), checkDeadline, "", 1)
- if not hitDeadline then
- deadline = deadline + 0.5
- end
- hitDeadline = true
- error("too long without yielding", 0)
- end
-end
-
-local function checkArg(n, have, ...)
- have = type(have)
- local function check(want, ...)
- if not want then
- return false
- else
- return have == want or check(...)
- end
- end
- if not check(...) then
- local msg = string.format("BAD argument #%d (%s expected, got %s)",
- n, table.concat({...}, " or "), have)
- error(msg, 3)
- end
-end
-
--------------------------------------------------------------------------------
-
---[[ This is pretty much a straight port of Lua's pattern matching code from
- the standard PUC-Rio C implementation. We want to have this in plain Lua
- for the sandbox, so that timeouts also apply while matching stuff, which
- can take a looong time for certain "evil" patterns.
- It passes the pattern matching unit tests from Lua 5.2's test suite, so
- that should be good enough. ]]
-do
- local CAP_UNFINISHED = -1
- local CAP_POSITION = -2
- local L_ESC = '%'
- local SPECIALS = "^$*+?.([%-"
- local SHORT_STRING = 500 -- use native implementations for short strings
-
- local string_find, string_lower, string_match, string_gmatch, string_gsub =
- string.find, string.lower, string.match, string.gmatch, string.gsub
-
- local match -- forward declaration
-
- local strptr
- local strptr_mt = {__index={
- step = function(self, count)
- self.pos = self.pos + (count or 1)
- return self
- end,
- head = function(self, len)
- return string.sub(self.data, self.pos, self.pos + (len or self:len()) - 1)
- end,
- len = function(self)
- return #self.data - (self.pos - 1)
- end,
- char = function(self, offset)
- local pos = self.pos + (offset or 0)
- if pos == #self.data + 1 then
- return "\0"
- end
- return string.sub(self.data, pos, pos)
- end,
- copy = function(self, offset)
- return strptr(self.data, self.pos + (offset or 0))
- end
- },
- __add = function(a, b)
- if type(b) == "table" then
- return a.pos + b.pos
- else
- return a:copy(b)
- end
- end,
- __sub = function(a, b)
- if type(b) == "table" then
- return a.pos - b.pos
- else
- return a:copy(-b)
- end
- end,
- __eq = function(a, b)
- return a.data == b.data and a.pos == b.pos
- end,
- __lt = function(a, b)
- assert(a.data == b.data)
- return a.pos < b.pos
- end,
- __le = function(a, b)
- assert(a.data == b.data)
- return a.pos <= b.pos
- end
- }
- function strptr(s, pos)
- return setmetatable({
- data = s,
- pos = pos or 1
- }, strptr_mt)
- end
-
- local function islower(b) return b >= 'a' and b <= 'z' end
- local function isupper(b) return b >= 'A' and b <= 'Z' end
- local function isalpha(b) return islower(b) or isupper(b) end
- local function iscntrl(b) return b <= '\007' or (b >= '\010' and b <= '\017') or (b >= '\020' and b <= '\027') or (b >= '\030' and b <= '\037' and b ~= ' ') or b == '\177' end
- local function isdigit(b) return b >= '0' and b <= '9' end
- local function ispunct(b) return (b >= '{' and b <= '~') or (b == '`') or (b >= '[' and b <= '_') or (b == '@') or (b >= ':' and b <= '?') or (b >= '(' and b <= '/') or (b >= '!' and b <= '\'') end
- local function isspace(b) return b == '\t' or b == '\n' or b == '\v' or b == '\f' or b == '\r' or b == ' ' end
- local function isalnum(b) return isalpha(b) or isdigit(b) end
- local function isxdigit(b) return isdigit(b) or (b >= 'a' and b <= 'f') or (b >= 'A' and b <= 'F') end
- local function isgraph(b) return not iscntrl(b) and not isspace(b) end
-
- -- translate a relative string position: negative means back from end
- local function posrelat(pos, len)
- if pos >= 0 then return pos
- elseif -pos > len then return 0
- else return len + pos + 1
- end
- end
-
- local function check_capture(ms, l)
- l = l - '1'
- if l < 0 or l >= ms.level or ms.capture[l].len == CAP_UNFINISHED then
- error("invalid capture index %" .. (l + 1))
- end
- return l
- end
-
- local function capture_to_close(ms)
- local level = ms.level
- while level > 0 do
- level = level - 1
- if ms.capture[level].len == CAP_UNFINISHED then
- return level
- end
- end
- return error("invalid pattern capture")
- end
-
- local function classend(ms, p)
- local p0 = p:char() p = p:copy(1)
- if p0 == L_ESC then
- if p == ms.p_end then
- error("malformed pattern (ends with %)")
- end
- return p:step(1)
- elseif p0 == '[' then
- if p:char() == '^' then
- p:step()
- end
- repeat -- look for a `]'
- if p == ms.p_end then
- error("malformed pattern (missing ])")
- end
- p:step()
- if p:char(-1) == L_ESC then
- if p < ms.p_end then
- p:step() -- skip escapes (e.g. `%]')
- end
- end
- until p:char() == ']'
- return p:step()
- else
- return p
- end
- end
-
- local function match_class(c, cl)
- local res
- local cll = string_lower(cl)
- if cll == 'a' then res = isalpha(c)
- elseif cll == 'c' then res = iscntrl(c)
- elseif cll == 'd' then res = isdigit(c)
- elseif cll == 'g' then res = isgraph(c)
- elseif cll == 'l' then res = islower(c)
- elseif cll == 'p' then res = ispunct(c)
- elseif cll == 's' then res = isspace(c)
- elseif cll == 'u' then res = isupper(c)
- elseif cll == 'w' then res = isalnum(c)
- elseif cll == 'x' then res = isxdigit(c)
- elseif cll == 'z' then res = c == '\0' -- deprecated option
- else return cl == c
- end
- if islower(cl) then return res
- else return not res
- end
- end
-
- local function matchbracketclass(c, p, ec)
- local sig = true
- p = p:copy(1)
- if p:char() == '^' then
- sig = false
- p:step() -- skip the `^'
- end
- while p < ec do
- if p:char() == L_ESC then
- p:step()
- if match_class(c, p:char()) then
- return sig
- end
- elseif p:char(1) == '-' and p + 2 < ec then
- p:step(2)
- if p:char(-2) <= c and c <= p:char() then
- return sig
- end
- elseif p:char() == c then
- return sig
- end
- p:step()
- end
- return not sig
- end
-
- local function singlematch(ms, s, p, ep)
- if s >= ms.src_end then
- return false
- end
- local p0 = p:char()
- if p0 == '.' then return true -- matches any char
- elseif p0 == L_ESC then return match_class(s:char(), p:char(1))
- elseif p0 == '[' then return matchbracketclass(s:char(), p, ep:copy(-1))
- else return p:char() == s:char()
- end
- end
-
- local function matchbalance(ms, s, p)
- if p >= ms.p_end - 1 then
- error("malformed pattern (missing arguments to %b)")
- end
- if s:char() ~= p:char() then return nil end
- local b = p:char()
- local e = p:char(1)
- local cont = 1
- s = s:copy()
- while s:step() < ms.src_end do
- if s:char() == e then
- cont = cont - 1
- if cont == 0 then return s:step() end
- elseif s:char() == b then
- cont = cont + 1
- end
- end
- return nil -- string ends out of balance
- end
-
- local function max_expand(ms, s, p, ep)
- local i = 0 -- counts maximum expand for item
- while singlematch(ms, s:copy(i), p, ep) do
- i = i + 1
- end
- -- keeps trying to match with the maximum repetitions
- while i >= 0 do
- local res = match(ms, s:copy(i), ep:copy(1))
- if res then return res end
- i = i - 1 -- else didn't match; reduce 1 repetition to try again
- end
- return nil
- end
-
- local function min_expand(ms, s, p, ep)
- s = s:copy()
- while true do
- local res = match(ms, s, ep:copy(1))
- if res ~= nil then
- return res
- elseif singlematch(ms, s, p, ep) then
- s:step() -- try with one more repetition
- else return nil
- end
- end
- end
-
- local function start_capture(ms, s, p, what)
- local level = ms.level
- ms.capture[level] = ms.capture[level] or {}
- ms.capture[level].init = s:copy()
- ms.capture[level].len = what
- ms.level = level + 1
- local res = match(ms, s, p)
- if res == nil then -- match failed?
- ms.level = ms.level - 1 -- undo capture
- end
- return res
- end
-
- local function end_capture(ms, s, p)
- local l = capture_to_close(ms)
- ms.capture[l].len = s - ms.capture[l].init -- close capture
- local res = match(ms, s, p)
- if res == nil then -- match failed?
- ms.capture[l].len = CAP_UNFINISHED -- undo capture
- end
- return res
- end
-
- local function match_capture(ms, s, l)
- l = check_capture(ms, l)
- local len = ms.capture[l].len
- if ms.src_end - s >= len and
- ms.capture[l].init:head(len) == s:head(len)
- then
- return s:copy(len)
- else return nil
- end
- end
-
- function match(ms, s, p)
- s = s:copy()
- p = p:copy()
- ::init:: -- using goto's to optimize tail recursion
- if p ~= ms.p_end then
- local p0 = p:char()
- if p0 == '(' then -- start capture
- if p:char(1) == ')' then -- position capture?
- s = start_capture(ms, s, p:copy(2), CAP_POSITION)
- else
- s = start_capture(ms, s, p:copy(1), CAP_UNFINISHED)
- end
- goto brk
- elseif p0 == ')' then -- end capture
- s = end_capture(ms, s, p:copy(1))
- goto brk
- elseif p0 == '$' then
- if p + 1 ~= ms.p_end then -- is the `$' the last char in pattern?
- goto dflt -- no; go to default
- end
- s = (s == ms.src_end) and s or nil -- check end of string
- goto brk
- elseif p0 == L_ESC then -- escaped sequences not in the format class[*+?-]?
- local p1 = p:char(1)
- if p1 == 'b' then -- balanced string?
- s = matchbalance(ms, s, p:copy(2))
- if s ~= nil then
- p:step(4)
- goto init -- return match(ms, s, p + 4)
- end
- -- else fail (s == nil)
- elseif p1 == 'f' then -- frontier?
- p:step(2)
- if p:char() ~= '[' then
- error("missing [ after %f in pattern")
- end
- local ep = classend(ms, p) -- points to what is next
- local previous = (s == ms.src_init) and '\0' or s:char(-1)
- if not matchbracketclass(previous, p, ep:copy(-1)) and
- matchbracketclass(s:char(), p, ep:copy(-1))
- then
- p = ep
- goto init -- return match(ms, s, ep)
- end
- s = nil -- match failed
- elseif isdigit(p:char(1)) then -- capture results (%0-%9)?
- s = match_capture(ms, s, p:char(1))
- if s ~= nil then
- p:step(2)
- goto init -- return match(ms, s, p + 2)
- end
- else
- goto dflt
- end
- goto brk
- end
- ::dflt:: do
- local ep = classend(ms, p) -- points to what is next
- local ep0 = ep:char()
- if not singlematch(ms, s, p, ep) then
- if ep0 == '*' or ep0 == '?' or ep0 == '-' then -- accept empty?
- p = ep:copy(1)
- goto init -- return match(ms, s, ep + 1)
- else -- '+' or no suffix
- s = nil -- fail
- end
- else -- matched once
- if ep0 == '?' then -- optional
- local res = match(ms, s:copy(1), ep:copy(1))
- if res ~= nil then
- s = res
- else
- p = ep:copy(1)
- goto init -- else return match(ms, s, ep + 1)
- end
- elseif ep0 == '+' then -- 1 or more repetitions
- s = max_expand(ms, s:copy(1), p, ep) -- 1 match already done
- elseif ep0 == '*' then -- 0 or more repetitions
- s = max_expand(ms, s, p, ep)
- elseif ep0 == '-' then -- 0 or more repetitions (minimum)
- s = min_expand(ms, s, p, ep)
- else
- s:step()
- p = ep
- goto init -- else return match(ms, s+1, ep);
- end
- end
- end
- ::brk::
- end
- return s
- end
-
- local function push_onecapture(ms, i, s, e)
- if i >= ms.level then
- if i == 0 then -- ms->level == 0, too
- return s:head(e - s) -- add whole match
- else
- error("invalid capture index")
- end
- else
- local l = ms.capture[i].len;
- if l == CAP_UNFINISHED then error("unfinished capture") end
- if l == CAP_POSITION then
- return ms.capture[i].init - ms.src_init + 1
- else
- return ms.capture[i].init:head(l)
- end
- end
- end
-
- local function push_captures(ms, s, e)
- local nlevels = (ms.level == 0 and s) and 1 or ms.level
- local captures = {}
- for i = 0, nlevels - 1 do
- table.insert(captures, push_onecapture(ms, i, s, e))
- end
- return table.unpack(captures)
- end
-
- -- check whether pattern has no special characters
- local function nospecials(p)
- for i = 1, #p do
- for j = 1, #SPECIALS do
- if p:sub(i, i) == SPECIALS:sub(j, j) then
- return false
- end
- end
- end
- return true
- end
-
- local function str_find_aux(str, pattern, init, plain, find)
- checkArg(1, str, "string")
- checkArg(2, pattern, "string")
- checkArg(3, init, "number", "nil")
-
- if #str < SHORT_STRING then
- return (find and string_find or string_match)(str, pattern, init, plain)
- end
-
- local s = strptr(str)
- local p = strptr(pattern)
- local init = posrelat(init or 1, #str)
- if init < 1 then init = 1
- elseif init > #str + 1 then -- start after string's end?
- return nil -- cannot find anything
- end
- -- explicit request or no special characters?
- if find and (plain or nospecials(pattern)) then
- -- do a plain search
- local s2 = string_find(str, pattern, init, true)
- if s2 then
- return s2-s.pos + 1, s2 - s.pos + p:len()
- end
- else
- local s1 = s:copy(init - 1)
- local anchor = p:char() == '^'
- if anchor then p:step() end
- local ms = {
- src_init = s,
- src_end = s:copy(s:len()),
- p_end = p:copy(p:len()),
- capture = {}
- }
- repeat
- ms.level = 0
- local res = match(ms, s1, p)
- if res ~= nil then
- if find then
- return s1.pos - s.pos + 1, res.pos - s.pos, push_captures(ms, nil, nil)
- else
- return push_captures(ms, s1, res)
- end
- end
- until s1:step() > ms.src_end or anchor
- end
- return nil -- not found
- end
-
- local function str_find(s, pattern, init, plain)
- return str_find_aux(s, pattern, init, plain, true)
- end
-
- local function str_match(s, pattern, init)
- return str_find_aux(s, pattern, init, false, false)
- end
-
- local function str_gmatch(s, pattern)
- checkArg(1, s, "string")
- checkArg(2, pattern, "string")
-
- if #s < SHORT_STRING then
- return string_gmatch(s, pattern, repl, n)
- end
-
- local s = strptr(s)
- local p = strptr(pattern)
- local start = 0
- return function()
- ms = {
- src_init = s,
- src_end = s:copy(s:len()),
- p_end = p:copy(p:len()),
- capture = {}
- }
- for offset = start, ms.src_end.pos - 1 do
- local src = s:copy(offset)
- ms.level = 0
- local e = match(ms, src, p)
- if e ~= nil then
- local newstart = e - s
- if e == src then newstart = newstart + 1 end -- empty match? go at least one position
- start = newstart
- return push_captures(ms, src, e)
- end
- end
- return nil -- not found
- end
- end
-
- local function add_s(ms, b, s, e, r)
- local news = tostring(r)
- local i = 1
- while i <= #news do
- if news:sub(i, i) ~= L_ESC then
- b = b .. news:sub(i, i)
- else
- i = i + 1 -- skip ESC
- if not isdigit(news:sub(i, i)) then
- b = b .. news:sub(i, i)
- elseif news:sub(i, i) == '0' then
- b = b .. s:head(e - s)
- else
- b = b .. push_onecapture(ms, news:sub(i, i) - '1', s, e) -- add capture to accumulated result
- end
- end
- i = i + 1
- end
- return b
- end
-
- local function add_value(ms, b, s, e, r, tr)
- local res
- if tr == "function" then
- res = r(push_captures(ms, s, e))
- elseif tr == "table" then
- res = r[push_onecapture(ms, 0, s, e)]
- else -- LUA_TNUMBER or LUA_TSTRING
- return add_s(ms, b, s, e, r)
- end
- if not res then -- nil or false?
- res = s:head(e - s) -- keep original text
- elseif type(res) ~= "string" and type(res) ~= "number" then
- error("invalid replacement value (a "..type(res)..")")
- end
- return b .. res -- add result to accumulator
- end
-
- local function str_gsub(s, pattern, repl, n)
- checkArg(1, s, "string")
- checkArg(2, pattern, "string")
- checkArg(3, repl, "number", "string", "function", "table")
- checkArg(4, n, "number", "nil")
-
- if #s < SHORT_STRING or type(repl) == "function" then
- return string_gsub(s, pattern, repl, n)
- end
-
- local src = strptr(s);
- local p = strptr(pattern)
- local tr = type(repl)
- local max_s = n or (#s + 1)
- local anchor = p:char() == '^'
- if anchor then
- p:step() -- skip anchor character
- end
- n = 0
- local b = ""
- local ms = {
- src_init = src:copy(),
- src_end = src:copy(src:len()),
- p_end = p:copy(p:len()),
- capture = {}
- }
- while n < max_s do
- ms.level = 0
- local e = match(ms, src, p)
- if e then
- n = n + 1
- b = add_value(ms, b, src, e, repl, tr)
- end
- if e and e > src then -- non empty match?
- src = e -- skip it
- elseif src < ms.src_end then
- b = b .. src:char()
- src:step()
- else break
- end
- if anchor then break end
- end
- b = b .. src:head()
- return b, n -- number of substitutions
- end
-
- string.find = str_find
- string.match = str_match
- string.gmatch = str_gmatch
- string.gsub = str_gsub
-end
-
--------------------------------------------------------------------------------
-
-local function spcall(...)
- local result = table.pack(pcall(...))
- if not result[1] then
- error(tostring(result[2]), 0)
- else
- return table.unpack(result, 2, result.n)
- end
-end
-
-local sgcco
-
-local function sgcf(self, gc)
- while true do
- self, gc = coroutine.yield(pcall(gc, self))
- end
-end
-
-local function sgc(self)
- local oldDeadline, oldHitDeadline = deadline, hitDeadline
- local mt = debug.getmetatable(self)
- mt = rawget(mt, "mt")
- local gc = rawget(mt, "__gc")
- if type(gc) ~= "function" then
- return
- end
- if not sgcco then
- sgcco = coroutine.create(sgcf)
- end
- debug.sethook(sgcco, checkDeadline, "", hookInterval)
- deadline, hitDeadline = math.min(oldDeadline, computer.realTime() + 0.5), true
- local _, result, reason = coroutine.resume(sgcco, self, gc)
- debug.sethook(sgcco)
- if coroutine.status(sgcco) == "dead" then
- sgcco = nil
- end
- deadline, hitDeadline = oldDeadline, oldHitDeadline
- if not result then
- error(reason, 0)
- end
-end
-
---[[ This is the global environment we make available to userland programs. ]]
--- You'll notice that we do a lot of wrapping of native functions and adding
--- parameter checks in those wrappers. This is to avoid errors from the host
--- side that would push error objects - which are userdata and cannot be
--- persisted.
-local sandbox, libprocess
-sandbox = {
- assert = assert,
- dofile = function(filename)
- local program, reason = loadfile(filename)
- if not program then
- return error(reason .. ':' .. filename, 0)
- end
- return program()
- end, -- in boot/*_base.lua
- error = error,
- _G = nil, -- see below
- getmetatable = function(t)
- if type(t) == "string" then -- don't allow messing with the string mt
- return nil
- end
- local result = getmetatable(t)
- -- check if we have a wrapped __gc using mt
- if type(result) == "table" and system.allowGC() and rawget(result, "__gc") == sgc then
- result = rawget(result, "mt")
- end
- return result
- end,
- ipairs = ipairs,
- load = function(ld, source, mode, env)
- if not system.allowBytecode() then
- mode = "t"
- end
- return load(ld, source, mode, env or sandbox)
- end,
- loadfile = function(filename, mode, env)
- local file, reason = io.open(filename)
- if not file then
- return nil, reason
- end
- local source, reason = file:read("*a")
- file:close()
- if not source then
- return nil, reason
- end
- if string.sub(source, 1, 1) == "#" then
- local endline = string.find(source, "\n", 2, true)
- if endline then
- source = string.sub(source, endline + 1)
- else
- source = ""
- end
- end
- return load(source, "=" .. filename, mode, env)
- end, -- in boot/*_base.lua
- next = next,
- pairs = pairs,
- pcall = function(...)
- local result = table.pack(pcall(...))
- checkDeadline()
- return table.unpack(result, 1, result.n)
- end,
- print = _G.print, -- in boot/*_base.lua
- rawequal = rawequal,
- rawget = rawget,
- rawlen = rawlen,
- rawset = rawset,
- select = select,
- setmetatable = function(t, mt)
- if type(mt) ~= "table" then
- return setmetatable(t, mt)
- end
- if rawget(mt, "__gc") ~= nil then -- If __gc is set to ANYTHING not `nil`, we're gonna have issues
- -- Garbage collector callbacks apparently can't be sandboxed after
- -- all, because hooks are disabled while they're running. So we just
- -- disable them altogether by default.
- if system.allowGC() then
- -- For all user __gc functions we enforce a much tighter deadline.
- -- This is because these functions may be called from the main
- -- thread under certain circumstanced (such as when saving the world),
- -- which can lead to noticeable lag if the __gc function behaves badly.
- local sbmt = {} -- sandboxed metatable. only for __gc stuff, so it's
- -- kinda ok to have a shallow copy instead... meh.
- for k, v in next, mt do
- sbmt[k] = v
- end
- sbmt.__gc = sgc
- sbmt.mt = mt
- mt = sbmt
- else
- -- Don't allow marking for finalization, but use the raw metatable.
- local gc = rawget(mt, "__gc")
- rawset(mt, "__gc", nil) -- remove __gc
- local ret = table.pack(pcall(setmetatable, t, mt))
- rawset(mt, "__gc", gc) -- restore __gc
- if not ret[1] then error(ret[2], 0) end
- return table.unpack(ret, 2, ret.n)
- end
- end
- return setmetatable(t, mt)
- end,
- tonumber = tonumber,
- tostring = tostring,
- type = type,
- _VERSION = _VERSION:match("5.3") and "Lua 5.3" or "Lua 5.2",
- xpcall = function(f, msgh, ...)
- local handled = false
- local result = table.pack(xpcall(f, function(...)
- if handled then
- return ...
- else
- handled = true
- return msgh(...)
- end
- end, ...))
- checkDeadline()
- return table.unpack(result, 1, result.n)
- end,
-
- coroutine = {
- create = coroutine.create,
- resume = function(co, ...) -- custom resume part for bubbling sysyields
- checkArg(1, co, "thread")
- local args = table.pack(...)
- while true do -- for consecutive sysyields
- debug.sethook(co, checkDeadline, "", hookInterval)
- local result = table.pack(
- coroutine.resume(co, table.unpack(args, 1, args.n)))
- debug.sethook(co) -- avoid gc issues
- checkDeadline()
- if result[1] then -- success: (true, sysval?, ...?)
- if coroutine.status(co) == "dead" then -- return: (true, ...)
- return true, table.unpack(result, 2, result.n)
- elseif result[2] ~= nil then -- yield: (true, sysval)
- args = table.pack(coroutine.yield(result[2]))
- else -- yield: (true, nil, ...)
- return true, table.unpack(result, 3, result.n)
- end
- else -- error: result = (false, string)
- return false, result[2]
- end
- end
- end,
- running = coroutine.running,
- status = coroutine.status,
- wrap = function(f) -- for bubbling coroutine.resume
- local co = coroutine.create(f)
- return function(...)
- local result = table.pack(sandbox.coroutine.resume(co, ...))
- if result[1] then
- return table.unpack(result, 2, result.n)
- else
- error(result[2], 0)
- end
- end
- end,
- yield = function(...) -- custom yield part for bubbling sysyields
- return coroutine.yield(nil, ...)
- end
- },
-
- string = {
- byte = string.byte,
- char = string.char,
- dump = string.dump,
- find = string.find,
- format = string.format,
- gmatch = string.gmatch,
- gsub = string.gsub,
- len = string.len,
- lower = string.lower,
- match = string.match,
- rep = string.rep,
- reverse = string.reverse,
- sub = string.sub,
- upper = string.upper
- },
-
- table = {
- concat = table.concat,
- insert = table.insert,
- pack = table.pack,
- remove = table.remove,
- sort = table.sort,
- unpack = table.unpack
- },
-
- math = {
- abs = math.abs,
- acos = math.acos,
- asin = math.asin,
- atan = math.atan,
- atan2 = math.atan2,
- ceil = math.ceil,
- cos = math.cos,
- cosh = math.cosh,
- deg = math.deg,
- exp = math.exp,
- floor = math.floor,
- fmod = math.fmod,
- frexp = math.frexp,
- huge = math.huge,
- ldexp = math.ldexp,
- log = math.log,
- max = math.max,
- min = math.min,
- modf = math.modf,
- pi = math.pi,
- pow = math.pow or function(a, b) -- Deprecated in Lua 5.3
- return a^b
- end,
- rad = math.rad,
- random = function(...)
- return spcall(math.random, ...)
- end,
- randomseed = function(seed)
- spcall(math.randomseed, seed)
- end,
- sin = math.sin,
- sinh = math.sinh,
- sqrt = math.sqrt,
- tan = math.tan,
- tanh = math.tanh
- },
-
- -- Deprecated in Lua 5.3.
- bit32 = bit32 and {
- arshift = bit32.arshift,
- band = bit32.band,
- bnot = bit32.bnot,
- bor = bit32.bor,
- btest = bit32.btest,
- bxor = bit32.bxor,
- extract = bit32.extract,
- replace = bit32.replace,
- lrotate = bit32.lrotate,
- lshift = bit32.lshift,
- rrotate = bit32.rrotate,
- rshift = bit32.rshift
- },
-
- io = nil, -- in lib/io.lua
-
- os = {
- clock = os.clock,
- date = function(format, time)
- return spcall(os.date, format, time)
- end,
- difftime = function(t2, t1)
- return t2 - t1
- end,
- execute = nil, -- in boot/*_os.lua
- exit = nil, -- in boot/*_os.lua
- remove = nil, -- in boot/*_os.lua
- rename = nil, -- in boot/*_os.lua
- time = function(table)
- checkArg(1, table, "table", "nil")
- return os.time(table)
- end,
- tmpname = nil, -- in boot/*_os.lua
- },
-
- debug = {
- getinfo = function(...)
- local result = debug.getinfo(...)
- if result then
- -- Only make primitive information available in the sandbox.
- return {
- source = result.source,
- short_src = result.short_src,
- linedefined = result.linedefined,
- lastlinedefined = result.lastlinedefined,
- what = result.what,
- currentline = result.currentline,
- nups = result.nups,
- nparams = result.nparams,
- isvararg = result.isvararg,
- name = result.name,
- namewhat = result.namewhat,
- istailcall = result.istailcall
- }
- end
- end,
- traceback = debug.traceback
- },
-
-
- checkArg = checkArg
-}
-sandbox._G = sandbox
-
--------------------------------------------------------------------------------
-
--- path for any ingame libraries
-package.path = "/net/torvald/terrarum/virtualcomputer/assets/lua/?.lua;" .. package.path
-
-local screenbufferdim = term.width() * term.height()
-local screencolours = 4
-if term.isCol() then screencolours = 8
-elseif term.isTeletype() then screencolours = 1 end
-local screenbuffersize = screenbufferdim * screencolours / 8
-
-if not computer.prompt then computer.prompt = DC3.."> "..DC4 end
-if not computer.verbose then computer.verbose = true end -- print debug info
-if not computer.loadedCLayer then computer.loadedCLayer = {} end -- list of loaded compatibility layers
--- if no bootloader is pre-defined via EFI, use default one
-if not computer.bootloader then computer.bootloader = "boot/efi" end
-if not computer.OEM then computer.OEM = "" end
-machine.totalMemory = _G.totalMemory
-if not computer.bellpitch then computer.bellpitch = 950 end
-local getMemory = function()
- collectgarbage()
- return collectgarbage("count") * 1024 - 6.5*1048576 + screenbuffersize
-end -- that magic number: how much basic system takes
--- totalMemory: implemented in Kotlin class
-machine.freeMemory = function() return totalMemory() - getMemory() end
-
--- load libraries that coded in Lua
-require("ROMLIB")
-
--- POST passed, initialise beeper
-speaker.enqueue(80, computer.bellpitch) -- term.bell sometimes get squelched
-
--- load bios, if any
-if fs.exists(computer.bootloader) then fs.dofile(computer.bootloader) end
-
--- halt/run luaprompt upon the termination of bios.
--- Valid BIOS should load OS and modify 'shell.status' to 'shell.halt' before terminating itself.
-if shell.status == shell.halt then __haltsystemexplicit__() goto quit end
-
--- load Lua prompt, if bios is not found
-dofile "/net/torvald/terrarum/virtualcomputer/assets/lua/TBASIC.lua"
-
-::quit::
-machine.closeInputString()
-return
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/luaold/BRAINFUCK.lua b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/luaold/BRAINFUCK.lua
deleted file mode 100644
index ab82a8745..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/luaold/BRAINFUCK.lua
+++ /dev/null
@@ -1,47 +0,0 @@
---[[
-From https://github.com/prapin/LuaBrainFuck/blob/master/brainfuck.lua
-
-LuaBrainFuck License
---------------------
-
-LuaBrainFuck is placed under the same license as Lua itself,
-so licensed under terms of the MIT license reproduced below.
-This means that the library is free software and can be used for both academic
-and commercial purposes at absolutely no cost.
-
-===============================================================================
-
-Copyright (C) 2012 Patrick Rapin, CH-1543 Grandcour
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-
-===============================================================================
-
-(end of COPYRIGHT)
-
-Example usage: require "brainfuck" "+++>>> your BF code here <<<---"
- ]]
-return function(s)
- local subst = {["+"]="v=v+1 ", ["-"]="v=v-1 ", [">"]="i=i+1 ", ["<"]="i=i-1 ",
- ["."] = "w(v)", [","]="v=r()", ["["]="while v~=0 do ", ["]"]="end "}
- local env = setmetatable({ i=0, t=setmetatable({},{__index=function() return 0 end}),
- r=function() return io.read(1):byte() end, w=function(c) io.write(string.char(c)) end },
- {__index=function(t,k) return t.t[t.i] end, __newindex=function(t,k,v) t.t[t.i]=v end })
- load(s:gsub("[^%+%-<>%.,%[%]]+",""):gsub(".", subst), "brainfuck", "t", env)()
-end
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/luaold/CCAPI.lua b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/luaold/CCAPI.lua
deleted file mode 100644
index db36fa7b7..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/luaold/CCAPI.lua
+++ /dev/null
@@ -1,159 +0,0 @@
---[[
--- ComputerCraft API compatibility layer
- Usage: require("CCAPI")
-
- Created by minjaesong on 2016-09-16.
---]]
-
---------------
--- PREAMBLE --
---------------
-
-if term.isTeletype() then error("This is a teletype; cannot use CCAPI layer") end
-
-
-table.insert(computer.loadedCLayer, "CCAPI")
-
-
-local function intLog2(i)
- if i == 0 then return 0 end
- local log = 0
- if bit32.band(i, 0xffff0000) ~= 0 then i = bit32.rshift(i, 16) log = 16 end
- if i >= 256 then i = bit32.rshift(i, 8) log = log + 8 end
- if i >= 16 then i = bit32.rshift(i, 8) log = log + 4 end
- if i >= 4 then i = bit32.rshift(i, 8) log = log + 2 end
- return log + bit32.rshift(i, 1)
-end
-
-
------------------------
--- BIT API Extension --
------------------------
-
-bit.blshift = bit32.lshift(n, bits)
-bit.brshift = bit32.arshift(n, bits)
-bit.blogic_rshift = bit32.rshift(n, bits)
-
-
-----------------
--- COLORS API --
-----------------
-
-_G.colors = {}
-
-colors.white = 0x1
-colors.orange = 0x2
-colors.magenta = 0x4
-colors.lightBlue = 0x8
-colors.yellow = 0x10
-colors.lime = 0x20
-colors.pink = 0x40
-colors.gray = 0x80
-colors.grey = 0x80
-colors.lightGray = 0x100
-colors.lightGrey = 0x100
-colors.cyan = 0x200
-colors.purple = 0x400
-colors.blue = 0x800
-colors.brown = 0x1000
-colors.green = 0x2000
-colors.red = 0x4000
-colors.black = 0x8000
-
-local function normaliseCCcol(cccol)
- if cccol >= 0x1 and cccol <= 0xFFFF then
- return intLog2(cccol)
- else
- error("invalid CC Colors: "..cccol)
- end
-end
-
-
-_G.colours = _G.colors
-
-
---------------
--- TERM API --
---------------
-
--- paint_index -> Terminal colour index
-local ccToGameCol = {--pink
- 1, 5, 7, 10, 4, 11, 15, 2, 3, 10, 8, 9, 14, 12, 6, 0
-}
-
--- "a" -> 10, "3" -> 3
-local function cHexToInt(c)
- if type(c) == "number" then -- char
- if c >= 48 and c <= 57 then
- return c - 48
- elseif c >= 65 and c <= 70 then
- return c - 65 + 10
- elseif c >= 97 and c <= 102 then
- return c - 97 + 10
- else
- return 0
- end
- elseif type(c) == "string" then -- single-letter string
- if c:byte(1) >= 48 and c:byte(1) <= 57 then
- return c:byte(1) - 48
- elseif c:byte(1) >= 65 and c:byte(1) <= 70 then
- return c:byte(1) - 65 + 10
- elseif c:byte(1) >= 97 and c:byte(1) <= 102 then
- return c:byte(1) - 97 + 10
- else
- --error("unrepresentable: " .. c)
- -- return black, as defined in http://www.computercraft.info/wiki/Term.blit
- return 0
- end
- else
- error("bad argument (string or number expected, got "..type(c)..")")
- end
-end
-
--- str, str, str
-term.blit = function(text, foreCol, backCol)
- assert(
- type(text) == "string" and type(backCol) == "string" and type(foreCol) == "string",
- "bad argument: (string, string, string expected, got "..type(text)..", "..type(foreCol)..", "..type(backCol)..")"
- )
- if #text ~= #foreCol or #text ~= #backCol or #foreCol ~= #backCol then
- error("arguments must be the same length")
- end
-
- for i = 1, #text do
- term.setForeCol(ccToGameCol[1 + cHexToInt(foreCol:byte(i))])
- term.setBackCol(ccToGameCol[1 + cHexToInt(backCol:byte(i))])
- term.emit(text:byte(i))
- term.moveCursor(term.getX() + 1, term.getY())
- end
-end
-
-term.getCursorPos = term.getCursor
-term.setCursorPos = term.moveCursor
-term.setCursorBlink = term.blink
-term.isColor = term.isCol
-term.getSize = term.size
-term.setTextColor = function(cccol) term.setForeCol(ccToGameCol[normaliseCCcol(cccol)]) end
-term.getTextColor = term.getForeCol
-term.setBackgroundColor = function(cccol) term.setBackCol(ccToGameCol[normaliseCCcol(cccol)]) end
-term.getBackgroundColor = term.getBackCol
-
-
---------------------
--- FILESYSTEM API --
---------------------
-
-fs.makeDir = fs.mkdir
-fs.move = fs.mv
-fs.copy = fs.cp
-fs.delete = fs.rm
-fs.combine = fs.concat
-fs.getDir = fs.parent
-fs.run = fs.dofile
-
-
-------------------
--- DOWN AND OUT --
-------------------
-
-if computer.verbose then print("ComputerCraft compatibility layer successfully loaded.") end
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/luaold/ROMLIB.lua b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/luaold/ROMLIB.lua
deleted file mode 100644
index 3521556bb..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/luaold/ROMLIB.lua
+++ /dev/null
@@ -1,434 +0,0 @@
---[[
- Created by minjaesong on 2016-09-15.
---]]
-
--------------
--- ALIASES --
--------------
-
---_G.io = {} -- we make our own sandbox'd system
-
---[[fs.dofile = function(p, ...)
- local f = fs.open(p, "r")
- local s = f.readAll()
- _G.runscript(s, "="..p, ...)
-end]] -- implementation moved to BOOT.lua
-
-_G.loadstring = _G.load
-
---_G.dofile = function(f) fs.dofile(f) end
-
-
-fs.fetchText = function(p)
- local file = fs.open(p, "r")
- local text = file.readAll()
- file.close()
- return text
-end
-
------------------------------------------
--- INPUTSTREAM AND SCANNER (java-like) --
------------------------------------------
---[[
-In whatever code that actually runs everything (computer),
- there must be:
-
-override fun keyPressed(key: Int, c: Char) {
- super.keyPressed(key, c)
- vt.keyPressed(key, c)
-
- if (key == Key.RETURN) {
- val input = vt.closeInputString()
- }
-}
-
-...it basically says to close the input if RETURN is hit,
- and THIS exact part will close the input for this function.
-]]
-_G.__scanforline__ = function(echo) -- pass '1' to not echo; pass nothing to echo
- machine.closeInputString()
- machine.openInput(echo or 0)
- _G.__scanMode__ = "line"
- local s
- repeat -- we can do this ONLY IF lua execution process is SEPARATE THREAD
- s = machine.__readFromStdin()
- until s
- -- input is closed when RETURN is hit. See above comments.
- return s
-end
-
--- use Keys API to identify the keycode
---[[_G.__scanforkey__ = function(echo) -- pass '1' to not echo; pass nothing to echo
- machine.closeInputString()
- machine.openInput(echo or 0)
- _G.__scanMode__ = "a_key"
- local key
- repeat -- we can do this ONLY IF lua execution process is SEPARATE THREAD
- key = machine.getLastKeyPress()
- until key
- -- input is closed when any key is hit. See above comments.
- return key
-end]] -- DELETED: use _G.input.isKeyDown(keycode)
-
---- ---
--- IO IMPLEMENTATION --
---- ---
-
-
-io.__openfile__ = "stdin"
-io.stdin = "stdin"
-io.stdout = "stdout"
-io.stderr = "stderr"
-
-io.open = fs.open
-
-io.input = function(luafile)
- io.__openfile__ = luafile
-end
-
-io.read = function(option)
- if io.__openfile__ == "stdin" then
- local input = {}
-
- -- RETURN not hit
- while true do
- local inkey = machine.__readFromStdin()
- if inkey == 13 or inkey == 10 then
- break
- elseif inkey == 8 or inkey == 127 then
- io.write(string.char(inkey))
- table.remove(input)
- elseif inkey > 0 then
- io.write(string.char(inkey))
- table.insert(input, string.char(inkey))
- end
- end
- -- RETURN finally hit
- io.write("\n")
-
- return table.concat(input)
- end
-
- function _readAll()
- return io.open(io.__openfile__).readAll()
- end
-
- function _readLine()
- return io.open(io.__openfile__).readLine()
- end
-
- options = {}
- options["*n"] = function() error("Read number is not supported, yet!") end--_readNumber
- options["*a"] = _readAll
- options["*l"] = _readLine
-end
-
------------------
--- PRINTSTREAM --
------------------
-
--- only useful when IO is "opening" stdin
---[[io.write = function(...)
- local args = {...}
- for _, v in ipairs(args) do
- local s
- if v == nil then
- s = "nil"
- else
- s = tostring(v)
- end
- term.write(s)
- end
-end]]
--- for some reason, inputstream above kills 'print' function.
--- So we rewrite it.
---[[_G.print = function(...) -- dependent on above io.write reimpl
- local args = {...}
-
- io.write(args[1])
-
- if (#args > 1) then
- for i = 2, #args do
- io.write("\t")
- io.write(args[i])
- end
- end
-
- io.write("\n")
-end]]
-
-
----------------
--- SHELL API --
----------------
-
-_G.shell = {}
-shell.status = shell.ok
-
--- run a script with path (string) and argstable (table)
-shell.run = function(path, argstable)
- -- check for interpreter key "#!"
- local f = fs.open(path, "r")
- local s = f.readAll()
- f.close()
-
- if s:sub(1,2) == "#!" then
- local interpreter = s:sub(3)
- if not argstable then
- xpcall(function() fs.dofile(interpreter..".lua", path) end, function(err) print(DLE..err) end)
- else
- xpcall(function() fs.dofile(interpreter..".lua", path, table.unpack(argstable)) end, function(err) print(DLE..err) end)
- end
- else
- if not argstable then
- xpcall(function() fs.dofile(path) end, function(err) print(DLE..err) end)
- else
- xpcall(function() fs.dofile(path, table.unpack(argstable)) end, function(err) print(DLE..err) end)
- end
- end
-end
-
-
-shell.ok = 0
-shell.halt = 127
-
-
---------------
--- HEXUTILS --
---------------
-
-_G.hexutils = {}
-
-_G.hexutils.toHexString = function(byteString)
- assert(type(byteString) == "string", error("Expected string."))
-
- -- speedup
- local function iToHex(i)
- if i == 0 then return "0"
- elseif i == 1 then return "1"
- elseif i == 2 then return "2"
- elseif i == 3 then return "3"
- elseif i == 4 then return "4"
- elseif i == 5 then return "5"
- elseif i == 6 then return "6"
- elseif i == 7 then return "7"
- elseif i == 8 then return "8"
- elseif i == 9 then return "9"
- elseif i == 10 then return "a"
- elseif i == 11 then return "b"
- elseif i == 12 then return "c"
- elseif i == 13 then return "d"
- elseif i == 14 then return "e"
- elseif i == 15 then return "f"
- else error("unrepresentable: " .. i)
- end
- end
-
- local ret = ""
-
- for i = 1, #byteString do
- local c = byteString:byte(i)
- local msb = iToHex(bit32.rshift(c, 4) % 16)
- local lsb = iToHex(c % 16)
-
- ret = ret .. (msb .. lsb)
- end
-
- return ret
-end
-
-
---------------
--- KEYS API --
---------------
--- ComputerCraft compliant
-local keycodeNumToName = {
- ["30"] = "a",
- ["48"] = "b",
- ["46"] = "c",
- ["32"] = "d",
- ["18"] = "e",
- ["33"] = "f",
- ["34"] = "g",
- ["35"] = "h",
- ["23"] = "i",
- ["36"] = "j",
- ["37"] = "k",
- ["38"] = "l",
- ["50"] = "m",
- ["49"] = "n",
- ["24"] = "o",
- ["25"] = "p",
- ["16"] = "q",
- ["19"] = "r",
- ["31"] = "s",
- ["20"] = "t",
- ["22"] = "u",
- ["47"] = "v",
- ["17"] = "w",
- ["45"] = "x",
- ["21"] = "y",
- ["44"] = "z",
- ["2"] = "one",
- ["3"] = "two",
- ["4"] = "three",
- ["5"] = "four",
- ["6"] = "five",
- ["7"] = "six",
- ["8"] = "seven",
- ["9"] = "eight",
- ["10"] = "nine",
- ["11"] = "zero",
- ["12"] = "minus",
- ["13"] = "equals",
- ["14"] = "backspace",
- ["15"] = "tab",
- ["26"] = "leftBracket",
- ["27"] = "rightBracket",
- ["28"] = "enter",
- ["29"] = "leftCtrl",
- ["39"] = "semiColon",
- ["40"] = "apostrophe",
- ["41"] = "grave",
- ["42"] = "leftShift",
- ["43"] = "backslash",
- ["51"] = "comma",
- ["52"] = "period",
- ["53"] = "slash",
- ["54"] = "rightShift",
- ["55"] = "multiply",
- ["56"] = "leftAlt",
- ["57"] = "space",
- ["58"] = "capsLock",
- ["59"] = "f1",
- ["60"] = "f2",
- ["61"] = "f3",
- ["62"] = "f4",
- ["63"] = "f5",
- ["64"] = "f6",
- ["65"] = "f7",
- ["66"] = "f8",
- ["67"] = "f9",
- ["68"] = "f10",
- ["69"] = "numLock",
- ["70"] = "scollLock",
- ["87"] = "f11",
- ["88"] = "f12",
- ["89"] = "f13",
- ["90"] = "f14",
- ["91"] = "f15",
- ["144"] = "cimcumflex",
- ["145"] = "at",
- ["146"] = "colon",
- ["147"] = "underscore",
- ["157"] = "rightCtrl",
- ["184"] = "rightAlt",
- ["197"] = "pause",
- ["199"] = "home",
- ["200"] = "up",
- ["201"] = "pageUp",
- ["203"] = "left",
- ["205"] = "right",
- ["207"] = "end",
- ["208"] = "down",
- ["209"] = "pageDown",
- ["210"] = "insert",
- ["211"] = "delete",
- ["219"] = "leftCommand"
-}
-
-_G.keys = {
- ["a"] = 30,
- ["b"] = 48,
- ["c"] = 46,
- ["d"] = 32,
- ["e"] = 18,
- ["f"] = 33,
- ["g"] = 34,
- ["h"] = 35,
- ["i"] = 23,
- ["j"] = 36,
- ["k"] = 37,
- ["l"] = 38,
- ["m"] = 50,
- ["n"] = 49,
- ["o"] = 24,
- ["p"] = 25,
- ["q"] = 16,
- ["r"] = 19,
- ["s"] = 31,
- ["t"] = 20,
- ["u"] = 22,
- ["v"] = 47,
- ["w"] = 17,
- ["x"] = 45,
- ["y"] = 21,
- ["z"] = 44,
- ["one"] = 2,
- ["two"] = 3,
- ["three"] = 4,
- ["four"] = 5,
- ["five"] = 6,
- ["six"] = 7,
- ["seven"] = 8,
- ["eight"] = 9,
- ["nine"] = 10,
- ["zero"] = 11,
- ["minus"] = 12,
- ["equals"] = 13,
- ["backspace"] = 14,
- ["tab"] = 15,
- ["leftBracket"] = 26,
- ["rightBracket"] = 27,
- ["enter"] = 28,
- ["leftCtrl"] = 29,
- ["semiColon"] = 39,
- ["apostrophe"] = 40,
- ["grave"] = 41,
- ["leftShift"] = 42,
- ["backslash"] = 43,
- ["comma"] = 51,
- ["period"] = 52,
- ["slash"] = 53,
- ["rightShift"] = 54,
- ["multiply"] = 55,
- ["leftAlt"] = 56,
- ["space"] = 57,
- ["capsLock"] = 58,
- ["f1"] = 59,
- ["f2"] = 60,
- ["f3"] = 61,
- ["f4"] = 62,
- ["f5"] = 63,
- ["f6"] = 64,
- ["f7"] = 65,
- ["f8"] = 66,
- ["f9"] = 67,
- ["f10"] = 68,
- ["numLock"] = 69,
- ["scollLock"] = 70,
- ["f11"] = 87,
- ["f12"] = 88,
- ["f13"] = 89,
- ["f14"] = 90,
- ["f15"] = 91,
- ["cimcumflex"] = 144,
- ["at"] = 145,
- ["colon"] = 146,
- ["underscore"] = 147,
- ["rightCtrl"] = 157,
- ["rightAlt"] = 184,
- ["pause"] = 197,
- ["home"] = 199,
- ["up"] = 200,
- ["pageUp"] = 201,
- ["left"] = 203,
- ["right"] = 205,
- ["end"] = 207,
- ["down"] = 208,
- ["pageDown"] = 209,
- ["insert"] = 210,
- ["delete"] = 211,
- ["leftCommand"] = 219
-}
-_G.keys.getName = function(code) return keycodeNumToName[tostring(code)] end
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/luaold/TBASEXEC.lua b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/luaold/TBASEXEC.lua
deleted file mode 100644
index 90df86867..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/luaold/TBASEXEC.lua
+++ /dev/null
@@ -1,497 +0,0 @@
---[[
-TBASIC: Simple BASIC language based on the Commodore BASIC Version 2.
-
-(C64 rulz? Nope.)
-
-
-How to use in your program:
-
- 1. load the script by:
- if you're using ComputerCraft, use:
- os.loadAPI "TBASEXEC.lua"
- else, use:
- require "TBASEXEC"
-
- 2. run:
- _TBASIC.EXEC(string of whole command)
-]]
-
-if os and os.loadAPI then -- ComputerCraft
- os.loadAPI "TBASINCL.lua"
-else
- require "TBASINCL"
-end
-
-table.concat = function(t, delimeter)
- if #t == 0 then return "" end
- local outstr = t[1]
- for i = 2, #t do
- outstr = outstr..delimeter..tostring(t[i])
- end
-
- return outstr
-end
-
--- Copy from TBASINCL; looks like OpenComputers has a bug...
-function string_hash(str)
- local hash = 2166136261
- for i = 1, #str do
- hash = hash * 16777619
- hash = bit.bxor(hash, str:byte(i))
- end
- return hash
-end
-
-
-
-
-
--- INTERPRETER STATUS ---------------------------------------------------------
-
-local programlist = {}
-
--- LEXER ----------------------------------------------------------------------
-
-local function appendcommand(lineno, statement)
- if lineno > _TBASIC._INTPRTR.MAXLINES then
- _TBASIC._ERROR.LINETOOBIG()
- elseif lineno < 0 then
- _TBASIC._ERROR.NOLINENUM()
- else
- programlist[lineno] = statement
- end
-end
-
-do -- Avoid heap allocs for performance
- local tokens = {" ", "\t", ",", "(", ")"} -- initial obvious tokens
- local longest_token_len = 0
- -- build 'tokens' table from list of operators from the language
- for _, v in ipairs(_TBASIC._OPERATR) do
- if not v:match("[A-Za-z]") then -- we want non-alphabetic operators as a token
- table.insert(tokens, v)
- -- get longest_token_len, will be used for 'lookahead'
- local tokenlen = #v
- if longest_token_len < #v then
- longest_token_len = #v
- end
- end
- end
- -- sort them out using ther hash for binary search
- table.sort(tokens, function(a, b) return string_hash(a) < string_hash(b) end)
-
-
- function parsewords(line)
- if line == nil then return end
-
- -----------------------
- -- check line sanity --
- -----------------------
-
- -- filter for IF statement
- if line:sub(1, 2):upper() == "IF" then
- -- no matching THEN
- if not line:match("[Tt][Hh][Ee][Nn]") then
- _TBASIC._ERROR.NOMATCHING("IF", "THEN")
- -- assignment on IF clause
- elseif line:match("[Ii][Ff][^\n]+[Tt][Hh][Ee][Nn]"):match("[^=+%-*/%%<>!]=[^=<>]") or
- line:match("[Ii][Ff][^\n]+[Tt][Hh][Ee][Nn]"):match(":=") then
- _TBASIC._ERROR.ASGONIF()
- end
- end
-
- --------------------------------------------------
- -- automatically infer and insert some commands --
- --------------------------------------------------
- -- (This is starting to get dirty...)
-
- -- unary minus
- for matchobj in line:gmatch("%-[0-9]+") do
- local newline = line:gsub(matchobj, "MINUS "..matchobj:sub(2, #matchobj))
- line = newline
- end
- -- conditional for IF
- -- if IF statement has no appended paren
- if line:sub(1, 2):upper() == "IF" and not line:match("[Ii][Ff][ ]*%(") then
- local newline = line:gsub("[Ii][Ff]", "IF ( ", 1):gsub("[Tt][Hh][Ee][Nn]", " ) THEN", 1)
- line = newline
- end
- -- special treatment for FOR
- if line:sub(1, 3):upper() == "FOR" then
- if line:match("[0-9]?%.[0-9]") then -- real number used (e.g. "3.14", ".5")
- _TBASIC._ERROR.ILLEGALARG()
- else
- local varnameintm = line:match(" [^\n]+[ =]")
-
- if varnameintm then
- local varname = varnameintm:match("[^= ]+")
- if varname then
- local newline = line:gsub(" "..varname.."[ =]", " $"..varname.." "..varname.." = ")
- line = newline:gsub("= =", "=")
- else
- _TBASIC._ERROR.SYNTAX()
- end
- end
- -- basically, "FOR x x = 1 TO 10", which converts to "x x 1 10 TO = FOR",
- -- which is executed (in RPN) in steps of:
- -- "x x 1 10 TO = FOR"
- -- "x x (arr) = FOR"
- -- "x FOR" -- see this part? we need extra 'x' to feed for the FOR statement to function
- end
- end
-
-
-
- printdbg("parsing line", line)
-
-
-
- lextable = {}
- isquote = false
- quotemode = false
- wordbuffer = ""
- local function flush()
- if (#wordbuffer > 0) then
- table.insert(lextable, wordbuffer)
- wordbuffer = ""
- end
- end
- local function append(char)
- wordbuffer = wordbuffer..char
- end
- local function append_no_whitespace(char)
- if char ~= " " and char ~= "\t" then
- wordbuffer = wordbuffer..char
- end
- end
-
- -- return: lookless_count on success, nil on failure
- local function isdelimeter(string)
- local cmpval = function(table_elem) return string_hash(table_elem) end
- local lookless_count = #string
- local ret = nil
- repeat
- ret = table.binsearch(tokens, string:sub(1, lookless_count), cmpval)
- lookless_count = lookless_count - 1
- until ret or lookless_count < 1
- return ret and lookless_count + 1 or false
- end
-
- local i = 1 -- Lua Protip: variable in 'for' is immutable, and is different from general variable table, even if they have same name
- while i <= #line do
- local c = string.char(line:byte(i))
-
- local lookahead = line:sub(i, i+longest_token_len)
-
- if isquote then
- if c == [["]] then
- flush()
- isquote = false
- else
- append(c)
- end
- else
- if c == [["]] then
- isquote = true
- append_no_whitespace("~")
- else
- local delimsize = isdelimeter(lookahead) -- returns nil if no matching delimeter found
- if delimsize then
- flush() -- flush buffer
- append_no_whitespace(lookahead:sub(1, delimsize))
- flush() -- flush this delimeter
- i = i + delimsize - 1
- else
- append_no_whitespace(c)
- end
- end
- end
-
- i = i + 1
- end
- flush() -- don't forget this!
-
-
- return lextable
- end
-end
-
-local function readprogram(program)
- for line in program:gmatch("[^\n]+") do
- lineno = line:match("[0-9]+ ", 1)
-
- if not lineno then
- _TBASIC._ERROR.NOLINENUM()
- end
-
- statement = line:sub(#lineno + 1)
-
- appendcommand(tonumber(lineno), statement)
- end
-end
-
-do -- Avoid heap allocs for performance
- local function stackpush(t, v)
- t[#t + 1] = v
- end
-
- local function stackpop(t)
- local v = t[#t]
- t[#t] = nil
- return v
- end
-
- local function stackpeek(t)
- local v = t[#t]
- return v
- end
-
- local function unmark(word)
- if type(word) == "table" then return word end
- return word:sub(2, #word)
- end
-
- local function isoperator(word)
- if word == nil then return false end
- return word:byte(1) == 35
- end
-
- local isvariable = _TBASIC.isvariable
- local isnumber = _TBASIC.isnumber
- local isstring = _TBASIC.isstring
-
- local function isuserfunc(word)
- if type(word) == "table" then return false end
- if word == nil then return false end
- return word:byte(1) == 64
- end
-
- local function isbuiltin(word)
- if type(word) == "table" then return false end
- if word == nil then return false end
- return word:byte(1) == 38
- end
-
- local function iskeyword(word)
- if word == nil then return false end
- return isoperator(word) or isuserfunc(word) or isbuiltin(word)
- end
-
- local function isassign(word)
- if word == nil then return false end
- return word ~= "==" and word ~= ">=" and word ~= "<=" and word:byte(#word) == 61
- end
-
- -- returns truthy value "terminate_loop" upon termination of loop; nil otherwise.
- local function execword(word, args)
- if not _TBASIC.__appexit then
- printdbg("--> execword", word)
- printdbg("--> execword_args", table.unpack(args))
-
- if word == "IF" then
- printdbg("--> branch statement 'IF'")
- if not _TBASIC.__readvar(args[1]) then -- if condition 'false'
- printdbg("--> if condition 'false'", table.unpack(args))
- return "terminate_loop" -- evaluated as 'true' to Lua
- else
- printdbg("--> if condition 'true'", table.unpack(args))
- end
- end
-
- printdbg("--> execword_outarg", table.unpack(args))
- result = _TBASIC.LUAFN[word][1](table.unpack(args))
-
- printdbg("--> result", result)
- stackpush(execstack, result)
- end
- end
-
- function printdbg(...)
- local debug = false
- if debug then print("DBG", ...) end
- end
-
-
- function interpretline(line)
- if not _TBASIC.__appexit then
- --[[
- impl
-
- 1. (normalise expr using parsewords)
- 2. use _TBASIC.RPNPARSR to convert to RPN
- 3. execute RPN op set like FORTH
-
- * "&" - internal functions
- * "@" - user-defined functions
- * "$" - variables (builtin constants and user-defined) -- familiar, eh?
- * "#" - operators
- * "~" - strings
- * none prepended - data (number or string)
- ]]
-
- lextable = parsewords(line)
- local vararg = -13 -- magic
-
-
- if lextable and lextable[1] ~= nil then
- if lextable[1]:upper() == "REM" then return nil end
-
- printdbg("lextable", table.concat(lextable, "|"))
-
- -- execute expression
- exprlist = _TBASIC.TORPN(lextable) -- 2 2 #+ &PRINT for "PRINT 2+2"
-
- printdbg("trying to exec", table.concat(exprlist, " "), "\n--------")
-
- execstack = {}
-
- for _, word in ipairs(exprlist) do
- printdbg("stack before", table.concat(execstack, " "))
- printdbg("word", word)
-
- if iskeyword(word) then
- printdbg("is keyword")
-
- funcname = unmark(word)
- args = {}
- argsize = _TBASIC._GETARGS(funcname)
-
- printdbg("argsize", argsize)
-
- if not argsize then
- _TBASIC._ERROR.DEV_UNIMPL(funcname)
- else
- if argsize ~= vararg then
- -- consume 'argsize' elements from the stack
- for argcnt = argsize, 1, -1 do
- if #execstack == 0 then
- _TBASIC._ERROR.ARGMISSING(funcname)
- end
- args[argcnt] = stackpop(execstack)
- end
- else
- -- consume entire stack
- local reversedargs = {}
-
- while #execstack > 0 and
- (isvariable(stackpeek(execstack)) or isnumber(stackpeek(execstack)) or
- isstring(stackpeek(execstack)))
- do
- stackpush(reversedargs, stackpop(execstack))
- end
- -- reverse 'args'
- while #reversedargs > 0 do
- stackpush(args, stackpop(reversedargs))
- end
- end
-
- local terminate_loop = execword(funcname, args)
-
- if terminate_loop then
- printdbg("--> termination of loop")
- printdbg("--------")
- break
- end
- end
- elseif isvariable(word) then
- printdbg("is variable")
- stackpush(execstack, word) -- push raw variable ($ sign retained)
- else
- printdbg("is data")
- stackpush(execstack, word) -- push number or string
- end
-
- printdbg("stack after", table.concat(execstack, " "))
- printdbg("--------")
- end
-
- -- if execstack is not empty, something is wrong
- if #execstack > 0 then
- _TBASIC._ERROR.SYNTAX() -- cannot reliably pinpoint which statement has error; use generic error
- end
- end
- end
- end
-end
-
-
-local function termination_condition()
- return terminated or
- _TBASIC.__appexit or
- #_TBASIC._INTPRTR.CALLSTCK > _TBASIC._INTPRTR.STACKMAX
-end
-
-local function fetchnextcmd()
- cmd = nil
- repeat
- _TBASIC._INTPRTR.PROGCNTR = _TBASIC._INTPRTR.PROGCNTR + 1
- cmd = programlist[_TBASIC._INTPRTR.PROGCNTR]
-
- if _TBASIC._INTPRTR.PROGCNTR > _TBASIC._INTPRTR.MAXLINES then
- terminated = true
- break
- end
- until cmd ~= nil
-
- if cmd ~= nil then
- if _TBASIC._INTPRTR.TRACE then
- print("PC", _TBASIC._INTPRTR.PROGCNTR)
- end
-
- return cmd
- end
-end
-
-
-local function interpretall()
-
- terminated = false
-
- repeat
- interpretline(fetchnextcmd())
- until termination_condition()
-end
-
--- END OF LEXER ---------------------------------------------------------------
-
--- _TBASIC.SHOWLUAERROR = false -- commented; let the shell handle it
-
-local testprogram = nil
-
-_G._TBASIC.EXEC = function(cmdstring) -- you can access this interpreter with this global function
- _TBASIC._INTPRTR.RESET()
- programlist = {} -- wipe out previous commands from interpreter (do not delete)
- readprogram(cmdstring)
- interpretall()
-end
-
-
-if testprogram then
- _TBASIC._INTPRTR.RESET()
- programlist = {} -- wipe out previous commands from interpreter (do not delete)
- readprogram(testprogram)
- interpretall()
-end
-
-
---[[
-Terran BASIC (TBASIC)
-Copyright (c) 2016 Torvald (minjaesong) and the contributors.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the Software), to deal in the
-Software without restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
-Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-]]
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/luaold/TBASEXTN.lua b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/luaold/TBASEXTN.lua
deleted file mode 100644
index cf16c66c2..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/luaold/TBASEXTN.lua
+++ /dev/null
@@ -1,34 +0,0 @@
--- TBASIC extension
-
--- these are utilities. Do not touch these lines
-local __assert = _TBASIC.__assert
-local __assertlhand = _TBASIC.__assertlhand
-local __assertrhand = _TBASIC.__assertrhand
-local __checknumber = _TBASIC.__checknumber
-local __checkstring = _TBASIC.__checkstring
-local __readvar = _TBASIC.__readvar
-local __resolvevararg = _TBASIC.__resolvevarar
-local vararg = -13 -- magic
--- end of utilities
-
-
--- these are the sample code for defining your own words
---[[
--- actual function that does the job
-local function _fnupgoer(n)
- print("Up-goer "..__checknumber(n).." goes up!")
-end
-
--- add the word UPGOER to word list
-table.insert(_TBASIC._FNCTION, "UPGOER")
--- add the actual function '_fnupgoer' and its number of arguments (1) to
--- '_TBASIC.LUAFN'. 'UPGOER' part should match with the word you just
--- inserted to _TBASIC._FNCTION.
-_TBASIC.LUAFN.UPGOER = {_fnupgoer, 1}
-]]
-
-
--- little debugger's blessing
-local function _fnenableluatrace() _TBASIC.SHOWLUAERROR = true end
-table.insert(_TBASIC._FNCTION, "LUATRACEON")
-_TBASIC.LUAFN.LUATRACEON = {_fnenableluatrace, 0}
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/luaold/TBASIC.lua b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/luaold/TBASIC.lua
deleted file mode 100644
index 23ed8855d..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/luaold/TBASIC.lua
+++ /dev/null
@@ -1,292 +0,0 @@
---[[
-TBASIC shell
-
-Synopsis: TBASIC (filename)
-If no file is specified, interactive mode will be started
-
-
-To debug EXEC and/or INCL, there's line ```local debug = false``` on each file; change it to ```true``` manually
-and you are all set.
-]]
-
-
-if os and os.loadAPI then -- ComputerCraft
- os.loadAPI "TBASINCL.lua"
- os.loadAPI "TBASEXEC.lua"
-else
- require "TBASINCL"
- require "TBASEXEC"
-end
-
-args = {...}
-
-print(_G._TBASIC._HEADER)
-_TBASIC.PROMPT()
-_TBASIC.SHOWLUAERROR = false
-
-
-local function concat_lines(lines, startindex, endindex)
- local out = ""
- for i = startindex or 1, endindex or _TBASIC._INTPRTR.MAXLINES do
- if lines[i] ~= nil then
- out = out.."\n"..tostring(i).." "..lines[i]
- end
- end
-
- return out
-end
-
-
-if args[1] then
- local prog = nil
- if fs and fs.open then -- ComputerCraft
- local inp = assert(fs.open(args[1], "r"))
- prog = inp:readAll()
- inp:close()
- else
- local inp = assert(io.open(args[1], "r"))
- prog = inp:read("*all")
- inp:close()
- end
-
- _TBASIC.EXEC(prog)
-else
- local terminate_app = false
-
- local ptn_nums = "[0-9]+"
- local renum_targets = {"GOTO[ ]+"..ptn_nums, "GOSUB[ ]+"..ptn_nums }
-
- local lines = {}
-
- local linenum_match = "[0-9]+ "
-
- local get_linenum = function(line) return line:sub(1,6):match(linenum_match, 1) end -- line:sub(1,6) limits max linumber to be 99999
- local split_num_and_statements = function(line)
- local linenum = get_linenum(line)
- local statements = line:sub(#linenum + 1)
- return tonumber(linenum), statements
- end
-
- while not terminate_app do
- local __read = false
- local line = io.read()
-
- -- tokenise line by " "
- local args = {} -- shadows system args
- for word in line:gmatch("[^ ]+") do
- table.insert(args, word:upper())
- end
-
-
- -- TODO more elegant code than IF-ELSEIF-ELSE
-
- -- massive if-else for running command, cos implementing proper command executor is too expensive here
- if line:sub(1,6):match(linenum_match) then -- enter new command
- local linenum, statements = split_num_and_statements(line)
- lines[tonumber(linenum)] = statements
- __read = true
- elseif args[1] == "NEW" then
- lines = {}
- elseif args[1] == "RUN" then
- _TBASIC.EXEC(concat_lines(lines))
- elseif args[1] == "LIST" then -- LIST, LIST 42, LIST 10-80
- if not args[2] then
- print(concat_lines(lines))
- else
- if args[2]:match("-") then -- ranged
- local range = {}
- for n in args[2]:gmatch("[^-]+") do
- table.insert(range, n)
- end
- local rangestart = tonumber(range[1])
- local rangeend = tonumber(range[2])
-
- if not rangestart or not rangeend then
- _TBASIC._ERROR.ILLEGALARG()
- else
- print(concat_lines(lines, rangestart, rangeend))
- end
- else
- local linenum = tonumber(args[2])
- if not linenum then
- _TBASIC._ERROR.ILLEGALARG()
- else
- print(concat_lines(lines, linenum, linenum))
- end
- end
- end
- _TBASIC.PROMPT()
- __read = true
- elseif args[1] == "DELETE" then -- DELETE 30, DELETE 454-650
- if not args[2] then
- _TBASIC._ERROR.ILLEGALARG()
- else
- if args[2]:match("-") then -- ranged
- local range = {}
- for n in args[2]:gmatch("[^-]+") do
- table.insert(range, n)
- end
- local rangestart = tonumber(range[1])
- local rangeend = tonumber(range[2])
-
- if not rangestart or not rangeend then
- _TBASIC._ERROR.ILLEGALARG()
- else
- for i = rangestart, rangeend do
- lines[i] = nil
- end
- end
- else
- local linenum = tonumber(args[2])
- if not linenum then
- _TBASIC._ERROR.ILLEGALARG()
- else
- lines[linenum] = nil
- end
- end
- end
- elseif args[1] == "EXIT" then
- terminate_app = true
- break
- elseif args[1] == "SAVE" then
- local status, err = pcall(function()
- if fs and fs.open then -- computercraft
- local file = fs.open(args[2], "w")
- file.write(concat_lines(lines))
- file.close()
- else
- local file = assert(io.open(args[2], "w"))
- file:write(concat_lines(lines))
- file:close()
- end
- end
- )
- if err then
- if _TBASIC.SHOWLUAERROR then
- print(err)
- end
- _TBASIC._ERROR.IOERR()
- else
- print("FILE SAVED")
- end
- elseif args[1] == "LOAD" then
- local status, err = pcall(function()
- lines = {}
- if fs and fs.open then -- computercraft
- local file = fs.open(args[2], "r")
- local data = file.readAll("*all")
- for dataline in data:gmatch("[^\n]+") do
- if #dataline > 0 then
- local linenum, statements = split_num_and_statements(dataline)
- lines[linenum] = statements
- end
- end
- file.close()
- else
- local file = assert(io.open(args[2], "r"))
- local data = file:read("*all")
- for dataline in data:gmatch("[^\n]+") do
- if #dataline > 0 then
- local linenum, statements = split_num_and_statements(dataline)
- lines[linenum] = statements
- end
- end
- file:close()
- end
- end
- )
- if err then
- if _TBASIC.SHOWLUAERROR then
- error(err)
- end
- _TBASIC._ERROR.IOERR()
- else
- print("FILE LOADED")
- end
- elseif args[1] == "RENUM" then
- local statement_table = {}
- local renumbering_table = {}
- local new_linenum_counter = 10
- -- first, get the list of commands, without line number indexing
- for i = 1, _TBASIC._INTPRTR.MAXLINES do
- if lines[i] ~= nil then
- --table.insert(statement_table, lines[i])
- statement_table[new_linenum_counter] = lines[i]
- renumbering_table[i] = new_linenum_counter
-
- -- test
- --print("old line", i, "new line", new_linenum_counter)
-
- new_linenum_counter = new_linenum_counter + 10
- end
- end
- -- copy statement_table into lines table
- lines = statement_table
-
- -- re-number GOTO and GOSUB line numbers
- local line_counter = 0 -- loop counter
- for line_pc = 0, _TBASIC._INTPRTR.MAXLINES do
- local line = lines[line_pc]
- if line then
- line_counter = line_counter + 1
-
- -- replace
- -- extract a <- "GOTO 320"
- -- extract n_from from a (320), make n_to from it
- -- make new string b <- "GOTO "..n_to
- for _, match_string in ipairs(renum_targets) do
- local match = line:match(match_string)
- if match then
- local matching_statement = match:gsub("[ ]+"..ptn_nums, "")
- local target_line_old = tonumber(match:match(ptn_nums))
- local target_line_new = renumbering_table[target_line_old]
-
- local gsub_from = match
- local gsub_to = matching_statement.." "..target_line_new
-
- -- test
- --print("matching_statement", matching_statement, "target_line_old", target_line_old, "target_line_new", target_line_new)
- --print("gsub_from", gsub_from, "gsub_to", gsub_to)
-
- -- substitute
- lines[line_pc] = line:gsub(gsub_from, gsub_to)
- end
- end
- end
- end
- elseif #line == 0 and line:byte(1) ~= 10 and line:byte(1) ~= 13 then
- __read = true
- else
- _TBASIC.EXEC("1 "..line) -- execute command right away
- end
-
- -- reset
- if not __read then
- _TBASIC.PROMPT()
- end
- end
-end
-
-
---[[
-Terran BASIC (TBASIC)
-Copyright (c) 2016 Torvald (minjaesong) and the contributors.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the Software), to deal in the
-Software without restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
-Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-]]
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/luaold/TBASINCL.lua b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/luaold/TBASINCL.lua
deleted file mode 100644
index 01e21a52c..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/luaold/TBASINCL.lua
+++ /dev/null
@@ -1,1409 +0,0 @@
--- TBASIC includes
-
-if not _G.bit and not _G.bit32 then
- error("This lua implementation does not have bit/bit32 library, aborting.")
-end
-
-if not _G.unpack and not table.unpack then
- error("This lua implementation does not have unpack() function, aborting.")
-end
-
-if _G.bit32 then _G.bit = bit32 end -- Lua 5.2 and LuaJIT compatibility (which has 'bit32' but no 'bit')
-if _G.unpack and not _G.table.unpack then _G.table.unpack = unpack end -- LuaJIT compatibility
-
-
--- simple binary search stole and improved from Kotlin Language
--- @param cmpval: function that returns numerical value of the value used for searching.
--- implementation: function(s) return whateverhashornumber(s) end
--- e.g. function(s) return string.hash(s) end -- for string values
--- you must implement it by yourself!
-do -- Avoid heap allocs for performance
- local default_cmp_fn = function(s) return string.hash(tostring(s)) end
-
- function table.binsearch(t, value, cmpval)
- local low = 1
- local high = #t
- local cmp = cmpval or default_cmp_fn
-
- local value = cmp(value)
-
- while low <= high do
- local mid = bit.rshift((low + high), 1)
- local midVal = t[mid]
-
- if value > cmp(midVal) then
- low = mid + 1
- elseif value < cmp(midVal) then
- high = mid - 1
- else
- return mid -- key found
- end
- end
- return nil -- key not found
- end
-end
-
-
-_G._TBASIC = {}
-_G._TBASIC._VERNUM = 0x0004 -- 0.4
-_G._TBASIC._VERSION = tonumber(string.format("%d.%d", bit.rshift(_TBASIC._VERNUM, 8), bit.band(_TBASIC._VERNUM, 0xFF)))
-_G._TBASIC._HEADER = string.format(" **** TERRAN BASIC V%d.%d **** ", bit.rshift(_TBASIC._VERNUM, 8), bit.band(_TBASIC._VERNUM, 0xFF))
-_G._TBASIC.PROMPT = function() print("\nREADY.") end
-_G._TBASIC._INVOKEERR = function(msg, msg1)
- if msg1 then
- print("?L".._G._TBASIC._INTPRTR.PROGCNTR..": "..msg.." "..msg1)
- else
- print("?L".._G._TBASIC._INTPRTR.PROGCNTR..": "..msg, "ERROR")
- end
- if _TBASIC.SHOWLUAERROR then error("Error thrown") end
- --os.exit(1) -- terminate
- _G._TBASIC.__appexit = true -- duh, computercraft
-end
-_G._TBASIC._ERROR = {
- SYNTAX = function() _TBASIC._INVOKEERR("SYNTAX") end,
- SYNTAXAT = function(word) _TBASIC._INVOKEERR("SYNTAX ERROR AT", "'"..word.."'") end,
- TYPE = function() _TBASIC._INVOKEERR("TYPE MISMATCH") end,
- ILLEGALNAME = function(name, reason)
- if reason then
- _TBASIC._INVOKEERR("ILLEGAL NAME: ".."'"..name.."'", "REASON:"..reason)
- else
- _TBASIC._INVOKEERR("ILLEGAL NAME:", "'"..name.."'")
- end
- end,
- ILLEGALARG = function(expected, got)
- if (not expected) and (not got) then
- _TBASIC._INVOKEERR("ILLEGAL QUANTITY")
- elseif not got then
- _TBASIC._INVOKEERR(expected:upper().." EXPECTED")
- else
- _TBASIC._INVOKEERR(expected:upper().." EXPECTED,", "GOT "..got:upper())
- end
- end,
- NOSUCHLINE = function(line) _TBASIC._INVOKEERR("NO SUCH LINE:", line) end,
- NULFN = function(var) _TBASIC._INVOKEERR("UNDEFINED FUNCTION:", "'"..var.."'") end,
- NULVAR = function(var) _TBASIC._INVOKEERR("UNDEFINED VARIABLE:", "'"..var.."'") end,
- DIV0 = function() _TBASIC._INVOKEERR("DIVISION BY ZERO") end,
- NAN = function() _TBASIC._INVOKEERR("NOT A NUMBER") end,
- INDETERMINANT = function() _TBASIC._INVOKEERR("INDETERMINANT MATH") end, -- 0^0 is NOT indeterminant, it's 1. This is the language spec.
- STACKOVFL = function() _TBASIC._INVOKEERR("TOO MANY RECURSION") end,
- LINETOOBIG = function() _TBASIC._INVOKEERR("TOO BIG LINE NUMBER") end,
- NOLINENUM = function() _TBASIC._INVOKEERR("NO LINE NUMBER") end,
- ABORT = function(reason)
- if reason then
- _TBASIC._INVOKEERR("PROGRAM", "ABORTED: "..reason)
- else
- _TBASIC._INVOKEERR("PROGRAM", "ABORTED")
- end
- end,
- ARGMISSING = function(fname, remark)
- if remark then
- _TBASIC._INVOKEERR("MISSING ARGUMENT(S) FOR", "'"..fname.."' ("..remark..")")
- else
- _TBASIC._INVOKEERR("MISSING ARGUMENT(S) FOR", "'"..fname.."'")
- end
- end,
- NOMATCHING = function(fname, match) _TBASIC._INVOKEERR("'"..fname.."' HAS NO MACTHING", "'"..match.."'") end,
- TOOLONGEXEC = function() _TBASIC._INVOKEERR("TOO LONG WITHOUT YIELDING") end,
- RETURNWOSUB = function() _TBASIC._INVOKEERR("RETURN WITHOUT GOSUB") end,
- NEXTWOFOR = function() _TBASIC._INVOKEERR("NEXT WITHOUT FOR") end,
- ASGONIF = function() _TBASIC._INVOKEERR("ASSIGNMENT ON IF CLAUSE") end,
- SHELLCMD = function() _TBASIC._INVOKEERR("THIS IS A SHELL COMMAND") end,
- IOERR = function() _TBASIC._INVOKEERR("READ/WRITE") end,
-
- DEV_FUCKIT = function() _TBASIC._INVOKEERR("FEELING DIRTY") end,
- DEV_UNIMPL = function(fname) _TBASIC._INVOKEERR("UNIMPLEMENTED SYNTAX:", "'"..fname.."'") end
-}
-_G._TBASIC._FNCTION = {
- -- variable control
- "CLR", -- deletes all user-defined variables and functions
- "DIM", -- allocates an array
- "DEF", -- defines new function. Synopsis "DEF FN FOOBAR(arg)"
- "FN", -- denotes function
- -- flow control
- "GO", "GOTO", -- considered harmful
- "GOSUB", "RETURN",
- "FOR", "NEXT", "IN",
- "DO", -- reserved only
- "IF", "THEN",
- "LABEL", -- line number alias
- --"ELSE", "ELSEIF", -- reserved only, will not be implemented
- "END", -- terminate program cleanly
- "ABORT", -- break as if an error occured
- "ABORTM", -- ABORT with message
- -- stdio
- "PRINT",
- "INPUT",
- "GET", -- read single key
- "HTAB", "TAB", -- set cursor's X position
- "VTAB", -- set cursor's Y position
- "SCROLL",
- "CLS", -- clear screen
- "TEXTCOL", -- foreground colour
- "BACKCOL", -- background colour
- -- mathematics
- "ABS", "SIN", "COS", "TAN", "FLOOR", "CEIL", "ROUND", "LOG",
- "INT", -- integer part of a number (3.78 -> 3, -3.03 -> -3)
- "RND", -- random number 0.0 <= x < 1.0
- "SGN", -- sign of a number (-1, 0, 1)
- "SQRT", -- square root
- "CBRT", -- cubic root
- "MAX", "MIN",
- "INV", -- returns (1.0 / arg)
- "RAD", -- converts deg into rad
- -- string manipulation
- "LEN",
- "LEFT", -- just like in Excel
- "MID", -- -- just like in Excel (substring)
- "RIGHT", -- just like in Excel
- -- type conversion
- "ASC", -- converts a charactor into its code point
- "CHR", -- converts an integer into corresponding character
- "STR", -- number to string
- "VAL", -- string to number
- -- misc
- "REM", -- mark this line as comment
- "NEW", -- clean up any programs on the buffer (this is a Shell function)
- -- pc speaker
- "BEEP", -- beeps. Synopsis: "BEEP", "BEEP [pattern]" (not for CC)
- "TEMIT", -- emits a tone. Synopsis: "TEMIT [frequency] [seconds]" (not for CC)
- -- commands
- "RUN", -- run a program or a line. Synopsis: "RUN", "RUN [line]" (this is a Shell function)
- "LIST", -- list currently entered program. Synopsis: "LIST", "LIST [line]", "LIST [from "-" to]" (this is a Shell function)
- "NEW", -- clear program lines buffer (this is a Shell function)
- "RENUM", -- re-number BASIC statements (this is a Shell function)
- "DELETE", -- delete line (this is a Shell function)
- -- external IO
- "LOAD", -- file load. Synopsis: "LOAD [filename]"
- "SAVE", -- file save. Synopsis: "SAVE [filename]"
-}
-_G._TBASIC._OPERATR = {
- -- operators
- ">>>", "<<", ">>", "|", "&", "XOR", "!", -- bitwise operations
- ";", -- string concatenation
- "==", ">", "<", "<=", "=<", ">=", "=>",
- "!=", "<>", "><", -- not equal
- "=", ":=", -- assign
- "AND", "OR", "NOT",
- "^", -- math.pow, 0^0 should return 1.
- "*", "/", "+", "-", -- arithmetic operations
- "%", -- math.fmod
- "TO", "STEP", -- integer sequence operator
- "MINUS", -- unary minus
- "+=", "-=", "*=", "/=", "%=" -- C-style assign
-}
-_G._TBASIC._INTPRTR = {}
-_G._TBASIC._INTPRTR.TRACE = false -- print program counter while execution
-_G._TBASIC.SHOWLUAERROR = true
-
-local function stackpush(t, v)
- t[#t + 1] = v
-end
-
-local function stackpop(t)
- local v = t[#t]
- t[#t] = nil
- return v
-end
-
-local function stackpeek(t)
- local v = t[#t]
- return v
-end
-
-function string.hash(str)
- local hash = 2166136261
- for i = 1, #str do
- hash = hash * 16777619
- hash = bit.bxor(hash, str:byte(i))
- end
- return hash
-end
-
-_G._TBASIC._INTPRTR.RESET = function()
- _TBASIC.__appexit = false
- _TBASIC._INTPRTR.PROGCNTR = 0
- _TBASIC._INTPRTR.MAXLINES = 63999
- _TBASIC._INTPRTR.VARTABLE = {} -- table of variables. [NAME] = data
- _TBASIC._INTPRTR.FNCTABLE = {} -- table of functions. [NAME] = array of strings? (TBA)
- _TBASIC._INTPRTR.CALLSTCK = {} -- return points (line number)
- _TBASIC._INTPRTR.LINELABL = {} -- LABEL statement table
- _TBASIC._INTPRTR.STACKMAX = 2000
- _TBASIC._INTPRTR.CNSTANTS = {
- M_PI = 3.141592653589793, -- this is a standard implementation
- M_2PI = 6.283185307179586, -- this is a standard implementation
- M_E = 2.718281828459045, -- this is a standard implementation
- M_ROOT2 = 1.414213562373095, -- this is a standard implementation
- TRUE = true,
- FALSE = false,
- NIL = nil,
- _VERSION = _TBASIC._VERSION
- }
-end
-
-
-
--- FUNCTION IMPLEMENTS --------------------------------------------------------
-
-local function __readvar(varname)
- -- if varname is a string that can be represented as number, returns tonumber(varname) ("4324" -> 4324)
- -- if varname is a TBASIC string, return resolved string ("~FOOBAR" -> "FOOBAR")
- -- if varname is a TBASIC variable, return resolved variable ("$FOO" -> any value stored in variable 'FOO')
-
- --print("readvar_varname", varname)
-
- if type(varname) == "table" or type(varname) == "nil" or type(varname) == "boolean" then
- return varname
- end
-
- if tonumber(varname) then
- return tonumber(varname)
- end
-
- if varname:byte(1) == 126 then
- return varname:sub(2, #varname)
- end
-
- if varname:byte(1) == 36 then
- local data = varname:sub(2, #varname)
- if tonumber(data) then
- return tonumber(data)
- else
- -- try for constants
- local retval = _TBASIC._INTPRTR.CNSTANTS[data:upper()]
- if retval ~= nil then return retval
- -- try for variable table
- else return _TBASIC._INTPRTR.VARTABLE[data:upper()] end
- end
- else
- return varname -- already resolved
- end
-end
-
-local function __assert(aarg, expected)
- local arg = __readvar(aarg)
-
- if type(arg) ~= expected then
- _TBASIC._ERROR.ILLEGALARG(expected, type(arg))
- return
- end
-end
-
-local function __assertlhand(llval, expected)
- local lval = __readvar(llval)
-
- if type(lval) ~= expected then
- _TBASIC._ERROR.ILLEGALARG("LHAND: "..expected, type(lval))
- return
- end
-end
-
-local function __assertrhand(rrval, expected)
- local rval = __readvar(rrval)
-
- if type(rval) ~= expected then
- _TBASIC._ERROR.ILLEGALARG("RHAND: "..expected, type(rval))
- return
- end
-end
-
-local function __checknumber(aarg)
- local arg = __readvar(aarg)
-
- if arg == nil then
- _TBASIC._ERROR.ILLEGALARG("number", type(arg))
- return
- else
- if type(arg) == "table" then
- repeat
- tval = arg[1]
- arg = tval
- until type(tval) ~= "table"
- end
-
- n = tonumber(arg)
- if n == nil then
- _TBASIC._ERROR.ILLEGALARG("number", type(arg))
- return
- else
- return n
- end
- end
-end
-
-local function __checkstring(aarg)
- local arg = __readvar(aarg)
-
- if type(arg) == "function" then
- _TBASIC._ERROR.ILLEGALARG("STRING/NUMBER/BOOL", type(arg))
- return
- end
-
- if type(arg) == "table" then
- repeat
- tval = arg[1]
- arg = tval
- until type(tval) ~= "table"
- end
-
- local strarg = tostring(arg)
- return strarg:byte(1) == 126 and strarg:sub(2, #strarg) or strarg
-end
-
-local function __resolvevararg(...)
- local ret = {}
- for _, varname in ipairs({...}) do
- table.insert(ret, __readvar(varname))
- end
- return ret
-end
-
-_G._TBASIC.__assert = __assert
-_G._TBASIC.__assertlhand = __assertlhand
-_G._TBASIC.__assertrhand = __assertrhand
-_G._TBASIC.__checknumber = __checknumber
-_G._TBASIC.__checkstring = __checkstring
-_G._TBASIC.__readvar = __readvar
-_G._TBASIC.__resolvevararg = __resolvevararg
-
-
---[[
-Function implementations
-
- Cautions:
-* Every function that returns STRING must prepend "~"
- ]]
-
-
-local function _fnprint(...)
- function printarg(arg)
- if type(arg) == "function" then
- _TBASIC._ERROR.SYNTAX()
- return
- end
-
- if type(arg) == "boolean" then
- if arg then io.write(" TRUE")
- else io.write(" FALSE") end
- elseif _TBASIC.isstring(arg) then
- io.write(__checkstring(arg))
- elseif _TBASIC.isnumber(arg) then -- if argument can be turned into a number (e.g. 14321, "541")
- io.write(" "..arg)
- elseif type(arg) == "table" then
- printarg(arg[1]) -- recursion
- else
- io.write(tostring(arg))
- end
- end
-
- local args = __resolvevararg(...)
-
- if #args < 1 then
- io.write ""
- else
- for i, arg in ipairs(args) do
- if i > 1 then io.write "\t" end
-
- printarg(arg)
- end
- end
-
- io.write "\n"
-end
-
-local function _fngoto(lnum)
- local linenum = nil
- if _TBASIC.isnumber(lnum) then
- linenum = __checknumber(lnum)
- else
- linenum = _TBASIC._INTPRTR.LINELABL[__checkstring(lnum)]
- end
-
- if linenum == nil or linenum < 1 then
- _TBASIC._ERROR.NOSUCHLINE(linenum)
- return
- end
-
- _TBASIC._INTPRTR.PROGCNTR = linenum - 1
-end
-
-local function _fnnewvar(varname, value)
- _TBASIC._INTPRTR.VARTABLE[varname:upper()] = __readvar(value)
-end
-
-local function _fngosub(lnum)
- local linenum = nil
- if _TBASIC.isnumber(lnum) then
- linenum = __checknumber(lnum)
- else
- linenum = _TBASIC._INTPRTR.LINELABL[__checkstring(lnum)]
- end
-
- stackpush(_TBASIC._INTPRTR.CALLSTCK, _TBASIC._INTPRTR.PROGCNTR) -- save current line number
- _fngoto(linenum)
-end
-
-local function _fnreturn()
- if #_TBASIC._INTPRTR.CALLSTCK == 0 then -- nowhere to return
- _TBASIC._ERROR.RETURNWOSUB()
- return
- end
-
- local return_line = stackpop(_TBASIC._INTPRTR.CALLSTCK) + 1 -- the line has GOSUB, so advance one
- _fngoto(return_line)
-end
-
-local function _fnabort()
- _TBASIC._ERROR.ABORT()
-end
-
-local function _fnabortmsg(reason)
- _TBASIC._ERROR.ABORT(__checkstring(__readvar(reason)))
-end
-
-local function _fnif(bbool)
- local bool = __readvar(bbool)
-
- __assert(bool, "boolean")
-
- if bool == nil then
- _TBASIC._ERROR.ILLEGALARG()
- return
- end
-
- if not bool then
- _TBASIC._INTPRTR.PROGCNTR = _TBASIC._INTPRTR.PROGCNTR + 1
- end
-end
-
-local function _fnnop()
- return
-end
-
-local function _fnfor(seq)
- stackpush(_TBASIC._INTPRTR.CALLSTCK, _TBASIC._INTPRTR.PROGCNTR)
-end
-
-local function _fnnext(...)
- if #_TBASIC._INTPRTR.CALLSTCK == 0 then -- nowhere to return
- _TBASIC._ERROR.NEXTWOFOR()
- return
- end
-
- local variables = {...} -- array of strings(varname) e.g. "$X, $Y, $Z"
- local branch = false
- -- dequeue intsequences
- for i, v in ipairs(variables) do
- local t = nil
- if _TBASIC.isvariable(v) then
- t = _TBASIC._INTPRTR.VARTABLE[v:sub(2, #v)]
-
- if type(t) ~= "table" then
- _TBASIC._ERROR.ILLEGALARG("ARRAY", type(t))
- return
- end
-
- table.remove(t, 1)
-
- -- unassign variable
- if #t == 0 then
- _TBASIC._INTPRTR.VARTABLE[v] = nil
- branch = true
- end
- else
- _TBASIC._ERROR.ILLEGALARG("ARRAY", type(t))
- return
- end
- end
-
- -- branch? or go back?
- if not branch then
- _fngoto(stackpeek(_TBASIC._INTPRTR.CALLSTCK) + 1) -- the line has FOR statement
- else
- stackpop(_TBASIC._INTPRTR.CALLSTCK) -- dump the stack
- end
-end
-
-local function _fnabs(n)
- return math.abs(__checknumber(n))
-end
-
-local function _fnsin(n)
- return math.sin(__checknumber(n))
-end
-
-local function _fncos(n)
- return math.cos(__checknumber(n))
-end
-
-local function _fntan(n)
- return math.tan(__checknumber(n))
-end
-
-local function _fntorad(n)
- return math.rad(__checknumber(n))
-end
-
-local function _fnascii(char)
- return __checkstring(char):byte(1)
-end
-
-local function _fncbrt(n)
- return __checknumber(n)^3
-end
-
-local function _fnceil(n)
- return math.ceil(__checknumber(n))
-end
-
-local function _fnchar(code)
- return "~"..string.char(__checknumber(code)) -- about "~".. ? read the cautions above!
-end
-
-local function _fnfloor(n)
- return math.floor(__checknumber(n))
-end
-
-local function _fngetkeycode(...)
- -- TODO get a single character from the keyboard and saves the code of the character to the given variable(s)
-end
-
-local function _fnint(n)
- num = __checknumber(n)
- return num >= 0 and math.floor(n) or math.ceil(n)
-end
-
-local function _fnmultinv(n) -- multiplicative invert
- return 1.0 / __checknumber(n)
-end
-
-local function _fnsubstrleft(str, n)
- return "~"..__checkstring(str):sub(1, __checknumber(n))
-end
-
-local function _fnsubstr(str, left, right)
- return "~"..__checkstring(str):sub(__checknumber(left), __checknumber(right))
-end
-
-local function _fnsubstrright(str, n)
- return "~"..__checkstring(str):sub(-__checknumber(n))
-end
-
-local function _fnlen(var)
- local value = __readvar(var)
- return #value
-end
-
-local function _fnloge(n)
- return math.log(__checknumber(n))
-end
-
-local function _fnmax(...)
- local args = __resolvevararg(...)
- if #args < 1 then
- _TBASIC._ERROR.ARGMISSING("MAX")
- return
- end
-
- local max = -math.huge
- for _, i in ipairs(args) do
- local n = __checknumber(i)
- if max < n then max = n end
- end
- return max
-end
-
-local function _fnmin(...)
- local args = __resolvevararg(...)
- if #args < 1 then
- _TBASIC._ERROR.ARGMISSING("MIN")
- return
- end
-
- local min = math.huge
- for _, i in ipairs(args) do
- local n = __checknumber(i)
- if min > n then min = n end
- end
- return min
-end
-
-local function _fnrand()
- return math.random()
-end
-
-local function _fnround(n)
- return math.floor(__checknumber(n) + 0.5)
-end
-
-local function _fnsign(n)
- local num = __checknumber(n)
- return num > 0 and 1.0 or num < 0 and -1.0 or 0.0
-end
-
-local function _fnsqrt(n)
- return __checknumber(n)^(0.5)
-end
-
-local function _fntostring(n)
- local ret = tostring(__checknumber(n))
- if not ret then
- _TBASIC._ERROR.ILLEGALARG()
- return
- else
- return "~"..ret
- end
-end
-
-local function _fntonumber(s)
- if tonumber(s) then return s end
- return tonumber(__checkstring(s))
-end
-
-local function _fntan(n)
- return math.tan(__checknumber(n))
-end
-
-local function _fninput(...) -- INPUT(var1, [var2, var3 ...])
- local args = {...}
- local prompt = "YOUR INPUT ? "
- local prompt_numbered = "YOUR INPUT (%d OF %d) ? "
-
- function prompt_and_get_input()
- -- if there's two or more input, a number will be shown
- if #args >= 2 then
- io.write(string.format(prompt_numbered, argcount, #args))
- else
- io.write(prompt)
- end
- io.flush() -- print out the line right away
-
- local value = io.read()
-
- return value
- end
-
- if #args < 1 then
- _TBASIC._ERROR.ARGMISSING("INPUT")
- return
- else
- for argcount, varname in ipairs(args) do
- local inputvalue = nil
- while inputvalue == nil or inputvalue == "" do
- inputvalue = prompt_and_get_input()
- _opassign(varname, inputvalue)
- end
- end
- end
-end
-
-local function _fnlabel(lname)
- _TBASIC._INTPRTR.LINELABL[__checkstring(lname)] = _TBASIC._INTPRTR.PROGCNTR
-end
-
-
-
--- OPERATOR IMPLEMENTS --------------------------------------------------------
-
-local function booleanise(bool)
- return bool and "$TRUE" or "$FALSE"
-end
-
-function _opconcat(llval, rrval)
- local lval = __readvar(llval)
- local rval = __readvar(rrval)
-
- if type(lval) == "function" then _TBASIC._ERROR.ILLEGALARG("VALUE", "FUNCTION") return end
- if type(rval) == "function" then _TBASIC._ERROR.ILLEGALARG("VALUE", "FUNCTION") return end
-
- local l = (type(lval) == "string" and lval:byte(1)) == 126 and lval:sub(2, #lval) or __checkstring(lval)
- local r = (type(rval) == "string" and rval:byte(1)) == 126 and rval:sub(2, #rval) or __checkstring(rval)
-
- return "~"..l..r
-end
-
-function _opplus(lval, rval)
- local l = __checknumber(lval)
- local r = __checknumber(rval)
-
- return l + r
-end
-
-function _optimes(lval, rval)
- local l = __checknumber(lval)
- local r = __checknumber(rval)
-
- return l * r
-end
-
-function _opminus(lval, rval)
- local l = __checknumber(lval)
- local r = __checknumber(rval)
-
- return l - r
-end
-
-function _opdiv(lval, rval)
- local l = __checknumber(lval)
- local r = __checknumber(rval)
-
- if l == 0 and r == 0 then
- _TBASIC._ERROR.INDETERMINANT()
- return
- elseif r == 0 then
- _TBASIC._ERROR.DIV0()
- return
- else
- return _optimes(l, 1.0 / r)
- end
-end
-
-function _opmodulo(lval, rval)
- local expected = "number"
- local l = __checknumber(lval)
- local r = __checknumber(rval)
-
- return math.fmod(l, r)
-end
-
-function _oppower(lval, rval)
- local expected = "number"
- local l = __checknumber(lval)
- local r = __checknumber(rval)
-
- return math.pow(l, r) -- 0^0 is 1 according to the spec, and so is the Lua's.
-end
-
-function _opassign(var, value)
- if _TBASIC.isnumber(var) or _TBASIC.isfunction(var) or _TBASIC.isoperator(var) or _TBASIC.isargsep(var) then
- _TBASIC._ERROR.ILLEGALNAME(var)
- return
- end
-
- -- remove missed "$"
- local varname = var:byte(1) == 36 and var:sub(2, #var) or var
-
- -- if it still has "$", the programmer just broke the law
- if varname:byte(1) == 36 then
- _TBASIC._ERROR.ILLEGALNAME(varname, "HAS ILLEGAL CHARACTER '$'")
- return
- end
-
- _TBASIC._INTPRTR.VARTABLE[varname:upper()] = __readvar(value)
-end
-
-function _opeq(llval, rrval)
- local lval = __readvar(llval)
- local rval = __readvar(rrval)
-
- if tonumber(lval) and tonumber(rval) then
- return booleanise(tonumber(lval) == tonumber(rval))
- else
- return booleanise(__checkstring(lval) == __checkstring(rval))
- end
-end
-
-function _opne(llval, rrval)
- local lval = __readvar(llval)
- local rval = __readvar(rrval)
-
- if tonumber(lval) and tonumber(rval) then
- return booleanise(tonumber(lval) ~= tonumber(rval))
- else
- return booleanise(__checkstring(lval) ~= __checkstring(rval))
- end
-end
-
-function _opgt(lval, rval)
- local expected = "number"
- local l = __checknumber(lval)
- local r = __checknumber(rval)
-
- return booleanise(l > r)
-end
-
-function _oplt(lval, rval)
- local expected = "number"
- local l = __checknumber(lval)
- local r = __checknumber(rval)
-
- return booleanise(l < r)
-end
-
-function _opge(lval, rval)
- local expected = "number"
- local l = __checknumber(lval)
- local r = __checknumber(rval)
-
- return booleanise(l >= r)
-end
-
-function _ople(lval, rval)
- local expected = "number"
- local l = __checknumber(lval)
- local r = __checknumber(rval)
-
- return booleanise(l <= r)
-end
-
-function _opband(lval, rval)
- local expected = "number"
- local l = __checknumber(lval)
- local r = __checknumber(rval)
-
- return bit.band(l, r)
-end
-
-function _opbor(lval, rval)
- local expected = "number"
- local l = __checknumber(lval)
- local r = __checknumber(rval)
-
- return bit.bor(l, r)
-end
-
-function _opbxor(lval, rval)
- local expected = "number"
- local l = __checknumber(lval)
- local r = __checknumber(rval)
-
- return bit.bxor(l, r)
-end
-
-function _opbnot(val)
- local expected = "number"
- local v = __checknumber(val)
-
- return bit.bnot(v)
-end
-
-function _oplshift(lval, rval)
- local expected = "number"
- local l = __checknumber(lval)
- local r = __checknumber(rval)
-
- return bit.lshift(l, r)
-end
-
-function _oprshift(lval, rval)
- local expected = "number"
- local l = __checknumber(lval)
- local r = __checknumber(rval)
-
- return bit.arshift(l, r)
-end
-
-function _opurshift(lval, rval)
- local expected = "number"
- local l = __checknumber(lval)
- local r = __checknumber(rval)
-
- return bit.rshift(l, r)
-end
-
-function _opland(lhand, rhand)
- return booleanise(__readvar(lhand) and __readvar(rhand))
-end
-
-function _oplor(lhand, rhand)
- return booleanise(__readvar(lhand) or __readvar(rhand))
-end
-
-function _oplnot(rhand)
- return booleanise(not __readvar(rhand))
-end
-
-function _opintrange(x, y) -- x TO y -> {x..y}
- local from = __checknumber(x)
- local to = __checknumber(y)
-
- local seq = {}
- if from < to then
- for i = from, to do
- table.insert(seq, i)
- end
- else
- for i = from, to, -1 do
- table.insert(seq, i)
- end
- end
-
- return seq
-end
-
-function _opintrangestep(sseq, sstp) -- i know you can just use "for i = from, to, step"
- local seq = __readvar(sseq)
- local stp = __readvar(sstp)
- local step = __checknumber(stp) -- but that's just how not this stack machine works...
- __assert(seq, "table")
-
- if step == 1 then return seq end
- if step < 1 then _TBASIC._ERROR.ILLEGALARG() return end
-
- local newseq = {}
- for i, v in ipairs(seq) do
- if i % step == 1 then
- table.insert(newseq, v)
- end
- end
-
- return newseq
-end
-
-function _opunaryminus(n)
- local num = __checknumber(n)
- return -num
-end
-
-function _opplusassign(var, value)
- if type(__readvar(var)) == "number" then
- _opassign(var, __readvar(var) + __checknumber(value))
- else
- _TBASIC._ERROR.ILLEGALARG()
- return
- end
-end
-
-function _opminusassign(var, value)
- if type(__readvar(var)) == "number" then
- _opassign(var, __readvar(var) - __checknumber(value))
- else
- _TBASIC._ERROR.ILLEGALARG()
- return
- end
-end
-
-function _optimesassign(var, value)
- if type(__readvar(var)) == "number" then
- _opassign(var, __readvar(var) * __checknumber(value))
- else
- _TBASIC._ERROR.ILLEGALARG()
- return
- end
-end
-
-function _opdivassign(var, value)
- if type(__readvar(var)) == "number" then
- if __checknumber(value) == 0 then
- _TBASIC._ERROR.DIV0()
- return
- else
- _opassign(var, __readvar(var) / __checknumber(value))
- end
- else
- _TBASIC._ERROR.ILLEGALARG()
- return
- end
-end
-
-function _opmodassign(var, value)
- if type(__readvar(var)) == "number" then
- if __checknumber(value) == 0 then
- _TBASIC._ERROR.DIV0()
- return
- else
- _opassign(var, math.fmod(__readvar(var), __checknumber(value)))
- end
- else
- _TBASIC._ERROR.ILLEGALARG()
- return
- end
-end
-
-
-local vararg = -13 -- magic
-
-_G._TBASIC.LUAFN = {
- -- variable control
- CLR = {function() _TBASIC._INTPRTR.VARTABLE = {} end, 0},
- -- flow control
- IF = {_fnif, 1},
- THEN = {_fnnop, 0},
- GOTO = {_fngoto, 1},
- GOSUB = {_fngosub, 1},
- RETURN = {_fnreturn, 0},
- END = {function() _G._TBASIC.__appexit = true end, 0},
- ABORT = {_fnabort, 0},
- ABORTM = {_fnabortmsg, 1},
- FOR = {_fnfor, 1},
- NEXT = {_fnnext, vararg},
- LABEL = {_fnlabel, 1},
- -- stdio
- PRINT = {_fnprint, vararg},
- INPUT = {_fninput, vararg},
- -- mathematics
- ABS = {_fnabs, 1},
- CBRT = {_fncbrt, 1},
- CEIL = {_fnceil, 1},
- COS = {_fncos, 1},
- FLOOR = {_fnfloor, 1},
- INT = {_fnint, 1},
- INV = {_fnmultinv, 1},
- LOG = {_fnloge, 1},
- MAX = {_fnmax, vararg},
- MIN = {_fnmin, vararg},
- RAD = {_fntorad, 1},
- RND = {_fnrand, 0},
- ROUND = {_fnround, 1},
- SGN = {_fnsign, 1},
- SIN = {_fnsin, 1},
- SQRT = {_fnsqrt, 1},
- TAN = {_fntan, 1},
- -- string manipulation
- LEFT = {_fnsubstrleft, 2},
- LEN = {_fnlen, 1},
- MID = {_fnsubstr, 3},
- RIGHT = {_fnsubstrright, 2},
- -- type conversion
- ASC = {_fnascii, 1},
- CHR = {_fnchar, 1},
- STR = {_fntostring, 1},
- VAL = {_fntonumber, 1},
- ---------------
- -- operators --
- ---------------
- [";"] = {_opconcat, 2},
- ["+"] = {_opplus, 2},
- ["*"] = {_optimes, 2},
- ["-"] = {_opminus, 2},
- ["/"] = {_opdiv, 2},
- ["%"] = {_opmodulo, 2},
- ["^"] = {_oppower, 2},
- ["=="] = {_opeq, 2},
- ["!="] = {_opne, 2}, ["<>"] = {_opne, 2}, ["><"] = {_opne, 2},
- [">="] = {_opge, 2}, ["=>"] = {_opge, 2},
- ["<="] = {_ople, 2}, ["=<"] = {_ople, 2},
- [">"] = {_opgt, 2},
- ["<"] = {_oplt, 2},
- ["="] = {_opassign, 2}, [":="] = {_opassign, 2},
- ["+="] = {_opplusassign, 2}, ["-="] = {_opminusassign, 2},
- ["*="] = {_optimesassign, 2}, ["/="] = {_opdivassign, 2}, ["%="] = {_opmodassign, 2},
- MINUS = {_opunaryminus, 1},
- -- logical operators
- AND = {_opland, 2},
- OR = {_oplor, 2},
- NOT = {_oplnot, 1},
- -- bit operators
- ["<<"] = {_oplshift, 2},
- [">>"] = {_oprshift, 2}, -- bit.arshift
- [">>>"] = {_opurshift, 2}, -- bit.rshift
- ["|"] = {_opbor, 2},
- ["&"] = {_opband, 2},
- ["!"] = {_opbnot, 1},
- XOR = {_opbxor, 2},
- -- int sequence
- TO = {_opintrange, 2},
- STEP = {_opintrangestep, 2},
- -- misc
- REM = {_fnnop, 0}
-}
-_G._TBASIC._GETARGS = function(func)
- local f = _TBASIC.LUAFN[func]
- if f == nil then return nil end
- return f[2]
-end
-
-
-
--- PARSER IMPL ----------------------------------------------------------------
-
-local opprecedence = {
- {":=", "=", "+=", "-=", "*=", "/=", "%="}, -- least important
- {"OR"},
- {"AND"},
- {"|"},
- {"XOR"},
- {"&"},
- {"==", "!=", "<>", "><"},
- {"<=", ">=", "=<", "=>", "<", ">"},
- {"TO", "STEP"},
- {">>>", "<<", ">>"},
- {";"},
- {"+", "-"},
- {"*", "/", "%"},
- {"NOT", "!"},
- {"^"}, -- most important
- {"MINUS"}
-}
-local opassoc = {
- rtl = {";", "^", "NOT", "!"}
-}
-local function exprerr(token)
- _TBASIC._ERROR.SYNTAXAT(token)
-end
-function _op_precd(op)
- -- take care of prematurely prepended '#'
- local t1 = op:byte(1) == 35 and op:sub(2, #op) or op
- op = t1:upper()
-
- for i = 1, #opprecedence do
- for _, op_in_quo in ipairs(opprecedence[i]) do
- if op == op_in_quo then
- return i
- end
- end
- end
- exprerr("precedence of "..op)
-end
-
-function _op_isrtl(op)
- for _, v in ipairs(opassoc.rtl) do
- if op == v then return true end
- end
- return false
-end
-
-function _op_isltr(op)
- return not _op_isrtl(op)
-end
-
-
-
-function _G._TBASIC.isnumber(token)
- return tonumber(token) and true or false
-end
-
-function _G._TBASIC.isoperator(token)
- if token == nil then return false end
-
- -- take care of prematurely prepended '#'
- local t1 = token:byte(1) == 35 and token:sub(2, #token) or token
- token = t1
-
- for _, tocheck in ipairs(_TBASIC._OPERATR) do
- if tocheck == token:upper() then return true end
- end
- return false
-end
-
-function _G._TBASIC.isvariable(word)
- if type(word) == "number" then return false end
- if type(word) == "boolean" then return true end
- if type(word) == "table" then return true end
- if word == nil then return false end
- return word:byte(1) == 36
-end
-
-function _G._TBASIC.isargsep(token)
- return token == ","
-end
-
-function _G._TBASIC.isfunction(token)
- if token == nil then return false end
-
- -- take care of prematurely prepended '&'
- local t1 = token:byte(1) == 38 and token:sub(2, #token) or token
- token = t1
-
- -- try for builtin
- local cmpval = function(table_elem) return string.hash(table_elem) end
-
- local found = table.binsearch(_TBASIC._FNCTION, token, cmpval)
-
- if found then
- return true
- end
-
- -- try for user-defined functions
- found = table.binsearch(_TBASIC._INTPRTR.FNCTABLE, token, cmpval)
- if found then -- found is either Table or Nil. We want boolean value.
- return true
- else
- return false
- end
-end
-
-function _G._TBASIC.isstring(token)
- if type(token) ~= "string" then return false end
- return token:byte(1) == 126
-end
-
-
-
-local function printdbg(...)
- local debug = false
- if debug then print("TBASINCL", ...) end
-end
-
-
--- implementation of the Shunting Yard algo
-_G._TBASIC.TORPN = function(exprarray)
- local stack = {}
- local outqueue = {}
-
- local loophookkeylist = {}
- local function infloophook(key)
- if not _G[key] then
- _G[key] = 0
- table.insert(loophookkeylist, key)
- end
- _G[key] = _G[key] + 1
-
- if _G[key] > 50000 then
- error(key..": too long without yielding")
- end
- end
-
- local isfunction = _TBASIC.isfunction
- local isoperator = _TBASIC.isoperator
- local isargsep = _TBASIC.isargsep
- local isnumber = _TBASIC.isnumber
- local isstring = _TBASIC.isstring
-
- for _, token in ipairs(exprarray) do--expr:gmatch("[^ ]+") do
- if token == nil then error("Token is nil!") end
-
- -- hack: remove single prepended whitespace
- t1 = token:byte(1) == 32 and token:sub(2, #token) or token
- token = t1
-
- printdbg("TOKEN", "'"..token.."'")
- if isfunction(token:upper()) then
- printdbg("is function")
-
- stackpush(stack, "&"..token:upper())
- elseif isargsep(token) then
- printdbg("is argument separator")
-
- if not (stackpeek(stack) == "(" or #stack == 0) then
- repeat
- stackpush(outqueue, stackpop(stack))
-
- infloophook("repeat1")
- until stackpeek(stack) == "(" or #stack == 0
- end
- -- no left paren encountered, ERROR!
- if #stack == 0 then exprerr(token) end -- misplaces sep or mismatched parens
- elseif isoperator(token) then
- printdbg("is operator")
-
- local o1 = token
-
- while isoperator(stackpeek(stack)) and (
- (_op_isltr(o1) and _op_precd(o1) <= _op_precd(stackpeek(stack))) or
- (_op_isrtl(o1) and _op_precd(o1) < _op_precd(stackpeek(stack)))
- ) do
- local o2 = stackpeek(stack)
-
- printdbg("--> push o2 to stack, o2:", o2)
-
- stackpop(stack) -- drop
- stackpush(outqueue, (o2:byte(1) == 35) and o2 or "#"..o2:upper()) -- try to rm excess '#'
-
- infloophook("while")
- end
-
- stackpush(stack, "#"..o1:upper())
- elseif token == "(" then
- stackpush(stack, token)
- elseif token == ")" then
- while stackpeek(stack) ~= "(" do
- if #stack == 0 then
- exprerr(token)
- end
-
- printdbg("--> stack will pop", stackpeek(stack))
-
- stackpush(outqueue, stackpop(stack))
-
- infloophook("")
- end
-
- printdbg("--> will drop", stackpeek(stack), "(should be left paren!)")
-
- --[[found_left_paren = false
- if stackpeek(stack) ~= "(" then
- exprerr(token)
- else
- found_left_paren = true
- end]]
- stackpop(stack) -- drop
-
- printdbg("--> stack peek after drop", stackpeek(stack))
-
- if isfunction(stackpeek(stack)) then
- printdbg("--> will enq fn", stackpeek(stack))
- stackpush(outqueue, stackpop(stack))
- end
- printdbg("--> STACKTRACE_ITMD", table.concat(stack, " "))
- printdbg("--> OUTPUT_ITMD", table.concat(outqueue, " "))
-
- -- stack empty without finding left paren, ERROR!
- --if not found_left_paren and #stack == 0 then exprerr(token) end -- mismatched parens
- elseif isstring(token) or isnumber(token) then
- printdbg("is data")
- stackpush(outqueue, token) -- arbitrary data
- else -- a word without '~' or anything; assume it's a variable name
- printdbg("is variable")
- stackpush(outqueue, "$"..token:upper())
- end
- printdbg("STACKTRACE", table.concat(stack, " "))
- printdbg("OUTPUT", table.concat(outqueue, " "))
- printdbg()
- end
-
- while #stack > 0 do
- if stackpeek(stack) == "(" or stackpeek(stack) == ")" then
- exprerr("(paren)") -- mismatched parens
- end
- stackpush(outqueue, stackpop(stack))
-
- infloophook("while3")
- end
-
- printdbg("FINAL RESULT: "..table.concat(outqueue, " "))
-
- for _, key in ipairs(loophookkeylist) do
- _G[key] = nil
- end
-
- return outqueue
-end
-
-
--- INIT -----------------------------------------------------------------------
-
--- load extensions
-local status, err = pcall(
- function()
- if os and os.loadAPI then -- ComputerCraft
- os.loadAPI "TBASEXTN.lua"
- else
- require "TBASEXTN"
- end
- end
-)
-if err then
- error(err)
-end
-
-
---sort builtin keywords list
-table.sort(_TBASIC._FNCTION, function(a, b) return string.hash(a) < string.hash(b) end)
-
-
-_G._TBASIC._INTPRTR.RESET()
-
-
-
---[[
-Terran BASIC (TBASIC)
-Copyright (c) 2016 Torvald (minjaesong) and the contributors.
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the Software), to deal in the
-Software without restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
-Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
-]]
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/luaold/rombasicman.txt b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/luaold/rombasicman.txt
deleted file mode 100644
index fd7ff4ba3..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/assets/luaold/rombasicman.txt
+++ /dev/null
@@ -1 +0,0 @@
-// TODO Fill in from work_files/romapidoc/romapidoc.tex
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/computer/BLIT.kt b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/computer/BLIT.kt
deleted file mode 100644
index c250682c7..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/computer/BLIT.kt
+++ /dev/null
@@ -1,87 +0,0 @@
-package net.torvald.terrarum.modulecomputers.virtualcomputer.computer
-
-import net.torvald.UnsafeHelper
-import net.torvald.UnsafePtr
-import net.torvald.terrarum.AppLoader
-import net.torvald.terrarum.CommonResourcePool
-
-/**
- * Blit is a display adapter that operates in pixel-space, with resolution of 224x320 with bit depth of one.
- *
- * This Blit is inspired by the real-world Blit terminal from 1982 by Bell Labs.
- *
- * @link https://en.wikipedia.org/wiki/Blit_(computer_terminal)
- *
- * Created by minjaesong on 2019-07-22.
- */
-class BLIT {
-
- private val framebuffer = UnsafeHelper.allocate(W.toLong() * H)
-
- var scrollOffsetX = 0
- var scrollOffsetY = 0
- var textCursorPos = 0
-
- // each pixel is a byte. I know, 7 bits wasted, but whatever.
-
- // any conversion to texture/GDX pixmap/etc must be done by other system.
- // at least you can memcpy() them using UnsafeHelper
- // TODO test memcpy() over pixmap and native memory
-
- private fun toAddr(x: Int, y: Int) = (W * y + x) % framebuffer.size
-
- fun drawPict(x: Int, y: Int, bytes: ByteArray, width: Int) {
- for (yy in 0L until bytes.size / width) {
- val writeAddr = toAddr(x, y)
-
- UnsafeHelper.memcpyRaw(
- bytes, UnsafeHelper.getArrayOffset(bytes) + yy * width,
- null, framebuffer.ptr + writeAddr,
- width.toLong()
- )
- }
- }
-
- fun drawLetter(px: Int, py: Int, char: Int) {
- for (yy in 0L until 13L) {
- UnsafeHelper.memcpy(
- fontRom.ptr + (FONTROMW * (char / FONTROMCOLS) * FONTH * yy) + (char % FONTROMCOLS) * FONTW,
- toAddr(px, py),
- FONTW.toLong()
- )
- }
- }
-
-
- /**
- * Notes:
- *
- * - The font ROM will not be redefine-able. Just draw your shape on the pixel space.
- */
- companion object {
- const val W = 240
- const val H = 320
-
- const val FONTW = 6
- const val FONTH = 10
-
- const val FONTROMW = 192
- const val FONTROMH = 80
-
- const val FONTROMCOLS = FONTROMW / FONTW
- const val FONTROMROWS = FONTROMH / FONTH
-
- const val TEXT_OFFSET_X = 0 // hand-calculated value
- const val TEXT_OFFSET_Y = 4 // hand-calculated value
- // so, y=0..3 and y=317..320 won't be touched by the text drawing
-
- init {
- // load common font rom
- CommonResourcePool.addToLoadingList("dwarventech.computers.blit.fontrom") {
- // TODO
- }
- }
-
- private val fontRom = CommonResourcePool.getAs("dwarventech.computers.blit.fontrom")
- }
-}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/computer/LoadTerrarumIOLib.kt b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/computer/LoadTerrarumIOLib.kt
deleted file mode 100644
index e370728bf..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/computer/LoadTerrarumIOLib.kt
+++ /dev/null
@@ -1,12 +0,0 @@
-package net.torvald.terrarum.modulecomputers.virtualcomputer.computer
-
-import java.io.RandomAccessFile
-
-/**
- * Created by minjaesong on 2019-07-13.
- */
-class TEVDFile(path: String, mode: String) : RandomAccessFile(path, mode) {
-
-
-
-}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/computer/LoadTerrarumTermLib.kt b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/computer/LoadTerrarumTermLib.kt
deleted file mode 100644
index 6eba95c67..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/computer/LoadTerrarumTermLib.kt
+++ /dev/null
@@ -1,76 +0,0 @@
-package net.torvald.terrarum.modulecomputers.virtualcomputer.computer
-
-import net.torvald.terrarum.gameactors.ai.luaTableOf
-import net.torvald.terrarum.gameactors.ai.toLua
-import org.luaj.vm2.Globals
-import org.luaj.vm2.LuaError
-import org.luaj.vm2.LuaValue
-
-/**
- * Created by minjaesong on 2019-07-10.
- */
-object LoadTerrarumTermLib {
-
- operator fun invoke(globals: Globals, terminal: MDA) {
- globals.addZeroArgFun("term.getCursor") {
- luaTableOf(
- (terminal.cursor % terminal.width).toLua(),
- (terminal.cursor / terminal.height).toLua()
- )
- }
- globals.addTwoArgFun("term.setCursor") { p0, p1 ->
- terminal.setCursor(p0.checkint(), p1.checkint())
- LuaValue.NIL
- }
- globals.addZeroArgFun("term.getCursorBlink") {
- terminal.blink.toLua()
- }
- globals.addOneArgFun("term.setCursorBlink") { p0 ->
- terminal.blink = p0.checkboolean()
- LuaValue.NIL
- }
- globals.addZeroArgFun("term.getTextColor") {
- terminal.foreground.toLua()
- }
- globals.addZeroArgFun("term.getBackgroundColor") {
- terminal.background.toLua()
- }
- globals.addOneArgFun("term.setTextColor") { p0 ->
- terminal.foreground = p0.checkint()
- LuaValue.NIL
- }
- globals.addOneArgFun("term.setBackgroundColor") { p0 ->
- terminal.background = p0.checkint()
- LuaValue.NIL
- }
- globals.addZeroArgFun("term.getSize") {
- luaTableOf(
- (terminal.width).toLua(),
- (terminal.height).toLua()
- )
- }
- globals.addZeroArgFun("term.clear") {
- terminal.clear()
- LuaValue.NIL
- }
- globals.addZeroArgFun("term.clearLine") {
- terminal.clearCurrentLine()
- LuaValue.NIL
- }
- globals.addOneArgFun("term.scroll") { p0 ->
- if (p0.checkint() < 0)
- throw LuaError("Scroll amount must be a positive number")
- terminal.scroll(p0.toint())
- LuaValue.NIL
- }
- globals.addOneArgFun("term.write") { p0 ->
- terminal.print(p0.checkjstring())
- LuaValue.NIL
- }
- globals.addThreeArgFun("term.setText") { p0, p1, p2 ->
- terminal.setOneText(p0.checkint(), p1.checkint(), p2.checkint().toByte())
- LuaValue.NIL
- }
- }
-
-}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/computer/LuaComputerVM.kt b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/computer/LuaComputerVM.kt
deleted file mode 100644
index 3363a4b15..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/computer/LuaComputerVM.kt
+++ /dev/null
@@ -1,697 +0,0 @@
-package net.torvald.terrarum.modulecomputers.virtualcomputer.computer
-
-import net.torvald.terrarum.KVHashMap
-import net.torvald.terrarum.Second
-import net.torvald.terrarum.ceilInt
-import org.luaj.vm2.Globals
-import org.luaj.vm2.LoadState
-import org.luaj.vm2.LuaError
-import org.luaj.vm2.LuaValue
-import org.luaj.vm2.compiler.LuaC
-import org.luaj.vm2.lib.*
-import org.luaj.vm2.lib.jse.*
-import org.lwjgl.BufferUtils
-import org.lwjgl.openal.AL10
-import java.io.InputStream
-import java.io.OutputStream
-import java.io.PrintStream
-import java.io.Reader
-import java.nio.ByteBuffer
-import java.util.*
-
-/**
- * A part that makes "computer fixture" actually work
- *
- * @param avFixtureComputer : actor values for FixtureComputerBase
- *
- * @param term : terminal that is connected to the computer fixtures, null if not connected any.
- * Created by minjaesong on 2016-09-10.
- */
-class LuaComputerVM(val display: MDA) {
-
- val DEBUG = true
-
- lateinit private var luaJ_globals: Globals
-
- var stdout: PrintStream? = null
- private set
- var stderr: PrintStream? = null
- private set
- var stdin: InputStream? = null
- private set
-
-
- val UUID = java.util.UUID.randomUUID().toString()
-
- val computerValue = KVHashMap()
-
- var isHalted = false
-
- var stdinInput: Int = -1
- private set
-
-
- // os-related functions. These are called "machine" library-wise.
- private val startupTimestamp: Long = System.currentTimeMillis()
- /** Time elapsed since the power is on. */
- val milliTime: Int
- get() = (System.currentTimeMillis() - startupTimestamp).toInt()
-
-
- init {
- initSandbox()
- }
-
- fun initSandbox() {
- val luaJ_globals = Globals()
- luaJ_globals.load(JseBaseLib())
- luaJ_globals.load(PackageLib())
- luaJ_globals.load(Bit32Lib())
- luaJ_globals.load(TableLib())
- luaJ_globals.load(JseStringLib())
- luaJ_globals.load(CoroutineLib())
- luaJ_globals.load(JseMathLib())
- luaJ_globals.load(JseIoLib())
- luaJ_globals.load(JseOsLib())
- luaJ_globals.load(LuajavaLib())
- LoadState.install(luaJ_globals)
- LuaC.install(luaJ_globals)
-
- stdout = TerminalPrintStream(this)
- stderr = TerminalPrintStream(this)
- stdin = TerminalInputStream(this)
-
- luaJ_globals.STDOUT = stdout
- luaJ_globals.STDERR = stderr
- luaJ_globals.STDIN = stdin
-
- luaJ_globals["bit"] = luaJ_globals["bit32"]
-
- // load libraries
- LoadTerrarumTermLib(luaJ_globals, display)
-
- // secure the sandbox
- //luaJ_globals["io"] = LuaValue.NIL
- // dubug should be sandboxed in BOOT.lua (use OpenComputers code)
- //val sethook = luaJ_globals["debug"]["sethook"]
- //luaJ_globals["debug"] = LuaValue.NIL
-
-
- }
-
- fun update(delta: Float) {
-
- if (currentExecutionThread.state == Thread.State.TERMINATED) {
- threadRun = false
- }
-
-
-
-
- if (!isHalted) {
- runBeepQueueManager(delta)
- }
- }
-
- fun keyPressed(c: Int) {
- stdinInput = c
-
- // wake thread
- runnableRunCommand.resume()
-
- synchronized(stdin!!) {
- (stdin as java.lang.Object).notifyAll()
- }
- }
-
- fun openStdin() {
- stdinInput = -1
- // sleep the thread
- runnableRunCommand.pause()
- }
-
- lateinit var currentExecutionThread: Thread
- private set
- lateinit var runnableRunCommand: ThreadRunCommand
- private set
- private var threadRun = false
-
- fun runCommand(line: String, env: String) {
- if (!threadRun) {
- runnableRunCommand = ThreadRunCommand(luaJ_globals, line, env)
- currentExecutionThread = Thread(null, runnableRunCommand, "LuaJ Separated")
- currentExecutionThread.start()
- threadRun = true
- }
- }
-
- fun runCommand(reader: Reader, filename: String) {
- if (!threadRun) {
- runnableRunCommand = ThreadRunCommand(luaJ_globals, reader, filename)
- currentExecutionThread = Thread(null, runnableRunCommand, "LuaJ Separated")
- currentExecutionThread.start()
- threadRun = true
- }
- }
-
- /**
- * @link https://stackoverflow.com/questions/16758346/how-pause-and-then-resume-a-thread#16758373
- */
- class ThreadRunCommand : Runnable {
-
- private val mode: Int
- private val arg1: Any
- private val arg2: String
- private val lua: Globals
-
- @Volatile private var running = true
- @Volatile private var paused = false
- private val pauseLock = java.lang.Object()
-
- constructor(luaInstance: Globals, line: String, env: String) {
- mode = 0
- arg1 = line
- arg2 = env
- lua = luaInstance
- }
-
- constructor(luaInstance: Globals, reader: Reader, filename: String) {
- mode = 1
- arg1 = reader
- arg2 = filename
- lua = luaInstance
- }
-
- override fun run() {
- synchronized(pauseLock) {
- if (!running) { // may have changed while waiting to
- // synchronize on pauseLock
- return
- }
- if (paused) {
- try {
- pauseLock.wait() // will cause this Thread to block until
- // another thread calls pauseLock.notifyAll()
- // Note that calling wait() will
- // relinquish the synchronized lock that this
- // thread holds on pauseLock so another thread
- // can acquire the lock to call notifyAll()
- // (link with explanation below this code)
- }
- catch (ex: InterruptedException) {
- return
- }
-
- if (!running) { // running might have changed since we paused
- return
- }
- }
- }
-
-
- try {
- val chunk: LuaValue
- if (mode == 0)
- chunk = lua.load(arg1 as String, arg2)
- else if (mode == 1)
- chunk = lua.load(arg1 as Reader, arg2)
- else
- throw IllegalArgumentException("Unsupported mode: $mode")
-
-
- chunk.call()
- }
- catch (e: LuaError) {
- e.printStackTrace(System.err)
- //lua.STDERR.println("${SimpleTextTerminal.ASCII_DLE}${e.message}${SimpleTextTerminal.ASCII_DC4}")
- }
- }
-
- fun stop() {
- running = false
- // you might also want to do this:
- //interrupt()
- }
-
- fun pause() {
- // you may want to throw an IllegalStateException if !running
- paused = true
- }
-
- fun resume() {
- synchronized(pauseLock) {
- paused = false
- pauseLock.notifyAll() // Unblocks thread
- }
- }
- }
-
- class ComputerEmitTone(val computer: LuaComputerVM) : TwoArgFunction() {
- override fun call(millisec: LuaValue, freq: LuaValue): LuaValue {
- computer.playTone(millisec.checkdouble().toFloat(), freq.checkdouble())
- return LuaValue.NONE
- }
- }
-
- ///////////////////
- // BEEPER DRIVER //
- ///////////////////
-
- private val beepMaxLen = 10f
- // let's regard it as a tracker...
- private val beepQueue = ArrayList>()
- private var beepCursor = -1
- private var beepQueueLineExecTimer: Second = 0f
- private var beepQueueFired = false
-
- private fun runBeepQueueManager(delta: Float) {
- // start emitTone queue
- if (beepQueue.size > 0 && beepCursor == -1) {
- beepCursor = 0
- }
-
- // advance emitTone queue
- if (beepCursor >= 0 && beepQueueLineExecTimer >= beepQueueGetLenOfPtn(beepCursor)) {
- beepQueueLineExecTimer -= beepQueueGetLenOfPtn(beepCursor)
- beepCursor += 1
- beepQueueFired = false
- }
-
- // complete emitTone queue
- if (beepCursor >= beepQueue.size) {
- clearBeepQueue()
- }
-
- // actually play queue
- if (beepCursor >= 0 && beepQueue.size > 0 && !beepQueueFired) {
- playTone(beepQueue[beepCursor].first, beepQueue[beepCursor].second)
- beepQueueFired = true
-
- // delete sources that is finished. AL is limited to 256 sources. If you exceed it,
- // we won't get any more sounds played.
- AL10.alSourcei(oldBeepSource, AL10.AL_BUFFER, 0)
- AL10.alDeleteSources(oldBeepSource)
- AL10.alDeleteBuffers(oldBeepBuffer)
- }
-
- if (beepQueueFired) beepQueueLineExecTimer += delta
- }
-
- fun clearBeepQueue() {
- beepQueue.clear()
- beepCursor = -1
- beepQueueLineExecTimer = 0f
-
- //AL.destroy()
-
- if (DEBUG) println("[TerrarumComputerOld] !! Beep queue clear")
- }
-
- fun enqueueBeep(duration: Double, freq: Double) {
- beepQueue.add(Pair(Math.min(duration.toFloat(), beepMaxLen), freq))
- }
-
- fun beepQueueGetLenOfPtn(ptnIndex: Int) = beepQueue[ptnIndex].first
-
-
- ////////////////////
- // TONE GENERATOR //
- ////////////////////
-
- private val sampleRate = 44100
- private var beepSource: Int = -1
- private var beepBuffer: Int = -1
- private var oldBeepSource: Int = -1
- private var oldBeepBuffer: Int = -1
- var audioData: ByteBuffer? = null
-
- /**
- * @param duration : milliseconds
- * @param rampUp
- * @param rampDown
- *
- * ,---. (true, true) ,---- (true, false) ----. (false, true) ----- (false, false)
- */
- private fun makeAudioData(duration: Second, freq: Double,
- rampUp: Boolean = true, rampDown: Boolean = true): ByteBuffer {
-
- TODO("with duration as Seconds")
-
- val audioDataSize = duration.times(sampleRate).ceilInt()
- val audioData = BufferUtils.createByteBuffer(audioDataSize)
-
- /*val realDuration = duration * sampleRate / 1000
- val chopSize = freq / sampleRate
-
- val amp = Math.max(4600.0 / freq, 1.0)
- val nHarmonics = if (freq >= 22050.0) 1
- else if (freq >= 11025.0) 2
- else if (freq >= 5512.5) 3
- else if (freq >= 2756.25) 4
- else if (freq >= 1378.125) 5
- else if (freq >= 689.0625) 6
- else 7
-
- val transitionThre = 974.47218
-
- // TODO volume ramping?
- if (freq == 0.0) {
- for (_ in 0..audioDataSize - 1) {
- audioData.put(0x00.toByte())
- }
- }
- else if (freq < transitionThre) { // chopper generator (for low freq)
- for (tsart in 0..audioDataSize - 1) {
- var sine: Double = amp * Math.cos(Math.PI * 2 * () * chopSize)
- if (sine > 0.79) sine = 0.79
- else if (sine < -0.79) sine = -0.79
- audioData.put(
- (0.5 + 0.5 * sine).times(0xFF).roundToInt().toByte()
- )
- }
- }
- else { // harmonics generator (for high freq)
- for (x in 0..realDuration - 1) {
- var sine: Double = 0.0
- for (k in 1..nHarmonics) { // mix only odd harmonics in order to make a squarewave
- sine += Math.sin(Math.PI * 2 * (2*k - 1) * chopSize * x) / (2*k - 1)
- }
- audioData.put(
- (0.5 + 0.5 * sine).times(0xFF).roundToInt().toByte()
- )
- }
- }*/
-
- audioData.rewind()
-
- return audioData
- }
-
- private fun playTone(length: Second, freq: Double) {
- /*audioData = makeAudioData(leninmilli, freq)
-
-
- if (!AL.isCreated()) AL.create()
-
-
- // Clear error stack.
- AL10.alGetError()
-
- oldBeepBuffer = beepBuffer
- beepBuffer = AL10.alGenBuffers()
- checkALError()
-
- try {
- AL10.alBufferData(beepBuffer, AL10.AL_FORMAT_MONO8, audioData, sampleRate)
- checkALError()
-
- oldBeepSource = beepSource
- beepSource = AL10.alGenSources()
- checkALError()
-
- try {
- AL10.alSourceQueueBuffers(beepSource, beepBuffer)
- checkALError()
-
- AL10.alSource3f(beepSource, AL10.AL_POSITION, 0f, 0f, 1f)
- AL10.alSourcef(beepSource, AL10.AL_REFERENCE_DISTANCE, 1f)
- AL10.alSourcef(beepSource, AL10.AL_MAX_DISTANCE, 1f)
- AL10.alSourcef(beepSource, AL10.AL_GAIN, 0.3f)
- checkALError()
-
- AL10.alSourcePlay(beepSource)
- checkALError()
- }
- catch (e: ALException) {
- AL10.alDeleteSources(beepSource)
- }
- }
- catch (e: ALException) {
- AL10.alDeleteSources(beepSource)
- }*/
- }
-
- // Custom implementation of Util.checkALError() that uses our custom exception.
- private fun checkALError() {
- val errorCode = AL10.alGetError()
- if (errorCode != AL10.AL_NO_ERROR) {
- throw ALException(errorCode)
- }
- }
-
-}
-
-class TerminalPrintStream(val host: LuaComputerVM) : PrintStream(TerminalOutputStream(host))
-
-class TerminalOutputStream(val host: LuaComputerVM) : OutputStream() {
- override fun write(b: Int) = host.display.write(b.and(0xFF).toByte())
-}
-
-class TerminalInputStream(val host: LuaComputerVM) : InputStream() {
-
- override fun read(): Int {
- //System.err.println(Thread.currentThread().name)
- // would display "LuaJ Separated", which means this InputStream will not block main thread
-
- /*host.openStdin()
- synchronized(this) {
- (this as java.lang.Object).wait()
- }*/
-
- return 65//host.stdinInput
- }
-
-}
-
-class ALException(errorCode: Int) : Exception("ALerror: $errorCode") {
-
-}
-
-
-/**
- * Install a function into the lua.
- * @param identifier How you might call this lua function. E.g. "term.println"
- */
-fun Globals.addOneArgFun(identifier: String, function: (p0: LuaValue) -> LuaValue) {
- val theActualFun = object : OneArgFunction() {
- override fun call(p0: LuaValue): LuaValue {
- return function(p0)
- }
- }
-
- val tableNames = identifier.split('.')
-
- if (tableNames.isEmpty()) throw IllegalArgumentException("Identifier is empty")
-
- //println(tableNames)
-
- if (this[tableNames[0]].isnil()) {
- this[tableNames[0]] = LuaValue.tableOf()
- }
- else if (!this[tableNames[0]].istable()) {
- throw IllegalStateException("Redefinition: '${tableNames[0]}' (${this[tableNames[0]]})")
- }
-
- var currentTable = this[tableNames[0]]
-
- // turn nils into tables
- if (tableNames.size > 1) {
- tableNames.slice(1..tableNames.lastIndex).forEachIndexed { index, it ->
- if (currentTable[it].isnil()) {
- currentTable[it] = LuaValue.tableOf()
- }
- else if (!currentTable[it].istable()) {
- throw IllegalStateException("Redefinition: '${tableNames.slice(0..(index + 1)).joinToString(".")}' (${currentTable[it]})")
- }
-
- currentTable = currentTable[it]
- }
-
- // actually put the function onto the target
- // for some reason, memoisation doesn't work here so we use recursion to reach the target table as generated above
- tailrec fun putIntoTheTableRec(luaTable: LuaValue, recursionCount: Int) {
- if (recursionCount == tableNames.lastIndex - 1) {
- luaTable[tableNames[tableNames.lastIndex]] = theActualFun
- }
- else {
- putIntoTheTableRec(luaTable[tableNames[recursionCount + 1]], recursionCount + 1)
- }
- }
-
- putIntoTheTableRec(this[tableNames[0]], 0)
- }
- else {
- this[tableNames[0]] = theActualFun
- }
-}
-
-/**
- * Install a function into the lua.
- * @param identifier How you might call this lua function. E.g. "term.println"
- */
-fun Globals.addZeroArgFun(identifier: String, function: () -> LuaValue) {
- val theActualFun = object : ZeroArgFunction() {
- override fun call(): LuaValue {
- return function()
- }
- }
-
- val tableNames = identifier.split('.')
-
- if (tableNames.isEmpty()) throw IllegalArgumentException("Identifier is empty")
-
- //println(tableNames)
-
- if (this[tableNames[0]].isnil()) {
- this[tableNames[0]] = LuaValue.tableOf()
- }
- else if (!this[tableNames[0]].istable()) {
- throw IllegalStateException("Redefinition: '${tableNames[0]}' (${this[tableNames[0]]})")
- }
-
- var currentTable = this[tableNames[0]]
-
- // turn nils into tables
- if (tableNames.size > 1) {
- tableNames.slice(1..tableNames.lastIndex).forEachIndexed { index, it ->
- if (currentTable[it].isnil()) {
- currentTable[it] = LuaValue.tableOf()
- }
- else if (!currentTable[it].istable()) {
- throw IllegalStateException("Redefinition: '${tableNames.slice(0..(index + 1)).joinToString(".")}' (${currentTable[it]})")
- }
-
- currentTable = currentTable[it]
- }
-
- // actually put the function onto the target
- // for some reason, memoisation doesn't work here so we use recursion to reach the target table as generated above
- tailrec fun putIntoTheTableRec(luaTable: LuaValue, recursionCount: Int) {
- if (recursionCount == tableNames.lastIndex - 1) {
- luaTable[tableNames[tableNames.lastIndex]] = theActualFun
- }
- else {
- putIntoTheTableRec(luaTable[tableNames[recursionCount + 1]], recursionCount + 1)
- }
- }
-
- putIntoTheTableRec(this[tableNames[0]], 0)
- }
- else {
- this[tableNames[0]] = theActualFun
- }
-}
-
-/**
- * Install a function into the lua.
- * @param identifier How you might call this lua function. E.g. "term.println"
- */
-fun Globals.addTwoArgFun(identifier: String, function: (p0: LuaValue, p1: LuaValue) -> LuaValue) {
- val theActualFun = object : TwoArgFunction() {
- override fun call(p0: LuaValue, p1: LuaValue): LuaValue {
- return function(p0, p1)
- }
- }
-
- val tableNames = identifier.split('.')
-
- if (tableNames.isEmpty()) throw IllegalArgumentException("Identifier is empty")
-
- //println(tableNames)
-
- if (this[tableNames[0]].isnil()) {
- this[tableNames[0]] = LuaValue.tableOf()
- }
- else if (!this[tableNames[0]].istable()) {
- throw IllegalStateException("Redefinition: '${tableNames[0]}' (${this[tableNames[0]]})")
- }
-
- var currentTable = this[tableNames[0]]
-
- // turn nils into tables
- if (tableNames.size > 1) {
- tableNames.slice(1..tableNames.lastIndex).forEachIndexed { index, it ->
- if (currentTable[it].isnil()) {
- currentTable[it] = LuaValue.tableOf()
- }
- else if (!currentTable[it].istable()) {
- throw IllegalStateException("Redefinition: '${tableNames.slice(0..(index + 1)).joinToString(".")}' (${currentTable[it]})")
- }
-
- currentTable = currentTable[it]
- }
-
- // actually put the function onto the target
- // for some reason, memoisation doesn't work here so we use recursion to reach the target table as generated above
- tailrec fun putIntoTheTableRec(luaTable: LuaValue, recursionCount: Int) {
- if (recursionCount == tableNames.lastIndex - 1) {
- luaTable[tableNames[tableNames.lastIndex]] = theActualFun
- }
- else {
- putIntoTheTableRec(luaTable[tableNames[recursionCount + 1]], recursionCount + 1)
- }
- }
-
- putIntoTheTableRec(this[tableNames[0]], 0)
- }
- else {
- this[tableNames[0]] = theActualFun
- }
-}
-
-/**
- * Install a function into the lua.
- * @param identifier How you might call this lua function. E.g. "term.println"
- */
-fun Globals.addThreeArgFun(identifier: String, function: (p0: LuaValue, p1: LuaValue, p2: LuaValue) -> LuaValue) {
- val theActualFun = object : ThreeArgFunction() {
- override fun call(p0: LuaValue, p1: LuaValue, p2: LuaValue): LuaValue {
- return function(p0, p1, p2)
- }
- }
-
- val tableNames = identifier.split('.')
-
- if (tableNames.isEmpty()) throw IllegalArgumentException("Identifier is empty")
-
- //println(tableNames)
-
- if (this[tableNames[0]].isnil()) {
- this[tableNames[0]] = LuaValue.tableOf()
- }
- else if (!this[tableNames[0]].istable()) {
- throw IllegalStateException("Redefinition: '${tableNames[0]}' (${this[tableNames[0]]})")
- }
-
- var currentTable = this[tableNames[0]]
-
- // turn nils into tables
- if (tableNames.size > 1) {
- tableNames.slice(1..tableNames.lastIndex).forEachIndexed { index, it ->
- if (currentTable[it].isnil()) {
- currentTable[it] = LuaValue.tableOf()
- }
- else if (!currentTable[it].istable()) {
- throw IllegalStateException("Redefinition: '${tableNames.slice(0..(index + 1)).joinToString(".")}' (${currentTable[it]})")
- }
-
- currentTable = currentTable[it]
- }
-
- // actually put the function onto the target
- // for some reason, memoisation doesn't work here so we use recursion to reach the target table as generated above
- tailrec fun putIntoTheTableRec(luaTable: LuaValue, recursionCount: Int) {
- if (recursionCount == tableNames.lastIndex - 1) {
- luaTable[tableNames[tableNames.lastIndex]] = theActualFun
- }
- else {
- putIntoTheTableRec(luaTable[tableNames[recursionCount + 1]], recursionCount + 1)
- }
- }
-
- putIntoTheTableRec(this[tableNames[0]], 0)
- }
- else {
- this[tableNames[0]] = theActualFun
- }
-}
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/computer/MDA.kt b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/computer/MDA.kt
deleted file mode 100644
index 50dfe1c2c..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/computer/MDA.kt
+++ /dev/null
@@ -1,246 +0,0 @@
-package net.torvald.terrarum.modulecomputers.virtualcomputer.computer
-
-import net.torvald.UnsafeHelper
-import net.torvald.terrarum.AppLoader
-import net.torvald.terrarum.gameworld.fmod
-import java.io.OutputStream
-import java.io.PrintStream
-import java.nio.charset.Charset
-
-/**
- * Only one kind of display adapter should exist in the game: they add nothing to the game and the game
- * shouldn't put much emphasis on computers anyway.
- *
- * The actual draw code must not exist in this class!
- *
- * Created by minjaesong on 2019-07-09.
- */
-class MDA(val width: Int, val height: Int) {
-
- companion object {
- val charset: Charset = Charset.forName("cp437")
- }
-
- init {
- if (width % 2 == 1) throw IllegalArgumentException("Display width must be an even number (width = $width)")
- }
-
- private val arrayElemOffset = 8L * if (AppLoader.is32BitJVM) 1 else 2 // 8 for 32-bit, 16 for 64-bit
-
- private val glyphs = UnsafeHelper.allocate(width.toLong() * height + 1) // extra one byte is absolutely needed
- private val attributes = UnsafeHelper.allocate(width.toLong() * height + 1)
-
- var cursor = 0
- private set
- var background = 0
- var foreground = 1
- var blink = true
-
- init {
- glyphs.fillWith(0)
- attributes.fillWith(1)
- }
-
- /*
- Attibutes memory map:
-
- for every byte:
-
- (msb) 00bb 00ff (lsb)
-
- where:
-
- bb: background colour
- ff: foreground colour
-
- Colours:
-
- 0: black
- 1: light grey
- 2: dark grey
- 3: white
-
- */
-
- fun toAttribute(back: Int, fore: Int) = (back.shl(4) or fore).toByte()
-
- private fun wrapAround(x: Int, y: Int) = (x fmod width) to (y fmod height)
- private fun toAddress(x: Int, y: Int) = (y * width + x).toLong()
- inline private fun Pair.toAddress() = toAddress(this.first, this.second)
-
- fun rawGet(offset: Int) = glyphs[offset.toLong()] to attributes[offset.toLong()]
-
- fun get(x: Int, y: Int): Pair {
- val a = wrapAround(x, y).toAddress()
- return glyphs[a] to attributes[a]
- }
-
- fun set(x: Int, y: Int, glyph: Byte, attribute: Byte) {
- val a = wrapAround(x, y).toAddress()
- glyphs[a] = glyph
- attributes[a] = attribute
- }
-
- private fun set(offset: Int, glyph: Byte, attribute: Byte) {
- glyphs[offset.toLong()] = glyph
- attributes[offset.toLong()] = attribute
- }
-
- fun setCursor(x: Int, y: Int) {
- cursor = wrapAround(x, y).toAddress().toInt()
- }
-
- // SETTEXT methods should not deal with the scrolling, it must be handled by the PRINT methods.
-
- /** Bulk write method. Any control characers will be represented as a glyph, rather than an actual control sequence.
- * E.g. '\n' will print a symbol. */
- fun setText(x: Int, y: Int, text: ByteArray, attribute: ByteArray) {
- UnsafeHelper.memcpyRaw(text, arrayElemOffset, null, glyphs.ptr + wrapAround(x, y).toAddress(), text.size.toLong())
- UnsafeHelper.memcpyRaw(attribute, arrayElemOffset, null, attributes.ptr + wrapAround(x, y).toAddress(), text.size.toLong())
- }
-
- private fun setText(offset: Int, text: ByteArray, attribute: ByteArray) {
- UnsafeHelper.memcpyRaw(text, arrayElemOffset, null, glyphs.ptr + offset, text.size.toLong())
- UnsafeHelper.memcpyRaw(attribute, arrayElemOffset, null, attributes.ptr + offset, text.size.toLong())
- }
-
- /** Bulk write method. Any control characers will be represented as a glyph, rather than an actual control sequence.
- * E.g. '\n' will print a symbol. */
- fun setText(x: Int, y: Int, text: ByteArray, attribute: Byte) {
- setText(x, y, text, ByteArray(text.size) { attribute })
- }
-
- private fun setText(offset: Int, text: ByteArray, attribute: Byte = toAttribute(background, foreground)) {
- setText(offset, text, ByteArray(text.size) { attribute })
- }
-
- /** Bulk write method. Any control characers will be represented as a glyph, rather than an actual control sequence.
- * E.g. '\n' will print a symbol. */
- inline fun setText(x: Int, y: Int, text: ByteArray) {
- setText(x, y, text, toAttribute(background, foreground))
- }
-
- fun setOneText(x: Int, y: Int, text: Byte, attribute: Byte = toAttribute(background, foreground)) {
- val o = wrapAround(x, y).toAddress()
- glyphs[o] = text
- attributes[o] = attribute
- }
-
- private fun setOneText(offset: Int, text: Byte, attribute: Byte = toAttribute(background, foreground)) {
- glyphs[offset.toLong()] = text
- attributes[offset.toLong()] = attribute
- }
-
-
-
- fun println(text: String) {
- print(text)
- write(0x0A)
- }
- inline fun print(text: String) {
- print(text.toByteArray(charset))
- }
-
- fun println(text: ByteArray) {
- print(text)
- write(0x0A)
- }
- fun print(text: ByteArray) {
- text.forEach { write(it) }
- }
-
- fun write(text: Byte) {
- when (text) {
- // LF
- 0x0A.toByte() -> newline()
- // all others (e.g. CR)
- in 0x00.toByte()..0x0D.toByte() -> { /* do nothing */ }
-
- else -> {
- setOneText(cursor, text)
- cursor += 1
-
- if (cursor > width * height) {
- scroll(1)
- }
- }
- }
-
- }
-
- fun clear() {
- glyphs.fillWith(0)
- attributes.fillWith(toAttribute(background, foreground))
- cursor = 0
- }
-
- fun clearCurrentLine() {
- clearLine(cursor / width)
- }
-
- fun clearLine(line: Int) {
- val lineOffset = line * width
- for (i in 0L until width) {
- glyphs[lineOffset + i] = 0
- }
- }
-
- fun clearLineAfterCursor() {
- val lineOffset = (cursor / width) * width
- for (i in (cursor % width).toLong() until width) {
- glyphs[lineOffset + i] = 0
- }
- }
-
- /**
- * moves text and the current cursor position
- */
- fun scroll(amount: Int) {
- val offset = (width * amount).toLong()
- if (amount < 0) throw IllegalArgumentException("amount = $amount")
-
- UnsafeHelper.memcpy(glyphs, offset, glyphs, 0L, glyphs.size - offset)
- UnsafeHelper.memcpy(attributes, offset, attributes, 0L, attributes.size - offset)
-
- cursor -= offset.toInt()
- if (cursor < 0) cursor = 0
-
- clearLineAfterCursor()
- }
-
- /**
- * Advance one line, scroll the screen if necessary
- */
- fun newline() {
- cursor += width
-
- if (cursor >= width * height) {
- scroll(1)
- }
-
- cursor = (cursor / width) * width // set cursorX to 0
- clearLineAfterCursor()
- }
-
- fun dispose() {
- glyphs.destroy()
- attributes.destroy()
- }
-}
-
-private class MDAOutputStream(val mda: MDA) : OutputStream() {
- override fun write(b: Int) {
- mda.write(b.toByte())
- }
-}
-
-class MDAPrintStream(val mda: MDA) : PrintStream(MDAOutputStream(mda)) {
- override fun print(s: String?) {
- mda.print((s ?: "").toByteArray(MDA.charset))
- }
-
- override fun println(s: String?) {
- print(s)
- mda.newline()
- }
-}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/computer/TerrarumComputerOld.kt.txt b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/computer/TerrarumComputerOld.kt.txt
deleted file mode 100644
index 15336c4a8..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/computer/TerrarumComputerOld.kt.txt
+++ /dev/null
@@ -1,585 +0,0 @@
-package net.torvald.terrarum.modulecomputers.virtualcomputer.computer
-
-import net.torvald.terrarum.KVHashMap
-import net.torvald.terrarum.Second
-import net.torvald.terrarum.Terrarum
-import net.torvald.terrarum.ceilInt
-import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.VDUtil
-import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.VirtualDisk
-import net.torvald.terrarum.modulecomputers.virtualcomputer.worldobject.ComputerPartsCodex
-import org.luaj.vm2.Globals
-import org.luaj.vm2.LuaError
-import org.luaj.vm2.LuaTable
-import org.luaj.vm2.LuaValue
-import org.luaj.vm2.lib.TwoArgFunction
-import org.luaj.vm2.lib.ZeroArgFunction
-import org.luaj.vm2.lib.jse.JsePlatform
-import org.lwjgl.BufferUtils
-import org.lwjgl.openal.AL10
-import java.io.*
-import java.nio.ByteBuffer
-import java.util.*
-import java.util.logging.Level
-import kotlin.collections.HashMap
-
-/**
- * A part that makes "computer fixture" actually work
- *
- * @param avFixtureComputer : actor values for FixtureComputerBase
- *
- * @param term : terminal that is connected to the computer fixtures, null if not connected any.
- * Created by minjaesong on 2016-09-10.
- */
-class TerrarumComputerOldOld(peripheralSlots: Int) {
-
- val DEBUG_UNLIMITED_MEM = false
- val DEBUG = true
-
-
- val maxPeripherals: Int = if (DEBUG) 32 else peripheralSlots
-
-
- lateinit var luaJ_globals: Globals
- private set
-
- var stdout: PrintStream? = null
- private set
- var stderr: PrintStream? = null
- private set
- var stdin: InputStream? = null
- private set
-
- val processorCycle: Int // number of Lua statement to process per tick (1/100 s)
- get() = ComputerPartsCodex.getProcessorCycles(computerValue.getAsInt("processor") ?: 0)
- val memSize: Int // in bytes; max: 8 GB
- get() {
- if (DEBUG_UNLIMITED_MEM) return 16.shl(20)// 16 MB
-
- var size = 0
- for (i in 0..3)
- size += ComputerPartsCodex.getRamSize(computerValue.getAsInt("memSlot$i")!!)
-
- return size
- }
-
- val UUID = java.util.UUID.randomUUID().toString()
-
- val computerValue = KVHashMap()
-
- var isHalted = false
-
- lateinit var term: net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Teletype
- private set
-
- val peripheralTable = Array(peripheralSlots, { null }) // index == slot number
-
- var stdinInput: Int = -1
- private set
-
-
- // os-related functions. These are called "machine" library-wise.
- private val startupTimestamp: Long = System.currentTimeMillis()
- /** Time elapsed since the power is on. */
- val milliTime: Int
- get() = (System.currentTimeMillis() - startupTimestamp).toInt()
-
- /** String:
- * if it's UUID, formatted UUID as string, always 36 chars
- * if not (test purpose only!), just String
- */
- val diskRack = HashMap()
-
- fun attachDisk(slot: String, filename: String) {
- computerValue[slot] = filename
-
- // put disk in diskRack
- if (filename.isNotEmpty() && filename.isNotBlank()) {
- diskRack[slot] = VDUtil.readDiskArchive(
- File(Terrarum.currentSaveDir.path + "/computers/$filename").absoluteFile,
- Level.WARNING,
- { },
- net.torvald.terrarum.modulecomputers.virtualcomputer.luaapi.Filesystem.sysCharset
- )
- }
- }
-
- init {
- computerValue["memslot0"] = 4864 // -1 indicates mem slot is empty
- computerValue["memslot1"] = -1 // put index of item here
- computerValue["memslot2"] = -1 // ditto.
- computerValue["memslot3"] = -1 // do.
-
- computerValue["processor"] = -1 // do.
-
- // as in "dev/hda"; refers hard disk drive (and no partitioning)
- attachDisk("hda", "uuid_testhda")
- attachDisk("hdb", "")
- attachDisk("hdc", "")
- attachDisk("hdd", "")
- // as in "dev/fd1"; refers floppy disk drive
- attachDisk("fd1", "")
- attachDisk("fd2", "")
- attachDisk("fd3", "")
- attachDisk("fd4", "")
- // SCSI connected optical drive
- attachDisk("sda", "")
-
- // boot device
- computerValue["boot"] = "hda"
- }
-
- fun getPeripheral(tableName: String): net.torvald.terrarum.modulecomputers.virtualcomputer.peripheral.Peripheral? {
- peripheralTable.forEach {
- if (it?.tableName == tableName)
- return it
- }
- return null
- }
-
- fun getPeripheralSlot(tableName: String): Int? {
- peripheralTable.forEachIndexed { index, peri ->
- if (peri?.tableName == tableName)
- return index
- }
- return null
- }
-
- /** @return installed slot */
- fun attachPeripheral(peri: net.torvald.terrarum.modulecomputers.virtualcomputer.peripheral.Peripheral): Int {
- (0..maxPeripherals - 1).forEach {
- try {
- attachPeripheralTo(peri, it)
- return it
- }
- catch (tryNext: RuntimeException) { }
- }
-
- throw RuntimeException("No vacant peripheral slot")
- }
-
- fun attachPeripheralTo(peri: net.torvald.terrarum.modulecomputers.virtualcomputer.peripheral.Peripheral, slot: Int) {
- if (peripheralTable[slot] == null) {
- peripheralTable[slot] = peri
- peri.loadLib(luaJ_globals)
- println("[TerrarumComputerOld] loading peripheral $peri")
- }
- else {
- throw RuntimeException("Peripheral slot is already taken by: ${peripheralTable[slot]?.tableName}")
- }
- }
-
- fun detachPeripheral(peri: net.torvald.terrarum.modulecomputers.virtualcomputer.peripheral.Peripheral) {
- // search for the peripheral
- var found = -1
- for (i in 0..maxPeripherals - 1) {
- if (peripheralTable[i] == peri) {
- found = i
- break
- }
- }
- if (found >= 0) {
- peripheralTable[found] = null
- println("[TerrarumComputerOld] unloading peripheral $peri")
- }
- else {
- throw IllegalArgumentException("Peripheral not exists: $peri")
- }
- }
-
- fun attachTerminal(term: net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Teletype) {
- this.term = term
- initSandbox(term)
- }
-
- fun initSandbox(term: net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Teletype) {
- luaJ_globals = JsePlatform.debugGlobals()
-
- stdout = net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.TerminalPrintStream(this)
- stderr = net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.TerminalPrintStream(this)
- stdin = net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.TerminalInputStream(this)
-
- luaJ_globals.STDOUT = stdout
- luaJ_globals.STDERR = stderr
- luaJ_globals.STDIN = stdin
-
- luaJ_globals["bit"] = luaJ_globals["bit32"]
-
- // load libraries
- net.torvald.terrarum.modulecomputers.virtualcomputer.luaapi.Term(luaJ_globals, term)
- net.torvald.terrarum.modulecomputers.virtualcomputer.luaapi.Security(luaJ_globals)
- net.torvald.terrarum.modulecomputers.virtualcomputer.luaapi.Filesystem(luaJ_globals, this)
- net.torvald.terrarum.modulecomputers.virtualcomputer.luaapi.HostAccessProvider(luaJ_globals, this)
- net.torvald.terrarum.modulecomputers.virtualcomputer.luaapi.Input(luaJ_globals, this)
- net.torvald.terrarum.modulecomputers.virtualcomputer.luaapi.PcSpeakerDriver(luaJ_globals, this)
- net.torvald.terrarum.modulecomputers.virtualcomputer.luaapi.WorldInformationProvider(luaJ_globals)
-
- // secure the sandbox
- //luaJ_globals["io"] = LuaValue.NIL
- // dubug should be sandboxed in BOOT.lua (use OpenComputers code)
- //val sethook = luaJ_globals["debug"]["sethook"]
- //luaJ_globals["debug"] = LuaValue.NIL
-
- // ROM BASIC
- val inputStream = javaClass.getResourceAsStream("/net/torvald/terrarum/modulecomputers/virtualcomputer/virtualcomputer/assets/lua/BOOT.lua")
- runCommand(InputStreamReader(inputStream), "=boot")
-
- // computer-related global functions
- luaJ_globals["totalMemory"] = LuaFunGetTotalMem(this)
-
- luaJ_globals["computer"] = LuaTable()
- // rest of the "computer" APIs should be implemented in BOOT.lua
-
-
-
- // load every peripheral if we're in DEBUG
- if (DEBUG) {
- attachPeripheral(net.torvald.terrarum.modulecomputers.virtualcomputer.peripheral.PeripheralInternet(this))
- attachPeripheral(net.torvald.terrarum.modulecomputers.virtualcomputer.peripheral.PeripheralPSG(this))
- // ...
- }
- }
-
- fun update(delta: Float) {
-
- if (currentExecutionThread.state == Thread.State.TERMINATED) {
- threadRun = false
- }
-
-
-
-
- if (!isHalted) {
- runBeepQueueManager(delta)
- }
- }
-
- fun keyPressed(key: Int, c: Char) {
- stdinInput = c.toInt()
-
- // wake thread
- runnableRunCommand.resume()
-
- synchronized(stdin!!) {
- (stdin as java.lang.Object).notifyAll()
- }
- }
-
- fun openStdin() {
- stdinInput = -1
- // sleep the thread
- runnableRunCommand.pause()
- }
-
- lateinit var currentExecutionThread: Thread
- private set
- lateinit var runnableRunCommand: ThreadRunCommand
- private set
- private var threadRun = false
-
- fun runCommand(line: String, env: String) {
- if (!threadRun) {
- runnableRunCommand = ThreadRunCommand(luaJ_globals, line, env)
- currentExecutionThread = Thread(null, runnableRunCommand, "LuaJ Separated")
- currentExecutionThread.start()
- threadRun = true
- }
- }
-
- fun runCommand(reader: Reader, filename: String) {
- if (!threadRun) {
- runnableRunCommand = ThreadRunCommand(luaJ_globals, reader, filename)
- currentExecutionThread = Thread(null, runnableRunCommand, "LuaJ Separated")
- currentExecutionThread.start()
- threadRun = true
- }
- }
-
- class ThreadRunCommand : Runnable {
-
- private val mode: Int
- private val arg1: Any
- private val arg2: String
- private val lua: Globals
-
- @Volatile private var running = true
- @Volatile private var paused = false
- private val pauseLock = java.lang.Object()
-
- constructor(luaInstance: Globals, line: String, env: String) {
- mode = 0
- arg1 = line
- arg2 = env
- lua = luaInstance
- }
-
- constructor(luaInstance: Globals, reader: Reader, filename: String) {
- mode = 1
- arg1 = reader
- arg2 = filename
- lua = luaInstance
- }
-
- override fun run() {
- synchronized(pauseLock) {
- if (!running) { // may have changed while waiting to
- // synchronize on pauseLock
- return
- }
- if (paused) {
- try {
- pauseLock.wait() // will cause this Thread to block until
- // another thread calls pauseLock.notifyAll()
- // Note that calling wait() will
- // relinquish the synchronized lock that this
- // thread holds on pauseLock so another thread
- // can acquire the lock to call notifyAll()
- // (link with explanation below this code)
- }
- catch (ex: InterruptedException) {
- return
- }
-
- if (!running) { // running might have changed since we paused
- return
- }
- }
- }
-
-
- try {
- val chunk: LuaValue
- if (mode == 0)
- chunk = lua.load(arg1 as String, arg2)
- else if (mode == 1)
- chunk = lua.load(arg1 as Reader, arg2)
- else
- throw IllegalArgumentException("Unsupported mode: $mode")
-
-
- chunk.call()
- }
- catch (e: LuaError) {
- e.printStackTrace(System.err)
- //lua.STDERR.println("${SimpleTextTerminal.ASCII_DLE}${e.message}${SimpleTextTerminal.ASCII_DC4}")
- }
- }
-
- fun stop() {
- running = false
- // you might also want to do this:
- //interrupt()
- }
-
- fun pause() {
- // you may want to throw an IllegalStateException if !running
- paused = true
- }
-
- fun resume() {
- synchronized(pauseLock) {
- paused = false
- pauseLock.notifyAll() // Unblocks thread
- }
- }
- }
-
- class LuaFunGetTotalMem(val computer: TerrarumComputerOldOld) : ZeroArgFunction() {
- override fun call(): LuaValue {
- return LuaValue.valueOf(computer.memSize)
- }
- }
-
- class ComputerEmitTone(val computer: TerrarumComputerOldOld) : TwoArgFunction() {
- override fun call(millisec: LuaValue, freq: LuaValue): LuaValue {
- computer.playTone(millisec.checkdouble().toFloat(), freq.checkdouble())
- return LuaValue.NONE
- }
- }
-
- ///////////////////
- // BEEPER DRIVER //
- ///////////////////
-
- private val beepMaxLen = 10f
- // let's regard it as a tracker...
- private val beepQueue = ArrayList>()
- private var beepCursor = -1
- private var beepQueueLineExecTimer: Second = 0f
- private var beepQueueFired = false
-
- private fun runBeepQueueManager(delta: Float) {
- // start emitTone queue
- if (beepQueue.size > 0 && beepCursor == -1) {
- beepCursor = 0
- }
-
- // advance emitTone queue
- if (beepCursor >= 0 && beepQueueLineExecTimer >= beepQueueGetLenOfPtn(beepCursor)) {
- beepQueueLineExecTimer -= beepQueueGetLenOfPtn(beepCursor)
- beepCursor += 1
- beepQueueFired = false
- }
-
- // complete emitTone queue
- if (beepCursor >= beepQueue.size) {
- clearBeepQueue()
- }
-
- // actually play queue
- if (beepCursor >= 0 && beepQueue.size > 0 && !beepQueueFired) {
- playTone(beepQueue[beepCursor].first, beepQueue[beepCursor].second)
- beepQueueFired = true
-
- // delete sources that is finished. AL is limited to 256 sources. If you exceed it,
- // we won't get any more sounds played.
- AL10.alSourcei(oldBeepSource, AL10.AL_BUFFER, 0)
- AL10.alDeleteSources(oldBeepSource)
- AL10.alDeleteBuffers(oldBeepBuffer)
- }
-
- if (beepQueueFired) beepQueueLineExecTimer += delta
- }
-
- fun clearBeepQueue() {
- beepQueue.clear()
- beepCursor = -1
- beepQueueLineExecTimer = 0f
-
- //AL.destroy()
-
- if (DEBUG) println("[TerrarumComputerOld] !! Beep queue clear")
- }
-
- fun enqueueBeep(duration: Double, freq: Double) {
- beepQueue.add(Pair(Math.min(duration.toFloat(), beepMaxLen), freq))
- }
-
- fun beepQueueGetLenOfPtn(ptnIndex: Int) = beepQueue[ptnIndex].first
-
-
- ////////////////////
- // TONE GENERATOR //
- ////////////////////
-
- private val sampleRate = 44100
- private var beepSource: Int = -1
- private var beepBuffer: Int = -1
- private var oldBeepSource: Int = -1
- private var oldBeepBuffer: Int = -1
- var audioData: ByteBuffer? = null
-
- /**
- * @param duration : milliseconds
- * @param rampUp
- * @param rampDown
- *
- * ,---. (true, true) ,---- (true, false) ----. (false, true) ----- (false, false)
- */
- private fun makeAudioData(duration: Second, freq: Double,
- rampUp: Boolean = true, rampDown: Boolean = true): ByteBuffer {
-
- TODO("with duration as Seconds")
-
- val audioDataSize = duration.times(sampleRate).ceilInt()
- val audioData = BufferUtils.createByteBuffer(audioDataSize)
-
- /*val realDuration = duration * sampleRate / 1000
- val chopSize = freq / sampleRate
-
- val amp = Math.max(4600.0 / freq, 1.0)
- val nHarmonics = if (freq >= 22050.0) 1
- else if (freq >= 11025.0) 2
- else if (freq >= 5512.5) 3
- else if (freq >= 2756.25) 4
- else if (freq >= 1378.125) 5
- else if (freq >= 689.0625) 6
- else 7
-
- val transitionThre = 974.47218
-
- // TODO volume ramping?
- if (freq == 0.0) {
- for (_ in 0..audioDataSize - 1) {
- audioData.put(0x00.toByte())
- }
- }
- else if (freq < transitionThre) { // chopper generator (for low freq)
- for (tsart in 0..audioDataSize - 1) {
- var sine: Double = amp * Math.cos(Math.PI * 2 * () * chopSize)
- if (sine > 0.79) sine = 0.79
- else if (sine < -0.79) sine = -0.79
- audioData.put(
- (0.5 + 0.5 * sine).times(0xFF).roundToInt().toByte()
- )
- }
- }
- else { // harmonics generator (for high freq)
- for (x in 0..realDuration - 1) {
- var sine: Double = 0.0
- for (k in 1..nHarmonics) { // mix only odd harmonics in order to make a squarewave
- sine += Math.sin(Math.PI * 2 * (2*k - 1) * chopSize * x) / (2*k - 1)
- }
- audioData.put(
- (0.5 + 0.5 * sine).times(0xFF).roundToInt().toByte()
- )
- }
- }*/
-
- audioData.rewind()
-
- return audioData
- }
-
- private fun playTone(length: Second, freq: Double) {
- /*audioData = makeAudioData(leninmilli, freq)
-
-
- if (!AL.isCreated()) AL.create()
-
-
- // Clear error stack.
- AL10.alGetError()
-
- oldBeepBuffer = beepBuffer
- beepBuffer = AL10.alGenBuffers()
- checkALError()
-
- try {
- AL10.alBufferData(beepBuffer, AL10.AL_FORMAT_MONO8, audioData, sampleRate)
- checkALError()
-
- oldBeepSource = beepSource
- beepSource = AL10.alGenSources()
- checkALError()
-
- try {
- AL10.alSourceQueueBuffers(beepSource, beepBuffer)
- checkALError()
-
- AL10.alSource3f(beepSource, AL10.AL_POSITION, 0f, 0f, 1f)
- AL10.alSourcef(beepSource, AL10.AL_REFERENCE_DISTANCE, 1f)
- AL10.alSourcef(beepSource, AL10.AL_MAX_DISTANCE, 1f)
- AL10.alSourcef(beepSource, AL10.AL_GAIN, 0.3f)
- checkALError()
-
- AL10.alSourcePlay(beepSource)
- checkALError()
- }
- catch (e: ALException) {
- AL10.alDeleteSources(beepSource)
- }
- }
- catch (e: ALException) {
- AL10.alDeleteSources(beepSource)
- }*/
- }
-
- // Custom implementation of Util.checkALError() that uses our custom exception.
- private fun checkALError() {
- val errorCode = AL10.alGetError()
- if (errorCode != AL10.AL_NO_ERROR) {
- throw net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.ALException(errorCode)
- }
- }
-
-}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/luaapi/FilesystemDir.kt.txt b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/luaapi/FilesystemDir.kt.txt
deleted file mode 100644
index b2c44ae59..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/luaapi/FilesystemDir.kt.txt
+++ /dev/null
@@ -1,521 +0,0 @@
-package net.torvald.terrarum.modulecomputers.virtualcomputer.luaapi
-
-import org.luaj.vm2.*
-import org.luaj.vm2.lib.OneArgFunction
-import org.luaj.vm2.lib.TwoArgFunction
-import org.luaj.vm2.lib.ZeroArgFunction
-import net.torvald.terrarum.Terrarum
-import net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld
-import net.torvald.terrarum.modulecomputers.virtualcomputer.luaapi.Term.Companion.checkIBM437
-import java.io.*
-import java.nio.file.Files
-import java.nio.file.NoSuchFileException
-import java.nio.file.Path
-import java.nio.file.Paths
-import java.util.*
-
-/**
- * computer directory:
- * .../computers/
- * media/hda/ -> .../computers//
- *
- * Created by minjaesong on 2016-09-17.
- *
- *
- * NOTES:
- * Don't convert '\' to '/'! Rev-slash is used for escape character in sh, and we're sh-compatible!
- * Use .absoluteFile whenever possible; there's fuckin oddity! (http://bugs.java.com/bugdatabase/view_bug.do;:YfiG?bug_id=4483097)
- */
-@Deprecated("Fuck permission and shit, we go virtual. Use FilesystemTar")
-internal class FilesystemDir(globals: Globals, computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) {
-
- init {
- // load things. WARNING: THIS IS MANUAL!
- globals["fs"] = LuaValue.tableOf()
- globals["fs"]["list"] = ListFiles(computer) // CC compliant
- globals["fs"]["exists"] = FileExists(computer) // CC/OC compliant
- globals["fs"]["isDir"] = IsDirectory(computer) // CC compliant
- globals["fs"]["isFile"] = IsFile(computer)
- globals["fs"]["isReadOnly"] = IsReadOnly(computer) // CC compliant
- globals["fs"]["getSize"] = GetSize(computer) // CC compliant
- globals["fs"]["mkdir"] = Mkdir(computer)
- globals["fs"]["mv"] = Mv(computer)
- globals["fs"]["cp"] = Cp(computer)
- globals["fs"]["rm"] = Rm(computer)
- globals["fs"]["concat"] = ConcatPath(computer) // OC compliant
- globals["fs"]["open"] = OpenFile(computer) //CC compliant
- globals["fs"]["parent"] = GetParentDir(computer)
- // fs.dofile defined in BOOT
- // fs.fetchText defined in ROMLIB
- }
-
- companion object {
- fun ensurePathSanity(path: LuaValue) {
- if (path.checkIBM437().contains(Regex("""\.\.""")))
- throw LuaError("'..' on path is not supported.")
- if (!isValidFilename(path.checkIBM437()))
- throw IOException("path contains invalid characters")
- }
-
- var isCaseInsensitive: Boolean
-
- init {
- try {
- val uuid = UUID.randomUUID().toString()
- val lowerCase = File(Terrarum.currentSaveDir, uuid + "oc_rox")
- val upperCase = File(Terrarum.currentSaveDir, uuid + "OC_ROX")
- // This should NEVER happen but could also lead to VERY weird bugs, so we
- // make sure the files don't exist.
- if (lowerCase.exists()) lowerCase.delete()
- if (upperCase.exists()) upperCase.delete()
-
- lowerCase.createNewFile()
-
- val insensitive = upperCase.exists()
- lowerCase.delete()
-
- isCaseInsensitive = insensitive
-
- println("[Filesystem] Case insensitivity: $isCaseInsensitive")
- }
- catch (e: IOException) {
- System.err.println("[Filesystem] Couldn't determine if the file system is case sensitive, falling back to insensitive.")
- e.printStackTrace(System.out)
- isCaseInsensitive = true
- }
- }
-
- // Worst-case: we're on Windows or using a FAT32 partition mounted in *nix.
- // Note: we allow / as the path separator and expect all \s to be converted
- // accordingly before the path is passed to the file system.
- private val invalidChars = Regex("""[<>:"|?*\u0000-\u001F]""") // original OC uses Set(); we use regex
-
- fun isValidFilename(name: String) = !name.contains(invalidChars)
-
- fun String.validatePath() : String {
- if (!isValidFilename(this)) {
- throw IOException("path contains invalid characters")
- }
- return this
- }
-
- /** actual directory: /Saves//computers//
- * directs media/ directory to / directory
- */
- fun net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld.getRealPath(luapath: LuaValue) : String {
- // direct mounted paths to real path
- val computerDir = Terrarum.currentSaveDir.absolutePath + "/computers/"
- /* if not begins with "(/?)media/", direct to boot
- * else, to corresponding drives
- *
- * List of device names (these are auto-mounted. why? primitivism :p):
- * = hda - hdd: hard disks
- * = fd1 - fd4: floppy drives
- * = sda: whatever external drives, usually a CD
- * = boot: current boot device
- */
-
- // remove first '/' in path
- var path = luapath.checkIBM437().validatePath()
- if (path.startsWith('/')) path = path.substring(1)
-
- val finalPath: String
-
- if (path.startsWith("media/")) {
- val device = path.substring(6, 9)
- val subPath = path.substring(9)
- finalPath = computerDir + this.computerValue.getAsString("device") + subPath
- }
- else {
- finalPath = computerDir + this.computerValue.getAsString("boot") + "/" + path
- }
-
- // remove trailing slash
- return if (finalPath.endsWith("\\") || finalPath.endsWith("/"))
- finalPath.substring(0, finalPath.length - 1)
- else
- finalPath
- }
-
- fun combinePath(base: String, local: String) : String {
- return "$base$local".replace("//", "/")
- }
- }
-
- /**
- * @param cname == UUID of the drive
- *
- * actual directory: /Saves//computers//
- */
- class ListFiles(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
- override fun call(path: LuaValue) : LuaValue {
- FilesystemDir.ensurePathSanity(path)
-
- println("ListFiles: got path ${path.checkIBM437()}")
-
- val table = LuaTable()
- val file = File(computer.getRealPath(path)).absoluteFile
- try {
- file.list().forEachIndexed { i, s -> table.insert(i, LuaValue.valueOf(s)) }
- }
- catch (e: NullPointerException) {}
- return table
- }
- }
-
- /** Don't use this. Use isFile */
- class FileExists(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
- override fun call(path: LuaValue) : LuaValue {
- FilesystemDir.ensurePathSanity(path)
-
- return LuaValue.valueOf(Files.exists(Paths.get(computer.getRealPath(path)).toAbsolutePath()))
- }
- }
-
- class IsDirectory(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
- override fun call(path: LuaValue) : LuaValue {
- FilesystemDir.ensurePathSanity(path)
-
- val isDir = Files.isDirectory(Paths.get(computer.getRealPath(path)).toAbsolutePath())
- val exists = Files.exists(Paths.get(computer.getRealPath(path)).toAbsolutePath())
-
- return LuaValue.valueOf(isDir || exists)
- }
- }
-
- class IsFile(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
- override fun call(path: LuaValue) : LuaValue {
- FilesystemDir.ensurePathSanity(path)
-
- // check if the path is file by checking:
- // 1. isfile
- // 2. canwrite
- // 3. length
- // Why? Our Java simply wants to fuck you.
-
- val path = Paths.get(computer.getRealPath(path)).toAbsolutePath()
- var result = false
- result = Files.isRegularFile(path)
-
- if (!result) result = Files.isWritable(path)
-
- if (!result)
- try { result = Files.size(path) > 0 }
- catch (e: NoSuchFileException) { result = false }
-
- return LuaValue.valueOf(result)
- }
- }
-
- class IsReadOnly(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
- override fun call(path: LuaValue) : LuaValue {
- FilesystemDir.ensurePathSanity(path)
-
- return LuaValue.valueOf(!Files.isWritable(Paths.get(computer.getRealPath(path)).toAbsolutePath()))
- }
- }
-
- /** we have 4GB file size limit */
- class GetSize(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
- override fun call(path: LuaValue) : LuaValue {
- FilesystemDir.ensurePathSanity(path)
-
- return LuaValue.valueOf(Files.size(Paths.get(computer.getRealPath(path)).toAbsolutePath()).toInt())
- }
- }
-
- // TODO class GetFreeSpace
-
- /**
- * difference with ComputerCraft: it returns boolean, true on successful.
- */
- class Mkdir(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
- override fun call(path: LuaValue) : LuaValue {
- FilesystemDir.ensurePathSanity(path)
-
- return LuaValue.valueOf(File(computer.getRealPath(path)).absoluteFile.mkdir())
- }
- }
-
- /**
- * moves a directory, overwrites the target
- */
- class Mv(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : TwoArgFunction() {
- override fun call(from: LuaValue, to: LuaValue) : LuaValue {
- FilesystemDir.ensurePathSanity(from)
- FilesystemDir.ensurePathSanity(to)
-
- val fromFile = File(computer.getRealPath(from)).absoluteFile
- var success = fromFile.copyRecursively(
- File(computer.getRealPath(to)).absoluteFile, overwrite = true
- )
- if (success) success = fromFile.deleteRecursively()
- else return LuaValue.valueOf(false)
- return LuaValue.valueOf(success)
- }
- }
-
- /**
- * copies a directory, overwrites the target
- * difference with ComputerCraft: it returns boolean, true on successful.
- */
- class Cp(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : TwoArgFunction() {
- override fun call(from: LuaValue, to: LuaValue) : LuaValue {
- FilesystemDir.ensurePathSanity(from)
- FilesystemDir.ensurePathSanity(to)
-
- return LuaValue.valueOf(
- File(computer.getRealPath(from)).absoluteFile.copyRecursively(
- File(computer.getRealPath(to)).absoluteFile, overwrite = true
- )
- )
- }
- }
-
- /**
- * difference with ComputerCraft: it returns boolean, true on successful.
- */
- class Rm(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
- override fun call(path: LuaValue) : LuaValue {
- FilesystemDir.ensurePathSanity(path)
-
- return LuaValue.valueOf(
- File(computer.getRealPath(path)).absoluteFile.deleteRecursively()
- )
- }
- }
-
- class ConcatPath(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : TwoArgFunction() {
- override fun call(base: LuaValue, local: LuaValue) : LuaValue {
- FilesystemDir.ensurePathSanity(base)
- FilesystemDir.ensurePathSanity(local)
-
- val combinedPath = combinePath(base.checkIBM437().validatePath(), local.checkIBM437().validatePath())
- return LuaValue.valueOf(combinedPath)
- }
- }
-
- /**
- * @param mode: r, rb, w, wb, a, ab
- *
- * Difference: TEXT MODE assumes CP437 instead of UTF-8!
- *
- * When you have opened a file you must always close the file handle, or else data may not be saved.
- *
- * FILE class in CC:
- * (when you look thru them using file = fs.open("./test", "w")
- *
- * file = {
- * close = function()
- * -- write mode
- * write = function(string)
- * flush = function() -- write, keep the handle
- * writeLine = function(string) -- text mode
- * -- read mode
- * readLine = function() -- text mode
- * readAll = function()
- * -- binary read mode
- * read = function() -- read single byte. return: number or nil
- * -- binary write mode
- * write = function(byte)
- * writeBytes = function(string as bytearray)
- * }
- */
- class OpenFile(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : TwoArgFunction() {
- override fun call(path: LuaValue, mode: LuaValue) : LuaValue {
- FilesystemDir.ensurePathSanity(path)
-
-
-
- val mode = mode.checkIBM437().toLowerCase()
- val luaClass = LuaTable()
- val file = File(computer.getRealPath(path)).absoluteFile
-
- if (mode.contains(Regex("""[aw]""")) && !file.canWrite())
- throw LuaError("Cannot open file for " +
- "${if (mode.startsWith('w')) "read" else "append"} mode" +
- ": is readonly.")
-
-
-
-
- when (mode) {
- "r" -> {
- try {
- val fr = FileReader(file)
- luaClass["close"] = FileClassClose(fr)
- luaClass["readLine"] = FileClassReadLine(fr)
- luaClass["readAll"] = FileClassReadAll(file.toPath())
- }
- catch (e: FileNotFoundException) {
- e.printStackTrace()
- throw LuaError(
- if (e.message != null && e.message!!.contains(Regex("""[Aa]ccess (is )?denied""")))
- "$path: access denied."
- else
- "$path: no such file."
- )
- }
- }
- "rb" -> {
- try {
- val fis = FileInputStream(file)
- luaClass["close"] = FileClassClose(fis)
- luaClass["read"] = FileClassReadByte(fis)
- luaClass["readAll"] = FileClassReadAll(file.toPath())
- }
- catch (e: FileNotFoundException) {
- e.printStackTrace()
- throw LuaError("$path: no such file.")
- }
- }
- "w", "a" -> {
- try {
- val fw = FileWriter(file, (mode.startsWith('a')))
- luaClass["close"] = FileClassClose(fw)
- luaClass["write"] = FileClassPrintText(fw)
- luaClass["writeLine"] = FileClassPrintlnText(fw)
- luaClass["flush"] = FileClassFlush(fw)
- }
- catch (e: FileNotFoundException) {
- e.printStackTrace()
- throw LuaError("$path: is a directory.")
- }
- }
- "wb", "ab" -> {
- try {
- val fos = FileOutputStream(file, (mode.startsWith('a')))
- luaClass["close"] = FileClassClose(fos)
- luaClass["write"] = FileClassWriteByte(fos)
- luaClass["writeBytes"] = FileClassWriteBytes(fos)
- luaClass["flush"] = FileClassFlush(fos)
- }
- catch (e: FileNotFoundException) {
- e.printStackTrace()
- throw LuaError("$path: is a directory.")
- }
- }
- }
-
- return luaClass
- }
- }
-
- class GetParentDir(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
- override fun call(path: LuaValue) : LuaValue {
- FilesystemDir.ensurePathSanity(path)
-
- var pathSB = StringBuilder(path.checkIBM437())
-
- // backward travel, drop chars until '/' has encountered
- while (!pathSB.endsWith('/'))
- pathSB.deleteCharAt(pathSB.lastIndex - 1)
-
- // drop trailing '/'
- if (pathSB.endsWith('/'))
- pathSB.deleteCharAt(pathSB.lastIndex - 1)
-
- return LuaValue.valueOf(pathSB.toString())
- }
- }
-
-
- //////////////////////////////
- // OpenFile implementations //
- //////////////////////////////
-
- private class FileClassClose(val fo: Any) : ZeroArgFunction() {
- override fun call() : LuaValue {
- if (fo is FileOutputStream)
- fo.close()
- else if (fo is FileWriter)
- fo.close()
- else if (fo is FileReader)
- fo.close()
- else if (fo is FileInputStream)
- fo.close()
- else
- throw IllegalArgumentException("Unacceptable file output: must be either Input/OutputStream or Reader/Writer.")
-
- return LuaValue.NONE
- }
- }
-
- private class FileClassWriteByte(val fos: FileOutputStream) : OneArgFunction() {
- override fun call(byte: LuaValue) : LuaValue {
- fos.write(byte.checkint())
-
- return LuaValue.NONE
- }
- }
-
- private class FileClassWriteBytes(val fos: FileOutputStream) : OneArgFunction() {
- override fun call(byteString: LuaValue) : LuaValue {
- val byteString = byteString.checkIBM437()
- val bytearr = ByteArray(byteString.length, { byteString[it].toByte() })
- fos.write(bytearr)
-
- return LuaValue.NONE
- }
- }
-
- private class FileClassPrintText(val fw: FileWriter) : OneArgFunction() {
- override fun call(string: LuaValue) : LuaValue {
- val text = string.checkIBM437()
- fw.write(text)
- return LuaValue.NONE
- }
- }
-
- private class FileClassPrintlnText(val fw: FileWriter) : OneArgFunction() {
- override fun call(string: LuaValue) : LuaValue {
- val text = string.checkIBM437() + "\n"
- fw.write(text)
- return LuaValue.NONE
- }
- }
-
- private class FileClassFlush(val fo: Any) : ZeroArgFunction() {
- override fun call() : LuaValue {
- if (fo is FileOutputStream)
- fo.flush()
- else if (fo is FileWriter)
- fo.flush()
- else
- throw IllegalArgumentException("Unacceptable file output: must be either OutputStream or Writer.")
-
- return LuaValue.NONE
- }
- }
-
- private class FileClassReadByte(val fis: FileInputStream) : ZeroArgFunction() {
- override fun call() : LuaValue {
- val readByte = fis.read()
- return if (readByte == -1) LuaValue.NIL else LuaValue.valueOf(readByte)
- }
- }
-
- private class FileClassReadAllBytes(val path: Path) : ZeroArgFunction() {
- override fun call() : LuaValue {
- val byteArr = Files.readAllBytes(path)
- val s: String = java.lang.String(byteArr, "IBM437").toString()
- return LuaValue.valueOf(s)
- }
- }
-
- private class FileClassReadAll(val path: Path) : ZeroArgFunction() {
- override fun call() : LuaValue {
- return FileClassReadAllBytes(path).call()
- }
- }
-
- /** returns NO line separator! */
- private class FileClassReadLine(val fr: FileReader) : ZeroArgFunction() {
- val scanner = Scanner(fr.readText()) // no closing; keep the scanner status persistent
-
- override fun call() : LuaValue {
- return if (scanner.hasNextLine()) LuaValue.valueOf(scanner.nextLine())
- else LuaValue.NIL
- }
- }
-}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/luaapi/FilesystemFactory.kt.txt b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/luaapi/FilesystemFactory.kt.txt
deleted file mode 100644
index f691f51c1..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/luaapi/FilesystemFactory.kt.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-package net.torvald.terrarum.modulecomputers.virtualcomputer.luaapi
-
-/**
- * Created by minjaesong on 2016-09-17.
- */
-class FilesystemFactory {
-}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/luaapi/FilesystemTEVD.kt.txt b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/luaapi/FilesystemTEVD.kt.txt
deleted file mode 100644
index a133ea446..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/luaapi/FilesystemTEVD.kt.txt
+++ /dev/null
@@ -1,512 +0,0 @@
-package net.torvald.terrarum.modulecomputers.virtualcomputer.luaapi
-
-import net.torvald.terrarum.modulecomputers.virtualcomputer.luaapi.Term.Companion.checkIBM437
-import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.*
-import net.torvald.terrarum.modulecomputers.virtualcomputer.tvd.VDUtil.VDPath
-import org.luaj.vm2.Globals
-import org.luaj.vm2.LuaError
-import org.luaj.vm2.LuaValue
-import java.io.IOException
-import java.nio.charset.Charset
-import java.util.*
-
-/**
- * computer directory:
- * .../computers/
- * media/hda/ -> .../computers//
- *
- * Created by minjaesong on 2016-09-17.
- *
- *
- * NOTES:
- * Don't convert '\' to '/'! Rev-slash is used for escape character in sh, and we're sh-compatible!
- * Use .absoluteFile whenever possible; there's fuckin oddity! (http://bugs.java.com/bugdatabase/view_bug.do;:YfiG?bug_id=4483097)
- */
-internal class Filesystem(globals: Globals, computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) {
-
- /*init {
- // load things. WARNING: THIS IS MANUAL!
- globals["fs"] = LuaValue.tableOf()
- globals["fs"]["list"] = ListFiles(computer) // CC compliant
- globals["fs"]["exists"] = FileExists(computer) // CC/OC compliant
- globals["fs"]["isDir"] = IsDirectory(computer) // CC compliant
- globals["fs"]["isFile"] = IsFile(computer)
- globals["fs"]["isReadOnly"] = IsReadOnly(computer) // CC compliant
- globals["fs"]["getSize"] = GetSize(computer) // CC compliant
- globals["fs"]["mkdir"] = Mkdir(computer)
- globals["fs"]["mv"] = Mv(computer)
- globals["fs"]["cp"] = Cp(computer)
- globals["fs"]["rm"] = Rm(computer)
- globals["fs"]["concat"] = ConcatPath(computer) // OC compliant
- globals["fs"]["open"] = OpenFile(computer) //CC compliant
- globals["fs"]["parent"] = GetParentDir(computer)
- // fs.dofile defined in BOOT
- // fs.fetchText defined in ROMLIB
- }*/
-
- companion object {
- val sysCharset = Charset.forName("CP437")
-
- fun LuaValue.checkPath(): String {
- if (this.checkIBM437().contains(Regex("""\.\.""")))
- throw LuaError("'..' on path is not supported.")
- return this.checkIBM437().validatePath()
- }
-
- // Worst-case: we're on Windows or using a FAT32 partition mounted in *nix.
- // Note: we allow / as the path separator and expect all \s to be converted
- // accordingly before the path is passed to the file system.
- private val invalidChars = Regex("""[<>:"|?*\u0000-\u001F]""") // original OC uses Set(); we use regex
-
- fun isValidFilename(name: String) = !name.contains(invalidChars)
-
- fun String.validatePath() : String {
- if (!isValidFilename(this)) {
- throw IOException("path contains invalid characters")
- }
- return this
- }
-
- /**
- * return value is there for chaining only.
- */
- fun VDPath.dropMount(): VDPath {
- if (this.hierarchy.size >= 2 && this[0].toCanonicalString(sysCharset) == "media") {
- this.hierarchy.removeAt(0) // drop "media"
- this.hierarchy.removeAt(0) // drop whatever mount symbol
- }
- return this
- }
-
- /**
- * if path is {media, someUUID, subpath}, redirects to
- * computer.diskRack[SOMEUUID]->subpath
- * else, computer.diskRack["hda"]->subpath
- */
- fun net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld.getFile(path: VDPath) : DiskEntry? {
- val disk = this.getTargetDisk(path)
-
- if (disk == null) return null
-
- path.dropMount()
-
- return VDUtil.getFile(disk, path)
- }
-
- /**
- * if path is like {media, fd1, subpath}, return
- * computer.diskRack["fd1"]
- * else, computer.diskRack[]
- */
- fun net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld.getTargetDisk(path: VDPath) : VirtualDisk? {
- if (path.hierarchy.size >= 2 &&
- Arrays.equals(path[0], "media".toEntryName(DiskEntry.NAME_LENGTH, sysCharset))) {
- val diskName = path[1].toCanonicalString(sysCharset)
- val disk = this.diskRack[diskName]
-
- return disk
- }
- else {
- return this.diskRack[this.computerValue.getAsString("boot")]
- }
- }
-
- fun net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld.getDirectoryEntries(path: VDPath) : Array? {
- val directory = this.getFile(path)
-
- if (directory == null) return null
- return VDUtil.getDirectoryEntries(this.getTargetDisk(path)!!, directory)
- }
-
- fun combinePath(base: String, local: String) : String {
- return "$base$local".replace("//", "/")
- }
-
- private fun tryBool(action: () -> Unit): LuaValue {
- try {
- action()
- return LuaValue.valueOf(true)
- }
- catch (gottaCatchemAll: Exception) {
- return LuaValue.valueOf(false)
- }
- }
- } // end of Companion Object
-
- /*
-
- /**
- * @param cname == UUID of the drive
- *
- * actual directory: /Saves//computers//
- */
- class ListFiles(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
- override fun call(path: LuaValue) : LuaValue {
- val path = VDPath(path.checkPath(), sysCharset)
-
- val table = LuaTable()
- try {
- val directoryContents = computer.getDirectoryEntries(path)!!
- println("[Filesystem] directoryContents size: ${directoryContents.size}")
- directoryContents.forEachIndexed { index, diskEntry ->
- table.insert(index + 1, LuaValue.valueOf(diskEntry.filename.toCanonicalString(sysCharset)))
- }
- }
- catch (e: KotlinNullPointerException) {}
- return table
- }
- }
-
- class FileExists(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
- override fun call(path: LuaValue) : LuaValue {
- val path = VDPath(path.checkPath(), sysCharset)
- val disk = computer.getTargetDisk(path)
-
- if (disk == null) return LuaValue.valueOf(false)
-
- return LuaValue.valueOf(
- VDUtil.getFile(disk, path.dropMount()) != null
- )
- }
- }
-
- class IsDirectory(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
- override fun call(path: LuaValue) : LuaValue {
- val path = VDPath(path.checkPath(), sysCharset)
- return LuaValue.valueOf(computer.getFile(path)?.contents is EntryDirectory)
- }
- }
-
- class IsFile(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
- override fun call(path: LuaValue) : LuaValue {
- val path = VDPath(path.checkPath(), sysCharset)
- return LuaValue.valueOf(computer.getFile(path)?.contents is EntryFile)
- }
- }
-
- class IsReadOnly(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
- override fun call(path: LuaValue) : LuaValue {
- return LuaValue.valueOf(false)
- }
- }
-
- /** we have 2 GB file size limit */
- class GetSize(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
- override fun call(path: LuaValue) : LuaValue {
- val path = VDUtil.VDPath(path.checkPath(), sysCharset)
- val file = computer.getFile(path)
- try {
- if (file!!.contents is EntryFile)
- return LuaValue.valueOf(file.contents.getSizePure().toInt())
- else if (file.contents is EntryDirectory)
- return LuaValue.valueOf(file.contents.entryCount)
- }
- catch (e: KotlinNullPointerException) {
- }
-
- return LuaValue.NONE
- }
- }
-
- // TODO class GetFreeSpace
-
- /**
- * returns true on success
- */
- class Mkdir(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
- override fun call(path: LuaValue) : LuaValue {
- return tryBool {
- val path = VDPath(path.checkPath(), sysCharset)
- val disk = computer.getTargetDisk(path)!!
- val dirList = computer.getDirectoryEntries(path.getParent())
- var makeNew = true
-
- // check dupes
- if (dirList != null) {
- for (entry in dirList) {
- if (Arrays.equals(path.last(), entry.filename)) {
- makeNew = false
- break
- }
- }
- }
-
- if (makeNew) {
- VDUtil.addDir(disk, path.getParent(), path.last())
- }
- }
- }
- }
-
- /**
- * moves a directory, overwrites the target
- */
- class Mv(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : TwoArgFunction() {
- override fun call(from: LuaValue, to: LuaValue) : LuaValue {
- return tryBool {
- val pathFrom = VDPath(from.checkPath(), sysCharset)
- val disk1 = computer.getTargetDisk(pathFrom)
- val pathTo = VDPath(to.checkPath(), sysCharset)
- val disk2 = computer.getTargetDisk(pathTo)
-
- VDUtil.moveFile(disk1!!, pathFrom, disk2!!, pathTo)
- }
- }
- }
-
- /**
- * copies a directory, overwrites the target
- * difference with ComputerCraft: it returns boolean, true on successful.
- */
- class Cp(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : TwoArgFunction() {
- override fun call(from: LuaValue, to: LuaValue) : LuaValue {
- return tryBool {
- val pathFrom = VDPath(from.checkPath(), sysCharset)
- val disk1 = computer.getTargetDisk(pathFrom)!!
- val pathTo = VDPath(to.checkPath(), sysCharset)
- val disk2 = computer.getTargetDisk(pathTo)!!
-
- val oldFile = VDUtil.getFile(disk2, pathTo)
-
- try {
- VDUtil.deleteFile(disk2, pathTo)
- }
- catch (e: FileNotFoundException) {
- "Nothing to delete beforehand"
- }
-
- val file = VDUtil.getFile(disk1, pathFrom)!!
- try {
- VDUtil.addFile(disk2, pathTo.getParent(), file)
- }
- catch (e: FileNotFoundException) {
- // roll back delete on disk2
- if (oldFile != null) {
- VDUtil.addFile(disk2, oldFile.parentEntryID, oldFile)
- throw FileNotFoundException("No such destination")
- }
- }
- }
- }
- }
-
- /**
- * difference with ComputerCraft: it returns boolean, true on successful.
- */
- class Rm(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
- override fun call(path: LuaValue) : LuaValue {
- return tryBool {
- val path = VDPath(path.checkPath(), sysCharset)
- val disk = computer.getTargetDisk(path)!!
-
- VDUtil.deleteFile(disk, path)
- }
- }
- }
-
- class ConcatPath(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : TwoArgFunction() {
- override fun call(base: LuaValue, local: LuaValue) : LuaValue {
- TODO()
- }
- }
-
- /**
- * @param mode: r, rb, w, wb, a, ab
- *
- * Difference: TEXT MODE assumes CP437 instead of UTF-8!
- *
- * When you have opened a file you must always close the file handle, or else data may not be saved.
- *
- * FILE class in CC:
- * (when you look thru them using file = fs.open("./test", "w")
- *
- * file = {
- * close = function()
- * -- write mode
- * write = function(string)
- * flush = function() -- write, keep the handle
- * writeLine = function(string) -- text mode
- * -- read mode
- * readLine = function() -- text mode
- * readAll = function()
- * -- binary read mode
- * read = function() -- read single byte. return: number or nil
- * -- binary write mode
- * write = function(byte)
- * writeBytes = function(string as bytearray)
- * }
- */
- class OpenFile(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : TwoArgFunction() {
- override fun call(path: LuaValue, mode: LuaValue) : LuaValue {
- val path = VDPath(path.checkPath(), sysCharset)
- val disk = computer.getTargetDisk(path)!!
-
- path.dropMount()
-
- val mode = mode.checkIBM437().toLowerCase()
- val luaClass = LuaTable()
- val fileEntry = computer.getFile(path)!!
-
- if (fileEntry.contents is EntryDirectory) {
- throw LuaError("File '${fileEntry.getFilenameString(sysCharset)}' is directory.")
- }
-
- val file = fileEntry.contents as EntryFile
-
- if (mode.contains(Regex("""[aw]""")))
- throw LuaError("Cannot open file for " +
- "${if (mode.startsWith('w')) "read" else "append"} mode" +
- ": is readonly.")
-
-
- when (mode) {
- "r" -> {
- try {
- val fr = StringReader(String(file.bytes.toByteArray(), sysCharset))//FileReader(file)
- luaClass["close"] = FileClassClose(fr)
- luaClass["readLine"] = FileClassReadLine(fr)
- luaClass["readAll"] = FileClassReadAll(file)
- }
- catch (e: FileNotFoundException) {
- e.printStackTrace()
- throw LuaError(
- if (e.message != null && e.message!!.contains(Regex("""[Aa]ccess (is )?denied""")))
- "$path: access denied."
- else
- "$path: no such file."
- )
- }
- }
- "rb" -> {
- try {
- val fis = ByteArrayInputStream(file.bytes.toByteArray())
- luaClass["close"] = FileClassClose(fis)
- luaClass["read"] = FileClassReadByte(fis)
- luaClass["readAll"] = FileClassReadAll(file)
- }
- catch (e: FileNotFoundException) {
- e.printStackTrace()
- throw LuaError("$path: no such file.")
- }
- }
- "w", "a" -> {
- try {
- val fw = VDFileWriter(fileEntry, mode.startsWith('a'), sysCharset)
- luaClass["close"] = FileClassClose(fw)
- luaClass["write"] = FileClassPrintText(fw)
- luaClass["writeLine"] = FileClassPrintlnText(fw)
- luaClass["flush"] = FileClassFlush(fw)
- }
- catch (e: FileNotFoundException) {
- e.printStackTrace()
- throw LuaError("$path: is a directory.")
- }
- }
- "wb", "ab" -> {
- try {
- val fos = VDFileOutputStream(fileEntry, mode.startsWith('a'), sysCharset)
- luaClass["close"] = FileClassClose(fos)
- luaClass["write"] = FileClassWriteByte(fos)
- luaClass["writeBytes"] = FileClassWriteBytes(fos)
- luaClass["flush"] = FileClassFlush(fos)
- }
- catch (e: FileNotFoundException) {
- e.printStackTrace()
- throw LuaError("$path: is a directory.")
- }
- }
- }
-
- return luaClass
- }
- }
-
- class GetParentDir(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
- override fun call(path: LuaValue) : LuaValue {
- val path = VDPath(path.checkPath(), sysCharset).getParent()
- return LuaValue.valueOf(path.toString())
- }
- }
-
-
- //////////////////////////////
- // OpenFile implementations //
- //////////////////////////////
-
- private class FileClassClose(val fo: Closeable) : ZeroArgFunction() {
- override fun call() : LuaValue {
- fo.close()
- return LuaValue.NONE
- }
- }
-
- private class FileClassWriteByte(val fos: VDFileOutputStream) : OneArgFunction() {
- override fun call(byte: LuaValue) : LuaValue {
- fos.write(byte.checkint())
-
- return LuaValue.NONE
- }
- }
-
- private class FileClassWriteBytes(val fos: VDFileOutputStream) : OneArgFunction() {
- override fun call(byteString: LuaValue) : LuaValue {
- val byteString = byteString.checkIBM437()
- val bytearr = ByteArray(byteString.length, { byteString[it].toByte() })
- fos.write(bytearr)
-
- return LuaValue.NONE
- }
- }
-
- private class FileClassPrintText(val fw: VDFileWriter) : OneArgFunction() {
- override fun call(string: LuaValue) : LuaValue {
- val text = string.checkIBM437()
- fw.write(text)
- return LuaValue.NONE
- }
- }
-
- private class FileClassPrintlnText(val fw: VDFileWriter) : OneArgFunction() {
- override fun call(string: LuaValue) : LuaValue {
- val text = string.checkIBM437() + "\n"
- fw.write(text)
- return LuaValue.NONE
- }
- }
-
- private class FileClassFlush(val fo: Flushable) : ZeroArgFunction() {
- override fun call() : LuaValue {
- fo.flush()
- return LuaValue.NONE
- }
- }
-
- private class FileClassReadByte(val fis: ByteArrayInputStream) : ZeroArgFunction() {
- override fun call() : LuaValue {
- val readByte = fis.read()
- return if (readByte == -1) LuaValue.NIL else LuaValue.valueOf(readByte)
- }
- }
-
- private class FileClassReadAllBytes(val file: EntryFile) : ZeroArgFunction() {
- override fun call() : LuaValue {
- return LuaValue.valueOf(String(file.bytes.toByteArray(), sysCharset))
- }
- }
-
- private class FileClassReadAll(val file: EntryFile) : ZeroArgFunction() {
- override fun call() : LuaValue {
- return LuaValue.valueOf(String(file.bytes.toByteArray(), sysCharset))
- }
- }
-
- /** returns NO line separator! */
- private class FileClassReadLine(fr: Reader) : ZeroArgFunction() {
- val scanner = Scanner(fr.readText()) // no closing; keep the scanner status persistent
-
- override fun call() : LuaValue {
- return if (scanner.hasNextLine()) LuaValue.valueOf(scanner.nextLine())
- else LuaValue.NIL
- }
- }*/
-}
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/luaapi/HostAccessProvider.kt.txt b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/luaapi/HostAccessProvider.kt.txt
deleted file mode 100644
index ea1363fbc..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/luaapi/HostAccessProvider.kt.txt
+++ /dev/null
@@ -1,78 +0,0 @@
-package net.torvald.terrarum.modulecomputers.virtualcomputer.luaapi
-
-import net.torvald.terrarum.gameactors.ai.toLua
-import org.luaj.vm2.lib.OneArgFunction
-import org.luaj.vm2.lib.ZeroArgFunction
-import net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld
-import net.torvald.terrarum.modulecomputers.virtualcomputer.luaapi.Term.Companion.checkIBM437
-import net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Teletype
-import org.luaj.vm2.*
-
-/**
- * Provide Lua an access to computer object that is in Java
- *
- * The "machine" refers to the computer fixture itself in the game world.
- *
- * Created by minjaesong on 2016-09-19.
- */
-internal class HostAccessProvider(globals: Globals, computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) {
-
- init {
- globals["machine"] = LuaTable()
- globals["machine"]["println"] = PrintLn()
- globals["machine"]["isHalted"] = IsHalted(computer)
-
-
- globals["machine"]["__readFromStdin"] = NativeReadStdin(computer)
-
- globals["machine"]["milliTime"] = NativeGetMilliTime(computer)
-
- globals["machine"]["sleep"] = NativeThreadSleep(computer)
-
- globals["__haltsystemexplicit__"] = HaltComputer(computer)
- }
-
- class PrintLn(): OneArgFunction() {
- override fun call(p0: LuaValue): LuaValue {
- if (p0.isnumber())
- println(p0.checkdouble())
- else
- println(p0.checkIBM437())
- return LuaValue.NONE
- }
- }
-
- class IsHalted(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld): ZeroArgFunction() {
- override fun call(): LuaValue {
- return LuaValue.valueOf(computer.isHalted)
- }
- }
-
- class NativeReadStdin(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : ZeroArgFunction() {
- override fun call(): LuaValue {
- return computer.stdin!!.read().toLua()
- }
- }
-
- class HaltComputer(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : ZeroArgFunction() {
- override fun call() : LuaValue {
- computer.isHalted = true
- computer.luaJ_globals.load("""print(DC4.."system halted")""").call()
- return LuaValue.NONE
- }
- }
-
- /** Time elapsed since the power is on. */
- class NativeGetMilliTime(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : ZeroArgFunction() {
- override fun call(): LuaValue {
- return LuaValue.valueOf(computer.milliTime)
- }
- }
-
- class NativeThreadSleep(val computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OneArgFunction() {
- override fun call(mills: LuaValue): LuaValue {
- computer.currentExecutionThread.join(mills.checklong())
- return LuaValue.NONE
- }
- }
-}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/luaapi/Input.kt.txt b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/luaapi/Input.kt.txt
deleted file mode 100644
index d6583126e..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/luaapi/Input.kt.txt
+++ /dev/null
@@ -1,16 +0,0 @@
-package net.torvald.terrarum.modulecomputers.virtualcomputer.luaapi
-
-import com.badlogic.gdx.Gdx
-import org.luaj.vm2.Globals
-import org.luaj.vm2.LuaTable
-import org.luaj.vm2.LuaValue
-import org.luaj.vm2.lib.OneArgFunction
-import net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld
-
-/**
- * Created by minjaesong on 2016-09-25.
- */
-class Input(globals: Globals, computer: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) {
-
-
-}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/luaapi/PcSpeakerDriver.kt.txt b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/luaapi/PcSpeakerDriver.kt.txt
deleted file mode 100644
index b4ad407f5..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/luaapi/PcSpeakerDriver.kt.txt
+++ /dev/null
@@ -1,149 +0,0 @@
-package net.torvald.terrarum.modulecomputers.virtualcomputer.luaapi
-
-import org.luaj.vm2.Globals
-import org.luaj.vm2.LuaTable
-import org.luaj.vm2.LuaValue
-import org.luaj.vm2.lib.TwoArgFunction
-import org.luaj.vm2.lib.ZeroArgFunction
-import net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld
-import org.luaj.vm2.LuaFunction
-import org.luaj.vm2.lib.OneArgFunction
-
-/**
- * PC Speaker driver and arpeggiator (MONOTONE-style 4 channels)
- *
- * Notes are tuned to A440, equal temperament. This is an ISO standard.
- *
- * Created by minjaesong on 2016-09-27.
- */
-class PcSpeakerDriver(val globals: Globals, host: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) {
-
- init {
- globals["speaker"] = LuaTable()
- globals["speaker"]["enqueue"] = EnqueueTone(host)
- globals["speaker"]["clear"] = ClearQueue(host)
- globals["speaker"]["retune"] = Retune(globals)
- globals["speaker"]["resetTune"] = ResetTune(globals)
- globals["speaker"]["toFreq"] = StringToFrequency(globals)
- globals["speaker"]["__basefreq__"] = LuaValue.valueOf(BASE_FREQ) // every other PSGs should use this very variable
-
- // constants
- // e.g. speaker.A0 returns number 1
- fun Int.toNote(): String = NOTE_NAMES[this % 12] + this.plus(8).div(12).toString()
- fun Int.toNoteAlt(): String = NOTE_NAMES_ALT[this % 12] + this.plus(8).div(12).toString()
-
- for (i in 1..126) {
- globals["speaker"][i.toNote()] = i // sharps
- globals["speaker"][i.toNoteAlt()] = i // flats
- }
- }
-
- companion object {
- val BASE_FREQ = 27.5 // frequency of A0
- val NOTE_NAMES = arrayOf("GS", "A", "AS", "B", "C", "CS",
- "D", "DS", "E", "F", "FS", "G")
- val NOTE_NAMES_ALT = arrayOf("Ab", "A", "Bb", "B", "C", "Db",
- "D", "Eb", "E", "F", "Gb", "G")
-
- /** @param basefreq: Frequency of A-0 */
- fun Int.toFreq(basefreq: Double): Double = basefreq * Math.pow(2.0, (this - 1.0) / 12.0)
-
- /** @param "A-5", "B4", "C#5", ... */
- fun String.toNoteIndex(): Int {
- var notestr = this.replace("-", "")
- notestr = notestr.replace("#", "S")
-
- val baseNote = if (notestr.contains("S") || notestr.contains("b"))
- notestr.substring(0, 2)
- else
- notestr.substring(0, 1)
-
- var note: Int = NOTE_NAMES.indexOf(baseNote) // [0-11]
- if (note < 0) note = NOTE_NAMES_ALT.indexOf(baseNote) // search again
- if (note < 0) throw IllegalArgumentException("Unknown note: $this") // failed to search
-
- val octave: Int = notestr.replace(Regex("""[^0-9]"""), "").toInt()
- return octave.minus(if (note >= 4) 1 else 0) * 12 + note
- }
- }
-
- class EnqueueTone(val host: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : TwoArgFunction() {
- /**
- * @param freq: number (hertz) or string (A-4, A4, B#2, ...)
- */
- override fun call(second: LuaValue, freq: LuaValue): LuaValue {
- if (freq.isnumber())
- host.enqueueBeep(second.checkdouble(), freq.checkdouble())
- else {
- host.enqueueBeep(second.checkdouble(),
- freq.checkjstring().toNoteIndex()
- .toFreq(host.luaJ_globals["speaker"]["__basefreq__"].checkdouble())
- )
- }
- return LuaValue.NONE
- }
- }
-
- class ClearQueue(val host: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : ZeroArgFunction() {
- override fun call(): LuaValue {
- host.clearBeepQueue()
- return LuaValue.NONE
- }
- }
-
- class Retune(val globals: Globals) : LuaFunction() {
- /**
- * Examples: C256, A440, A#440, ...
- */
- override fun call(arg: LuaValue): LuaValue {
- val tuneName = arg.checkjstring()
-
- val baseNote = if (tuneName.contains("#") || tuneName.contains("b")) tuneName.substring(0, 2) else tuneName.substring(0, 1)
- val freq = tuneName.replace(Regex("""[^0-9]"""), "").toInt()
-
- // we're assuming the input to be C4, C#4, ... A4, A#4, B4
- // diffPivot corsp. to G#4, A4, ...
- val diffPivot = arrayOf(-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10) // 2^(12 / n)
- var diff = diffPivot[NOTE_NAMES.indexOf(baseNote)]
- if (diff < 0) diff = diffPivot[NOTE_NAMES_ALT.indexOf(baseNote)] // search again
- if (diff < 0) throw IllegalArgumentException("Unknown note: $baseNote") // failed to search
-
- val exp = -diff / 12.0
- val basefreq = freq * Math.pow(2.0, exp) / if (diff >= 3) 8.0 else 16.0 // converts whatever baseNote to A0
-
- globals["speaker"]["__basefreq__"] = basefreq
- return LuaValue.NONE
- }
-
- override fun call(): LuaValue {
- globals["speaker"]["__basefreq__"] = LuaValue.valueOf(BASE_FREQ)
- return LuaValue.NONE
- }
- }
-
- class ResetTune(val globals: Globals) : ZeroArgFunction() {
- override fun call(): LuaValue {
- globals["speaker"]["__basefreq__"] = LuaValue.valueOf(BASE_FREQ)
- return LuaValue.NONE
- }
- }
-
- /**
- * usage = speaker.toFreq(speaker.AS5) --'S' is a substitution for '#'
- */
- class StringToFrequency(val globals: Globals) : OneArgFunction() {
- /**
- * @param arg: number (note index) or string (A-4, A4, B#2, ...)
- */
- override fun call(arg: LuaValue): LuaValue {
- val note = if (arg.isint()) arg.checkint()
- else {
- arg.checkjstring().toNoteIndex()
- }
- val basefreq = globals["speaker"]["__basefreq__"].checkdouble()
-
- return LuaValue.valueOf(note.toFreq(basefreq))
- }
- }
-
-}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/luaapi/Security.kt.txt b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/luaapi/Security.kt.txt
deleted file mode 100644
index 9c4ab3346..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/luaapi/Security.kt.txt
+++ /dev/null
@@ -1,98 +0,0 @@
-package net.torvald.terrarum.modulecomputers.virtualcomputer.luaapi
-
-import org.luaj.vm2.Globals
-import org.luaj.vm2.LuaValue
-import org.luaj.vm2.lib.OneArgFunction
-import net.torvald.terrarum.gameworld.toUint
-import org.apache.commons.codec.binary.Base64
-import org.apache.commons.codec.digest.DigestUtils
-import java.security.SecureRandom
-
-/**
- * Hashes, CSPRNG, Base64
- *
- * Created by minjaesong on 2016-09-15.
- */
-internal class Security(globals: Globals) {
-
- init {
- // load things. WARNING: THIS IS MANUAL!
- globals["security"] = LuaValue.tableOf()
- globals["security"]["toSHA256"] = SHA256sum()
- globals["security"]["toSHA1"] = SHA1sum()
- globals["security"]["toMD5"] = MD5sum()
- globals["security"]["randomBytes"] = SecureRandomHex()
- globals["security"]["decodeBase64"] = DecodeBase64()
- globals["security"]["encodeBase64"] = EncodeBase64()
- }
-
- /** @return byteArray as String */
- class SHA256sum : OneArgFunction() {
- override fun call(p0: LuaValue): LuaValue {
- val hashBytes = DigestUtils.sha256(p0.checkjstring())
- return LuaValue.valueOf(hashBytes.toStringRepresentation())
- }
- }
-
- /** @return byteArray as String */
- class SHA1sum: OneArgFunction() {
- override fun call(p0: LuaValue): LuaValue {
- val hashBytes = DigestUtils.sha1(p0.checkjstring())
- return LuaValue.valueOf(hashBytes.toStringRepresentation())
- }
- }
-
- /** @return byteArray as String */
- class MD5sum: OneArgFunction() {
- override fun call(p0: LuaValue): LuaValue {
- val hashBytes = DigestUtils.md5(p0.checkjstring())
- return LuaValue.valueOf(hashBytes.toStringRepresentation())
- }
- }
-
- /** @return byteArray as String */
- class SecureRandomHex: OneArgFunction() {
- override fun call(byteSize: LuaValue): LuaValue {
- val bytes = ByteArray(byteSize.checkint())
- SecureRandom().nextBytes(bytes)
-
- return LuaValue.valueOf(bytes.toStringRepresentation())
- }
- }
-
- /** @return String */
- class DecodeBase64: OneArgFunction() {
- override fun call(base64: LuaValue): LuaValue {
- val decodedBytes = Base64.decodeBase64(base64.checkjstring())
- return LuaValue.valueOf(decodedBytes.toStringRepresentation())
- }
- }
-
- /** @return byteArray as String */
- class EncodeBase64: OneArgFunction() {
- override fun call(inputString: LuaValue): LuaValue {
- val inputBytes = inputString.checkjstring().toByteArray(charset("UTF-8"))
- return LuaValue.valueOf(Base64.encodeBase64(inputBytes).toStringRepresentation())
- }
- }
-
- companion object {
- val hexLookup = charArrayOf(
- '0', '1', '2', '3', '4', '5', '6', '7',
- '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
- )
-
- fun Byte.toHexString(): String {
- val bInt = this.toUint()
- return "${hexLookup[bInt.shr(8).and(0xf)]}${hexLookup[bInt.and(0xf)]}"
- }
-
- /** essentially, 0xFC to 0xFC.toChar() */
- fun ByteArray.toStringRepresentation(): String {
- val sb = StringBuilder()
- for (b in this)
- sb.append(b.toChar())
- return sb.toString()
- }
- }
-}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/luaapi/Term.kt.txt b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/luaapi/Term.kt.txt
deleted file mode 100644
index c9a0487ba..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/luaapi/Term.kt.txt
+++ /dev/null
@@ -1,284 +0,0 @@
-package net.torvald.terrarum.modulecomputers.virtualcomputer.luaapi
-
-import org.luaj.vm2.*
-import org.luaj.vm2.lib.*
-import net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Teletype
-import net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Terminal
-import java.nio.charset.Charset
-
-/**
- * Controls terminal as if it was a monitor
- * (not sending control sequences but just drives it directly)
- *
- * Created by minjaesong on 2016-09-12.
- */
-internal class Term(globals: Globals, term: net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Teletype) {
-
- init {
- // load things. WARNING: THIS IS MANUAL!
- globals["term"] = LuaValue.tableOf()
- globals["term"]["write"] = Term.WriteString(term)
- globals["term"]["print"] = Term.PrintString(term)
- globals["term"]["newLine"] = Term.NewLine(term)
- globals["term"]["moveCursor"] = Term.MoveCursor(term) // TTY function
- globals["term"]["width"] = Term.GetWidth(term)
- globals["term"]["scroll"] = Term.Scroll(term)
- globals["term"]["isTeletype"] = Term.IsTeletype(term)
- globals["term"]["bell"] = Term.Bell(term)
-
- if (term is net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Terminal) {
- globals["term"]["emitRaw"] = Term.EmitRaw(term)
- globals["term"]["emit"] = Term.Emit(term)
- globals["term"]["emitString"] = Term.EmitString(term)
- globals["term"]["resetColor"] = Term.ResetColour(term)
- globals["term"]["resetColour"] = Term.ResetColour(term)
- globals["term"]["clear"] = Term.Clear(term)
- globals["term"]["clearLine"] = Term.ClearLine(term)
- globals["term"]["setCursor"] = Term.SetCursor(term)
- globals["term"]["getCursor"] = Term.GetCursorPos(term)
- globals["term"]["getX"] = Term.GetCursorX(term)
- globals["term"]["getY"] = Term.GetCursorY(term)
- globals["term"]["setX"] = Term.SetCursorX(term)
- globals["term"]["setY"] = Term.SetCursorY(term)
- globals["term"]["setCursorBlink"] = Term.SetCursorBlink(term)
- globals["term"]["size"] = Term.GetSize(term)
- globals["term"]["height"] = Term.GetHeight(term)
- globals["term"]["isCol"] = Term.IsColour(term)
- globals["term"]["setForeCol"] = Term.SetForeColour(term)
- globals["term"]["setBackCol"] = Term.SetBackColour(term)
- globals["term"]["foreCol"] = Term.GetForeColour(term)
- globals["term"]["backCol"] = Term.GetBackColour(term)
- }
- }
-
- companion object {
- fun LuaValue.checkIBM437(): String {
- if (this is LuaString)
- return m_bytes.copyOfRange(m_offset, m_offset + m_length).toString(Charset.forName("CP437"))
- // it only works if Charset is ISO-8859, despite of the name "IBM437"
- // --> then would "CP437" work? -- Torvald at 2017-04-05
- else
- throw LuaError("bad argument (string expected, got ${this.typename()})")
- }
- }
-
- class Bell(val tty: net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Teletype) : OneArgFunction() {
- override fun call(pattern: LuaValue): LuaValue {
- tty.bell(pattern.checkjstring())
- return LuaValue.NONE
- }
- }
-
- class WriteString(val tty: net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Teletype) : LuaFunction() {
- override fun call(p0: LuaValue): LuaValue {
- if (tty is net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Terminal)
- tty.writeString(p0.checkIBM437(), tty.cursorX, tty.cursorY)
- else
- tty.writeChars(p0.checkIBM437())
- return LuaValue.NONE
- }
-
- override fun call(s: LuaValue, x: LuaValue, y: LuaValue): LuaValue {
- if (tty is net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Terminal)
- tty.writeString(s.checkIBM437(), x.checkint(), y.checkint())
- else
- throw LuaError("couldn't move cursor; TTY is one-dimensional")
- return LuaValue.NONE
- }
- }
-
- class PrintString(val tty: net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Teletype) : LuaFunction() {
- override fun call(p0: LuaValue): LuaValue {
- if (tty is net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Terminal)
- tty.printString(p0.checkIBM437(), tty.cursorX, tty.cursorY)
- else
- tty.printChars(p0.checkIBM437())
- return LuaValue.NONE
- }
-
- override fun call(s: LuaValue, x: LuaValue, y: LuaValue): LuaValue {
- if (tty is net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Terminal)
- tty.printString(s.checkIBM437(), x.checkint(), y.checkint())
- else
- throw LuaError("couldn't move cursor; TTY is one-dimensional")
- return LuaValue.NONE
- }
- }
-
- class NewLine(val tty: net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Teletype) : ZeroArgFunction() {
- override fun call(): LuaValue {
- tty.newLine()
- return LuaValue.NONE
- }
- }
-
- class EmitRaw(val term: net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Terminal) : ThreeArgFunction() {
- override fun call(p0: LuaValue, x: LuaValue, y: LuaValue): LuaValue {
- term.emitChar(p0.checkint(), x.checkint() - 1, y.checkint() - 1)
- return LuaValue.NONE
- }
- }
-
- // emitchar
- class Emit(val term: net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Terminal) : ThreeArgFunction() {
- override fun call(p0: LuaValue, x: LuaValue, y: LuaValue): LuaValue {
- term.emitChar(p0.checkint().toChar(), x.checkint() - 1, y.checkint() - 1)
- return LuaValue.NONE
- }
- }
-
- class EmitString(val term: net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Terminal) : ThreeArgFunction() {
- override fun call(p0: LuaValue, x: LuaValue, y: LuaValue): LuaValue {
- term.emitString(p0.checkIBM437(), x.checkint() - 1, y.checkint() - 1)
- return LuaValue.NONE
- }
- }
-
- class ResetColour(val term: net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Terminal) : ZeroArgFunction() {
- override fun call(): LuaValue {
- term.resetColour()
- return LuaValue.NONE
- }
- }
-
- class Clear(val term: net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Terminal) : ZeroArgFunction() {
- override fun call(): LuaValue {
- term.clear()
- return LuaValue.NONE
- }
- }
-
- class ClearLine(val term: net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Terminal) : ZeroArgFunction() {
- override fun call(): LuaValue {
- term.clearLine()
- return LuaValue.NONE
- }
- }
-
- /** term.setCursorPos(number x) */
- class MoveCursor(val tty: net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Teletype) : OneArgFunction() {
- override fun call(p0: LuaValue): LuaValue {
- for (i in 1..p0.checkint())
- tty.printChar(' ')
- return LuaValue.NONE
- }
- }
-
- class SetCursor(val term: net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Terminal) : TwoArgFunction() {
- override fun call(x: LuaValue, y: LuaValue): LuaValue {
- term.setCursor(x.checkint() - 1, y.checkint() - 1)
- return LuaValue.NONE
- }
- }
-
- /** One-based */
- class GetCursorPos(val term: net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Terminal) : VarArgFunction() {
- override fun invoke(args: Varargs?): Varargs {
- val ret = arrayOf(LuaValue.valueOf(term.cursorX + 1), LuaValue.valueOf(term.cursorY + 1))
- return LuaValue.varargsOf(ret)
- }
- }
-
- class GetCursorX(val term: net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Terminal) : ZeroArgFunction() {
- override fun call(): LuaValue {
- return LuaValue.valueOf(term.cursorX + 1)
- }
- }
-
- class GetCursorY(val term: net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Terminal) : ZeroArgFunction() {
- override fun call(): LuaValue {
- return LuaValue.valueOf(term.cursorY + 1)
- }
- }
-
- class SetCursorX(val term: net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Terminal) : OneArgFunction() {
- override fun call(p0: LuaValue): LuaValue {
- term.setCursor(p0.checkint() - 1, term.cursorY)
- return LuaValue.NONE
- }
- }
-
- class SetCursorY(val term: net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Terminal) : OneArgFunction() {
- override fun call(p0: LuaValue): LuaValue {
- term.setCursor(term.cursorX - 1, p0.checkint())
- return LuaValue.NONE
- }
- }
-
- /** term.setCursorBlink(boolean bool) */
- class SetCursorBlink(val term: net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Terminal) : OneArgFunction() {
- override fun call(p0: LuaValue): LuaValue {
- term.cursorBlink = p0.toboolean()
- return LuaValue.NONE
- }
- }
-
- class GetSize(val term: net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Terminal) : VarArgFunction() {
- override fun invoke(args: Varargs?): Varargs {
- val ret = arrayOf(LuaValue.valueOf(term.width), LuaValue.valueOf(term.height))
- return LuaValue.varargsOf(ret)
- }
- }
-
- class GetWidth(val tty: net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Teletype) : ZeroArgFunction() {
- override fun call(): LuaValue {
- return LuaValue.valueOf(tty.width)
- }
- }
-
- class GetHeight(val terminal: net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Terminal) : ZeroArgFunction() {
- override fun call(): LuaValue {
- return LuaValue.valueOf(terminal.height)
- }
- }
-
- class IsColour(val term: net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Terminal) : ZeroArgFunction() {
- override fun call(): LuaValue {
- return LuaValue.valueOf(term.coloursCount > 4)
- }
- }
-
- /** term.scroll(number n) */
- class Scroll(val tty: net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Teletype) : OneArgFunction() {
- override fun call(p0: LuaValue): LuaValue {
- if (tty is net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Terminal) tty.scroll(p0.checkint())
- else for (i in 1..p0.checkint()) tty.newLine()
- return LuaValue.NONE
- }
- }
-
- /** term.setTextColor(number color) */
- class SetForeColour(val term: net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Terminal) : OneArgFunction() {
- override fun call(p0: LuaValue): LuaValue {
- term.foreColour = p0.checkint()
- return LuaValue.NONE
- }
- }
-
- /** term.setBackgroundColor(number color) */
- class SetBackColour(val term: net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Terminal) : OneArgFunction() {
- override fun call(p0: LuaValue): LuaValue {
- term.backColour = p0.checkint()
- return LuaValue.NONE
- }
- }
-
- class GetForeColour(val term: net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Terminal) : ZeroArgFunction() {
- override fun call(): LuaValue {
- return LuaValue.valueOf(term.foreColour)
- }
- }
-
- class GetBackColour(val term: net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Terminal) : ZeroArgFunction() {
- override fun call(): LuaValue {
- return LuaValue.valueOf(term.backColour)
- }
- }
-
- class IsTeletype(val termInQuestion: net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Teletype) : ZeroArgFunction() {
- override fun call(): LuaValue {
- return LuaValue.valueOf(termInQuestion.coloursCount == 0)
- }
- }
-
-}
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/luaapi/WorldInformationProvider.kt.txt b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/luaapi/WorldInformationProvider.kt.txt
deleted file mode 100644
index 95d8b3927..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/luaapi/WorldInformationProvider.kt.txt
+++ /dev/null
@@ -1,93 +0,0 @@
-package net.torvald.terrarum.modulecomputers.virtualcomputer.luaapi
-
-import org.luaj.vm2.Globals
-import org.luaj.vm2.LuaFunction
-import net.torvald.terrarum.Terrarum
-import net.torvald.terrarum.modulebasegame.gameworld.GameWorldExtension
-import net.torvald.terrarum.modulebasegame.gameworld.WorldTime
-import org.luaj.vm2.LuaTable
-import org.luaj.vm2.LuaValue
-
-/**
- * Implementation of lua's os.date, to return world info of the game world.
- *
- * Created by minjaesong on 2016-09-28.
- */
-class WorldInformationProvider(globals: Globals) {
-
- init {
- globals["os"]["time"] = LuaValue.NIL // history is LONG! Our 32-bit Lua's epoch is destined to break down...
- globals["os"]["date"] = OsDateImpl()
- }
-
- companion object {
- fun getWorldTimeInLuaFormat() : LuaTable {
- val t = LuaTable()
- val time = if (Terrarum.ingame != null) (Terrarum.ingame!!.world as GameWorldExtension).worldTime else WorldTime()
-
- // int Terrarum World Time format
- t["hour"] = time.hours
- t["min"] = time.minutes
- t["wday"] = time.dayOfWeek
- t["year"] = time.years
- t["yday"] = time.yearlyDays
- t["month"] = time.months
- t["sec"] = time.seconds
- t["day"] = time.days
-
- return t
- }
-
- val defaultDateFormat = "%a %d %B %Y %X"
-
- /** evaluate single C date format */
- fun String.evalAsDate(): String {
- val time = if (Terrarum.ingame != null) (Terrarum.ingame!!.world as GameWorldExtension).worldTime else WorldTime()
- return when (this) {
- "%a" -> time.getDayNameShort()
- "%A" -> time.getDayNameFull()
- "%b" -> time.getMonthNameShort()
- "%B" -> time.getMonthNameFull()
- "%c" -> "%x".evalAsDate() + " " + "%X".evalAsDate()
- "%d" -> time.days.toString()
- "%H" -> time.hours.toString()
- "%I" -> throw IllegalArgumentException("%I: AM/PM concept does not exists.")
- "%M" -> time.minutes.toString()
- "%m" -> time.months.toString()
- "%p" -> throw IllegalArgumentException("%p: AM/PM concept does not exists.")
- "%S" -> time.seconds.toString()
- "%w" -> time.dayOfWeek.toString()
- "%x" -> "${String.format("%02d", time.years)}-${String.format("%02d", time.months)}-${String.format("%02d", time.days)}"
- "%X" -> "${String.format("%02d", time.hours)}:${String.format("%02d", time.minutes)}:${String.format("%02d", time.seconds)}"
- "%Y" -> time.years.toString()
- "%y" -> time.years.rem(100).toString()
- "%%" -> "%"
- else -> throw IllegalArgumentException("Unknown format string: $this")
- }
- }
-
- val acceptedDateFormats = arrayOf("%a", "%A", "%b", "%B", "%c", "%d", "%H", "%I", "%M", "%m", "%p", "%S", "%w", "%x", "%X", "%Y", "%y", "%%" )
- }
-
- /**
- * Changes: cannot get a representation of arbitrary time.
- */
- class OsDateImpl() : LuaFunction() {
- // no args
- override fun call(): LuaValue {
- return call(defaultDateFormat)
- }
-
- override fun call(format: LuaValue): LuaValue {
- var arg = format.checkjstring()
- acceptedDateFormats.forEach {
- if (arg.contains(it))
- arg = arg.replace(it, it.evalAsDate(), ignoreCase = false)
- }
- return LuaValue.valueOf(arg)
- }
-
-
- }
-
-}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/peripheral/CommLine.kt b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/peripheral/CommLine.kt
deleted file mode 100644
index 62670ef54..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/peripheral/CommLine.kt
+++ /dev/null
@@ -1,37 +0,0 @@
-package net.torvald.terrarum.modulecomputers.virtualcomputer.peripheral
-
-/**
- * Abstraction of the communication line. (e.g. serial cable)
- *
- * A cable may have multiple of CommLines (e.g. serial cable need two for Tx and Rx)
- *
- * Created by minjaesong on 2019-07-10.
- */
-open class CommLine(val bandwidth: Int) {
-
- open val postbox = StringBuilder()
-
- /**
- * Returns how many bytes are actually posted, e.g. 0 when band limit is exceeded.
- */
- open fun post(msg: String): Int {
- if (bandwidth >= msg.length) {
- postbox.append(msg)
- return msg.length
- }
- else if (postbox.length >= bandwidth) {
- return 0
- }
- else {
- postbox.append(msg.substring(0 until (bandwidth - postbox.length)))
- return bandwidth - postbox.length
- }
- }
-
- open fun get(): String {
- val s = postbox.toString()
- postbox.clear()
- return s
- }
-
-}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/peripheral/Peripheral.kt.txt b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/peripheral/Peripheral.kt.txt
deleted file mode 100644
index ade0d84c9..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/peripheral/Peripheral.kt.txt
+++ /dev/null
@@ -1,17 +0,0 @@
-package net.torvald.terrarum.modulecomputers.virtualcomputer.peripheral
-
-import org.luaj.vm2.Globals
-import org.luaj.vm2.LuaTable
-import org.luaj.vm2.LuaValue
-
-/**
- * Created by minjaesong on 2016-09-29.
- */
-abstract class Peripheral(val tableName: String) {
-
- abstract fun loadLib(globals: Globals)
-
- override fun toString(): String = "Peripheral:$tableName"
-
- abstract val memSize: Int
-}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/peripheral/PeripheralCharLCD.kt.txt b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/peripheral/PeripheralCharLCD.kt.txt
deleted file mode 100644
index aca5b2e20..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/peripheral/PeripheralCharLCD.kt.txt
+++ /dev/null
@@ -1,51 +0,0 @@
-package net.torvald.terrarum.modulecomputers.virtualcomputer.peripheral
-
-import com.badlogic.gdx.graphics.g2d.BitmapFont
-import com.badlogic.gdx.graphics.g2d.SpriteBatch
-import net.torvald.terrarum.ModMgr
-import org.luaj.vm2.Globals
-
-/**
- * Created by minjaesong on 2017-05-31.
- */
-class PeripheralCharLCD(val width: Int, val height: Int) : net.torvald.terrarum.modulecomputers.virtualcomputer.peripheral.Peripheral("charLCD") {
- /*companion object {
- private val fontSheet = BitmapFont(ModMgr.getPath("dwarventech", "mt-32.tga"), 16, 16)
- private val font = BitmapFont(fontSheet, 0.toChar())
- private val fontW = fontSheet.width / fontSheet.horizontalCount
- private val fontH = fontSheet.height / fontSheet.verticalCount
- }
-
- override fun loadLib(globals: Globals) {
- TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
- }
-
- override fun toString(): String {
- return super.toString()
- }
-
- override val memSize = width * height
-
- var cursor: Int = 0 // character LCDs are mostly single long line wrapped
-
- val memory = ByteArray(memSize) // temporary; replace with proper VMPeripheralWrapper
-
- /**
- * @param g Frame Buffer that holds the display of LCD screen
- */
- fun render(batch: SpriteBatch) {
- memory.forEachIndexed { index, byte ->
- font.draw(batch, "${byte.toChar()}", (index % width) * fontW.toFloat(), (index / width) * fontH.toFloat())
- }
- }*/
- override fun loadLib(globals: Globals) {
- TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
- }
-
- override fun toString(): String {
- return super.toString()
- }
-
- override val memSize: Int
- get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
-}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/peripheral/PeripheralInternet.kt.txt b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/peripheral/PeripheralInternet.kt.txt
deleted file mode 100644
index 9095d98c8..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/peripheral/PeripheralInternet.kt.txt
+++ /dev/null
@@ -1,44 +0,0 @@
-package net.torvald.terrarum.modulecomputers.virtualcomputer.peripheral
-
-import org.luaj.vm2.Globals
-import net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld
-import org.luaj.vm2.LuaTable
-import org.luaj.vm2.LuaValue
-import org.luaj.vm2.lib.OneArgFunction
-import java.io.BufferedReader
-import java.io.InputStreamReader
-import java.net.URL
-
-/**
- * Provides internet access.
- *
- * Created by minjaesong on 2016-09-24.
- */
-internal class PeripheralInternet(val host: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld)
-: net.torvald.terrarum.modulecomputers.virtualcomputer.peripheral.Peripheral("internet"){
-
- override val memSize = 1024
-
- override fun loadLib(globals: Globals) {
- globals["internet"] = LuaTable()
- globals["internet"]["fetch"] = FetchWebPage()
- }
-
- class FetchWebPage() : OneArgFunction() {
- override fun call(urlstr: LuaValue): LuaValue {
- val url = URL(urlstr.checkjstring())
- val inputstream = BufferedReader(InputStreamReader(url.openStream()))
-
- var inline = ""
- var readline = inputstream.readLine()
- while (readline != null) {
- inline += readline
- readline = inputstream.readLine()
- }
- inputstream.close()
-
- return LuaValue.valueOf(inline)
- }
- }
-
-}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/peripheral/PeripheralPSG.kt.txt b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/peripheral/PeripheralPSG.kt.txt
deleted file mode 100644
index 84605c0f9..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/peripheral/PeripheralPSG.kt.txt
+++ /dev/null
@@ -1,23 +0,0 @@
-package net.torvald.terrarum.modulecomputers.virtualcomputer.peripheral
-
-import net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld
-import org.luaj.vm2.Globals
-import org.luaj.vm2.LuaTable
-import org.luaj.vm2.LuaValue
-
-/**
- * Virtual driver for 4-track squarewave PSG, which has no ability of changing a duty cycle
- * but has a volume control (you'll need some other tracker than MONOTONE)
- *
- * Created by minjaesong on 2016-09-27.
- */
-internal class PeripheralPSG(val host: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld)
-: net.torvald.terrarum.modulecomputers.virtualcomputer.peripheral.Peripheral("psg") {
-
- override val memSize = 1024
-
- override fun loadLib(globals: Globals) {
- globals["psg"] = LuaTable()
- }
-
-}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/peripheral/PeripheralVideoCard.kt.txt b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/peripheral/PeripheralVideoCard.kt.txt
deleted file mode 100644
index 8f31afcf3..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/peripheral/PeripheralVideoCard.kt.txt
+++ /dev/null
@@ -1,659 +0,0 @@
-package net.torvald.terrarum.modulecomputers.virtualcomputer.peripheral
-
-import org.luaj.vm2.*
-import org.luaj.vm2.lib.*
-
-/**
- * Resolution: 640 x 200, non-square pixels
- *
- * Created by minjaesong on 2017-02-08.
- */
-/*class PeripheralVideoCard(val host: TerrarumComputerOld, val termW: Int = 80, val termH: Int = 25) :
- Peripheral("ppu") {
- companion object {
- val blockW = 8 // MUST BE 8
- val blockH = 8 // MUST BE 8
-
- /**
- * Converts consecutive lua table indexed from 1 as IntArray.
- * The lua table must not contain any nils in the sequence.
- */
- fun LuaTable.toIntArray(): IntArray {
- val arr = IntArray(this.keyCount())
- var k = 1
- while (true) {
- if (this[k].isnil()) break
-
- arr[k - 1] = this[k].checkint()
- k += 1
- }
-
- return arr
- }
- }
-
- val width = termW * blockW
- val height = termH * blockH
-
- val spritesCount = 256
-
- val vram = VRAM(width, height, spritesCount)
- val frameBuffer = ImageBuffer(width, height)
- val frameBufferImage = frameBuffer.image
-
- // hard-coded 8x8
- var fontRom = Array(256, { IntArray(blockH) })
-
- var showCursor = true
-
- private var cursorBlinkOn = true
- private var cursorBlinkTimer = 0
- private val cursorBlinkTime = 250
-
- init {
- // build it for first time
- resetTextRom()
-
- frameBufferImage.filter = Image.FILTER_NEAREST
- }
-
- val CLUT = VRAM.CLUT
- val colorsCount = CLUT.size
-
- val luaSpriteTable = LuaTable()
-
- var color = 15 // black
- set(value) {
- if (value >= colorsCount || value < 0) {
- throw IllegalArgumentException("Unknown colour: $value")
- }
- else {
- field = value
- }
- }
-
- val cursorSprite = ImageBuffer(blockW, blockH * 2)
- val cursorImage: Image
-
-
- override val memSize = 256 * 8 + (width * height * 2) + spritesCount * 16 * 7
- // fontRom + framebuffers + sprites
-
-
- init {
- Arrays.fill(cursorSprite.rgba, 0xFF.toByte())
- cursorImage = cursorSprite.image
-
- fun composeSpriteObject(spriteIndex: Int) : LuaValue {
- val sprite = vram.sprites[spriteIndex]
- val t = LuaTable()
-
- t["getColFromPal"] = SpriteGetColFromPal(sprite)
- t["setPixel"] = SpriteSetPixel(sprite)
- t["setPalSet"] = SpriteSetPaletteSet(sprite)
- t["setLine"] = SpriteSetLine(sprite)
- t["setAll"] = SpriteSetAll(sprite)
- t["setRotation"] = SpriteSetRotation(sprite)
- t["setFlipH"] = SpriteSetFlipH(sprite)
- t["setFlipV"] = SpriteSetFlipV(sprite)
-
- return t
- }
-
- (0..spritesCount - 1).forEach { luaSpriteTable[it + 1] = composeSpriteObject(it) }
- }
-
- fun buildFontRom(ref: String) {
- // load font rom out of TGA
- val imageRef = Image(ref)
- val image = imageRef.texture.textureData
- val imageWidth = imageRef.width
-
- for (i in 0..255) {
- for (y in 0..blockH - 1) {
- // letter mirrored horizontally!
- var scanline = 0
- for (x in 0..blockW - 1) {
- val subX = i % 16
- val subY = i / 16
- val bit = image[4 * ((subY * blockH + y) * imageWidth + blockW * subX + x) + 3] != 0.toByte()
- if (bit) scanline = scanline or (1 shl x)
- }
-
- fontRom[i][y] = scanline
- }
- }
- }
-
- override fun loadLib(globals: Globals) {
- globals["ppu"] = LuaTable()
- globals["ppu"]["setTextForeColor"] = SetTextForeColor(this)
- globals["ppu"]["getTextForeColor"] = GetTextForeColor(this)
- globals["ppu"]["setTextBackColor"] = SetTextBackColor(this)
- globals["ppu"]["getTextBackColor"] = GetTextBackColor(this)
- globals["ppu"]["setColor"] = SetDrawColor(this)
- globals["ppu"]["getColor"] = GetDrawColor(this)
- globals["ppu"]["emitChar"] = EmitChar(this)
- globals["ppu"]["clearAll"] = ClearAll(this)
- globals["ppu"]["clearBack"] = ClearBackground(this)
- globals["ppu"]["clearFore"] = ClearForeground(this)
-
- globals["ppu"]["getSpritesCount"] = GetSpritesCount(this)
- globals["ppu"]["width"] = GetWidth(this)
- globals["ppu"]["height"] = GetHeight(this)
-
-
- globals["ppu"]["getSprite"] = GetSprite(this)
-
- globals["ppu"]["drawRectBack"] = DrawRectBack(this)
- globals["ppu"]["drawRectFore"] = DrawRectFore(this)
- globals["ppu"]["fillRectBack"] = FillRectBack(this)
- globals["ppu"]["fillRectFore"] = FillRectFore(this)
- globals["ppu"]["drawString"] = DrawString(this)
- }
-
- private val spriteBuffer = ImageBuffer(VSprite.width * 2, VSprite.height)
-
- fun render(g: Graphics) {
- cursorBlinkTimer += AppLoader.getSmoothDelta().toFloat()
- if (cursorBlinkTimer > cursorBlinkTime) {
- cursorBlinkTimer -= cursorBlinkTime
- cursorBlinkOn = !cursorBlinkOn
- }
-
- fun VSprite.render() {
- if (this.isVisible) {
- val h = VSprite.height
- val w = VSprite.width
- if (rotation and 1 == 0) { // deg 0, 180
- (if (rotation == 0 && !vFlip || rotation == 2 && vFlip) 0..h - 1 else h - 1 downTo 0).forEachIndexed { ordY, y ->
- (if (rotation == 0 && !hFlip || rotation == 2 && hFlip) 0..w - 1 else w - 1 downTo 0).forEachIndexed { ordX, x ->
- val pixelData = data[y].ushr(2 * x).and(0b11)
- val col = getColourFromPalette(pixelData)
-
- if (this.drawWide) {
- spriteBuffer.setRGBA(ordX * 2, ordY, col.red, col.green, col.blue, col.alpha)
- spriteBuffer.setRGBA(ordX * 2 + 1, ordY, col.red, col.green, col.blue, col.alpha)
- }
- else {
- spriteBuffer.setRGBA(ordX, ordY, col.red, col.green, col.blue, col.alpha)
- }
- }
- }
- }
- else { // deg 90, 270
- (if (rotation == 3 && !hFlip || rotation == 1 && hFlip) 0..w - 1 else w - 1 downTo 0).forEachIndexed { ordY, y ->
- (if (rotation == 3 && !vFlip || rotation == 1 && vFlip) h - 1 downTo 0 else 0..h - 1).forEachIndexed { ordX, x ->
- val pixelData = data[y].ushr(2 * x).and(0b11)
- val col = getColourFromPalette(pixelData)
-
- if (this.drawWide) {
- spriteBuffer.setRGBA(ordY * 2, ordX, col.red, col.green, col.blue, col.alpha)
- spriteBuffer.setRGBA(ordY * 2 + 1, ordX, col.red, col.green, col.blue, col.alpha)
- }
- else {
- spriteBuffer.setRGBA(ordY, ordX, col.red, col.green, col.blue, col.alpha)
- }
- }
- }
- }
- }
- }
-
-
- System.arraycopy(vram.background.rgba, 0, frameBuffer.rgba, 0, vram.background.rgba.size)
- vram.sprites.forEach {
- if (it.isBackground) {
- it.render()
- frameBuffer.softwareRender(spriteBuffer, it.posX, it.posY)
- }
- }
- frameBuffer.softwareRender(vram.foreground, 0, 0)
- vram.sprites.forEach {
- if (!it.isBackground) {
- it.render()
- frameBuffer.softwareRender(spriteBuffer, it.posX, it.posY)
- }
- }
-
-
- val img = frameBuffer.image
- img.filter = Image.FILTER_NEAREST
- g.drawImage(img.getScaledCopy(blockW * termW, blockH * termH * 2), 0f, 0f)
-
-
- if (cursorBlinkOn && showCursor) {
- g.drawImage(
- cursorImage,
- host.term.cursorX * blockW.toFloat(),
- (host.term as Terminal).cursorY * blockH * 2f
- )
- }
-
-
- // scanlines
- g.color = Color(0, 0, 0, 40)
- g.lineWidth = 1f
- for (i in 1..blockH * termH * 2 step 2) {
- g.drawLine(0f, i.toFloat(), blockW * termW - 1f, i.toFloat())
- }
-
- img.destroy()
- }
-
- private var textColorFore = 49 // white
- private var textColorBack = 64 // transparent
-
- fun drawChar(c: Char, x: Int, y: Int, colFore: Int = textColorFore, colBack: Int = textColorBack) {
- val glyph = fontRom[c.toInt()]
-
- // software render
- for (gy in 0..blockH - 1) { for (gx in 0..blockW - 1) {
- val glyAlpha = glyph[gy] and (1 shl gx)
-
- if (glyAlpha != 0) {
- vram.setForegroundPixel(x + gx, y + gy, colFore)
- }
- else {
- vram.setForegroundPixel(x + gx, y + gy, colBack)
- }
- }}
- }
-
-
- fun clearBackground() {
- for (i in 0..width * height - 1) {
- vram.background.rgba[i] = if (i % 4 == 3) 0xFF.toByte() else 0x00.toByte()
- }
- }
-
- fun clearForeground() {
- for (i in 0..width * height - 1) {
- vram.foreground.rgba[i] = 0x00.toByte()
- }
- }
-
- fun clearAll() {
- for (i in 0..width * height - 1) {
- vram.background.rgba[i] = if (i % 4 == 3) 0xFF.toByte() else 0x00.toByte()
- vram.foreground.rgba[i] = 0x00.toByte()
- }
- }
-
- fun drawRectBack(x: Int, y: Int, w: Int, h: Int, c: Int = color) {
- for (it in 0..w - 1) {
- vram.setBackgroundPixel(x + it, y, c)
- vram.setBackgroundPixel(x + it, y + h - 1, c)
- }
- for (it in 1..h - 2) {
- vram.setBackgroundPixel(x, y + it, c)
- vram.setBackgroundPixel(x + w - 1, y + it, c)
- }
- }
-
- fun fillRectBack(x: Int, y: Int, w: Int, h: Int, c: Int = color) {
- for (py in 0..h - 1) { for (px in 0..w - 1) {
- vram.setBackgroundPixel(x + px, y + py, c)
- }}
- }
-
- fun drawRectFore(x: Int, y: Int, w: Int, h: Int, c: Int = color) {
- for (it in 0..w - 1) {
- vram.setForegroundPixel(x + it, y, c)
- vram.setForegroundPixel(x + it, y + h - 1, c)
- }
- for (it in 1..h - 2) {
- vram.setForegroundPixel(x, y + it, c)
- vram.setForegroundPixel(x + w - 1, y + it, c)
- }
- }
-
- fun fillRectFore(x: Int, y: Int, w: Int, h: Int, c: Int = color) {
- for (py in 0..h - 1) { for (px in 0..w - 1) {
- vram.setForegroundPixel(x + px, y + py, c)
- }}
- }
-
-
- fun getSprite(index: Int) = vram.sprites[index]
-
-
- private fun ImageBuffer.softwareRender(other: ImageBuffer, posX: Int, posY: Int) {
- for (y in 0..other.height - 1) {
- for (x in 0..other.width - 1) {
- val ix = posX + x
- val iy = posY + y
- if (ix >= 0 && iy >= 0 && ix < this.width && iy < this.height) {
- if (other.rgba[4 * (y * other.texWidth + x) + 3] != 0.toByte()) { // if not transparent
- this.rgba[4 * (iy * this.texWidth + ix) + 0] = other.rgba[4 * (y * other.texWidth + x) + 0]
- this.rgba[4 * (iy * this.texWidth + ix) + 1] = other.rgba[4 * (y * other.texWidth + x) + 1]
- this.rgba[4 * (iy * this.texWidth + ix) + 2] = other.rgba[4 * (y * other.texWidth + x) + 2]
- this.rgba[4 * (iy * this.texWidth + ix) + 3] = other.rgba[4 * (y * other.texWidth + x) + 3]
- }
- }
- }
- }
- }
-
- /**
- * Array be like, in binary; notice that glyphs are flipped horizontally:
- * ...
- * 00011000
- * 00011100
- * 00011000
- * 00011000
- * 00011000
- * 00011000
- * 01111111
- * 00000000
- * 00111111
- * 01100011
- * 01100000
- * 00111111
- * 00000011
- * 00000011
- * 01111111
- * 00000000
- * ...
- */
- fun setTextRom(data: Array) {
- for (i in 0..255) {
- for (y in 0..blockH - 1) {
- // letter mirrored horizontally!
- fontRom[i][y] = data[blockH * i + y]
- }
- }
- }
-
- fun resetTextRom() {
- buildFontRom("./assets/graphics/fonts/milky.tga")
- }
-
- ///////////////////
- // Lua functions //
- ///////////////////
-
- class SetTextForeColor(val videoCard: PeripheralVideoCard) : OneArgFunction() {
- override fun call(arg: LuaValue): LuaValue {
- videoCard.textColorFore = arg.checkint()
- return LuaValue.NONE
- }
- }
- class GetTextForeColor(val videoCard: PeripheralVideoCard) : ZeroArgFunction() {
- override fun call(): LuaValue {
- return videoCard.textColorFore.toLua()
- }
- }
- class SetTextBackColor(val videoCard: PeripheralVideoCard) : OneArgFunction() {
- override fun call(arg: LuaValue): LuaValue {
- videoCard.textColorBack = arg.checkint()
- return LuaValue.NONE
- }
- }
- class GetTextBackColor(val videoCard: PeripheralVideoCard) : ZeroArgFunction() {
- override fun call(): LuaValue {
- return videoCard.textColorBack.toLua()
- }
- }
- class SetDrawColor(val videoCard: PeripheralVideoCard) : OneArgFunction() {
- override fun call(arg: LuaValue): LuaValue {
- videoCard.color = arg.checkint()
- return LuaValue.NONE
- }
- }
- class GetDrawColor(val videoCard: PeripheralVideoCard) : ZeroArgFunction() {
- override fun call(): LuaValue {
- return videoCard.color.toLua()
- }
- }
- class GetWidth(val videoCard: PeripheralVideoCard) : ZeroArgFunction() {
- override fun call(): LuaValue {
- return videoCard.width.toLua()
- }
- }
- class GetHeight(val videoCard: PeripheralVideoCard) : ZeroArgFunction() {
- override fun call(): LuaValue {
- return videoCard.height.toLua()
- }
- }
- class EmitChar(val videoCard: PeripheralVideoCard) : ThreeArgFunction() {
- /** emitChar(char, x, y) */
- override fun call(arg1: LuaValue, arg2: LuaValue, arg3: LuaValue): LuaValue {
- videoCard.drawChar(arg1.checkint().toChar(), arg2.checkint(), arg3.checkint())
- return LuaValue.NONE
- }
- }
- class ClearAll(val videoCard: PeripheralVideoCard) : ZeroArgFunction() {
- override fun call(): LuaValue {
- videoCard.clearAll()
- return LuaValue.NONE
- }
- }
- class ClearBackground(val videoCard: PeripheralVideoCard) : ZeroArgFunction() {
- override fun call(): LuaValue {
- videoCard.clearBackground()
- return LuaValue.NONE
- }
- }
- class ClearForeground(val videoCard: PeripheralVideoCard) : ZeroArgFunction() {
- override fun call(): LuaValue {
- videoCard.clearForeground()
- return LuaValue.NONE
- }
- }
- class GetSpritesCount(val videoCard: PeripheralVideoCard) : ZeroArgFunction() {
- override fun call(): LuaValue {
- return videoCard.spritesCount.toLua()
- }
- }
- class GetSprite(val videoCard: PeripheralVideoCard) : OneArgFunction() {
- override fun call(arg: LuaValue): LuaValue {
- return videoCard.luaSpriteTable[arg.checkint() - 1]
- }
- }
- class DrawRectBack(val videoCard: PeripheralVideoCard) : FourArgFunction() {
- override fun call(arg1: LuaValue, arg2: LuaValue, arg3: LuaValue, arg4: LuaValue): LuaValue {
- videoCard.drawRectBack(arg1.checkint(), arg2.checkint(), arg3.checkint(), arg4.checkint())
- return LuaValue.NONE
- }
- }
- class FillRectBack(val videoCard: PeripheralVideoCard) : FourArgFunction() {
- override fun call(arg1: LuaValue, arg2: LuaValue, arg3: LuaValue, arg4: LuaValue): LuaValue {
- videoCard.fillRectBack(arg1.checkint(), arg2.checkint(), arg3.checkint(), arg4.checkint())
- return LuaValue.NONE
- }
- }
- class DrawRectFore(val videoCard: PeripheralVideoCard) : FourArgFunction() {
- override fun call(arg1: LuaValue, arg2: LuaValue, arg3: LuaValue, arg4: LuaValue): LuaValue {
- videoCard.drawRectFore(arg1.checkint(), arg2.checkint(), arg3.checkint(), arg4.checkint())
- return LuaValue.NONE
- }
- }
- class FillRectFore(val videoCard: PeripheralVideoCard) : FourArgFunction() {
- override fun call(arg1: LuaValue, arg2: LuaValue, arg3: LuaValue, arg4: LuaValue): LuaValue {
- videoCard.fillRectFore(arg1.checkint(), arg2.checkint(), arg3.checkint(), arg4.checkint())
- return LuaValue.NONE
- }
- }
- class DrawString(val videoCard: PeripheralVideoCard) : ThreeArgFunction() {
- override fun call(arg1: LuaValue, arg2: LuaValue, arg3: LuaValue): LuaValue {
- val str = arg1.checkjstring()
- val x = arg2.checkint()
- val y = arg3.checkint()
- str.forEachIndexed { i, c ->
- videoCard.drawChar(c, x + blockW * i, y)
- }
- return LuaValue.NONE
- }
- }
-
- /////////////
- // Sprites //
- /////////////
-
- private class SpriteGetColFromPal(val sprite: VSprite) : OneArgFunction() {
- override fun call(arg: LuaValue): LuaValue {
- return when (arg.checkint()) {
- 0 -> sprite.pal0.toLua()
- 1 -> sprite.pal1.toLua()
- 2 -> sprite.pal2.toLua()
- 3 -> sprite.pal3.toLua()
- else -> throw IndexOutOfBoundsException("Palette size: 4, input: ${arg.checkint()}")
- }
- }
- }
- private class SpriteSetPixel(val sprite: VSprite) : ThreeArgFunction() {
- override fun call(arg1: LuaValue, arg2: LuaValue, arg3: LuaValue): LuaValue {
- sprite.setPixel(arg1.checkint(), arg2.checkint(), arg3.checkint())
- return LuaValue.NONE
- }
- }
- private class SpriteSetPaletteSet(val sprite: VSprite) : OneArgFunction() {
- override fun call(arg: LuaValue): LuaValue {
- sprite.setPaletteSet(arg(1).checkint(), arg(2).checkint(), arg(3).checkint(), arg(4).checkint())
- return LuaValue.NONE
- }
- }
- private class SpriteSetLine(val sprite: VSprite) : TwoArgFunction() {
- override fun call(arg1: LuaValue, arg2: LuaValue): LuaValue {
- sprite.setLine(arg1.checkint(), arg2.checktable().toIntArray())
- return LuaValue.NONE
- }
- }
- private class SpriteSetAll(val sprite: VSprite) : OneArgFunction() {
- override fun call(arg: LuaValue): LuaValue {
- sprite.setAll(arg.checktable().toIntArray())
- return LuaValue.NONE
- }
- }
- private class SpriteSetRotation(val sprite: VSprite) : OneArgFunction() {
- override fun call(arg: LuaValue): LuaValue {
- sprite.rotation = arg.checkint()
- return LuaValue.NONE
- }
- }
- private class SpriteSetFlipH(val sprite: VSprite) : OneArgFunction() {
- override fun call(arg: LuaValue): LuaValue {
- sprite.hFlip = arg.checkboolean()
- return LuaValue.NONE
- }
- }
- private class SpriteSetFlipV(val sprite: VSprite) : OneArgFunction() {
- override fun call(arg: LuaValue): LuaValue {
- sprite.vFlip = arg.checkboolean()
- return LuaValue.NONE
- }
- }
-}
-
-class VRAM(pxlWidth: Int, pxlHeight: Int, nSprites: Int) {
- val sprites = Array(nSprites, { VSprite() })
-
- val background = ImageBuffer(pxlWidth, pxlHeight)
- val foreground = ImageBuffer(pxlWidth, pxlHeight) // text mode glyphs rendered here
-
- companion object {
- val CLUT = DecodeTapestry.colourIndices64 + Color(0, 0, 0, 0)
- }
-
-
- fun setBackgroundPixel(x: Int, y: Int, color: Int) {
- val col = CLUT[color]
- background.setRGBA(x, y, col.red, col.green, col.blue, 255)
- }
-
- fun setForegroundPixel(x: Int, y: Int, color: Int) {
- val col = CLUT[color]
- foreground.setRGBA(x, y, col.red, col.green, col.blue, col.alpha)
- }
-}
-
-class VSprite {
- companion object {
- val width = 8
- val height = 8
- }
-
- internal val CLUT = VRAM.CLUT
- internal val data = IntArray(height)
-
- var pal0 = 64 // transparent
- var pal1 = 56 // light cyan
- var pal2 = 19 // magenta
- var pal3 = 49 // white
-
- var posX = 0
- var posY = 0
-
- var hFlip = false
- var vFlip = false
- var rotation = 0
- set(value) { field = value % 4 }
-
- var isBackground = false
- var isVisible = false
- var drawWide = false
-
- fun setPaletteSet(col0: Int, col1: Int, col2: Int, col3: Int) {
- pal0 = col0
- pal1 = col1
- pal2 = col2
- pal3 = col3
- }
-
- fun getColourFromPalette(swatchNumber: Int): Color {
- val clutIndex = when (swatchNumber) {
- 0 -> pal0
- 1 -> pal1
- 2 -> pal2
- 3 -> pal3
- else -> throw IndexOutOfBoundsException("Palette size: 4, input: $swatchNumber")
- }
- return CLUT[clutIndex]
- }
-
- fun setPos(x: Int, y: Int) {
- posX = x
- posY = y
- }
-
- fun setPixel(x: Int, y: Int, color: Int) {
- data[y] = data[y] xor data[y].and(3 shl (2 * x)) // mask off desired area to 0b00
- data[y] = data[y] or (color shl (2 * x))
- }
-
- fun setLine(y: Int, rowData: IntArray) {
- for (i in 0..width - 1) {
- setPixel(i, y, rowData[i])
- }
- }
-
- fun setAll(data: IntArray) {
- for (i in 0..width * height - 1) {
- setPixel(i % width, i / width, data[i])
- }
- }
-}*/
-
-
-abstract class FourArgFunction : LibFunction() {
-
- abstract override fun call(arg1: LuaValue, arg2: LuaValue, arg3: LuaValue, arg4: LuaValue): LuaValue
-
- override fun call(): LuaValue {
- return call(LuaValue.NIL, LuaValue.NIL, LuaValue.NIL, LuaValue.NIL)
- }
-
- override fun call(arg: LuaValue): LuaValue {
- return call(arg, LuaValue.NIL, LuaValue.NIL, LuaValue.NIL)
- }
-
- override fun call(arg1: LuaValue, arg2: LuaValue): LuaValue {
- return call(arg1, arg2, LuaValue.NIL, LuaValue.NIL)
- }
-
- override fun invoke(varargs: Varargs): Varargs {
- return call(varargs.arg1(), varargs.arg(2), varargs.arg(3), varargs.arg(4))
- }
-
-}
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/standalone/StandaloneApp.kt b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/standalone/StandaloneApp.kt
deleted file mode 100644
index 357e48d8d..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/standalone/StandaloneApp.kt
+++ /dev/null
@@ -1,195 +0,0 @@
-package net.torvald.terrarum.modulecomputers.virtualcomputer.standalone
-
-import com.badlogic.gdx.Game
-import com.badlogic.gdx.Gdx
-import com.badlogic.gdx.InputProcessor
-import com.badlogic.gdx.backends.lwjgl.LwjglApplication
-import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration
-import com.badlogic.gdx.graphics.Color
-import com.badlogic.gdx.graphics.Texture
-import com.badlogic.gdx.graphics.g2d.SpriteBatch
-import net.torvald.EMDASH
-import net.torvald.terrarum.modulecomputers.virtualcomputer.computer.LuaComputerVM
-import net.torvald.terrarum.modulecomputers.virtualcomputer.computer.MDA
-import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
-
-/**
- * Created by minjaesong on 2019-07-09.
- */
-class StandaloneApp : Game() {
-
- lateinit var font: TextureRegionPack
-
- lateinit var background: Texture
- lateinit var execLed: Texture
- lateinit var waitLed: Texture
-
- lateinit var batch: SpriteBatch
-
- val display = MDA(64, 40)
- val vm = LuaComputerVM(display)
-
- override fun create() {
- font = TextureRegionPack(Gdx.files.internal("assets/mods/dwarventech/gui/lcd.tga"), 12, 16)
-
- background = Texture(Gdx.files.internal("assets/mods/dwarventech/gui/6440_textonly.png"))
- execLed = Texture(Gdx.files.internal("assets/mods/dwarventech/gui/led_green.tga"))
- waitLed = Texture(Gdx.files.internal("assets/mods/dwarventech/gui/led_orange.tga"))
-
- batch = SpriteBatch()
-
- Gdx.input.inputProcessor = StandaloneAppInputProcessor(vm)
- }
-
- private val height: Int; get() = Gdx.graphics.height
-
- private val lcdOffX = 74f
- private val lcdOffY = 56f
-
- private val lcdCol = arrayOf(
- Color(0x10101000),
- Color(0x101010AA),
- Color(0x10101055),
- Color(0x101010FF)
- )
-
- private var textCursorDrawTimer = 0f // 0f..0.5f: not draw
-
- init {
- vm.runCommand("""
- print("Hello, world!")
- while true do
- local s = io.read()
- print(s)
- end
- """.trimIndent(), "")
-
- /*vm.runCommand("""
- a = 0
- while true do
- print(a)
- a = a + 1
- end
- """.trimIndent(), "")*/
- }
-
-
-
- override fun render() {
- Gdx.graphics.setTitle("Terrarum Lua Computer Standalone $EMDASH F: ${Gdx.graphics.framesPerSecond}")
-
- //display.print(ByteArray(1){ (Math.random() * 255).toByte() })
- //display.print("@")
-
- batch.inUse {
- batch.color = Color.WHITE
- batch.draw(background, 0f, 0f)
-
-
- // draw the screen
- textCursorDrawTimer += Gdx.graphics.rawDeltaTime
- if (textCursorDrawTimer > 1f) textCursorDrawTimer -= 1f
-
- for (i in 0 until display.width * display.height) {
- val drawX = ((i % display.width) * font.tileW).toFloat()
- val drawY = ((i / display.width) * font.tileH).toFloat()
- val (g, a) = display.rawGet(i)
- val glyph = g.toUint()
- val glyphBack = glyph + 256
- val back = (a.toUint() ushr 4) % lcdCol.size
- val fore = a.toUint() % lcdCol.size
-
- if (display.blink && i == display.cursor && textCursorDrawTimer >= 0.5f) {
- batch.color = lcdCol[1]
- batch.draw(
- font.get(0, 8),
- lcdOffX + drawX,
- (this.height - font.tileH) - (lcdOffY + drawY)
- )
- }
- else {
- // print background
- batch.color = lcdCol[back]
- batch.draw(
- font.get(glyphBack % font.horizontalCount, glyphBack / font.horizontalCount),
- lcdOffX + drawX,
- (this.height - font.tileH) - (lcdOffY + drawY)
- )
- // print foreground
- batch.color = lcdCol[fore]
- batch.draw(
- font.get(glyph % font.horizontalCount, glyph / font.horizontalCount),
- lcdOffX + drawX,
- (this.height - font.tileH) - (lcdOffY + drawY)
- )
- }
-
- }
- // end of draw the screen
-
- }
-
-
- //vm.resumeExec()
- }
-
- override fun dispose() {
- background.dispose()
- display.dispose()
- //vm.destroy()
- }
-
- private inline fun SpriteBatch.inUse(action: () -> Unit) {
- this.begin()
- action.invoke()
- this.end()
- }
-
- private class StandaloneAppInputProcessor(private val vm: LuaComputerVM) : InputProcessor {
- override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
- return false
- }
-
- override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
- return false
- }
-
- override fun keyTyped(character: Char): Boolean {
- return false
- }
-
- override fun scrolled(amount: Int): Boolean {
- return false
- }
-
- override fun keyUp(keycode: Int): Boolean {
- return false
- }
-
- override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
- return false
- }
-
- override fun keyDown(keycode: Int): Boolean {
- vm.keyPressed(keycode)
- return false
- }
-
- override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
- return false
- }
- }
-
- private fun Byte.toUint() = java.lang.Byte.toUnsignedInt(this)
-}
-
-fun main(args: Array) {
- val config = LwjglApplicationConfiguration()
- config.width = 914
- config.height = 796
- config.foregroundFPS = 100
- config.vSyncEnabled = false
- config.resizable = false
-
- LwjglApplication(StandaloneApp(), config)
-}
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/terminal/GraphicsTerminal.kt.txt b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/terminal/GraphicsTerminal.kt.txt
deleted file mode 100644
index 14898c362..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/terminal/GraphicsTerminal.kt.txt
+++ /dev/null
@@ -1,305 +0,0 @@
-package net.torvald.terrarum.modulecomputers.virtualcomputer.terminal
-
-/**
- * Printing text using Term API triggers 'compatibility' mode, where you are limited to 16 colours.
- * Use PPU API for full 64 colours!
- *
- * Created by minjaesong on 2017-02-08.
- */
-/*class GraphicsTerminal(private val host: TerrarumComputerOld) : Terminal {
- lateinit var videoCard: PeripheralVideoCard
-
- override val width: Int; get() = videoCard.termW
- override val height: Int; get() = videoCard.termH
- override val coloursCount: Int; get() = videoCard.colorsCount
- override var cursorX = 0
- override var cursorY = 0
- override var cursorBlink = true
-
- val backDefault = 0 // black
- val foreDefault = 1 // white
-
- override var backColour = backDefault
- override var foreColour = foreDefault
-
- private val colourKey: Int
- get() = backColour.shl(4) or (foreColour).and(0xFF)
-
- override fun getColor(index: Int) = videoCard.CLUT[index]
-
- override val displayW: Int; get() = videoCard.width //+ 2 * borderSize
- override val displayH: Int; get() = videoCard.height //+ 2 * borderSize
-
- private lateinit var videoScreen: Image
-
- var TABSIZE = 4
-
- val errorColour = 6
-
- override fun printChars(s: String) {
- printString(s, cursorX, cursorY)
- }
-
- override fun update(gc: GameContainer, delta: Int) {
- wrap()
- }
-
- // copied from SimpleTextTerminal
- private fun wrap() {
- // wrap cursor
- if (cursorX < 0 && cursorY <= 0) {
- setCursor(0, 0)
- }
- else if (cursorX >= width) {
- setCursor(0, cursorY + 1)
- }
- else if (cursorX < 0) {
- setCursor(width - 1, cursorY - 1)
- }
- // auto scroll up
- if (cursorY >= height) {
- scroll()
- }
- }
-
- override fun render(gc: GameContainer, g: Graphics) {
- videoCard.render(g)
- }
-
- override fun keyPressed(key: Int, c: Char) {
- host.keyPressed(key, c)
- }
-
- override fun writeChars(s: String) {
- writeString(s, cursorX, cursorY)
- }
-
- /** Unlike lua function, this one in Zero-based. */
- override fun setCursor(x: Int, y: Int) {
- cursorX = x
- cursorY = y
- }
-
- override fun emitChar(bufferChar: Int, x: Int, y: Int) {
- videoCard.drawChar(
- bufferChar.and(0xFF).toChar(),
- x * PeripheralVideoCard.blockW,
- y * PeripheralVideoCard.blockH,
- CLUT16_TO_64[bufferChar.ushr(8).and(0xF)],
- CLUT16_TO_64[bufferChar.ushr(12).and(0xF)]
- )
- }
-
- override fun emitChar(c: Char, xx: Int, yy: Int) {
- wrap() // needed
- var nx = xx
- var ny = yy
- // wrap argument cursor
- if (xx < 0 && yy <= 0) {
- nx = 0
- ny = 0
- }
- else if (cursorX >= width) {
- println("arstenioarstoneirastneo")
- nx = 0
- ny += 1
- }
- else if (cursorX < 0) {
- nx = width - 1
- ny -= 1
- }
- // auto scroll up
- if (cursorY >= height) {
- scroll()
- ny -= 1
- }
-
- println("xx: $xx, yy: $yy")
- println("nx: $nx, ny: $ny")
-
- videoCard.drawChar(
- c,
- nx * PeripheralVideoCard.blockW,
- ny * PeripheralVideoCard.blockH,
- CLUT16_TO_64[foreColour]
- )
- }
-
- override fun printChar(c: Char) {
- if (c >= ' ' && c.toInt() != 127) {
- emitChar(c, cursorX, cursorY)
- cursorX += 1
- }
- else {
- if (BACKSPACE.contains(c)) {
- cursorX -= 1
- //wrap()
- emitChar(0.toChar(), cursorX, cursorY)
- }
- else {
- when (c) {
- ASCII_BEL -> bell(".")
- ASCII_TAB -> { cursorX = (cursorX).div(TABSIZE).times(TABSIZE) + TABSIZE }
- ASCII_LF -> { newLine(); System.err.println("LF ${Random().nextInt(100)}") }
- ASCII_FF -> clear()
- ASCII_CR -> { cursorX = 0 }
- ASCII_DC1, ASCII_DC2, ASCII_DC3,
- ASCII_DC4 -> { foreColour = c - ASCII_DC1 }
- ASCII_DLE -> { foreColour = errorColour }
- }
- }
- }
- }
-
- override fun emitString(s: String, x: Int, y: Int) {
- setCursor(x, y)
-
- for (i in 0..s.length - 1) {
- printChar(s[i])
- }
-
- setCursor(x, y)
- }
-
- override fun printString(s: String, x: Int, y: Int) {
- writeString(s, x, y)
- newLine()
- }
-
- override fun writeString(s: String, x: Int, y: Int) {
- setCursor(x, y)
-
- for (i in 0..s.length - 1) {
- printChar(s[i])
- }
- }
-
- override fun clear() {
- videoCard.clearForeground()
- }
-
- override fun clearLine() {
- //TODO("not implemented")
- }
-
- override fun newLine() {
- cursorX = 0; cursorY += 1
- //wrap()
- }
-
- override fun scroll(amount: Int) {
- val rgba = videoCard.vram.foreground.rgba
- val displacement = amount.abs() * PeripheralVideoCard.blockH * videoCard.vram.foreground.texWidth * 4
- if (amount >= 0) {
- System.arraycopy(
- rgba, displacement,
- rgba, 0,
- rgba.size - displacement
- )
- for (it in rgba.size - 1 downTo rgba.size - displacement + 1) { rgba[it] = 0.toByte() }
- }
- else {
- System.arraycopy(
- rgba, 0,
- rgba, displacement,
- rgba.size - displacement
- )
- for (it in 0..displacement - 1) { rgba[it] = 0.toByte() }
- }
-
- cursorY += -amount
- }
-
- /**
- * does not changes color setting in PPU
- */
- override fun setColour(back: Int, fore: Int) {
- foreColour = fore
- backColour = back
- }
-
- /**
- * does not changes color setting in PPU
- */
- override fun resetColour() {
- foreColour = foreDefault
- backColour = backDefault
- }
-
- /** // copied from SimpleTextTerminal
- * @param duration: milliseconds
- * @param freg: Frequency (float)
- */
- override fun emitTone(duration: Int, freq: Double) {
- host.clearBeepQueue()
- host.enqueueBeep(duration, freq)
- }
-
- // copied from SimpleTextTerminal
- /** for "emitTone code" on modern BIOS. */
- override fun bell(pattern: String) {
- host.clearBeepQueue()
-
- val freq: Double =
- if (host.luaJ_globals["computer"]["bellpitch"].isnil())
- 1000.0
- else
- host.luaJ_globals["computer"]["bellpitch"].checkdouble()
-
- for (c in pattern) {
- when (c) {
- '.' -> { host.enqueueBeep(80, freq); host.enqueueBeep(50, 0.0) }
- '-' -> { host.enqueueBeep(200, freq); host.enqueueBeep(50, 0.0) }
- '=' -> { host.enqueueBeep(500, freq); host.enqueueBeep(50, 0.0) }
- ' ' -> { host.enqueueBeep(200, 0.0) }
- ',' -> { host.enqueueBeep(50, 0.0) }
- else -> throw IllegalArgumentException("Unacceptable pattern: $c (from '$pattern')")
- }
- }
- }
-
- companion object {
- private val WHITE7500 = Color(0xe4eaff)
-
- val ASCII_NUL = 0.toChar()
- val ASCII_BEL = 7.toChar() // *BEEP!*
- val ASCII_TAB = 9.toChar() // move cursor to next (TABSIZE * yy) pos (5 -> 8, 3- > 4, 4 -> 8)
- val ASCII_LF = 10.toChar() // new line
- val ASCII_FF = 12.toChar() // new page
- val ASCII_CR = 13.toChar() // x <- 0
- val BACKSPACE = arrayOf(127.toChar(), 8.toChar()) // backspace and delete char (8 for WIN, 127 for OSX)
- val ASCII_DC1 = 17.toChar() // foreground colour 0
- val ASCII_DC2 = 18.toChar() // foreground colour 1
- val ASCII_DC3 = 19.toChar() // foreground colour 2
- val ASCII_DC4 = 20.toChar() // foreground colour 3
- val ASCII_DLE = 16.toChar() // error message colour
-
- val asciiControlInUse = charArrayOf(
- ASCII_NUL,
- ASCII_BEL,
- 8.toChar(),
- ASCII_TAB,
- ASCII_LF,
- ASCII_FF,
- ASCII_CR,
- 127.toChar(),
- ASCII_DC1,
- ASCII_DC2,
- ASCII_DC3,
- ASCII_DC4,
- ASCII_DLE
- )
-
- val CLUT = DecodeTapestry.colourIndices64
- val CLUT16_TO_64 = intArrayOf(
- 15, 49, 16, 48, 44, 29, 33, 18,
- 5, 22, 39, 26, 25, 10, 31, 13
- )
- }
-
- fun attachVideoCard(videocard: PeripheralVideoCard) {
- this.videoCard = videocard
-
- videoScreen = Image(videoCard.width, videoCard.height)
- }
-}*/
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/terminal/SimpleTextTerminal.kt.txt b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/terminal/SimpleTextTerminal.kt.txt
deleted file mode 100644
index 94696582c..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/terminal/SimpleTextTerminal.kt.txt
+++ /dev/null
@@ -1,381 +0,0 @@
-package net.torvald.terrarum.modulecomputers.virtualcomputer.terminal
-
-
-/**
- * Default text terminal.
- *
- * Created by minjaesong on 2016-09-07.
- */
-/*open class SimpleTextTerminal(
- phosphorColour: Color, override val width: Int, override val height: Int, private val host: TerrarumComputerOld,
- colour: Boolean = false, hires: Boolean = false
-) : Terminal {
-
- private val DEBUG = false
-
- /**
- * Terminals must support AT LEAST 4 colours.
- * Color index 0 must be default background, index 3 must be default foreground
- */
- open protected val colours = if (colour) CLUT else CLUT.copyOfRange(0, 4)
-
- val phosphor = if (colour) WHITE7500 else phosphorColour
- open val colourScreen = if (colour) Color(8, 8, 8) else Color(19, 19, 19)
-
- override val coloursCount: Int
- get() = colours.size
-
- val errorColour = if (coloursCount > 4) 6 else 1
-
- open val backDefault = 0 // STANDARD
- open val foreDefault = 3 // STANDARD
-
- override var backColour = backDefault
- override var foreColour = foreDefault
- private val colourKey: Int
- get() = backColour.shl(4) or (foreColour).and(0xFF)
-
- override var cursorX = 0
- override var cursorY = 0
- override var cursorBlink = true
-
- val screenBuffer = AAFrame(width, height, this)
-
- open protected val fontRef =
- "./assets/graphics/fonts/${
- if (hires) "milky.tga"
- else if (phosphor == GREEN || phosphor == AMBER) "MDA.tga"
- else "milkymda.tga"
- }"
- open protected val fontImg = Image(fontRef)
- open val fontW = fontImg.width / 16
- open val fontH = fontImg.height / 16
- open protected val font = SpriteSheetFont(SpriteSheet(fontRef, fontW, fontH), 0.toChar())
-
- val borderSize = 20
- override val displayW = fontW * width + 2 * borderSize
- override val displayH = fontH * height + 2 * borderSize
-
-
- var TABSIZE = 4
-
- private var cursorBlinkTimer = 0
- private val cursorBlinkLen = 250
- var cursorBlinkOn = true
- private set
-
-
-
- override fun getColor(index: Int): Color = colours[index]
-
- override fun update(gc: GameContainer, delta: Int) {
- cursorBlinkTimer = cursorBlinkTimer.plus(delta)
- if (cursorBlinkTimer > cursorBlinkLen) {
- cursorBlinkTimer -= cursorBlinkLen
- cursorBlinkOn = !cursorBlinkOn
- }
-
- wrap()
- }
-
- private fun wrap() {
- // wrap cursor
- if (cursorX < 0 && cursorY <= 0) {
- setCursor(0, 0)
- }
- else if (cursorX >= width) {
- setCursor(0, cursorY + 1)
- }
- else if (cursorX < 0) {
- setCursor(width - 1, cursorY - 1)
- }
- // auto scroll up
- if (cursorY >= height) {
- scroll()
- }
- }
-
- /**
- * pass UIcanvas to the parameter "g"
- */
- override fun render(gc: GameContainer, g: Graphics) {
- g.font = font
-
-
- blendNormal()
-
- // black background (this is mandatory)
- g.color = Color.black
- g.fillRect(0f, 0f, displayW.toFloat(), displayH.toFloat())
-
-
- // screen buffer
- for (y in 0..height - 1) {
- for (x in 0..width - 1) {
- val ch = screenBuffer.getChar(x, y)
-
- // background
- g.color = getColor(screenBuffer.getBackgroundColour(x, y))
- g.fillRect(fontW * x.toFloat() + borderSize, fontH * y.toFloat() + borderSize,
- fontW.toFloat(), fontH.toFloat())
-
- // foreground
- if (ch.toInt() != 0 && ch.toInt() != 32) {
- g.color = getColor(screenBuffer.getForegroundColour(x, y))
- g.drawString(
- Character.toString(ch),
- fontW * x.toFloat() + borderSize, fontH * y.toFloat() + borderSize)
- }
- }
- }
-
-
- // cursor
- if (cursorBlinkOn) {
- g.color = getColor(if (cursorBlink) foreDefault else backDefault)
-
- g.fillRect(
- fontW * cursorX.toFloat() + borderSize,
- fontH * cursorY.toFloat() + borderSize,
- fontW.toFloat(),
- fontH.toFloat()
- )
- }
-
- // colour base
- g.color = colourScreen
- blendScreen()
- g.fillRect(0f, 0f, fontW * width.toFloat() + 2 * borderSize, fontH * height.toFloat() + 2 * borderSize)
-
- // colour overlay
- g.color = phosphor
- blendMul()
- g.fillRect(0f, 0f, fontW * width.toFloat() + 2 * borderSize, fontH * height.toFloat() + 2 * borderSize)
-
-
-
- blendNormal()
-
- }
-
- /** Unlike lua function, this one in Zero-based. */
- override fun setCursor(x: Int, y: Int) {
- cursorX = x
- cursorY = y
- }
-
- /** Emits a bufferChar. Does not move cursor
- * It is also not affected by the control sequences; just print them out as symbol */
- override fun emitChar(bufferChar: Int, x: Int, y: Int) {
- try { screenBuffer.drawBuffer(x, y, bufferChar.toChar()) }
- catch (e: ArrayIndexOutOfBoundsException) { e.printStackTrace() }
- }
-
- /** Emits a char. Does not move cursor
- * It is also not affected by the control sequences; just print them out as symbol */
- override fun emitChar(c: Char, x: Int, y: Int) {
- try { screenBuffer.drawBuffer(x, y, c.toInt().and(0xFF).toChar(), colourKey) }
- catch (e: ArrayIndexOutOfBoundsException) { e.printStackTrace() }
- }
-
- /** Prints a char and move cursor accordingly. */
- override fun printChar(c: Char) {
- wrap()
- if (c >= ' ' && c.toInt() != 127) {
- emitChar(c, cursorX, cursorY)
- cursorX += 1
- }
- else {
- when (c) {
- ASCII_BEL -> bell(".")
- ASCII_BS -> { cursorX -= 1; wrap() }
- ASCII_TAB -> { cursorX = (cursorX).div(TABSIZE).times(TABSIZE) + TABSIZE }
- ASCII_LF -> newLine()
- ASCII_FF -> clear()
- ASCII_CR -> { cursorX = 0 }
- ASCII_DEL -> { cursorX -= 1; wrap(); emitChar(colourKey.shl(8), cursorX, cursorY) }
- ASCII_DC1, ASCII_DC2, ASCII_DC3, ASCII_DC4 -> { foreColour = c - ASCII_DC1 }
- ASCII_DLE -> { foreColour = errorColour }
- }
- }
- }
-
- /** (TTY): Prints a series of chars and move cursor accordingly, then LF
- * (term): printString() on current cursor pos */
- override fun printChars(s: String) {
- printString(s, cursorX, cursorY)
- }
-
- /** (TTY): Prints a series of chars and move cursor accordingly
- * (term): writeString() on current cursor pos */
- override fun writeChars(s: String) {
- writeString(s, cursorX, cursorY)
- }
-
- /** Emits a string and move cursor accordingly, then do LF */
- override fun printString(s: String, x: Int, y: Int) {
- writeString(s, x, y)
- newLine()
- }
-
- /** Emits a string and move cursor accordingly. */
- override fun writeString(s: String, x: Int, y: Int) {
- setCursor(x, y)
-
- for (i in 0..s.length - 1) {
- printChar(s[i])
- wrap()
- }
- }
-
- /** Emits a string, does not affected by control sequences. Does not move cursor */
- override fun emitString(s: String, x: Int, y: Int) {
- setCursor(x, y)
-
- for (i in 0..s.length - 1) {
- printChar(s[i])
- wrap()
- }
-
- setCursor(x, y)
- }
-
- override fun clear() {
- screenBuffer.clear(backColour)
- cursorX = 0
- cursorY = 0
- }
-
- override fun clearLine() {
- for (i in 0..width - 1)
- screenBuffer.drawBuffer(i, cursorY, 0.toChar(), colourKey)
- }
-
- override fun newLine() {
- cursorX = 0; cursorY += 1; wrap()
- }
-
- override fun scroll(amount: Int) {
- val offset = amount.times(width).abs()
- val bsize = screenBuffer.sizeof.ushr(1)
-
- if (amount == 0) return
-
- if (amount > 0) {
- for (i in 0..bsize - 1) {
- if (i < Math.min(bsize, bsize - offset - 1))
- // displace contents in buffer
- screenBuffer.frameBuffer[i] = screenBuffer.frameBuffer[i + offset]
- else
- // clean up garbages
- screenBuffer.frameBuffer[i] = 0.toChar()
- }
- cursorY -= amount
- }
- else {
- for (i in bsize - 1 downTo 0) {
- if (i > Math.max(offset - 1, 0))
- // displace contents in buffer
- screenBuffer.frameBuffer[i] = screenBuffer.frameBuffer[i - offset]
- else
- screenBuffer.frameBuffer[i] = 0.toChar()
- }
- cursorY += amount
- }
- }
-
- override fun setColour(back: Int, fore: Int) {
- backColour = back
- foreColour = fore
- }
-
- override fun resetColour() {
- backColour = backDefault
- foreColour = foreDefault
- }
-
- /**
- * @param duration: milliseconds
- * @param freg: Frequency (float)
- */
- override fun emitTone(duration: Int, freq: Double) {
- // println("!! Beep playing row $beepCursor, d ${Math.min(duration, maxDuration)} f $freq")
- host.clearBeepQueue()
- host.enqueueBeep(duration, freq)
- }
-
- /** for "emitTone code" on modern BIOS. */
- override fun bell(pattern: String) {
- host.clearBeepQueue()
-
- val freq: Double =
- if (host.luaJ_globals["computer"]["bellpitch"].isnil())
- 1000.0
- else
- host.luaJ_globals["computer"]["bellpitch"].checkdouble()
-
- for (c in pattern) {
- when (c) {
- '.' -> { host.enqueueBeep(80, freq); host.enqueueBeep(50, 0.0) }
- '-' -> { host.enqueueBeep(200, freq); host.enqueueBeep(50, 0.0) }
- '=' -> { host.enqueueBeep(500, freq); host.enqueueBeep(50, 0.0) }
- ' ' -> { host.enqueueBeep(200, 0.0) }
- ',' -> { host.enqueueBeep(50, 0.0) }
- else -> throw IllegalArgumentException("Unacceptable pattern: $c (from '$pattern')")
- }
- }
- }
-
- override fun keyPressed(key: Int, c: Char) {
- host.keyPressed(key, c)
- }
-
- private fun isOOB(x: Int, y: Int) =
- (x < 0 || y < 0 || x >= width || y >= height)
-
- companion object {
- val AMBER = Color(255, 183, 0) // P3, 602 nm
- val GREEN = Color(74, 255, 0) // P39, 525 nm
- val WHITE = Color(204, 223, 255) // approximation of white CRT I own
- private val WHITE7500 = Color(0xe4eaff)
- val BLUE_NOVELTY = Color(0x27d7ff)
- val RED = Color(250, 51, 0) // 632 nm
- val AMETHYST_NOVELTY = Color(0xc095ff)
-
- val ASCII_NUL = 0.toChar()
- val ASCII_BEL = 7.toChar() // *BEEP!*
- val ASCII_BS = 8.toChar() // x = x - 1
- val ASCII_TAB = 9.toChar() // move cursor to next (TABSIZE * yy) pos (5 -> 8, 3- > 4, 4 -> 8)
- val ASCII_LF = 10.toChar() // new line
- val ASCII_FF = 12.toChar() // new page
- val ASCII_CR = 13.toChar() // x <- 0
- val ASCII_DEL = 127.toChar() // backspace and delete char
- val ASCII_DC1 = 17.toChar() // foreground colour 0
- val ASCII_DC2 = 18.toChar() // foreground colour 1
- val ASCII_DC3 = 19.toChar() // foreground colour 2
- val ASCII_DC4 = 20.toChar() // foreground colour 3
- val ASCII_DLE = 16.toChar() // error message colour
-
- val asciiControlInUse = charArrayOf(
- ASCII_NUL,
- ASCII_BEL,
- ASCII_BS,
- ASCII_TAB,
- ASCII_LF,
- ASCII_FF,
- ASCII_CR,
- ASCII_DEL,
- ASCII_DC1,
- ASCII_DC2,
- ASCII_DC3,
- ASCII_DC4,
- ASCII_DLE
- )
-
- val CLUT = DecodeTapestry.colourIndices16
- }
-}*/
-
-class ALException(errorCode: Int) : Exception("ALerror: $errorCode") {
-
-}
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/terminal/Teletype.kt.txt b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/terminal/Teletype.kt.txt
deleted file mode 100644
index 15576abe0..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/terminal/Teletype.kt.txt
+++ /dev/null
@@ -1,37 +0,0 @@
-package net.torvald.terrarum.modulecomputers.virtualcomputer.terminal
-
-import com.badlogic.gdx.graphics.g2d.SpriteBatch
-
-/**
- * Created by minjaesong on 2016-09-14.
- */
-interface Teletype {
- val width: Int
- val displayW: Int
-
- var cursorX: Int
-
- /**
- * 0: Teletype
- * 4: Non-colour terminal (Note that '2' is invalid!)
- * >4: Colour terminal
- */
- val coloursCount: Int
-
- fun update(delta: Float)
- fun render(batch: SpriteBatch)
- fun keyPressed(key: Int, c: Char)
-
- /** Prints a char and move cursor accordingly */
- fun printChar(c: Char)
- /** (TTY): Prints a series of chars and move cursor accordingly, then LF
- * (term): printString() on current cursor pos */
- fun printChars(s: String)
- /** (TTY): Prints a series of chars and move cursor accordingly
- * (term): writeString() on current cursor pos */
- fun writeChars(s: String)
- fun newLine()
- fun scroll(amount: Int = 1)
-
- fun bell(pattern: String = ".")
-}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/terminal/TeletypeTerminal.kt.txt b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/terminal/TeletypeTerminal.kt.txt
deleted file mode 100644
index 388e3c6a2..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/terminal/TeletypeTerminal.kt.txt
+++ /dev/null
@@ -1,204 +0,0 @@
-package net.torvald.terrarum.modulecomputers.virtualcomputer.terminal
-
-import net.torvald.terrarum.blendMul
-import net.torvald.terrarum.blendNormal
-import java.util.*
-
-/**
- * Created by minjaesong on 2016-09-15.
- */
-/*class TeletypeTerminal : Teletype {
- override val width = 40
- override val displayW: Int
- get() = width * font.W
- /**
- * 0: Teletype
- * 4: Non-colour terminal (Note that '2' is invalid!)
- * >4: Colour terminal
- */
- override val coloursCount = 0
-
- override var cursorX = 0
-
- private val font = TTYFont()
-
- private var lineBuffer = StringBuilder()
-
- private var currentJob = 0
- private var currentJobStep = 0
- private var currentJobLen = 0
- private var currentJobQueue: Any? = null
- // make sure certain jobs deliberately take long time by doing them one-by-one, for each frame.
- private val JOB_IDLE = 0
- private val JOB_MOVEHEAD = 1
- private val JOB_PRINTCHAR = 2
- private val JOB_LINEFEED = 3
-
- override fun update(gc: GameContainer, delta: Int) {
- wrap()
-
- /*when (currentJob) {
- JOB_PRINTCHAR -> {
- printChar((currentJobQueue!! as String)[currentJobStep])
- currentJobStep += 1
- }
- JOB_LINEFEED -> {
- newLine()
- currentJobStep += 1
- }
- }*/
-
- if (currentJobStep > currentJobLen) {
- currentJob = JOB_IDLE
- currentJobLen = 0
- currentJobStep = 0
- currentJobQueue = null
- }
- }
-
- override fun render(gc: GameContainer, g: Graphics) {
- g.font = font
- g.drawString(lineBuffer.toString(), 0f, 0f)
- }
-
- val TABSIZE = 4
-
- /** Prints a char and move cursor accordingly */
- override fun printChar(c: Char) {
- wrap()
- if (c >= ' ' && c.toInt() != 127) {
- lineBuffer.append(c)
- cursorX += 1
- }
- else {
- when (c) {
- SimpleTextTerminal.ASCII_BEL -> bell()
- SimpleTextTerminal.ASCII_BS -> { cursorX -= 1; wrap() }
- SimpleTextTerminal.ASCII_TAB -> { cursorX = (cursorX).div(TABSIZE).times(TABSIZE) + TABSIZE }
- SimpleTextTerminal.ASCII_LF -> newLine()
- SimpleTextTerminal.ASCII_FF -> newLine()
- SimpleTextTerminal.ASCII_CR -> { cursorX = 0 }
- SimpleTextTerminal.ASCII_DEL -> { } // NOT supported, do nothing
- SimpleTextTerminal.ASCII_DC1, SimpleTextTerminal.ASCII_DC2, SimpleTextTerminal.ASCII_DC3, SimpleTextTerminal.ASCII_DC4
- -> { } // NOT supported, do nothing
- }
- }
- }
-
- /** (TTY): Prints a series of chars and move cursor accordingly
- * (term): writeString() on current cursor pos */
- override fun writeChars(s: String) {
- /*currentJob = JOB_PRINTCHAR
- currentJobLen = s.length
- currentJobQueue = s*/
- for (i in 0..s.length - 1)
- printChar(s[i])
- }
-
- /** (TTY): Prints a series of chars and move cursor accordingly, then LF
- * (term): writeString() on current cursor pos */
- override fun printChars(s: String) {
- /*currentJob = JOB_PRINTCHAR
- currentJobLen = s.length + 1
- currentJobQueue = "$s\n"*/
- writeChars("$s\n")
- }
-
- override fun newLine() {
- lineBuffer = StringBuilder()
- }
-
- override fun scroll(amount: Int) {
- if (amount < 0) throw IllegalArgumentException("cannot scroll up")
- if (amount == 1) { newLine(); return }
-
- currentJob = JOB_LINEFEED
- currentJobLen = amount
- }
-
- override fun bell(pattern: String) {
- throw UnsupportedOperationException("not implemented") //To change body of created functions use File | Settings | File Templates.
- }
-
- private fun wrap() {
- if (cursorX < 0) cursorX = 0
- else if (cursorX >= width) newLine()
- }
-
- var sb: StringBuilder = StringBuilder()
- private var inputOpen = false
- val DEBUG = true
-
- override fun keyPressed(key: Int, c: Char) {
- if (inputOpen) {
- if (c == SimpleTextTerminal.ASCII_CR)
- printChar(SimpleTextTerminal.ASCII_LF)
- else
- printChar(c)
- if (!SimpleTextTerminal.asciiControlInUse.contains(c)) sb.append(c)
- else if (c == SimpleTextTerminal.ASCII_DEL && sb.length > 0) sb.deleteCharAt(sb.length - 1)
- }
- }
-
- class TTYFont : Font {
-
- internal val fontSheet: SpriteSheet
-
- internal val W = 9
- internal val H = 12
-
- private val chars = arrayOf(
- '0','1','2','3','4','5','6','7',
- '8','9','[','#','@',':','>','?',
- ' ','A','B','C','D','E','F','G',
- 'H','I','&','.',']','(','<','\\',
- '^','J','K','L','M','N','O','P', // ^: escape for capital letter
- 'Q','R','-','¤','*',')',';','\'',
- '+','/','S','T','U','V','W','X',
- 'Y','Z','_',',','%','=','"','!'
- )
- private val mappingTable = HashMap()
-
- init {
- fontSheet = SpriteSheet("./assets/graphics/fonts/teletype_9x12.tga", W, H)
- chars.forEachIndexed { i, c -> mappingTable[c.toInt()] = i }
- }
-
- override fun getHeight(str: String): Int = H
-
- override fun getWidth(str: String): Int {
- var ret = 0
- for (i in 0..str.length - 1)
- ret += W
- return ret
- }
-
- override fun getLineHeight(): Int = H
-
- override fun drawString(x: Float, y: Float, text: String) = drawString(x, y, text, Color.white)
-
- override fun drawString(x: Float, y: Float, text: String, col: Color) {
- var thisCol = col
- var textPosOffset = 0
-
- for (i in 0..text.length - 1) {
- val index = charToSpriteNum(text.toUpperCase().codePointAt(i))
- val ch = text[i]
-
- if (index != null) {
- // main
- fontSheet.getSubImage(index % 8, index / 8).draw(
- x + textPosOffset, y, thisCol
- )
- }
- textPosOffset += W
- }
- }
-
- override fun drawString(x: Float, y: Float, text: String, col: Color, startIndex: Int, endIndex: Int) {
- throw UnsupportedOperationException()
- }
-
- private fun charToSpriteNum(ch: Int): Int? = mappingTable[ch]
- }
-}*/
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/terminal/Terminal.kt.txt b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/terminal/Terminal.kt.txt
deleted file mode 100644
index acc3254b3..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/terminal/Terminal.kt.txt
+++ /dev/null
@@ -1,64 +0,0 @@
-package net.torvald.terrarum.modulecomputers.virtualcomputer.terminal
-
-import com.badlogic.gdx.graphics.Color
-import com.badlogic.gdx.graphics.g2d.SpriteBatch
-import net.torvald.terrarum.Second
-
-/**
- * A terminal
- *
- * Framebuffer: USE net.torvald.aa.AAFrame
- *
- * Background color is fixed; text color is variable
- *
- * Created by minjaesong on 2016-09-07.
- */
-interface Terminal : net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Teletype {
- override val width: Int
- val height: Int
- override val coloursCount: Int
- override var cursorX: Int
- var cursorY: Int
- var cursorBlink: Boolean
- var backColour: Int
- var foreColour: Int
-
- // to be used in UI
- override val displayW: Int
- val displayH: Int
-
- fun getColor(index: Int): Color
- override fun update(delta: Float)
- override fun render(batch: SpriteBatch)
- override fun keyPressed(key: Int, c: Char)
-
- // API calls
- fun setCursor(x: Int, y: Int)
- /** Emits a bufferChar. Does not move cursor
- * It is also not affected by the control sequences; just print them out as symbol */
- fun emitChar(bufferChar: Int, x: Int, y: Int)
- /** Emits a char. Does not move cursor
- * It is also not affected by the control sequences; just print them out as symbol */
- fun emitChar(c: Char, x: Int, y: Int)
- /** Prints a char and move cursor accordingly. */
- override fun printChar(c: Char)
- /** Emits a string, does not affected by control sequences. Does not move cursor */
- fun emitString(s: String, x: Int, y: Int)
- /** Emits a string and move cursor accordingly, then do LF */
- fun printString(s: String, x: Int, y: Int)
- /** Emits a string and move cursor accordingly. */
- fun writeString(s: String, x: Int, y: Int)
- fun clear()
- fun clearLine()
- override fun newLine()
- override fun scroll(amount: Int)
- fun setColour(back: Int, fore: Int)
- fun resetColour()
- /**
- * @param duration: milliseconds
- * @param freg: Frequency (float)
- */
- fun emitTone(duration: Second, freq: Double)
-
- override fun bell(pattern: String)
-}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/terminal/TerminalInputStream.kt.txt b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/terminal/TerminalInputStream.kt.txt
deleted file mode 100644
index ba368caf3..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/terminal/TerminalInputStream.kt.txt
+++ /dev/null
@@ -1,23 +0,0 @@
-package net.torvald.terrarum.modulecomputers.virtualcomputer.terminal
-
-import net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld
-import java.io.InputStream
-
-/**
- * Created by minjaesong on 2016-09-10.
- */
-class TerminalInputStream(val host: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : InputStream() {
-
- override fun read(): Int {
- //System.err.println(Thread.currentThread().name)
- // would display "LuaJ Separated", which means this InputStream will not block main thread
-
- host.openStdin()
- synchronized(this) {
- (this as java.lang.Object).wait()
- }
-
- return host.stdinInput
- }
-
-}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/terminal/TerminalPrintStream.kt.txt b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/terminal/TerminalPrintStream.kt.txt
deleted file mode 100644
index 3a3856211..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/terminal/TerminalPrintStream.kt.txt
+++ /dev/null
@@ -1,14 +0,0 @@
-package net.torvald.terrarum.modulecomputers.virtualcomputer.terminal
-
-import net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld
-import java.io.OutputStream
-import java.io.PrintStream
-
-/**
- * Created by minjaesong on 2016-09-10.
- */
-class TerminalPrintStream(val host: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : PrintStream(TerminalOutputStream(host))
-
-class TerminalOutputStream(val host: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld) : OutputStream() {
- override fun write(b: Int) = host.term.printChar(b.and(0xFF).toChar())
-}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/worldobject/ComputerPartsCodex.kt.txt b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/worldobject/ComputerPartsCodex.kt.txt
deleted file mode 100644
index d02f06d63..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/worldobject/ComputerPartsCodex.kt.txt
+++ /dev/null
@@ -1,56 +0,0 @@
-package net.torvald.terrarum.modulecomputers.virtualcomputer.worldobject
-
-import java.util.*
-
-/**
- * Created by minjaesong on 2016-09-08.
- */
-object ComputerPartsCodex {
- val rams = HashMap() // id, capacity in bytes (0 bytes - 8 GBytes)
- val processors = HashMap() // id, cycles
- val harddisks = HashMap() // id, capacity in bytes
- val diskettes = HashMap() // id, capacity in bytes
- val opticaldiscs = HashMap() // id, capacity in bytes
-
- init {
- // in kilobytes
- rams.put(4864, 128.KiB())
- rams.put(4865, 192.KiB())
- rams.put(4866, 256.KiB())
- rams.put(4867, 384.KiB())
- rams.put(4868, 512.KiB())
- rams.put(4869, 768.KiB())
- rams.put(4870, 1024.KiB())
- rams.put(4871, 2048.KiB())
-
- processors.put(4872, 1000)
- processors.put(4873, 2000)
- processors.put(4874, 4000)
- processors.put(4875, 8000) // this is totally OP
-
- harddisks.put(4876, 1.MB())
- harddisks.put(4877, 2.MB())
- harddisks.put(4878, 5.MB())
- harddisks.put(4879, 10.MB())
-
- // Floppy disk: your primitive and only choice of removable storage
- diskettes.put(4880, 360.kB()) // single-sided
- diskettes.put(4881, 720.kB()) // double-sided
- diskettes.put(4882, 1440.kB()) // 3.5" HD
- diskettes.put(4883, 2880.kB()) // 3.5" ED
-
- // CD-Rs
- opticaldiscs.put(4884, 8.MB()) // arbitrary size
- }
-
- fun getRamSize(itemIndex: Int): Int = rams[itemIndex] ?: 0
- fun getProcessorCycles(itemIndex: Int): Int = processors[itemIndex] ?: 0
- fun getHDDSize(itemIndex: Int): Int = harddisks[itemIndex] ?: 0
- fun getFDDSize(itemIndex: Int): Int = diskettes[itemIndex] ?: 0
- fun getODDSize(itemIndex: Int): Int = opticaldiscs[itemIndex] ?: 0
-
- private fun Int.MB() = this * 1000000 // 1 MB == 1 000 000 bytes, bitches!
- private fun Int.kB() = this * 1000
- private fun Int.KiB() = this.shl(10)
- private fun Int.MiB() = this.shl(20)
-}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/worldobject/FixtureBasicTerminal.kt.txt b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/worldobject/FixtureBasicTerminal.kt.txt
deleted file mode 100644
index aca1d6ff7..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/worldobject/FixtureBasicTerminal.kt.txt
+++ /dev/null
@@ -1,24 +0,0 @@
-package net.torvald.terrarum.modulecomputers.virtualcomputer.worldobject
-
-import com.badlogic.gdx.graphics.Color
-import net.torvald.terrarum.modulebasegame.gameactors.BlockBox
-import net.torvald.terrarum.modulebasegame.gameactors.FixtureBase
-
-/**
- * Created by minjaesong on 2016-09-08.
- */
-class FixtureBasicTerminal(phosphor: Color) : FixtureBase(BlockBox(BlockBox.ALLOW_MOVE_DOWN, 1, 1)) {
-
- /*val computer = TerrarumComputerOld(8)
- val vt: Terminal = SimpleTextTerminal(phosphor, 80, 25, computer)
- val ui = UITextTerminal(vt)
-
- init {
- computer.attachTerminal(vt)
-
- collisionFlag = COLLISION_PLATFORM
-
- actorValue[AVKey.UUID] = UUID.randomUUID().toString()
- }*/
-
-}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/worldobject/FixtureComputerBase.kt.txt b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/worldobject/FixtureComputerBase.kt.txt
deleted file mode 100644
index f4bf81bfa..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/worldobject/FixtureComputerBase.kt.txt
+++ /dev/null
@@ -1,59 +0,0 @@
-package net.torvald.terrarum.modulecomputers.virtualcomputer.worldobject
-
-import net.torvald.terrarum.modulebasegame.gameactors.BlockBox
-import net.torvald.terrarum.modulebasegame.gameactors.FixtureBase
-
-/**
- * Created by minjaesong on 2016-09-08.
- */
-open class FixtureComputerBase : FixtureBase(BlockBox(BlockBox.NO_COLLISION, 1, 1)) {
-
- /** Connected terminal */
- var terminal: FixtureBasicTerminal? = null
-
- var computerInside: net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld? = null
-
- init {
- // UUID of the "brain"
- actorValue["computerid"] = "none"
-
-
- }
-
- ////////////////////////////////////
- // get the computer actually work //
- ////////////////////////////////////
-
- fun attachTerminal(uuid: String) {
- val fetchedTerminal = getTerminalByUUID(uuid)
- computerInside = net.torvald.terrarum.modulecomputers.virtualcomputer.computer.TerrarumComputerOld(8)
- computerInside!!.attachTerminal(fetchedTerminal!!)
- actorValue["computerid"] = computerInside!!.UUID
- }
-
- fun detatchTerminal() {
- terminal = null
- }
-
- private fun getTerminalByUUID(uuid: String): net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Terminal? {
- TODO("get terminal by UUID. Return null if not found")
- }
-
-
-
- ////////////////
- // game codes //
- ////////////////
-
- override fun update(delta: Float) {
- super.update(delta)
- if (terminal != null) terminal!!.update(delta)
- }
-
- fun keyPressed(key: Int, c: Char) {
- /*if (terminal != null) {
- terminal!!.vt.keyPressed(key, c)
- computerInside!!.keyPressed(key, c)
- }*/
- }
-}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/worldobject/ui/UITextTerminal.kt.txt b/src/net/torvald/terrarum/modulecomputers/virtualcomputer/worldobject/ui/UITextTerminal.kt.txt
deleted file mode 100644
index f4a191128..000000000
--- a/src/net/torvald/terrarum/modulecomputers/virtualcomputer/worldobject/ui/UITextTerminal.kt.txt
+++ /dev/null
@@ -1,60 +0,0 @@
-package net.torvald.terrarum.modulecomputers.virtualcomputer.worldobject.ui
-
-import com.badlogic.gdx.graphics.Camera
-import com.badlogic.gdx.graphics.g2d.SpriteBatch
-import net.torvald.terrarum.Second
-import net.torvald.terrarum.ui.*
-
-/**
- * Created by minjaesong on 2016-09-08.
- */
-class UITextTerminal(val terminal: net.torvald.terrarum.modulecomputers.virtualcomputer.terminal.Terminal) : UICanvas() {
-
-
- override var width: Int = terminal.displayW// + some
- override var height: Int = terminal.displayH// + frame
-
-
-
- /**
- * In milliseconds
- *
- * Timer itself is implemented in the handler.
- */
- override var openCloseTime: Second = OPENCLOSE_GENERIC
-
- override fun updateUI(delta: Float) {
- terminal.update(delta)
- }
-
- override fun renderUI(batch: SpriteBatch, camera: Camera) {
- //terminal.render(gc, terminalDisplay.graphics)
- }
-
- /**
- * Do not modify handler.openCloseCounter here.
- */
- override fun doOpening(delta: Float) {
- }
-
- /**
- * Do not modify handler.openCloseCounter here.
- */
- override fun doClosing(delta: Float) {
- }
-
- /**
- * Do not modify handler.openCloseCounter here.
- */
- override fun endOpening(delta: Float) {
- }
-
- /**
- * Do not modify handler.openCloseCounter here.
- */
- override fun endClosing(delta: Float) {
- }
-
- override fun dispose() {
- }
-}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/tests/ColorMapTest.kt b/src/net/torvald/terrarum/tests/ColorMapTest.kt
index c4bbc7825..a966ca182 100644
--- a/src/net/torvald/terrarum/tests/ColorMapTest.kt
+++ b/src/net/torvald/terrarum/tests/ColorMapTest.kt
@@ -3,8 +3,8 @@ package net.torvald.terrarum.tests
import com.badlogic.gdx.Game
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Screen
-import com.badlogic.gdx.backends.lwjgl.LwjglApplication
-import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration
import com.badlogic.gdx.graphics.glutils.ShaderProgram
import net.torvald.terrarum.GdxColorMap
@@ -53,16 +53,9 @@ class ColorMapTest : Game() {
fun main(args: Array) {
ShaderProgram.pedantic = false
- val appConfig = LwjglApplicationConfiguration()
- appConfig.vSyncEnabled = false
- appConfig.resizable = false//true;
- //appConfig.width = 1072; // IMAX ratio
- //appConfig.height = 742; // IMAX ratio
- appConfig.width = 1110 // photographic ratio (1.5:1)
- appConfig.height = 740 // photographic ratio (1.5:1)
- appConfig.backgroundFPS = 9999
- appConfig.foregroundFPS = 9999
- appConfig.forceExit = false
-
- LwjglApplication(ColorMapTest(), appConfig)
+ val appConfig = Lwjgl3ApplicationConfiguration()
+ appConfig.useVsync(false)
+ appConfig.setResizable(false)
+ appConfig.setWindowedMode(1110, 740)
+ Lwjgl3Application(ColorMapTest(), appConfig)
}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/tests/MakeKeylayoutFile.kt b/src/net/torvald/terrarum/tests/MakeKeylayoutFile.kt
index bc61f1ee6..bd72e5684 100644
--- a/src/net/torvald/terrarum/tests/MakeKeylayoutFile.kt
+++ b/src/net/torvald/terrarum/tests/MakeKeylayoutFile.kt
@@ -2,8 +2,8 @@ package net.torvald.terrarum.tests
import com.badlogic.gdx.*
import com.badlogic.gdx.Input.Keys.*
-import com.badlogic.gdx.backends.lwjgl.LwjglApplication
-import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration
import com.badlogic.gdx.graphics.g2d.BitmapFont
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import net.torvald.EMDASH
@@ -133,15 +133,15 @@ class GetKeycode : Game() {
}
}
-fun main() {val appConfig = LwjglApplicationConfiguration()
- appConfig.resizable = false
- appConfig.width = 256
- appConfig.height = 64
- appConfig.foregroundFPS = 60
- appConfig.backgroundFPS = 60
+fun main() {
+ val appConfig = Lwjgl3ApplicationConfiguration()
+ appConfig.setResizable(false)
+ appConfig.setWindowedMode(256, 64)
+ appConfig.setForegroundFPS(2)
+ appConfig.setIdleFPS(2)
val gdxWindow = GetKeycode()
- LwjglApplication(gdxWindow, appConfig)
+ Lwjgl3Application(gdxWindow, appConfig)
MakeKeylayoutFile.invoke()
}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/tests/NoiseGenerator.kt b/src/net/torvald/terrarum/tests/NoiseGenerator.kt
index 2ba04a076..ca8ba39d6 100644
--- a/src/net/torvald/terrarum/tests/NoiseGenerator.kt
+++ b/src/net/torvald/terrarum/tests/NoiseGenerator.kt
@@ -4,8 +4,8 @@ import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input
import com.badlogic.gdx.InputAdapter
import com.badlogic.gdx.ScreenAdapter
-import com.badlogic.gdx.backends.lwjgl.LwjglApplication
-import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.Pixmap
@@ -45,11 +45,11 @@ class NoiseGenerator : ScreenAdapter() {
Gdx.input.inputProcessor = NoiseGeneratorController(this)
batch = SpriteBatch()
- camera = OrthographicCamera(AppLoader.appConfig.width.toFloat(), AppLoader.appConfig.height.toFloat())
+ camera = OrthographicCamera(AppLoader.screenSize.screenWf, AppLoader.screenSize.screenHf)
- camera.setToOrtho(true, AppLoader.appConfig.width.toFloat(), AppLoader.appConfig.height.toFloat())
+ camera.setToOrtho(true, AppLoader.screenSize.screenWf, AppLoader.screenSize.screenHf)
camera.update()
- Gdx.gl20.glViewport(0, 0, AppLoader.appConfig.width, AppLoader.appConfig.height)
+ Gdx.gl20.glViewport(0, 0, AppLoader.screenSize.screenW, AppLoader.screenSize.screenH)
pixmap = Pixmap(IMAGE_SIZE, IMAGE_SIZE, Pixmap.Format.RGBA8888)
texture = Texture(1, 1, Pixmap.Format.RGBA8888)
@@ -253,14 +253,10 @@ class NoiseGeneratorController(val host: NoiseGenerator) : InputAdapter() {
fun main(args: Array) {
ShaderProgram.pedantic = false
- val appConfig = LwjglApplicationConfiguration()
- appConfig.vSyncEnabled = false
- appConfig.resizable = false//true;
- appConfig.width = 1024
- appConfig.height = 1024
- appConfig.backgroundFPS = 9999
- appConfig.foregroundFPS = 9999
- appConfig.forceExit = false
+ val appConfig = Lwjgl3ApplicationConfiguration()
+ appConfig.useVsync(false)
+ appConfig.setResizable(false)
+ appConfig.setWindowedMode(1024, 1024)
- LwjglApplication(AppLoader(appConfig, NoiseGenerator()), appConfig)
+ Lwjgl3Application(AppLoader(appConfig, NoiseGenerator()), appConfig)
}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/tests/NoopRectTest.kt b/src/net/torvald/terrarum/tests/NoopRectTest.kt
index 58a6082b7..7027bdbf1 100644
--- a/src/net/torvald/terrarum/tests/NoopRectTest.kt
+++ b/src/net/torvald/terrarum/tests/NoopRectTest.kt
@@ -2,8 +2,8 @@ package net.torvald.terrarum.tests
import com.badlogic.gdx.Game
import com.badlogic.gdx.Gdx
-import com.badlogic.gdx.backends.lwjgl.LwjglApplication
-import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.Pixmap
@@ -15,10 +15,13 @@ import net.torvald.terrarum.Point2i
import net.torvald.terrarum.inUse
import net.torvald.terrarum.worlddrawer.toRGBA
+val RECTTEST_WIDTH = 768
+val RECTTEST_HEIGHT = 768
+
/**
* Created by minjaesong on 2019-02-04.
*/
-class NoopRectTest(val appConfig: LwjglApplicationConfiguration) : Game() {
+class NoopRectTest(val appConfig: Lwjgl3ApplicationConfiguration) : Game() {
private val SIZE = 100
@@ -47,7 +50,7 @@ class NoopRectTest(val appConfig: LwjglApplicationConfiguration) : Game() {
texture = Texture(1, 1, Pixmap.Format.RGBA8888)
batch = SpriteBatch()
- camera = OrthographicCamera(appConfig.width.toFloat(), appConfig.height.toFloat())
+ camera = OrthographicCamera(RECTTEST_WIDTH.toFloat(), RECTTEST_HEIGHT.toFloat())
camera.setToOrtho(true)
}
@@ -104,7 +107,7 @@ class NoopRectTest(val appConfig: LwjglApplicationConfiguration) : Game() {
batch.inUse {
batch.projectionMatrix = camera.combined
- batch.draw(texture, 0f, 0f, appConfig.width.toFloat(), appConfig.height.toFloat())
+ batch.draw(texture, 0f, 0f, RECTTEST_WIDTH.toFloat(), RECTTEST_HEIGHT.toFloat())
}
println()
@@ -167,12 +170,8 @@ class NoopRectTest(val appConfig: LwjglApplicationConfiguration) : Game() {
}
fun main(args: Array) {
- val appConfig = LwjglApplicationConfiguration()
- appConfig.forceExit = false
- appConfig.width = 768
- appConfig.height = 768
- appConfig.backgroundFPS = 2
- appConfig.foregroundFPS = 2
+ val appConfig = Lwjgl3ApplicationConfiguration()
+ appConfig.setWindowedMode(RECTTEST_WIDTH, RECTTEST_HEIGHT)
- LwjglApplication(NoopRectTest(appConfig), appConfig)
+ Lwjgl3Application(NoopRectTest(appConfig), appConfig)
}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/tests/SurroundPannerTest.kt b/src/net/torvald/terrarum/tests/SurroundPannerTest.kt
index 9faa38d9b..2f35e09a8 100644
--- a/src/net/torvald/terrarum/tests/SurroundPannerTest.kt
+++ b/src/net/torvald/terrarum/tests/SurroundPannerTest.kt
@@ -3,8 +3,8 @@ package net.torvald.terrarum.tests
import com.badlogic.gdx.Game
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.audio.Sound
-import com.badlogic.gdx.backends.lwjgl.LwjglApplication
-import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration
import com.badlogic.gdx.files.FileHandle
import java.awt.BorderLayout
import javax.swing.JFrame
@@ -59,15 +59,14 @@ class AudioPlayerSlave : Game() {
}
fun main(args: Array) {
- val appConfig = LwjglApplicationConfiguration()
- appConfig.vSyncEnabled = false
- appConfig.resizable = true
- appConfig.width = 256
- appConfig.height = 256
- appConfig.backgroundFPS = 20
- appConfig.foregroundFPS = 20
+ val appConfig = Lwjgl3ApplicationConfiguration()
+ appConfig.useVsync(false)
+ appConfig.setResizable(true)
+ appConfig.setWindowedMode(256, 256)
+ appConfig.setForegroundFPS(20)
+ appConfig.setIdleFPS(20)
- LwjglApplication(AudioPlayerSlave(), appConfig)
+ Lwjgl3Application(AudioPlayerSlave(), appConfig)
}
diff --git a/src/net/torvald/terrarum/tests/UIElemTest.kt b/src/net/torvald/terrarum/tests/UIElemTest.kt
index 1d1981894..cc72c118f 100644
--- a/src/net/torvald/terrarum/tests/UIElemTest.kt
+++ b/src/net/torvald/terrarum/tests/UIElemTest.kt
@@ -3,8 +3,8 @@ package net.torvald.terrarum.tests
import com.badlogic.gdx.ApplicationAdapter
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input
-import com.badlogic.gdx.backends.lwjgl.LwjglApplication
-import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.OrthographicCamera
@@ -110,14 +110,11 @@ class DummyTogglePane : UICanvas() {
fun main(args: Array) {
ShaderProgram.pedantic = false
- val appConfig = LwjglApplicationConfiguration()
- appConfig.vSyncEnabled = false
- appConfig.resizable = false
- appConfig.width = 800
- appConfig.height = 600
- appConfig.backgroundFPS = 60
- appConfig.foregroundFPS = 60
- appConfig.forceExit = false
+ val appConfig = Lwjgl3ApplicationConfiguration()
+ appConfig.useVsync(false)
+ appConfig.setResizable(false)
+ appConfig.setWindowedMode(800, 600)
+ appConfig.setForegroundFPS(60)
- LwjglApplication(UIElemTest(), appConfig)
+ Lwjgl3Application(UIElemTest(), appConfig)
}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/tests/UITestPad1.kt b/src/net/torvald/terrarum/tests/UITestPad1.kt
index ae6c38a1a..fe8ba78dd 100644
--- a/src/net/torvald/terrarum/tests/UITestPad1.kt
+++ b/src/net/torvald/terrarum/tests/UITestPad1.kt
@@ -3,8 +3,8 @@ package net.torvald.terrarum.tests
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.InputAdapter
import com.badlogic.gdx.ScreenAdapter
-import com.badlogic.gdx.backends.lwjgl.LwjglApplication
-import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.g2d.SpriteBatch
@@ -13,6 +13,9 @@ import net.torvald.terrarum.*
import net.torvald.terrarum.modulebasegame.TerrarumIngame
import net.torvald.terrarum.ui.UINSMenu
+val UITEST1_WIDTH = 1280
+val UITEST1_HEIGHT = 720
+
/**
* Created by minjaesong on 2018-12-09.
*/
@@ -67,13 +70,13 @@ class UITestPad1 : ScreenAdapter() {
Yaml(treeStr)
)
batch = SpriteBatch()
- camera = OrthographicCamera(AppLoader.appConfig.width.toFloat(), AppLoader.appConfig.height.toFloat())
+ camera = OrthographicCamera(UITEST1_WIDTH.toFloat(), UITEST1_HEIGHT.toFloat())
- camera.setToOrtho(true, AppLoader.appConfig.width.toFloat(), AppLoader.appConfig.height.toFloat())
+ camera.setToOrtho(true, UITEST1_WIDTH.toFloat(), UITEST1_HEIGHT.toFloat())
camera.update()
- Gdx.gl20.glViewport(0, 0, AppLoader.appConfig.width, AppLoader.appConfig.height)
+ Gdx.gl20.glViewport(0, 0, UITEST1_WIDTH, UITEST1_HEIGHT)
- resize(AppLoader.appConfig.width, AppLoader.appConfig.height)
+ resize(UITEST1_WIDTH, UITEST1_HEIGHT)
nsMenu.setPosition(0, 0)
nsMenu.setAsAlwaysVisible()
@@ -148,16 +151,10 @@ class UITestPad1Controller(val host: UITestPad1) : InputAdapter() {
fun main(args: Array) {
ShaderProgram.pedantic = false
- val appConfig = LwjglApplicationConfiguration()
- appConfig.vSyncEnabled = false
- appConfig.resizable = false//true;
- //appConfig.width = 1072; // IMAX ratio
- //appConfig.height = 742; // IMAX ratio
- appConfig.width = 1110 // photographic ratio (1.5:1)
- appConfig.height = 740 // photographic ratio (1.5:1)
- appConfig.backgroundFPS = 9999
- appConfig.foregroundFPS = 9999
- appConfig.forceExit = false
+ val appConfig = Lwjgl3ApplicationConfiguration()
+ appConfig.useVsync(false)
+ appConfig.setResizable(false)
+ appConfig.setWindowedMode(UITEST1_WIDTH, UITEST1_HEIGHT)
- LwjglApplication(AppLoader(appConfig, UITestPad1()), appConfig)
+ Lwjgl3Application(AppLoader(appConfig, UITestPad1()), appConfig)
}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/tests/WorldgenNoiseSandbox.kt b/src/net/torvald/terrarum/tests/WorldgenNoiseSandbox.kt
index d1edeab66..c72608629 100644
--- a/src/net/torvald/terrarum/tests/WorldgenNoiseSandbox.kt
+++ b/src/net/torvald/terrarum/tests/WorldgenNoiseSandbox.kt
@@ -3,8 +3,8 @@ package net.torvald.terrarum.tests
import com.badlogic.gdx.ApplicationAdapter
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input
-import com.badlogic.gdx.backends.lwjgl.LwjglApplication
-import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application
+import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration
import com.badlogic.gdx.graphics.Color
import com.badlogic.gdx.graphics.OrthographicCamera
import com.badlogic.gdx.graphics.Pixmap
@@ -29,8 +29,8 @@ import kotlin.math.sin
import kotlin.random.Random
import kotlin.coroutines.*
-const val WIDTH = 768
-const val HEIGHT = 512
+const val NOISEBOX_WIDTH = 768
+const val NOISEBOX_HEIGHT = 512
const val TWO_PI = Math.PI * 2
/**
@@ -60,13 +60,13 @@ class WorldgenNoiseSandbox : ApplicationAdapter() {
font = BitmapFont() // use default because fuck it
batch = SpriteBatch()
- camera = OrthographicCamera(WIDTH.toFloat(), HEIGHT.toFloat())
+ camera = OrthographicCamera(NOISEBOX_WIDTH.toFloat(), NOISEBOX_HEIGHT.toFloat())
camera.setToOrtho(false) // some elements are pre-flipped, while some are not. The statement itself is absolutely necessary to make edge of the screen as the origin
camera.update()
batch.projectionMatrix = camera.combined
- Gdx.gl20.glViewport(0, 0, WIDTH, HEIGHT)
+ Gdx.gl20.glViewport(0, 0, NOISEBOX_WIDTH, NOISEBOX_HEIGHT)
- testTex = Pixmap(WIDTH, HEIGHT, Pixmap.Format.RGBA8888)
+ testTex = Pixmap(NOISEBOX_WIDTH, NOISEBOX_HEIGHT, Pixmap.Format.RGBA8888)
testTex.blending = Pixmap.Blending.None
tempTex = Texture(1, 1, Pixmap.Format.RGBA8888)
@@ -112,10 +112,10 @@ class WorldgenNoiseSandbox : ApplicationAdapter() {
// draw timer
batch.inUse {
if (!generationTimeInMeasure) {
- font.draw(batch, "Generation time: ${generationTime} seconds", 8f, HEIGHT - 8f)
+ font.draw(batch, "Generation time: ${generationTime} seconds", 8f, NOISEBOX_HEIGHT - 8f)
}
else {
- font.draw(batch, "Generating...", 8f, HEIGHT - 8f)
+ font.draw(batch, "Generating...", 8f, NOISEBOX_HEIGHT - 8f)
}
}
}
@@ -129,7 +129,7 @@ class WorldgenNoiseSandbox : ApplicationAdapter() {
val colourNull = Color(0x1b3281ff)
- private val sampleOffset = WIDTH / 8.0
+ private val sampleOffset = NOISEBOX_WIDTH / 8.0
private val testColSet = arrayOf(
Color(0xff0000ff.toInt()),
@@ -222,8 +222,8 @@ class WorldgenNoiseSandbox : ApplicationAdapter() {
val runnables: List = (0 until testTex.width).sliceEvenly(genSlices).map { range -> {
val localJoise = getNoiseGenerator(seed)
for (x in range) {
- for (y in 0 until HEIGHT) {
- val sampleTheta = (x.toDouble() / WIDTH) * TWO_PI
+ for (y in 0 until NOISEBOX_HEIGHT) {
+ val sampleTheta = (x.toDouble() / NOISEBOX_WIDTH) * TWO_PI
val sampleX = sin(sampleTheta) * sampleOffset + sampleOffset // plus sampleOffset to make only
val sampleZ = cos(sampleTheta) * sampleOffset + sampleOffset // positive points are to be sampled
val sampleY = y.toDouble()
@@ -253,16 +253,13 @@ class WorldgenNoiseSandbox : ApplicationAdapter() {
fun main(args: Array) {
ShaderProgram.pedantic = false
- val appConfig = LwjglApplicationConfiguration()
- appConfig.vSyncEnabled = false
- appConfig.resizable = false
- appConfig.width = WIDTH
- appConfig.height = HEIGHT
- appConfig.backgroundFPS = 60
- appConfig.foregroundFPS = 60
- appConfig.forceExit = false
+ val appConfig = Lwjgl3ApplicationConfiguration()
+ appConfig.useVsync(false)
+ appConfig.setResizable(false)
+ appConfig.setWindowedMode(NOISEBOX_WIDTH, NOISEBOX_HEIGHT)
+ appConfig.setForegroundFPS(60)
- LwjglApplication(WorldgenNoiseSandbox(), appConfig)
+ Lwjgl3Application(WorldgenNoiseSandbox(), appConfig)
}
internal interface NoiseMaker {
diff --git a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt
index 7a061b719..b2e2d169d 100644
--- a/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt
+++ b/src/net/torvald/terrarum/ui/BasicDebugInfoWindow.kt
@@ -24,8 +24,8 @@ import net.torvald.terrarum.worlddrawer.WorldCamera
*/
class BasicDebugInfoWindow : UICanvas() {
- override var width: Int = AppLoader.screenW
- override var height: Int = AppLoader.screenH
+ override var width: Int = AppLoader.screenSize.screenW
+ override var height: Int = AppLoader.screenSize.screenH
override var openCloseTime: Float = 0f
@@ -194,8 +194,8 @@ class BasicDebugInfoWindow : UICanvas() {
}
/*drawHistogram(batch, LightmapRenderer.histogram,
- AppLoader.screenW - histogramW - TinyAlphNum.W * 2,
- AppLoader.screenH - histogramH - TinyAlphNum.H * 4
+ AppLoader.terrarumAppConfig.screenW - histogramW - TinyAlphNum.W * 2,
+ AppLoader.terrarumAppConfig.screenH - histogramH - TinyAlphNum.H * 4
)*/ // histogram building is currently bugged
batch.color = Color.WHITE
@@ -205,7 +205,7 @@ class BasicDebugInfoWindow : UICanvas() {
drawGamepadAxis(gamepad, batch,
gamepad.getAxis(AppLoader.getConfigInt("config_gamepadaxislx")),
gamepad.getAxis(AppLoader.getConfigInt("config_gamepadaxisly")),
- AppLoader.screenW - 128 - TinyAlphNum.W * 2,
+ AppLoader.screenSize.screenW - 128 - TinyAlphNum.W * 2,
line(3).toInt()
)
}
@@ -215,21 +215,21 @@ class BasicDebugInfoWindow : UICanvas() {
*/
// memory pressure
- AppLoader.fontSmallNumbers.draw(batch, "${ccY}MEM ", (AppLoader.screenW - 23 * TinyAlphNum.W - 2).toFloat(), line(1))
+ AppLoader.fontSmallNumbers.draw(batch, "${ccY}MEM ", (AppLoader.screenSize.screenW - 23 * TinyAlphNum.W - 2).toFloat(), line(1))
// thread count
AppLoader.fontSmallNumbers.draw(batch, "${ccY}CPUs${if (AppLoader.MULTITHREAD) ccG else ccR}${AppLoader.THREAD_COUNT.toString().padStart(2, ' ')}",
- (AppLoader.screenW - 2 - 8 * TinyAlphNum.W).toFloat(), line(2))
+ (AppLoader.screenSize.screenW - 2 - 8 * TinyAlphNum.W).toFloat(), line(2))
// memory texts
AppLoader.fontSmallNumbers.draw(batch, "${Terrarum.memJavaHeap}M",
- (AppLoader.screenW - 19 * TinyAlphNum.W - 2).toFloat(), line(1))
+ (AppLoader.screenSize.screenW - 19 * TinyAlphNum.W - 2).toFloat(), line(1))
AppLoader.fontSmallNumbers.draw(batch, "/${Terrarum.memNativeHeap}M/",
- (AppLoader.screenW - 14 * TinyAlphNum.W - 2).toFloat(), line(1))
+ (AppLoader.screenSize.screenW - 14 * TinyAlphNum.W - 2).toFloat(), line(1))
AppLoader.fontSmallNumbers.draw(batch, "${Terrarum.memXmx}M",
- (AppLoader.screenW - 7 * TinyAlphNum.W - 2).toFloat(), line(1))
+ (AppLoader.screenSize.screenW - 7 * TinyAlphNum.W - 2).toFloat(), line(1))
// FPS count
AppLoader.fontSmallNumbers.draw(batch, "${ccY}FPS${ccG}${Gdx.graphics.framesPerSecond.toString().padStart(3, ' ')}",
- (AppLoader.screenW - 3 - 15 * TinyAlphNum.W).toFloat(), line(2))
+ (AppLoader.screenSize.screenW - 3 - 15 * TinyAlphNum.W).toFloat(), line(2))
/**
* Bottom left
@@ -237,21 +237,21 @@ class BasicDebugInfoWindow : UICanvas() {
if (ingame != null) {
AppLoader.fontSmallNumbers.draw(batch, "${ccY}Actors total $ccG${ingame!!.actorContainerActive.size + ingame!!.actorContainerInactive.size}",
- TinyAlphNum.W * 2f, AppLoader.screenH - TinyAlphNum.H * 2f)
+ TinyAlphNum.W * 2f, AppLoader.screenSize.screenH - TinyAlphNum.H * 2f)
AppLoader.fontSmallNumbers.draw(batch, "${ccY}Active $ccG${ingame!!.actorContainerActive.size}",
- (TinyAlphNum.W * 2 + 17 * 8).toFloat(), AppLoader.screenH - TinyAlphNum.H * 2f)
+ (TinyAlphNum.W * 2 + 17 * 8).toFloat(), AppLoader.screenSize.screenH - TinyAlphNum.H * 2f)
AppLoader.fontSmallNumbers.draw(batch, "${ccY}Dormant $ccG${ingame!!.actorContainerInactive.size}",
- (TinyAlphNum.W * 2 + 28 * 8).toFloat(), AppLoader.screenH - TinyAlphNum.H * 2f)
+ (TinyAlphNum.W * 2 + 28 * 8).toFloat(), AppLoader.screenSize.screenH - TinyAlphNum.H * 2f)
if (ingame is TerrarumIngame) {
AppLoader.fontSmallNumbers.draw(batch, "${ccM}Particles $ccG${(ingame as TerrarumIngame).particlesActive}",
- (TinyAlphNum.W * 2 + 41 * 8).toFloat(), AppLoader.screenH - TinyAlphNum.H * 2f)
+ (TinyAlphNum.W * 2 + 41 * 8).toFloat(), AppLoader.screenSize.screenH - TinyAlphNum.H * 2f)
}
}
AppLoader.fontSmallNumbers.draw(batch, "${ccY}Actors rendering $ccG${IngameRenderer.renderingActorsCount}",
- TinyAlphNum.W * 2f, AppLoader.screenH - TinyAlphNum.H * 3f)
+ TinyAlphNum.W * 2f, AppLoader.screenSize.screenH - TinyAlphNum.H * 3f)
AppLoader.fontSmallNumbers.draw(batch, "${ccY}UIs rendering $ccG${IngameRenderer.renderingUIsCount}",
- TinyAlphNum.W * 2f + (21 * 8), AppLoader.screenH - TinyAlphNum.H * 3f)
+ TinyAlphNum.W * 2f + (21 * 8), AppLoader.screenSize.screenH - TinyAlphNum.H * 3f)
/**
* Bottom right
@@ -259,7 +259,7 @@ class BasicDebugInfoWindow : UICanvas() {
// processor and renderer
AppLoader.fontSmallNumbers.draw(batch, "$ccY$totalHardwareName",
- (AppLoader.screenW - (totalHardwareName.length + 2) * TinyAlphNum.W).toFloat(), AppLoader.screenH - TinyAlphNum.H * 2f)
+ (AppLoader.screenSize.screenW - (totalHardwareName.length + 2) * TinyAlphNum.W).toFloat(), AppLoader.screenSize.screenH - TinyAlphNum.H * 2f)
}
private val processorName = AppLoader.processor.replace(Regex(""" Processor|( CPU)? @ [0-9.]+GHz"""), "") + if (AppLoader.is32BitJVM) " (32-bit)" else ""
@@ -342,16 +342,16 @@ class BasicDebugInfoWindow : UICanvas() {
gdxSetBlendNormal()
Terrarum.inShapeRenderer {
it.color = uiColour
- it.rect(uiX.toFloat(), AppLoader.screenH - uiY.toFloat(), w, -h)
+ it.rect(uiX.toFloat(), AppLoader.screenSize.screenH - uiY.toFloat(), w, -h)
it.color = deadzoneColour
- it.rect(uiX + halfW - (halfW * deadzone), AppLoader.screenH - (uiY + halfH - halfH * deadzone), w * deadzone, -h * deadzone)
+ it.rect(uiX + halfW - (halfW * deadzone), AppLoader.screenSize.screenH - (uiY + halfH - halfH * deadzone), w * deadzone, -h * deadzone)
it.color = Color.WHITE
- it.line(uiX + halfW, AppLoader.screenH - (uiY + halfH), uiX + halfW + pointDX, AppLoader.screenH - (uiY + halfH + pointDY))
+ it.line(uiX + halfW, AppLoader.screenSize.screenH - (uiY + halfH), uiX + halfW + pointDX, AppLoader.screenSize.screenH - (uiY + halfH + pointDY))
it.color = Color.GRAY
}
batch.begin()
- AppLoader.fontSmallNumbers.draw(batch, gamepad.getName(), AppLoader.screenW - (gamepad.getName().length + 2f) * TinyAlphNum.W, uiY.toFloat() + h + 2)
+ AppLoader.fontSmallNumbers.draw(batch, gamepad.getName(), AppLoader.screenSize.screenW - (gamepad.getName().length + 2f) * TinyAlphNum.W, uiY.toFloat() + h + 2)
}
diff --git a/src/net/torvald/terrarum/ui/ConsoleWindow.kt b/src/net/torvald/terrarum/ui/ConsoleWindow.kt
index 374bafe58..2671c95e2 100644
--- a/src/net/torvald/terrarum/ui/ConsoleWindow.kt
+++ b/src/net/torvald/terrarum/ui/ConsoleWindow.kt
@@ -35,7 +35,7 @@ class ConsoleWindow : UICanvas() {
private val LINE_HEIGHT = 20
private val MESSAGES_DISPLAY_COUNT = 11
- override var width: Int = AppLoader.screenW
+ override var width: Int = AppLoader.screenSize.screenW
override var height: Int = LINE_HEIGHT * (MESSAGES_DISPLAY_COUNT + 1)
override var openCloseTime = 0f
diff --git a/src/net/torvald/terrarum/ui/Toolkit.kt b/src/net/torvald/terrarum/ui/Toolkit.kt
index 34860aae3..6beec5a44 100644
--- a/src/net/torvald/terrarum/ui/Toolkit.kt
+++ b/src/net/torvald/terrarum/ui/Toolkit.kt
@@ -26,7 +26,7 @@ object Toolkit {
fun drawCentered(batch: SpriteBatch, image: Texture, screenPosY: Int, ui: UICanvas? = null) {
val imageW = image.width
- val targetW = if (ui == null) AppLoader.screenW else ui.width
+ val targetW = if (ui == null) AppLoader.screenSize.screenW else ui.width
batch.draw(image, targetW.minus(imageW).ushr(1).toFloat(), screenPosY.toFloat())
}
diff --git a/src/net/torvald/terrarum/ui/UICanvas.kt b/src/net/torvald/terrarum/ui/UICanvas.kt
index f63e256df..de2e47736 100644
--- a/src/net/torvald/terrarum/ui/UICanvas.kt
+++ b/src/net/torvald/terrarum/ui/UICanvas.kt
@@ -148,7 +148,7 @@ abstract class UICanvas(
uiItems.add(uiItem)
}
- fun mouseInScreen(x: Int, y: Int) = x in 0 until AppLoader.appConfig.width && y in 0 until AppLoader.appConfig.height
+ fun mouseInScreen(x: Int, y: Int) = x in 0 until AppLoader.screenSize.screenW && y in 0 until AppLoader.screenSize.screenH
open fun mouseMoved(screenX: Int, screenY: Int): Boolean {
if (this.isVisible) {
@@ -191,10 +191,10 @@ abstract class UICanvas(
else return false
}
/** Called by the screen's InputProcessor */
- open fun scrolled(amount: Int): Boolean {
+ open fun scrolled(amountX: Float, amountY: Float): Boolean {
if (this.isVisible) {
- uiItems.forEach { it.scrolled(amount) }
- handler.subUIs.forEach { it.scrolled(amount) }
+ uiItems.forEach { it.scrolled(amountX, amountY) }
+ handler.subUIs.forEach { it.scrolled(amountX, amountY) }
return true
}
else return false
@@ -316,13 +316,13 @@ abstract class UICanvas(
).roundToInt()
Position.RIGHT -> ui.handler.posX = Movement.fastPullOut(
ui.handler.openCloseCounter / openCloseTime,
- AppLoader.screenWf,
- AppLoader.screenW - ui.width.toFloat()
+ AppLoader.screenSize.screenWf,
+ AppLoader.screenSize.screenW - ui.width.toFloat()
).roundToInt()
Position.BOTTOM -> ui.handler.posY = Movement.fastPullOut(
ui.handler.openCloseCounter / openCloseTime,
- AppLoader.screenHf,
- AppLoader.screenH - ui.height.toFloat()
+ AppLoader.screenSize.screenHf,
+ AppLoader.screenSize.screenH - ui.height.toFloat()
).roundToInt()
}
}
@@ -340,13 +340,13 @@ abstract class UICanvas(
).roundToInt()
Position.RIGHT -> ui.handler.posX = Movement.fastPullOut(
ui.handler.openCloseCounter / openCloseTime,
- AppLoader.screenW - ui.width.toFloat(),
- AppLoader.screenWf
+ AppLoader.screenSize.screenW - ui.width.toFloat(),
+ AppLoader.screenSize.screenWf
).roundToInt()
Position.BOTTOM -> ui.handler.posY = Movement.fastPullOut(
ui.handler.openCloseCounter / openCloseTime,
- AppLoader.screenH - ui.height.toFloat(),
- AppLoader.screenHf
+ AppLoader.screenSize.screenH - ui.height.toFloat(),
+ AppLoader.screenSize.screenHf
).roundToInt()
}
}
@@ -354,16 +354,16 @@ abstract class UICanvas(
when (position) {
Position.LEFT -> ui.handler.posX = 0
Position.TOP -> ui.handler.posY = 0
- Position.RIGHT -> ui.handler.posX = AppLoader.screenW - ui.width
- Position.BOTTOM -> ui.handler.posY = AppLoader.screenH - ui.height
+ Position.RIGHT -> ui.handler.posX = AppLoader.screenSize.screenW - ui.width
+ Position.BOTTOM -> ui.handler.posY = AppLoader.screenSize.screenH - ui.height
}
}
fun endClosingPopOut(ui: UICanvas, position: Position) {
when (position) {
Position.LEFT -> ui.handler.posX = -ui.width
Position.TOP -> ui.handler.posY = -ui.height
- Position.RIGHT -> ui.handler.posX = AppLoader.screenW
- Position.BOTTOM -> ui.handler.posY = AppLoader.screenH
+ Position.RIGHT -> ui.handler.posX = AppLoader.screenSize.screenW
+ Position.BOTTOM -> ui.handler.posY = AppLoader.screenSize.screenH
}
}
diff --git a/src/net/torvald/terrarum/ui/UIHandler.kt b/src/net/torvald/terrarum/ui/UIHandler.kt
index 8c84d5754..39f26f129 100644
--- a/src/net/torvald/terrarum/ui/UIHandler.kt
+++ b/src/net/torvald/terrarum/ui/UIHandler.kt
@@ -386,10 +386,10 @@ void main() {
return false
}
}
- fun scrolled(uiItems: List, amount: Int): Boolean {
+ fun scrolled(uiItems: List, amountX: Float, amountY: Float): Boolean {
if (isVisible) {
- uiItems.forEach { it.scrolled(amount) }
- subUIs.forEach { it.scrolled(amount) }
+ uiItems.forEach { it.scrolled(amountX, amountY) }
+ subUIs.forEach { it.scrolled(amountX, amountY) }
return true
}
else {
diff --git a/src/net/torvald/terrarum/ui/UIItem.kt b/src/net/torvald/terrarum/ui/UIItem.kt
index 67d201985..303e75393 100644
--- a/src/net/torvald/terrarum/ui/UIItem.kt
+++ b/src/net/torvald/terrarum/ui/UIItem.kt
@@ -106,11 +106,12 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
open var keyUpListener: ((Int) -> Unit)? = null
open var mouseMovedListener: ((Int, Int) -> Unit)? = null
open var touchDraggedListener: ((Int, Int, Int) -> Unit)? = null
- /** Parametres: screenX, screenY, pointer, button */
+ /** Parameters: screenX, screenY, pointer, button */
open var touchDownListener: ((Int, Int, Int, Int) -> Unit)? = null
open var touchUpListener: ((Int, Int, Int, Int) -> Unit)? = null
- open var scrolledListener: ((Int) -> Unit)? = null
- /** Parametres: relative mouseX, relative mouseY, button */
+ /** Parameters: amountX, amountY */
+ open var scrolledListener: ((Float, Float) -> Unit)? = null
+ /** Parameters: relative mouseX, relative mouseY, button */
open var clickOnceListener: ((Int, Int, Int) -> Unit)? = null
open var clickOnceListenerFired = false
@@ -219,9 +220,9 @@ abstract class UIItem(var parentUI: UICanvas, val initialX: Int, val initialY: I
return false
}
- open fun scrolled(amount: Int): Boolean {
+ open fun scrolled(amountX: Float, amountY: Float): Boolean {
if (parentUI.isVisible && scrolledListener != null) {
- scrolledListener!!.invoke(amount)
+ scrolledListener!!.invoke(amountX, amountY)
return true
}
diff --git a/src/net/torvald/terrarum/ui/UIItemImageButton.kt b/src/net/torvald/terrarum/ui/UIItemImageButton.kt
index f51553b52..68d0dc800 100644
--- a/src/net/torvald/terrarum/ui/UIItemImageButton.kt
+++ b/src/net/torvald/terrarum/ui/UIItemImageButton.kt
@@ -76,22 +76,6 @@ open class UIItemImageButton(
image.texture.dispose()
}
- override fun keyDown(keycode: Int): Boolean {
- return super.keyDown(keycode)
- }
-
- override fun keyUp(keycode: Int): Boolean {
- return super.keyUp(keycode)
- }
-
- override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
- return super.mouseMoved(screenX, screenY)
- }
-
- override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
- return super.touchDragged(screenX, screenY, pointer)
- }
-
override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
if (mouseUp && highlightable) {
highlighted = !highlighted
@@ -99,12 +83,4 @@ open class UIItemImageButton(
return super.touchDown(screenX, screenY, pointer, button)
}
-
- override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
- return super.touchUp(screenX, screenY, pointer, button)
- }
-
- override fun scrolled(amount: Int): Boolean {
- return super.scrolled(amount)
- }
}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/ui/UIItemImageGallery.kt b/src/net/torvald/terrarum/ui/UIItemImageGallery.kt
index 0bb9659e0..e771ba369 100644
--- a/src/net/torvald/terrarum/ui/UIItemImageGallery.kt
+++ b/src/net/torvald/terrarum/ui/UIItemImageGallery.kt
@@ -67,7 +67,7 @@ class UIItemImageGallery(
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
- override fun scrolled(amount: Int): Boolean {
+ override fun scrolled(amountX: Float, amountY: Float): Boolean {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
diff --git a/src/net/torvald/terrarum/ui/UIItemIntSlider.kt b/src/net/torvald/terrarum/ui/UIItemIntSlider.kt
index 6135e019f..c199f9cb7 100644
--- a/src/net/torvald/terrarum/ui/UIItemIntSlider.kt
+++ b/src/net/torvald/terrarum/ui/UIItemIntSlider.kt
@@ -115,7 +115,7 @@ class UIItemIntSlider(
override var touchUpListener: ((Int, Int, Int, Int) -> Unit)?
get() = super.touchUpListener
set(value) {}
- override var scrolledListener: ((Int) -> Unit)?
+ override var scrolledListener: ((Float, Float) -> Unit)?
get() = super.scrolledListener
set(value) {}
override var clickOnceListener: ((Int, Int, Int) -> Unit)?
@@ -128,42 +128,6 @@ class UIItemIntSlider(
get() = super.controllerInFocus
set(value) {}
- override fun update(delta: Float) {
- super.update(delta)
- }
-
- override fun render(batch: SpriteBatch, camera: Camera) {
- super.render(batch, camera)
- }
-
- override fun keyDown(keycode: Int): Boolean {
- return super.keyDown(keycode)
- }
-
- override fun keyUp(keycode: Int): Boolean {
- return super.keyUp(keycode)
- }
-
- override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
- return super.mouseMoved(screenX, screenY)
- }
-
- override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
- return super.touchDragged(screenX, screenY, pointer)
- }
-
- override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
- return super.touchDown(screenX, screenY, pointer, button)
- }
-
- override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
- return super.touchUp(screenX, screenY, pointer, button)
- }
-
- override fun scrolled(amount: Int): Boolean {
- return super.scrolled(amount)
- }
-
override fun dispose() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
diff --git a/src/net/torvald/terrarum/ui/UIItemTextArea.kt b/src/net/torvald/terrarum/ui/UIItemTextArea.kt
index 9abd6bded..29ce30324 100644
--- a/src/net/torvald/terrarum/ui/UIItemTextArea.kt
+++ b/src/net/torvald/terrarum/ui/UIItemTextArea.kt
@@ -46,36 +46,12 @@ class UIItemTextArea(
}
}
- override fun keyDown(keycode: Int): Boolean {
- return super.keyDown(keycode)
- }
-
- override fun keyUp(keycode: Int): Boolean {
- return super.keyUp(keycode)
- }
-
- override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
- return super.mouseMoved(screenX, screenY)
- }
-
- override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
- return super.touchDragged(screenX, screenY, pointer)
- }
-
- override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
- return super.touchDown(screenX, screenY, pointer, button)
- }
-
- override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
- return super.touchUp(screenX, screenY, pointer, button)
- }
-
- override fun scrolled(amount: Int): Boolean {
- scrollPos += amount * 3
+ override fun scrolled(amountX: Float, amountY: Float): Boolean {
+ scrollPos += Math.round(amountX * 3)
if (scrollPos > entireText.size - lineCount) scrollPos = entireText.size - lineCount
if (scrollPos < 0) scrollPos = 0
- return super.scrolled(amount)
+ return super.scrolled(amountX, amountY)
}
override fun dispose() {
diff --git a/src/net/torvald/terrarum/ui/UIItemTextButton.kt b/src/net/torvald/terrarum/ui/UIItemTextButton.kt
index fd2dcea06..a62b50554 100644
--- a/src/net/torvald/terrarum/ui/UIItemTextButton.kt
+++ b/src/net/torvald/terrarum/ui/UIItemTextButton.kt
@@ -111,32 +111,4 @@ open class UIItemTextButton(
override fun dispose() {
}
-
- override fun keyDown(keycode: Int): Boolean {
- return super.keyDown(keycode)
- }
-
- override fun keyUp(keycode: Int): Boolean {
- return super.keyUp(keycode)
- }
-
- override fun mouseMoved(screenX: Int, screenY: Int): Boolean {
- return super.mouseMoved(screenX, screenY)
- }
-
- override fun touchDragged(screenX: Int, screenY: Int, pointer: Int): Boolean {
- return super.touchDragged(screenX, screenY, pointer)
- }
-
- override fun touchDown(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
- return super.touchDown(screenX, screenY, pointer, button)
- }
-
- override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
- return super.touchUp(screenX, screenY, pointer, button)
- }
-
- override fun scrolled(amount: Int): Boolean {
- return super.scrolled(amount)
- }
}
diff --git a/src/net/torvald/terrarum/ui/UIItemTextButtonList.kt b/src/net/torvald/terrarum/ui/UIItemTextButtonList.kt
index 4e6b73bf4..17d480e2a 100644
--- a/src/net/torvald/terrarum/ui/UIItemTextButtonList.kt
+++ b/src/net/torvald/terrarum/ui/UIItemTextButtonList.kt
@@ -273,7 +273,7 @@ class UIItemTextButtonList(
return super.touchUp(screenX, screenY, pointer, button) || buttons.map { it.touchUp(screenX, screenY, pointer, button).toInt() }.sum() != 0
}
- override fun scrolled(amount: Int): Boolean {
- return super.scrolled(amount) || buttons.map { it.scrolled(amount).toInt() }.sum() != 0
+ override fun scrolled(amountX: Float, amountY: Float): Boolean {
+ return super.scrolled(amountX, amountY) || buttons.map { it.scrolled(amountX, amountY).toInt() }.sum() != 0
}
}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/ui/UIItemTransitionContainer.kt b/src/net/torvald/terrarum/ui/UIItemTransitionContainer.kt
index 9af8bcded..696495656 100644
--- a/src/net/torvald/terrarum/ui/UIItemTransitionContainer.kt
+++ b/src/net/torvald/terrarum/ui/UIItemTransitionContainer.kt
@@ -116,8 +116,8 @@ open class UIItemTransitionContainer(
return true
}
- override fun scrolled(amount: Int): Boolean {
- uis.forEachIndexed { index, ui -> if (timeToUpdate(index)) ui.scrolled(amount) }
+ override fun scrolled(amountX: Float, amountY: Float): Boolean {
+ uis.forEachIndexed { index, ui -> if (timeToUpdate(index)) ui.scrolled(amountX, amountY) }
return true
}
diff --git a/src/net/torvald/terrarum/ui/UINSMenu.kt b/src/net/torvald/terrarum/ui/UINSMenu.kt
index 97555317b..cefb6d07a 100644
--- a/src/net/torvald/terrarum/ui/UINSMenu.kt
+++ b/src/net/torvald/terrarum/ui/UINSMenu.kt
@@ -236,26 +236,6 @@ class UINSMenu(
return true
}
- override fun touchUp(screenX: Int, screenY: Int, pointer: Int, button: Int): Boolean {
- return super.touchUp(screenX, screenY, pointer, button)
- }
-
- override fun scrolled(amount: Int): Boolean {
- return super.scrolled(amount)
- }
-
- override fun keyDown(keycode: Int): Boolean {
- return super.keyDown(keycode)
- }
-
- override fun keyUp(keycode: Int): Boolean {
- return super.keyUp(keycode)
- }
-
- override fun keyTyped(character: Char): Boolean {
- return super.keyTyped(character)
- }
-
override fun resize(width: Int, height: Int) {
}
}
\ No newline at end of file
diff --git a/src/net/torvald/terrarum/worlddrawer/BlocksDrawerNew.kt b/src/net/torvald/terrarum/worlddrawer/BlocksDrawerNew.kt
index 7f7a5ea02..bfe1e0664 100644
--- a/src/net/torvald/terrarum/worlddrawer/BlocksDrawerNew.kt
+++ b/src/net/torvald/terrarum/worlddrawer/BlocksDrawerNew.kt
@@ -642,8 +642,8 @@ internal object BlocksDrawer {
var tilesInVertical = -1; private set
fun resize(screenW: Int, screenH: Int) {
- tilesInHorizontal = (AppLoader.screenWf / TILE_SIZE).ceilInt() + 1
- tilesInVertical = (AppLoader.screenHf / TILE_SIZE).ceilInt() + 1
+ tilesInHorizontal = (AppLoader.screenSize.screenWf / TILE_SIZE).ceilInt() + 1
+ tilesInVertical = (AppLoader.screenSize.screenHf / TILE_SIZE).ceilInt() + 1
val oldTH = (oldScreenW.toFloat() / TILE_SIZE).ceilInt() + 1
val oldTV = (oldScreenH.toFloat() / TILE_SIZE).ceilInt() + 1
@@ -669,9 +669,9 @@ internal object BlocksDrawer {
tilesQuad.setVertices(floatArrayOf( // WARNING! not ususal quads; TexCoords of Y is flipped
0f, 0f, 0f, 1f, 1f, 1f, 1f, 0f, 0f,
- AppLoader.screenWf, 0f, 0f, 1f, 1f, 1f, 1f, 1f, 0f,
- AppLoader.screenWf, AppLoader.screenHf, 0f, 1f, 1f, 1f, 1f, 1f, 1f,
- 0f, AppLoader.screenHf, 0f, 1f, 1f, 1f, 1f, 0f, 1f
+ AppLoader.screenSize.screenWf, 0f, 0f, 1f, 1f, 1f, 1f, 1f, 0f,
+ AppLoader.screenSize.screenWf, AppLoader.screenSize.screenHf, 0f, 1f, 1f, 1f, 1f, 1f, 1f,
+ 0f, AppLoader.screenSize.screenHf, 0f, 1f, 1f, 1f, 1f, 0f, 1f
))
tilesQuad.setIndices(shortArrayOf(0, 1, 2, 2, 3, 0))
}
diff --git a/src/net/torvald/terrarum/worlddrawer/FeaturesDrawer.kt b/src/net/torvald/terrarum/worlddrawer/FeaturesDrawer.kt
index 819ddee0e..18810fa94 100644
--- a/src/net/torvald/terrarum/worlddrawer/FeaturesDrawer.kt
+++ b/src/net/torvald/terrarum/worlddrawer/FeaturesDrawer.kt
@@ -45,7 +45,7 @@ object FeaturesDrawer {
* usually targeted for the environmental temperature (desert/winterland), hence the name.
*/
fun drawEnvOverlay(batch: SpriteBatch) {
- val onscreen_tiles_max = FastMath.ceil(AppLoader.screenH * AppLoader.screenW / FastMath.sqr (TILE_SIZE.toFloat())) * 2
+ val onscreen_tiles_max = FastMath.ceil(AppLoader.screenSize.screenH * AppLoader.screenSize.screenW / FastMath.sqr (TILE_SIZE.toFloat())) * 2
val onscreen_tiles_cap = onscreen_tiles_max / 4f
val onscreen_cold_tiles = BlockStats.getCount(*TILES_COLD).toFloat()
val onscreen_warm_tiles = BlockStats.getCount(*TILES_WARM).toFloat()
@@ -59,8 +59,8 @@ object FeaturesDrawer {
batch.color = ColourTemp(colTemp)
batch.fillRect(0f, 0f,
- AppLoader.screenW * if (zoom < 1) 1f / zoom else zoom,
- AppLoader.screenH * if (zoom < 1) 1f / zoom else zoom
+ AppLoader.screenSize.screenW * if (zoom < 1) 1f / zoom else zoom,
+ AppLoader.screenSize.screenH * if (zoom < 1) 1f / zoom else zoom
)
blendNormal(batch)
diff --git a/src/net/torvald/terrarum/worlddrawer/LightmapRendererNew.kt b/src/net/torvald/terrarum/worlddrawer/LightmapRendererNew.kt
index b94df502c..3ddf814bc 100644
--- a/src/net/torvald/terrarum/worlddrawer/LightmapRendererNew.kt
+++ b/src/net/torvald/terrarum/worlddrawer/LightmapRendererNew.kt
@@ -10,7 +10,6 @@ import net.torvald.terrarum.AppLoader.printdbg
import net.torvald.terrarum.blockproperties.Block
import net.torvald.terrarum.blockproperties.BlockCodex
import net.torvald.terrarum.blockproperties.Fluid
-import net.torvald.terrarum.concurrent.ThreadExecutor
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gameactors.Luminous
import net.torvald.terrarum.gameworld.BlockAddress
@@ -68,8 +67,8 @@ object LightmapRenderer {
const val overscan_open: Int = 40
const val overscan_opaque: Int = 10
- private var LIGHTMAP_WIDTH: Int = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(AppLoader.screenW).div(TILE_SIZE).ceilInt() + overscan_open * 2 + 3
- private var LIGHTMAP_HEIGHT: Int = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(AppLoader.screenH).div(TILE_SIZE).ceilInt() + overscan_open * 2 + 3
+ private var LIGHTMAP_WIDTH: Int = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(AppLoader.screenSize.screenW).div(TILE_SIZE).ceilInt() + overscan_open * 2 + 3
+ private var LIGHTMAP_HEIGHT: Int = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(AppLoader.screenSize.screenH).div(TILE_SIZE).ceilInt() + overscan_open * 2 + 3
//private val noopMask = HashSet((LIGHTMAP_WIDTH + LIGHTMAP_HEIGHT) * 2)
@@ -836,11 +835,11 @@ object LightmapRenderer {
// copied from BlocksDrawer, duh!
// FIXME 'lightBuffer' is not zoomable in this way
- val tilesInHorizontal = (AppLoader.screenWf / TILE_SIZE).ceilInt() + 1
- val tilesInVertical = (AppLoader.screenHf / TILE_SIZE).ceilInt() + 1
+ val tilesInHorizontal = (AppLoader.screenSize.screenWf / TILE_SIZE).ceilInt() + 1
+ val tilesInVertical = (AppLoader.screenSize.screenHf / TILE_SIZE).ceilInt() + 1
- LIGHTMAP_WIDTH = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(AppLoader.screenW).div(TILE_SIZE).ceilInt() + overscan_open * 2 + 3
- LIGHTMAP_HEIGHT = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(AppLoader.screenH).div(TILE_SIZE).ceilInt() + overscan_open * 2 + 3
+ LIGHTMAP_WIDTH = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(AppLoader.screenSize.screenW).div(TILE_SIZE).ceilInt() + overscan_open * 2 + 3
+ LIGHTMAP_HEIGHT = (Terrarum.ingame?.ZOOM_MINIMUM ?: 1f).inv().times(AppLoader.screenSize.screenH).div(TILE_SIZE).ceilInt() + overscan_open * 2 + 3
if (_init) {
lightBuffer.dispose()
diff --git a/src/net/torvald/terrarum/worlddrawer/WorldCamera.kt b/src/net/torvald/terrarum/worlddrawer/WorldCamera.kt
index ae967ca9c..7928c7d63 100644
--- a/src/net/torvald/terrarum/worlddrawer/WorldCamera.kt
+++ b/src/net/torvald/terrarum/worlddrawer/WorldCamera.kt
@@ -63,8 +63,8 @@ object WorldCamera {
fun update(world: GameWorld, player: ActorWithBody?) {
if (player == null) return
- width = AppLoader.screenW//FastMath.ceil(AppLoader.screenW / zoom) // div, not mul
- height = AppLoader.screenH//FastMath.ceil(AppLoader.screenH / zoom)
+ width = AppLoader.screenSize.screenW//FastMath.ceil(AppLoader.terrarumAppConfig.screenW / zoom) // div, not mul
+ height = AppLoader.screenSize.screenH//FastMath.ceil(AppLoader.terrarumAppConfig.screenH / zoom)
zoom = Terrarum.ingame?.screenZoom ?: 1f
zoomSamplePoint = (1f - 1f / zoom) / 2f // will never quite exceed 0.5
@@ -93,8 +93,8 @@ object WorldCamera {
private fun Int.clampCameraY(world: GameWorld): Int {
return if (this < 0)
0
- else if (this > world.height.times(TILE_SIZE) - AppLoader.screenH)
- world.height.times(TILE_SIZE) - AppLoader.screenH
+ else if (this > world.height.times(TILE_SIZE) - AppLoader.screenSize.screenH)
+ world.height.times(TILE_SIZE) - AppLoader.screenSize.screenH
else
this
}
diff --git a/terrarum.iml b/terrarum.iml
deleted file mode 100644
index 5ead1470d..000000000
--- a/terrarum.iml
+++ /dev/null
@@ -1,18 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/terrarum.terrarum.iml b/terrarum.terrarum.iml
new file mode 100644
index 000000000..b34d17a36
--- /dev/null
+++ b/terrarum.terrarum.iml
@@ -0,0 +1,33 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file