Compare commits
81 Commits
master
...
dev-databa
| Author | SHA1 | Date | |
|---|---|---|---|
| 350824a31f | |||
| 915988215d | |||
| 31f616e110 | |||
| a7b71073bf | |||
| 909b2d08de | |||
| 84ddf1c021 | |||
| 39e598ddc7 | |||
| 3a6e16ee2b | |||
| 3c0eab8fd8 | |||
| 1474266e89 | |||
| 1784e8fcd5 | |||
| 2d3d2abe33 | |||
| a9f6581a8d | |||
| a8e3346b4d | |||
| 8a4bd9e9b9 | |||
| 651ab1286c | |||
| 13150be611 | |||
| 58678de1d3 | |||
| 80fe00caba | |||
| 087f852b54 | |||
| 9588154a2f | |||
| a54ff65abe | |||
| 1345fa13c0 | |||
| d1c96735f0 | |||
| 2942c065ea | |||
| 490c3a9032 | |||
| 5e44a9eb28 | |||
| 3b7fcca6f3 | |||
| 5d62488695 | |||
| b0d2fd4695 | |||
| 2cd5f26451 | |||
| c75b6c8fea | |||
| a4c1d5a865 | |||
| b309485d18 | |||
| 8d3ef2b799 | |||
| 7be40debe7 | |||
| a4e515ed80 | |||
| e5ce1e7734 | |||
| 7a69996c55 | |||
| 237259d509 | |||
| a830c894ac | |||
| 622141f321 | |||
| 19175fbb93 | |||
| d5aa1859d6 | |||
| 6b55f9bbd9 | |||
| 3091d6b3f4 | |||
| 6cb4b30b2d | |||
| b6e1d224e5 | |||
| 9117c84653 | |||
| 7bfa12b539 | |||
| d30418d57a | |||
| accd746389 | |||
| cf55f238ff | |||
| 68d4b8c25d | |||
| 686592df33 | |||
| 28d85c4e02 | |||
| 5468fa9605 | |||
| daa70062f6 | |||
| f4d444635b | |||
| 58ef0a251e | |||
| 3b6990be85 | |||
| 3ff1bded99 | |||
| 88648fec62 | |||
| 4fbde4fc10 | |||
| 5cd6a1f014 | |||
| 4eb361f6e8 | |||
| f0feb378af | |||
| b3e1769ca9 | |||
| 8d6d9e5a0c | |||
| 5bac9fdb2f | |||
| 36344b82b0 | |||
| 26cf75ca88 | |||
| 5dc0dba29e | |||
| 20f3aa2b78 | |||
| d9ef26cfa7 | |||
| f1186b76a6 | |||
| 561b7cc39a | |||
| 96522b8e7e | |||
| 042235b481 | |||
| 9ef0a8abff | |||
| e57af981ea |
5
main.jmc
5
main.jmc
@ -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__() {}
|
function __tick__() {}
|
||||||
|
|||||||
110
src/database/benchmark.jmc
Normal file
110
src/database/benchmark.jmc
Normal 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
43
src/database/crypt.jmc
Normal 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
29
src/database/database.jmc
Normal 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
132
src/logger.jmc
Normal 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user