Mercurial > hg > batmud > maputils
changeset 2387:53c34aaf4515
Add PHP kludge for generating batclient.xml and necessary Makefile rules for
doing it when loc files change, but only if PHP interpreter can be found.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 06 Nov 2021 18:01:23 +0200 |
parents | 004131475fb7 |
children | e845f54be995 |
files | src/generate_batclient_xml.php world/Makefile |
diffstat | 2 files changed, 56 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/generate_batclient_xml.php Sat Nov 06 18:01:23 2021 +0200 @@ -0,0 +1,46 @@ +#!/usr/bin/php +<?php +// Prevent non-cli execution +if (php_sapi_name() != "cli" || !empty($_SERVER["REMOTE_ADDR"])) + die("You can only run this script as a commandline application.\n"); + +if (count($argv) < 5) +{ + die("Usage: ".$argv[0]." <path to mkloc> <path to loc files> <path to world.inc.ph> <outputfile.xml>\n"); +} + +// Stub config +$binMkLoc = $argv[1]; +$cfg["pathLocFiles"] = $argv[2]; +$cfg["worldConfig"] = $argv[3]; +$outFilename = $argv[4]; + + +// Check sanity +if (!file_exists($binMkLoc)) + die($binMkLoc." not found. Maputils package not built, or some other error occured.\n"); + +if (!file_exists($cfg["worldConfig"])) + die("Required continent/tradelane configuration file '".$cfg["worldConfig"]."' not found.\n"); + +require $cfg["worldConfig"]; + + +// Build and run command +$tmp = escapeshellcmd($binMkLoc)." -v -o ".escapeshellarg($outFilename)." -G xml "; + +foreach ($continentList as $cname => $cdata) +{ + if ($cdata[CTI_HAS_MAP] && $cdata[CTI_REG_CONT]) + { + // has a map + $tmp .= + "-l ".escapeshellarg($cfg["pathLocFiles"].$cname.".loc")." ". + "-c ".escapeshellarg($cdata[CTI_NAME])." ". + "-x ".escapeshellarg($worldMap["ox"] + $cdata[CTI_XOFFS])." ". + "-y ".escapeshellarg($worldMap["oy"] + $cdata[CTI_YOFFS])." "; + } +} + +passthru($tmp) == 0 or die("Error executing: ".$tmp."\n"); +?>
--- a/world/Makefile Sat Nov 06 17:59:29 2021 +0200 +++ b/world/Makefile Sat Nov 06 18:01:23 2021 +0200 @@ -68,6 +68,16 @@ changelog: changelog.txt @touch $@ +# Build batclient.xml +HAVE_PHP ?= $(shell php --version > /dev/null && echo "yes") +ifeq ($(HAVE_PHP),yes) +TARGETS += batclient.xml + +batclient.xml: $(addsuffix .loc,$(WORLD_MAPS)) $(MKLOC_BIN) ../www/world.inc.php + php ../src/generate_batclient_xml.php $(MKLOC_BIN) ./ ../www/world.inc.php $@ + +endif + # Upload changed files to site upload: $(TARGETS) $(LOCLIST) changelog.txt