|
1 | 1 | <?php |
| 2 | +/* |
| 3 | + * DFRawFunctions extension by Quietust |
| 4 | + * Dwarf Fortress Raw parser functions |
| 5 | + */ |
| 6 | + |
| 7 | +if (!defined('MEDIAWIKI')) |
| 8 | +{ |
| 9 | + echo "This file is an extension of the MediaWiki software and cannot be used standalone\n"; |
| 10 | + die(1); |
| 11 | +} |
2 | 12 |
|
3 | 13 | class DFRawFunctions |
4 | 14 | { |
| 15 | + |
| 16 | + public static function efDFRawFunctions_Initialize (Parser $parser) |
| 17 | + { |
| 18 | + $parser->setFunctionHook('df_raw', [ self::class, 'raw']); |
| 19 | + $parser->setFunctionHook('df_tag', [ self::class, 'tag']); |
| 20 | + $parser->setFunctionHook('df_tagentry', [ self::class, 'tagentry']); |
| 21 | + $parser->setFunctionHook('df_tagvalue', [ self::class, 'tagvalue']); |
| 22 | + $parser->setFunctionHook('df_foreachtag', [ self::class, 'foreachtag']); |
| 23 | + $parser->setFunctionHook('df_foreachtoken', [ self::class, 'foreachtoken']); |
| 24 | + $parser->setFunctionHook('df_makelist', [ self::class, 'makelist']); |
| 25 | + $parser->setFunctionHook('df_statedesc', [ self::class, 'statedesc']); |
| 26 | + $parser->setFunctionHook('df_cvariation', [ self::class, 'cvariation']); |
| 27 | + $parser->setFunctionHook('mreplace', [ self::class, 'mreplace']); |
| 28 | + $parser->setFunctionHook('delay', [ self::class, 'delay']); |
| 29 | + $parser->setFunctionHook('eval', [ self::class, 'evaluate']); |
| 30 | + return true; |
| 31 | + } |
5 | 32 | // Takes some raws and returns a 2-dimensional token array |
6 | 33 | // If 2nd parameter is specified, then only tags of the specified type will be returned |
7 | 34 | // Optional 3rd parameter allows specifying an array which will be filled with indentation for each line |
@@ -56,18 +83,28 @@ private static function loadFile ($data) |
56 | 83 | return $data; |
57 | 84 |
|
58 | 85 | global $wgDFRawPath; |
| 86 | + if ($wgDFRawPath == "") |
| 87 | + $wgDFRawPath = __DIR__ . '/raws'; |
59 | 88 | if (!is_dir($wgDFRawPath)) |
60 | | - return $data; |
61 | | - |
62 | | - $filename = explode(':', $data, 2); |
63 | | - if (count($filename) != 2) |
64 | | - return $data; |
65 | | - $filename = str_replace(array('/', '\\'), '', $filename); |
66 | | - |
67 | | - // HACK to handle both DF2012 and v0.34 - once the /raw pages for 0.34 have been fixed, this can go away |
68 | | - if ($filename[0] == 'DF2012') $filename[0] = 'v0.34'; |
| 89 | + return __DIR__ . $data; |
| 90 | + |
| 91 | + global $wgDFRawVersion; |
| 92 | + $version_name = explode(':', $data, 2); |
| 93 | + if ( count($version_name) == 2 and $version_name[0] != "") { |
| 94 | + $version_name = str_replace(array('/', '\\'), '', $version_name); |
| 95 | + $raw_version = $version_name[0]; |
| 96 | + $file_name = $version_name[1]; |
| 97 | + |
| 98 | + if ($raw_version == 'DF2012') $raw_version = 'v0.34'; // HACK to handle both DF2012 and v0.34 - once the /raw pages for 0.34 have been fixed, this can go away |
| 99 | + } else { |
| 100 | + if ( $wgDFRawVersion == "" ) |
| 101 | + return $data; |
| 102 | + |
| 103 | + $raw_version = $wgDFRawVersion; |
| 104 | + $file_name = str_replace(array('/', '\\', ":"), '', $data); |
| 105 | + } |
69 | 106 |
|
70 | | - $wantfile = $wgDFRawPath .'/'. $filename[0] .'/'. $filename[1]; |
| 107 | + $wantfile = $wgDFRawPath .'/'. $raw_version .'/'. $file_name; |
71 | 108 |
|
72 | 109 | if (!is_file($wantfile)) |
73 | 110 | return $data; |
@@ -281,12 +318,12 @@ public static function makelist (&$parser, $data = '', $object = '', $string = ' |
281 | 318 | $val = self::statedesc($parser, substr($data, $start, $end - $start), $getoffset, $checkoffset); |
282 | 319 | $rep_out[$i] = $val; |
283 | 320 | continue; |
284 | | - } |
| 321 | + } |
285 | 322 | foreach ($tags as $tag) |
286 | 323 | { |
287 | 324 | if (($tag[0] != $gettype) || ($getoffset >= count($tag))) |
288 | 325 | continue; |
289 | | - if (($checkoffset < 0) || (($checkoffset < count($tag)) && ($tag[$checkoffset] == $checkval))) |
| 326 | + if (($checkoffset < 0) || (($checkoffset < count($tag)) && ($tag[$checkoffset] == $checkval))) |
290 | 327 | { |
291 | 328 | $rep_out[$i] = $tag[$getoffset]; |
292 | 329 | break; |
|
0 commit comments