瀏覽代碼

add tools

rachels 2 年之前
父節點
當前提交
b9edb16b32
共有 7 個文件被更改,包括 242 次插入0 次删除
  1. 31 0
      tools/check_consistency.py
  2. 36 0
      tools/check_images.py
  3. 39 0
      tools/check_imageso.py
  4. 二進制
      tools/txt2gam.exe
  5. 44 0
      tools/txtmerge.py
  6. 46 0
      tools/txtsplit.py
  7. 46 0
      tools/txtsplit3.py

+ 31 - 0
tools/check_consistency.py

@@ -0,0 +1,31 @@
+#!/usr/bin/env python
+# checks to make sure that mod_public_WC.qproj is in sync with the location files
+
+import os
+import sys
+import re
+import io
+import xml.etree.ElementTree as ET
+import os.path
+
+# read the project xml file first
+tree = ET.parse('mod_public_WC.qproj')
+root = tree.getroot()
+
+
+xml_locations = []
+os_locations = os.listdir("locations")
+
+print "Locations missing from ./locations/:"
+for location in root.iter('Location'):
+    name = location.attrib['name'].replace("$","_")
+    xml_locations.append(name)
+    
+    if name not in os_locations:
+        print name
+
+
+print "Locations missing from .qproj:"
+for name in os_locations:
+    if name not in xml_locations:
+        print name

+ 36 - 0
tools/check_images.py

@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+
+import io
+import os
+import re
+import sys
+
+#path = os.getcwd()
+#print path
+
+startpattern = """mod/public_WC/"""
+imgFormats = ['jpg','jpeg','gif','png','mp4']
+
+images = []
+
+ifile = io.open(
+    "mod_public_WC.txt",
+    mode='rt',
+    encoding='utf-16'
+)
+text = ifile.read()
+for match in re.finditer(r"mod/public_WC/.+?[.](gif|jpg|jpeg|png|mp4)", text, flags=re.U):
+    imgfile = match.group().encode("utf-8")
+    randmatch = re.search(r"'\s*[+]\s*rand\s*[(]\s*(\d+)\s*[,]\s*(\d+)\s*[)]\s*[+]\s*'", imgfile)
+    if randmatch != None:
+        for i in range(int(randmatch.group(1)), 1+int(randmatch.group(2))):
+            images.append(re.sub(r"'\s*[+]\s*rand\s*[(].*?[)]\s*[+]\s*'", str(i), imgfile))
+    else:
+        images.append(imgfile)
+        
+ifile.close()
+
+for image in images:
+    if not re.search(r"[<$]", image) and not os.path.isfile(image):
+        print "Image not found:", image
+

+ 39 - 0
tools/check_imageso.py

@@ -0,0 +1,39 @@
+#!/usr/bin/env python
+
+import io
+import os
+import re
+
+#path = os.getcwd()
+#print path
+
+startpattern = """images/"""
+imgFormats = ['jpg','gif']
+
+infile = io.open('mod_public_WC.txt',mode='r',encoding='utf-16')
+lines = infile.readlines()
+
+images = []
+
+for name in os.listdir("locations"):
+    ifile = io.open(
+        os.path.join("locations", name),
+        mode='rt',
+        encoding='utf-8'
+    )
+    text = ifile.read()
+    for match in re.finditer(r"images.+?[.](gif|jpg|png)", text, flags=re.U):
+        imgfile = match.group().encode("utf-8")
+        randmatch = re.search(r"'\s*[+]\s*rand\s*[(]\s*(\d+)\s*[,]\s*(\d+)\s*[)]\s*[+]\s*'", imgfile)
+        if randmatch != None:
+            for i in range(int(randmatch.group(1)), 1+int(randmatch.group(2))):
+                images.append(re.sub(r"'\s*[+]\s*rand\s*[(].*?[)]\s*[+]\s*'", str(i), imgfile))
+        else:
+            images.append(imgfile)
+    
+    ifile.close()
+
+
+for image in images:
+    if not re.search(r"[<$]", image) and not os.path.isfile(image):
+        print "Image not found:", image

二進制
tools/txt2gam.exe


+ 44 - 0
tools/txtmerge.py

@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+# usage: txtmerge.py <input_dir> <output_file_name> 
+# does the exact opposite of txtsplit.py
+
+import os
+import sys
+import re
+import io 
+import xml.etree.ElementTree as ET
+
+assert len(sys.argv) == 3, "usage:\ntxtmerge.py <input_dir> <output_file_name>"
+idir = str(sys.argv[1])
+oname = str(sys.argv[2])
+
+# read the project xml file first
+# let's do this later in order to implement directory structure
+tree = ET.parse('mod_public_WC.qproj')
+root = tree.getroot()
+
+
+ofile = io.open(oname, 'w', encoding='utf-16', newline='\r\n')
+
+for location in root.iter('Location'):
+    iname = location.attrib['name']
+    iname = iname.replace("$","_")
+
+    try:
+        ifile = io.open(os.path.join(idir,iname + '.qsrc'), 'rt', encoding='utf-8')
+        text = ifile.read()
+
+        # make sure there's a line at the end of file
+        # (why wouldn't there be one? WINDOWS!
+        if text[-1] != u'\n':
+            text += u'\n\n'
+
+        ofile.write(text)
+        ifile.close()
+    except IOError:
+        print("WARNING: missing location %s" % iname)
+        pass
+
+ofile.close()
+    
+        

+ 46 - 0
tools/txtsplit.py

@@ -0,0 +1,46 @@
+#!/usr/bin/env python
+# usage: txtsplit.py <input_file_name> <output_dir>
+# splits a txt2gam file into individual location files
+# encoded in utf-8, for git to better handle
+
+import os
+import sys
+import re
+import io
+import xml.etree.ElementTree as ET
+
+assert len(sys.argv) == 3, "usage:\ntxtsplit.py <input_file_name> <output_dir>"
+iname = str(sys.argv[1])
+odir = str(sys.argv[2])
+
+# read the project xml file first
+# let's do this later in order to implement directory structure
+"""
+tree = ET.parse('mod_public_WC.qproj')
+root = tree.getroot()
+"""
+
+ifile = io.open(iname, 'rt', encoding='utf-16')
+
+counter = 1
+
+oname = None
+firstline = ifile.readline().replace(u'\ufeff','')
+match = re.search(ur'^#\s(\$?[_.\w]+)$', firstline)
+if match:
+    oname = os.path.join(odir, match.group(1).replace("$","_") + '.qsrc' )
+    counter += 1
+assert oname, "file is in the wrong format, must start with a location name"
+
+ofile = io.open(oname, 'w', encoding='utf-8')
+ofile.write(firstline)
+
+for line in ifile:
+    match = re.search(ur'^#\s(\$?[_.\w]+)$', line)
+    if match:
+        ofile.close()
+        oname = os.path.join(odir, match.group(1).replace("$","_") + '.qsrc' )
+        counter += 1
+        ofile = io.open(oname, 'w', encoding='utf-8')
+    ofile.write(line)
+        

+ 46 - 0
tools/txtsplit3.py

@@ -0,0 +1,46 @@
+#!/usr/bin/env python3
+# usage: txtsplit.py <input_file_name> <output_dir>
+# splits a txt2gam file into individual location files
+# encoded in utf-8, for git to better handle
+
+import os
+import sys
+import re
+import io
+import xml.etree.ElementTree as ET
+
+assert len(sys.argv) == 3, "usage:\ntxtsplit.py <input_file_name> <output_dir>"
+iname = str(sys.argv[1])
+odir = str(sys.argv[2])
+
+# read the project xml file first
+# let's do this later in order to implement directory structure
+"""
+tree = ET.parse('mod_public_WC.qproj')
+root = tree.getroot()
+"""
+
+ifile = io.open(iname, 'rt', encoding='utf-16')
+
+counter = 1
+
+oname = None
+firstline = ifile.readline().replace(u'\ufeff','')
+match = re.search('^#\s(\$?[_.\w]+)$', firstline)
+if match:
+    oname = os.path.join(odir, match.group(1).replace("$","_") + '.qsrc' )
+    counter += 1
+assert oname, "file is in the wrong format, must start with a location name"
+
+ofile = io.open(oname, 'w', encoding='utf-8')
+ofile.write(firstline)
+
+for line in ifile:
+    match = re.search('^#\s(\$?[_.\w]+)$', line)
+    if match:
+        ofile.close()
+        oname = os.path.join(odir, match.group(1).replace("$","_") + '.qsrc' )
+        counter += 1
+        ofile = io.open(oname, 'w', encoding='utf-8')
+    ofile.write(line)
+