<?php
require_once('includes/library/rxdata.php');
$folder = iconv('utf-8', 'gb2312', 'D:\\RPG\\Magic Towers\\Works\\拐彎の小街\\哀姬・夢魂燕(3)\\哀姬・夢魂燕\\Data\\');
if (!file_exists($folder)) {
die('文件夾不存在');
}
function get_map($id) {
global $folder;
$file = sprintf('%sMap%03d.rxdata', $folder, $id);
if (!file_exists($file)) {
return false;
}
return rxdata_load($file);
}
function show_dialogs($map_id, $additional_info = false) {
global $maps;
$map = get_map($map_id);
if (!$map) {
echo "該地圖不存在\n";
return;
}
echo '<h2>' . $maps[$map_id]->name . "</h2>\n";
if ($additional_info) {
$mapfile = get_map($map_id);
printf('<p class="info">(ID: %d,尺寸:%dx%d,事件數:%d)</p>', $map_id, $mapfile->width, $mapfile->height, count($map->events));
unset($mapfile);
}
$output = false;
foreach ($map->events as $event) {
foreach ($event->pages as $page) {
$has_dialogs = false;
foreach ($page->list as $list) {
if ($list->code == 101 || $list->code == 401) {
$has_dialogs = true;
}
}
if (!$has_dialogs) {
continue;
}
$output = true;
$paragraph = '';
$content_list = array();
foreach ($page->list as $list) {
if ($list->code == 101 || $list->code == 401) {
$line = $list->parameters[0];
$line = preg_replace('/\\\name\[([^\]]+)\]/', '<b>$1:</b>', $line);
if (!empty($paragraph) && (substr($line, 0, 3) == '<b>' || $list->code == 101)) {
array_push($content_list, $paragraph);
$paragraph = '';
}
$line = preg_replace('/\\\p\[\d+\]/', '', $line);
$paragraph .= $line;
}
}
if (!empty($paragraph)) {
array_push($content_list, $paragraph);
}
foreach ($content_list as $paragraph) {
echo '<p>' . $paragraph . "</p>\n";
}
echo '<br>';
}
}
if (!$output) {
echo "<p class=\"info\">[該地圖無對話內容]</p>\n<br>";
}
}
$maps = rxdata_load($folder . 'MapInfos.rxdata');
ksort($maps);
$additional_title = '';
if (isset($_GET['i'])) {
$map_id = intval($_GET['i']);
if (isset($maps[$map_id])) {
$map_name = $maps[$map_id]->name;
$additional_title = $map_name . ' - ';
}
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title><?php echo $additional_title; ?>哀姬·夢魂燕</title>
<link href="styles/main.css" rel="stylesheet" type="text/css">
<style>
.info {
color: grey;
font-family: '楷體';
}
</style>
</head>
<body>
<?php
if (isset($map_id)):
show_dialogs($map_id);
elseif (isset($_GET['all'])):
foreach ($maps as $id => $map) {
show_dialogs($id, true);
}
else:
?>
<p>[<a href="?all">查看全部對話</a>]</p>
<table width="500" border="1" cellpadding="4">
<tbody>
<tr>
<th scope="col">地圖ID</th>
<th scope="col">地圖名稱</th>
<th scope="col">地圖尺寸</th>
<th scope="col">事件數量</th>
</tr>
<?php
foreach ($maps as $id => $map):
$mapfile = get_map($id);
?>
<tr align="center">
<td><?php echo $id; ?></td>
<td align="left"><a href="?i=<?php echo $id; ?>"><?php echo $map->name; ?></a></td>
<td><?php printf('%dx%d', $mapfile->width, $mapfile->height); ?></td>
<td><?php echo count($mapfile->events); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</body>
</html>