Compare commits
No commits in common. "dev-database" and "master" have entirely different histories.
dev-databa
...
master
5
main.jmc
5
main.jmc
@ -1,6 +1,3 @@
|
||||
import "src/logger.jmc";
|
||||
import "src/database/crypt.jmc";
|
||||
import "src/database/database.jmc";
|
||||
import "src/commands.jmc";
|
||||
import "src/*";
|
||||
|
||||
function __tick__() {}
|
||||
|
||||
@ -1,110 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
@ -1,43 +0,0 @@
|
||||
@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);
|
||||
}
|
||||
}
|
||||
@ -1,29 +0,0 @@
|
||||
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
132
src/logger.jmc
@ -1,132 +0,0 @@
|
||||
@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