diff --git a/macro.inc.php b/macro.inc.php index ee18476..2877651 100644 --- a/macro.inc.php +++ b/macro.inc.php @@ -160,7 +160,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; } @@ -188,7 +188,15 @@ function macro_BOOL($jsm, $expr) */ function macro_IS_DEV($jsm) { - return taskman_propor("GAME_IS_DEV", 0); + return \taskman\getor("GAME_IS_DEV", 0); +} + +/** + * @global + */ +function macro_PROP($jsm, $expr) +{ + return \taskman\get($expr); } /** @@ -207,3 +215,49 @@ 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; +} + +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; +} +