From 96d5f0fd05097da4dee10dd7490baa315b69c1b8 Mon Sep 17 00:00:00 2001 From: cavesomething Date: Wed, 5 May 2010 10:46:35 +0000 Subject: [PATCH] Allow include blocks to use either relative or absolute paths to reference other .msg files. Maps still need to specify a full path in the slaying field of an event say. git-svn-id: svn://svn.code.sf.net/p/crossfire/code/maps/trunk@13121 282e977c-c81d-0410-88c4-b93c2d0d6712 --- python/dialog/npc_dialog.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/python/dialog/npc_dialog.py b/python/dialog/npc_dialog.py index 05c225024..6be508714 100644 --- a/python/dialog/npc_dialog.py +++ b/python/dialog/npc_dialog.py @@ -47,13 +47,16 @@ import cjson location = "defaultdialognamespace" -def parseJSON(filename): +def parseJSON(filename, relpath): global location parameters = [] for filenm in filename: - filepath = os.path.join(Crossfire.DataDirectory(), - Crossfire.MapDirectory(), - filenm) + if filenm[0] == "/": + filepath = os.path.join(Crossfire.DataDirectory(), + Crossfire.MapDirectory(), filenm[1:]) + else: + filepath = os.path.join(Crossfire.DataDirectory(), + Crossfire.MapDirectory(), relpath, filenm) try: f = open(filepath,'rb') except: @@ -79,7 +82,7 @@ def parseJSON(filename): if shouldinclude == 1: # this isn't a 'real' rule, so we don't include it, but we do # include the results of parsing it. - parameters.extend(parseJSON(newfiles)) + parameters.extend(parseJSON(newfiles, os.path.dirname(filepath))) else: Crossfire.Log(Crossfire.LogDebug, "Ignoring NPC dialog from %s, conditions not met" % newfiles) else: @@ -91,7 +94,7 @@ npc = Crossfire.WhoAmI() player = Crossfire.WhoIsActivator() if (Crossfire.ScriptParameters() != None): filename = Crossfire.ScriptParameters() - dialogs = parseJSON([filename]) + dialogs = parseJSON([filename], '') speech = Dialog(player, npc, location) index = 0;