Compare commits

...

81 Commits

Author SHA1 Message Date
350824a31f Fix tellraw issue and cleanup storages
All checks were successful
Deploy datapack to dev / Build (push) Successful in 7s
2025-03-28 17:45:52 -05:00
915988215d Allow logging to take storages as message inputs
All checks were successful
Deploy datapack to dev / Build (push) Successful in 7s
Message inputs with a leading "::" will be parsed as storages.

All other message inputs will be parsed as strings.
2025-03-28 12:54:05 -05:00
31f616e110 Start initializing tables
All checks were successful
Deploy datapack to dev / Build (push) Successful in 7s
2025-03-27 08:05:51 -05:00
a7b71073bf Update logger calls
All checks were successful
Deploy datapack to dev / Build (push) Successful in 9s
2025-03-26 16:56:23 -05:00
909b2d08de Merge branch 'dev' into dev-database
All checks were successful
Deploy datapack to dev / Build (push) Successful in 6s
2025-03-26 10:12:39 -05:00
84ddf1c021 Merge branch 'dev-logging' into dev
All checks were successful
Deploy datapack to dev / Build (push) Successful in 8s
2025-03-26 10:12:20 -05:00
39e598ddc7 Add body to logger and update existing calls 2025-03-26 10:09:32 -05:00
3a6e16ee2b Move benchmarks to separate modules
All checks were successful
Deploy datapack to dev / Build (push) Successful in 9s
2025-03-26 08:55:15 -05:00
3c0eab8fd8 Add arraytest3 to test on macro rather than two
All checks were successful
Deploy datapack to dev / Build (push) Successful in 8s
2025-03-23 10:44:53 -05:00
1474266e89 Change string to object, smh
All checks were successful
Deploy datapack to dev / Build (push) Successful in 7s
2025-03-23 10:23:18 -05:00
1784e8fcd5 Change keyword to use storages
All checks were successful
Deploy datapack to dev / Build (push) Successful in 7s
2025-03-23 10:08:32 -05:00
2d3d2abe33 Remove tellraw logs
All checks were successful
Deploy datapack to dev / Build (push) Successful in 8s
2025-03-23 02:24:54 -05:00
a9f6581a8d Fix storage ref in macro
All checks were successful
Deploy datapack to dev / Build (push) Successful in 7s
2025-03-23 02:13:15 -05:00
a8e3346b4d Fix index
All checks were successful
Deploy datapack to dev / Build (push) Successful in 7s
2025-03-23 02:03:15 -05:00
8a4bd9e9b9 Add helper functions
All checks were successful
Deploy datapack to dev / Build (push) Successful in 7s
2025-03-23 02:01:49 -05:00
651ab1286c Add say debug command
All checks were successful
Deploy datapack to dev / Build (push) Successful in 7s
2025-03-23 01:46:59 -05:00
13150be611 Add print to debug
All checks were successful
Deploy datapack to dev / Build (push) Successful in 7s
2025-03-23 01:37:45 -05:00
58678de1d3 Fix macro line
All checks were successful
Deploy datapack to dev / Build (push) Successful in 7s
2025-03-23 01:35:57 -05:00
80fe00caba Add index lookup in benchmark test
All checks were successful
Deploy datapack to dev / Build (push) Successful in 7s
2025-03-23 01:34:43 -05:00
087f852b54 Populate test .run()
All checks were successful
Deploy datapack to dev / Build (push) Successful in 7s
2025-03-23 01:21:44 -05:00
9588154a2f Populate clean function
All checks were successful
Deploy datapack to dev / Build (push) Successful in 7s
2025-03-23 01:11:18 -05:00
a54ff65abe Populate setup and various print functions for test
All checks were successful
Deploy datapack to dev / Build (push) Successful in 7s
2025-03-23 01:08:25 -05:00
1345fa13c0 Add cleanup for temp array storage
All checks were successful
Deploy datapack to dev / Build (push) Successful in 6s
2025-03-23 00:59:35 -05:00
d1c96735f0 Fix storage path
All checks were successful
Deploy datapack to dev / Build (push) Successful in 7s
2025-03-23 00:50:06 -05:00
2942c065ea Add actual test logic for arrayTest1
All checks were successful
Deploy datapack to dev / Build (push) Successful in 7s
2025-03-23 00:48:06 -05:00
490c3a9032 Change from for loop to Hardcode
All checks were successful
Deploy datapack to dev / Build (push) Successful in 7s
2025-03-22 21:55:43 -05:00
5e44a9eb28 Simplify "for" loop to try to get it running
All checks were successful
Deploy datapack to dev / Build (push) Successful in 6s
2025-03-22 21:35:45 -05:00
3b7fcca6f3 Add debug log to loop
All checks were successful
Deploy datapack to dev / Build (push) Successful in 6s
2025-03-22 21:33:50 -05:00
5d62488695 Edit test and add print for debug
All checks were successful
Deploy datapack to dev / Build (push) Successful in 7s
2025-03-22 21:27:28 -05:00
b0d2fd4695 Test integer hash with smaller values
All checks were successful
Deploy datapack to dev / Build (push) Successful in 6s
2025-03-22 18:48:36 -05:00
2cd5f26451 Fix lazy func param
All checks were successful
Deploy datapack to dev / Build (push) Successful in 5s
2025-03-21 20:28:44 -05:00
c75b6c8fea Add logging output to test function
All checks were successful
Deploy datapack to dev / Build (push) Successful in 5s
2025-03-21 20:27:38 -05:00
a4c1d5a865 Add another test case
All checks were successful
Deploy datapack to dev / Build (push) Successful in 6s
2025-03-21 20:25:21 -05:00
b309485d18 Add test function to actually run the tests
All checks were successful
Deploy datapack to dev / Build (push) Successful in 6s
2025-03-21 20:23:56 -05:00
8d3ef2b799 Tweak hash function and add test
All checks were successful
Deploy datapack to dev / Build (push) Successful in 7s
2025-03-21 20:22:12 -05:00
7be40debe7 Add cryptography module with hashing function
All checks were successful
Deploy datapack to dev / Build (push) Successful in 9s
2025-03-21 15:40:08 -05:00
a4e515ed80 Fix module imports 2025-03-21 13:22:52 -05:00
e5ce1e7734 Move database to submodule and add crytography mod 2025-03-21 13:20:18 -05:00
7a69996c55 Rename db test module to benchmark 2025-03-21 13:18:41 -05:00
237259d509 Add database testing module with array tests 2025-03-21 13:18:00 -05:00
a830c894ac Change entity selector
All checks were successful
Deploy datapack to dev / Build (push) Successful in 7s
2025-03-21 11:14:43 -05:00
622141f321 Fix missing semicolon
All checks were successful
Deploy datapack to dev / Build (push) Successful in 6s
2025-03-21 10:46:33 -05:00
19175fbb93 Add tabe creationg log message
All checks were successful
Deploy datapack to dev / Build (push) Successful in 7s
2025-03-21 10:39:27 -05:00
d5aa1859d6 Add database to imports
All checks were successful
Deploy datapack to dev / Build (push) Successful in 6s
2025-03-21 10:36:23 -05:00
6b55f9bbd9 Merge branch 'dev' into dev-database
All checks were successful
Deploy datapack to dev / Build (push) Successful in 6s
2025-03-21 10:26:09 -05:00
3091d6b3f4 Restructure imports in main.jmc
All checks were successful
Deploy datapack to dev / Build (push) Successful in 8s
2025-03-21 10:24:33 -05:00
6cb4b30b2d Merge pull request 'Create general purpose logging module' (#4) from dev-logging into dev
All checks were successful
Deploy datapack to dev / Build (push) Successful in 8s
Reviewed-on: #4
2025-03-11 20:31:37 -05:00
b6e1d224e5 Fix debug logging messages 2025-03-11 19:55:30 -05:00
9117c84653 Enable debug logging to bypass log level 2025-03-11 19:55:30 -05:00
7bfa12b539 Turn line into macro command 2025-03-11 19:55:30 -05:00
d30418d57a Fix log level message to display current log level 2025-03-11 19:55:30 -05:00
accd746389 Change logger type check to use temp var 2025-03-11 19:55:30 -05:00
cf55f238ff Add logger error for invalid type paramater 2025-03-11 19:55:30 -05:00
68d4b8c25d Add log level threshold
Set default log level to 3, or ERROR. Ensure log level isn't overriden
on reload. Add errors if log level is misconfigured.
2025-03-11 19:55:30 -05:00
686592df33 Add double-quotes back to log messages
Double-quotes were initially removed for aesthetic reasons. However, JMC
collapses whitespace, resulting in mangled message output. Double quotes
are converted to single quotes in compliled output.
2025-03-11 19:55:30 -05:00
28d85c4e02 Remove double-quotes from log messages 2025-03-11 19:55:30 -05:00
5468fa9605 Add "caller" paramteter to logger 2025-03-11 19:55:30 -05:00
daa70062f6 Show status after toggling logger 2025-03-11 19:55:30 -05:00
f4d444635b Revert logger status from printf to say 2025-03-11 19:55:30 -05:00
58ef0a251e Add logger status function 2025-03-11 19:55:30 -05:00
3b6990be85 Rename logger toggle function 2025-03-11 19:55:30 -05:00
3ff1bded99 Create logging module 2025-03-11 19:55:30 -05:00
88648fec62 Fix debug logging messages
All checks were successful
Deploy datapack to dev / Build (push) Successful in 7s
2025-03-11 17:12:53 -05:00
4fbde4fc10 Enable debug logging to bypass log level
All checks were successful
Deploy datapack to dev / Build (push) Successful in 7s
2025-03-11 16:56:49 -05:00
5cd6a1f014 Turn line into macro command
All checks were successful
Deploy datapack to dev / Build (push) Successful in 6s
2025-03-11 16:52:47 -05:00
4eb361f6e8 Fix log level message to display current log level
All checks were successful
Deploy datapack to dev / Build (push) Successful in 7s
2025-03-11 16:49:41 -05:00
f0feb378af Change logger type check to use temp var
All checks were successful
Deploy datapack to dev / Build (push) Successful in 7s
2025-03-11 15:39:21 -05:00
b3e1769ca9 Add logger error for invalid type paramater
All checks were successful
Deploy datapack to dev / Build (push) Successful in 7s
2025-03-11 15:32:46 -05:00
8d6d9e5a0c Add log level threshold
Set default log level to 3, or ERROR. Ensure log level isn't overriden
on reload. Add errors if log level is misconfigured.
2025-03-11 15:32:05 -05:00
5bac9fdb2f Add double-quotes back to log messages
All checks were successful
Deploy datapack to dev / Build (push) Successful in 7s
Double-quotes were initially removed for aesthetic reasons. However, JMC
collapses whitespace, resulting in mangled message output. Double quotes
are converted to single quotes in compliled output.
2025-03-11 14:51:06 -05:00
36344b82b0 Remove double-quotes from log messages
All checks were successful
Deploy datapack to dev / Build (push) Successful in 6s
2025-03-11 14:47:28 -05:00
26cf75ca88 Add "caller" paramteter to logger
All checks were successful
Deploy datapack to dev / Build (push) Successful in 7s
2025-03-11 14:43:14 -05:00
5dc0dba29e Show status after toggling logger
All checks were successful
Deploy datapack to dev / Build (push) Successful in 6s
2025-03-11 13:39:47 -05:00
20f3aa2b78 Revert logger status from printf to say
All checks were successful
Deploy datapack to dev / Build (push) Successful in 7s
2025-03-11 13:36:22 -05:00
d9ef26cfa7 Add logger status function
All checks were successful
Deploy datapack to dev / Build (push) Successful in 6s
2025-03-11 13:21:03 -05:00
f1186b76a6 Rename logger toggle function 2025-03-11 13:18:00 -05:00
561b7cc39a Create logging module
All checks were successful
Deploy datapack to dev / Build (push) Successful in 8s
2025-03-11 12:56:31 -05:00
96522b8e7e Fix storage path
All checks were successful
Deploy datapack to dev / Build (push) Successful in 7s
2025-03-11 11:18:45 -05:00
042235b481 change to tellraw
All checks were successful
Deploy datapack to dev / Build (push) Successful in 6s
2025-03-09 16:30:47 -05:00
9ef0a8abff change "createTable" test command
All checks were successful
Deploy datapack to dev / Build (push) Successful in 5s
2025-03-09 16:21:17 -05:00
e57af981ea add database
All checks were successful
Deploy datapack to dev / Build (push) Successful in 6s
2025-03-09 16:12:19 -05:00
5 changed files with 318 additions and 1 deletions

View File

@ -1,3 +1,6 @@
import "src/*";
import "src/logger.jmc";
import "src/database/crypt.jmc";
import "src/database/database.jmc";
import "src/commands.jmc";
function __tick__() {}

110
src/database/benchmark.jmc Normal file
View File

@ -0,0 +1,110 @@
class database.benchmark {
function arrayTest1.setup() {
::database.test.arrayTest1.array = [];
Hardcode.repeat(
indexString="[index]",
start=0,
stop=500,
function=() => {
::database.test.arrayTest1.array << {id: Hardcode.calc([index]+1), string: "entryHardcode.calc([index]+1)"};
}
);
}
function arrayTest1.print() {
tellraw @a {"nbt":"database.test.arrayTest1.array","storage":"ferdinland:ferdinland"};
}
function arrayTest1.clean() {
::database.test.arrayTest1.array.del();
::temp.arrayTest1.del();
}
function arrayTest1.run() {
::temp.arrayTest1 = ::database.test.arrayTest1.array;
::temp.keyword = "entry500";
Array.forEach(
"ferdinland:ferdinland",
"temp.arrayTest1",
() => {
if (Object.isEqual("ferdinland:ferdinland", "temp.arrayTest1[0].string", "ferdinland:ferdinland", "temp.keyword")) {
::temp.result = ::temp.arrayTest1[0];
}
if (Object.isEqual("ferdinland:ferdinland", "temp.arrayTest1[0].string", "ferdinland:ferdinland", "temp.keyword")) {
return;
}
}
);
::temp.arrayTest1.del();
::temp.keyword.del();
}
function arrayTest2.setup() {
::database.test.arrayTest2.array = [];
::database.test.arrayTest2.index = {};
Hardcode.repeat(
indexString="[index]",
start=0,
stop=500,
function=() => {
::database.test.arrayTest2.array << {id: Hardcode.calc([index]+1), string: "entryHardcode.calc([index]+1)"};
::database.test.arrayTest2.index += {entryHardcode.calc([index]+1): [index]};
}
);
}
function arrayTest2.printArray() {
tellraw @a {"nbt":"database.test.arrayTest2.array","storage":"ferdinland:ferdinland"};
}
function arrayTest2.printIndex() {
tellraw @a {"nbt":"database.test.arrayTest2.index","storage":"ferdinland:ferdinland"};
}
function arrayTest2.clean() {
::database.test.arrayTest2.array.del();
::database.test.arrayTest2.index.del();
}
function arrayTest2._searchIndex() {
$::temp.index = ::database.test.arrayTest2.index.$(keyword);
}
function arrayTest2._searchArray() {
$::temp.result = ::database.test.arrayTest2.array[$(index)];
}
function arrayTest2.run() {
::temp.keyword = "entry500";
this.arrayTest2._searchIndex() with ::temp;
this.arrayTest2._searchArray() with ::temp;
::temp.keyword.del();
::temp.index.del();
::temp.result.del();
}
function arrayTest3.setup() {
::database.test.arrayTest3.array = [];
::database.test.arrayTest3.index = {};
Hardcode.repeat(
indexString="[index]",
start=0,
stop=500,
function=() => {
::database.test.arrayTest3.array << {id: Hardcode.calc([index]+1), string: "entryHardcode.calc([index]+1)"};
::database.test.arrayTest3.index += {entryHardcode.calc([index]+1): [index]};
}
);
}
function arrayTest3.printArray() {
tellraw @a {"nbt":"database.test.arrayTest3.array","storage":"ferdinland:ferdinland"};
}
function arrayTest3.printIndex() {
tellraw @a {"nbt":"database.test.arrayTest3.index","storage":"ferdinland:ferdinland"};
}
function arrayTest3.clean() {
::database.test.arrayTest3.array.del();
::database.test.arrayTest3.index.del();
}
function arrayTest3._searchArray() {
$::temp.result = ::database.test.arrayTest3.array[string:$(keyword)];
}
function arrayTest3.run() {
::temp.keyword = "entry500";
this.arrayTest3._searchArray() with ::temp;
::temp.keyword.del();
::temp.result.del();
}
}

43
src/database/crypt.jmc Normal file
View File

@ -0,0 +1,43 @@
@lazy
function test_hashInteger(test_val) {
$integerToHash = $test_val;
tellraw @a $integerToHash.toString();
database.crypt.hashInteger();
tellraw @a $hashedInteger.toString();
database.crypt.clean();
tellraw @a $hashedInteger.toString();
}
class database.crypt {
function hashString() {}
function hashInteger() {
$cryptMultiplyer = 49;
$cryptConstant = 7;
$cryptPrime = 15331;
#
# $integerToHash must already be initialized
#
$hashedInteger = $integerToHash;
$hashedInteger *= $cryptMultiplyer;
$hashedInteger += $cryptConstant;
$hashedInteger %= $cryptPrime;
# run database.crypt.clean() after hased value is used
}
function clean() {
scoreboard players reset $integerToHash __variable__;
scoreboard players reset $hashInteger __variable__;
}
function test() {
test_hashInteger(48593758);
test_hashInteger(69871234);
}
}

29
src/database/database.jmc Normal file
View File

@ -0,0 +1,29 @@
import "benchmark.jmc";
@lazy //takes name of table. metadata must already exist.
function createTable(name) {
logger(2, database.createTable, "Creating table: $name", false);
Array.forEach(
"ferdinland:ferdinland",
"database.tables.$name.fields",
()=>{
::database.tables.$name.fields[0]
}
);
}
class database {
@add(__load__)
function __init__() {}
@add(this.__init__)
function schema() {}
@add(this.schema)
function tables.myTable() {
::database.tables.myTable.name = "myTable";
::database.tables.myTable.fields = [{name: "id", type: "int"}, {name: "testString", type: "string"];
createTable(myTable);
}
}

132
src/logger.jmc Normal file
View File

@ -0,0 +1,132 @@
@lazy
function messagePrinter(name, caller, message) {
::tmp.string = $message;
::tmp.sub = ::tmp.string[0:1];
if (String.isEqual("ferdinland:ferdinland", "tmp.sub", "::")) {
::temp.message = ::tmp.string[2:];
execute run {
switch($tmp_logger) {
case 5:
say "FATAL: ($caller) $(message)";
case 4:
say "ERROR: ($caller) $(message)";
case 3:
say "WARNING: ($caller) $(message)";
case 2:
say "INFO: ($caller) $(message)";
case 1:
say "DEBUG: ($caller) $(message)";
default:
return 0;
}
} with ::temp;
} else {
switch($tmp_logger) {
case 5:
say "FATAL: ($caller) $message";
case 4:
say "ERROR: ($caller) $message";
case 3:
say "WARNING: ($caller) $message";
case 2:
say "INFO: ($caller) $message";
case 1:
say "DEBUG: ($caller) $message";
default:
return 0;
}
}
::tmp.string.del();
::tmp.sub.del();
::tmp.message.del();
}
@lazy
function logger(type, caller, message, body) {
$tmp_logger = false;
$tmp_type = $type;
if ($temp_type > 6 || $temp_type < 1) {
say "The log type requested does not exist. Please find the caller ($caller) and resolve this issue.";
}
if ($temp_type >= $log_level || $logger) { $tmp_logger = $type; }
if (!$tmp_logger) {
return;
} else {
messagePrinter($type, $caller, $message);
$isBody = $body;
::tmp.body = $body;
execute run {
tellraw @a $(body);
} with ::tmp;
::tmp.body.del();
}
}
class logger {
@add(__load__)
function __init__() {
if (!$log_level) {
$log_level = 3;
} else if ($log_level > 5) {
say "The log level was too high. Resetting to default value.";
$log_level = 3;
}
execute run {
$say "The log level is set to $(0).";
} with [$log_level];
if (!$logger) {
$logger = false;
} else if ($logger) {
say "Debug logging is enabled. You should now see a test log message:";
logger(2, logger, "This is a test. Logging appears to be working as expected!", false);
} else {
say "This is not a log message. There appears to be something wrong with the logger. It has not been detected as `!true` or `true`. Please investigate.";
}
}
function toggle() {
switch($logger) {
case 0:
$logger = true;
this.status();
case 1:
$logger = false;
this.status();
}
}
function status() {
switch($logger) {
case 0:
say "Debug logging is disabled";
case 1:
say "Debug logging is enabled";
}
}
function test_fatal() {
logger(5, logger, "This is a test", false);
}
function test_error() {
logger(4, logger, "This is a test", false);
}
function test_warning() {
logger(3, logger, "This is a test", false);
}
function test_info() {
logger(2, logger, "This is a test", false);
}
function test_debug() {
logger(1, logger, "This is a test", false);
}
}