From 04179fcd262b8fa61b175bffea2492ef0d7cdd72 Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Mon, 29 May 2023 11:52:17 +0300 Subject: [PATCH 1/7] Adding UNWRAP macro which removes config surrounding braces --- macro.inc.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/macro.inc.php b/macro.inc.php index 460a527..bb0bec4 100644 --- a/macro.inc.php +++ b/macro.inc.php @@ -142,7 +142,7 @@ function macro_BOOL($jsm, $expr) */ function macro_IS_DEV($jsm) { - return taskman_propor("GAME_IS_DEV", 0); + return \taskman\getor("GAME_IS_DEV", 0); } /** @@ -161,3 +161,13 @@ function macro_ITEM($proc, $proto_id, $amount) return array('proto_id' => $proto_id, 'amount' => $amount); } +/** + * @global @raw_args + */ +function macro_UNWRAP($jsm, $content) +{ + $content = trim($content); + $content = ltrim($content, '{'); + $content = rtrim($content, '}'); + return $content; +} From d079c79d50155aad98a9f71334eb223307a65e0c Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Fri, 2 Jun 2023 15:33:30 +0300 Subject: [PATCH 2/7] Removing non-working stuff --- macro.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/macro.inc.php b/macro.inc.php index bb0bec4..3e718f4 100644 --- a/macro.inc.php +++ b/macro.inc.php @@ -114,7 +114,7 @@ function macro_SELF_CONF_ID($jsm) $proto_id = 0; $alias = ""; if(!\taskman\config_get_header($file, $proto_id, $alias)) - $proto_id = \taskman\config_get_id($file); + throw new Exception("No valid header for config: $file"); return $proto_id; } From fa18e07f23fb863bdbe1efceb532670cc529b559 Mon Sep 17 00:00:00 2001 From: "a.chubar" Date: Tue, 20 Jun 2023 19:32:41 +0300 Subject: [PATCH 3/7] Added PROP macro --- macro.inc.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/macro.inc.php b/macro.inc.php index 460a527..b8b807d 100644 --- a/macro.inc.php +++ b/macro.inc.php @@ -145,6 +145,14 @@ function macro_IS_DEV($jsm) return taskman_propor("GAME_IS_DEV", 0); } +/** + * @global + */ +function macro_PROP($jsm, $expr) +{ + return \taskman\get($expr); +} + /** * @global */ From d44fe3cccb7c5029ea4c1f966e2748eaa84873c2 Mon Sep 17 00:00:00 2001 From: "a.chubar" Date: Wed, 21 Jun 2023 12:11:35 +0300 Subject: [PATCH 4/7] Version v1.2.4 --- macro.inc.php | 1 + 1 file changed, 1 insertion(+) diff --git a/macro.inc.php b/macro.inc.php index 3cd609d..4a7e918 100644 --- a/macro.inc.php +++ b/macro.inc.php @@ -179,3 +179,4 @@ function macro_UNWRAP($jsm, $content) $content = rtrim($content, '}'); return $content; } + From eb0ee2a587502ac95e051ab2e6c7b11d18602f3c Mon Sep 17 00:00:00 2001 From: "a.chubar" Date: Wed, 21 Jun 2023 12:23:02 +0300 Subject: [PATCH 5/7] Version v1.2.5 --- macro.inc.php | 1 + 1 file changed, 1 insertion(+) diff --git a/macro.inc.php b/macro.inc.php index 4a7e918..2472e30 100644 --- a/macro.inc.php +++ b/macro.inc.php @@ -180,3 +180,4 @@ function macro_UNWRAP($jsm, $content) return $content; } + From 05e640d6a3629a3d33b2a83715c0e695ab52c5b0 Mon Sep 17 00:00:00 2001 From: "a.chubar" Date: Wed, 21 Jun 2023 12:24:45 +0300 Subject: [PATCH 6/7] Version v1.2.5 --- macro.inc.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/macro.inc.php b/macro.inc.php index 2472e30..3cd609d 100644 --- a/macro.inc.php +++ b/macro.inc.php @@ -179,5 +179,3 @@ function macro_UNWRAP($jsm, $content) $content = rtrim($content, '}'); return $content; } - - From 24b2a0ee457c34b6d5b903053d4cbc165d5b7281 Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Mon, 26 Jun 2023 15:09:45 +0300 Subject: [PATCH 7/7] Adding initial version of OVERRIDE(..) macro --- macro.inc.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/macro.inc.php b/macro.inc.php index 3e718f4..413137b 100644 --- a/macro.inc.php +++ b/macro.inc.php @@ -171,3 +171,39 @@ function macro_UNWRAP($jsm, $content) $content = rtrim($content, '}'); return $content; } + +function _array_merge_recursive_distinct(array $array1, array $array2) +{ + $merged = $array1; + + foreach($array2 as $key => $value) + { + if(is_array($value) && isset($merged[$key]) && is_array($merged[$key])) + $merged[$key] = _array_merge_recursive_distinct($merged[$key], $value); + else + $merged[$key] = $value; + } + + return $merged; +} + +/** + * @global @raw_args + */ +function macro_OVERRIDE($jsm, $content) +{ + $items = \jzon_parse($content); + if(!is_array($items)) + throw new Exception("OVERRIDE contents not an array"); + if(sizeof($items) != 2) + throw new Exception("OVERRIDE array size is not 2, it's " . sizeof($items)); + + $merged = _array_merge_recursive_distinct($items[0], $items[1]); + + $json = json_encode($merged, JSON_UNESCAPED_LINE_TERMINATORS | JSON_UNESCAPED_SLASHES); + $json = ltrim($json, '{'); + $json = rtrim($json, '}'); + + return $json; +} +