y * 365 * 24 * 60 * 60) + ($in->m * 30 * 24 * 60 * 60) + ($in->d * 24 * 60 * 60) + ($in->h * 60 * 60) + ($in->i * 60) + $in->s; if($sec <= 0) throw new Exception("Bad resulting interval in seconds '$sec' for spec '$spec'"); return $sec; } /** * @global */ function macro_WEEK_DATE($proc, $spec) { $parts = explode(" ", $spec); $dow_str = $parts[0]; $time_str = $parts[1]; $day = 0; switch ($dow_str) { case 'MONDAY': $day = 0; break; case 'TUESDAY': $day = 1; break; case 'WEDNESDAY': $day = 2; break; case 'THURSDAY': $day = 3; break; case 'FRIDAY': $day = 4; break; case 'SATURDAY': $day = 5; break; case 'SUNDAY': $day = 6; break; default: throw new Exception("Bad day of week: $spec"); } $stamp = strtotime($time_str); if($stamp === false) throw new Exception("Bad time: $spec"); $stamp += $day * 24 * 60 * 60; return $stamp; } /** * @global */ function macro_ENUM_OR($proc) { global $GAME_ROOT; $args = func_get_args(); array_shift($args); $class = array_shift($args); $opts = 0; for($i=0;$i 1) throw new Exception("Format indices gap: '{$res[0]}'"); $prev = $idx; } } return $res; } /** * @raw_args */ function macro_Q($proc, $value) { if(strpos(ltrim($value), '[') === 0) return $value; else return "\"$value\""; } /** * @global */ function macro_SELF_CONF_ID($jsm) { $file = $jsm->getRootFile(); $proto_id = 0; $alias = ""; if(!\taskman\config_get_header($file, $proto_id, $alias)) throw new Exception("No valid header for config: $file"); return $proto_id; } /** * @global */ function macro_SELF_SHORT_NAME($jsm) { $file = $jsm->getRootFile(); return str_replace(".conf.js", "", basename($file)); } /** * @global @raw_args */ function macro_BOOL($jsm, $expr) { $res = jsm_eval_string_value($jsm, $expr); return $res == 0 ? "false" : "true"; } /** * @global */ function macro_IS_DEV($jsm) { return \taskman\getor("GAME_IS_DEV", 0); } /** * @global */ function macro_PROP($jsm, $expr) { $res = \taskman\get($expr); if(is_string($res)) return '"'.$res.'"'; return $res; } /** * @global */ 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; }