Skip to content

Instantly share code, notes, and snippets.

@mrflay
Created April 11, 2013 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrflay/5364845 to your computer and use it in GitHub Desktop.
Save mrflay/5364845 to your computer and use it in GitHub Desktop.
Quick and dirty script for generating ZGM style visitor templates.
#!python
#
# Quick and dirty script for generating ZGM style visitor templates.
#
# Usage: Edit the 'dirs' and 'patterns' below to suit your project, then simply
# run the script in a python shell. The templates will be written to the
# templates.txt file in the current directory.
#
# Run 'depew -IT /path/to/your/island.pew templates.txt' to import the
# templates (note that all existing objects will be deleted)
import os
# The name of the generated template file.
template_filename = 'templates.txt'
# Root directory (note the double slashes for separating directories)
root = 'p:\\ca'
# Directories to look for models in (subdirs of root)
dirs = ['buildings','misc','plants','roads','rocks','signs']
# Pattern definitions
# Models are associated with a category using simple filename based pattern.
# {
# 'path':'foo', (optional) matches if the directory contains the string 'foo'
# 'name':'bar', (optional) matches if the filename contains the string 'bar'
# 'category':'industry', (required) the category to associate the model with (see below)
# 'match':'exact' (optional) if specified, only matches if 'path' and 'name' matches
# } the directory and filename completly.
patterns = [
{'path':'misc', 'category':'various'},
{'path':'roads', 'category':'roads'},
{'path':'rocks', 'category':'rocks'},
{'path':'signs', 'category':'signs'},
{'path':'plants','category':'plants'},
{'path':'buildings', 'category':'civilian'},
{'path':'sidewalks','category':'sidewalks'},
{'name':'army','category':'military'},
{'name':'stan.p3d','category':'military','match':'exact'},
{'name':'stan_east','category':'military'},
{'name':'mash','category':'military'},
{'name':'camo','category':'military'},
{'name':'ss_hangar','category':'military'},
{'name':'vez.p3d','category':'military','match':'exact'},
{'name':'ammo','category':'military'},
{'name':'fortress','category':'military'},
{'name':'beden_dekor','category':'military'},
{'name':'garaz','category':'military'},
{'name':'tovarna','category':'industry'},
{'name':'pristresek','category':'industry'},
{'name':'hlaska','category':'industry'},
{'name':'pristresek','category':'industry'},
{'name':'fuelstation','category':'industry'},
{'name':'hlidac','category':'industry'},
{'name':'nasypka','category':'industry'},
{'name':'trafo','category':'industry'},
{'name':'repair','category':'industry'},
{'name':'komin','category':'industry'},
{'name':'hangar_02','category':'industry'},
{'name':'budova','category':'industry'},
{'name':'benzina','category':'industry'},
{'name':'vez_ropa','category':'industry'},
{'name':'strazni_vez','category':'industry'},
{'name':'sign','category':'signs'},
{'name':'nabrezi','category':'pier'},
{'name':'molo','category':'pier'},
{'name':'majak','category':'pier'},
{'name':'zed','category':'walls'},
{'name':'ohrada_popelnice','category':'walls'},
{'name':'plot','category':'fences'},
{'name':'plutek','category':'fences'},
{'name':'pletivo','category':'fences'},
{'name':'zabradi_pruhovane','category':'fences'},
{'name':'zidka','category':'fences'},
{'name':'ruin','category':'ruins'},
{'name':'zboreny','category':'ruins'},
{'name':'afbarabizna','category':'ruins'},
{'name':'mesto','category':'ruins'},
{'name':'diera','category':'ruins'},
{'name':'wreck','category':'wrecks'},
]
# Category definitions
# Defines the available 'categories' and how the associated objects will displayed in visitor.
categories = {
# artificial
'various':{'name':'00_various_00','fg':'RGB_VARIOUS','bg':'RGB_BLACK','type':'ARTIFICIAL','marker':'RECTANGLE'},
'civilian':{'name':'01_civilian_01','fg':'RGB_CIVILIAN','bg':'RGB_BLACK','type':'ARTIFICIAL','marker':'RECTANGLE'},
'industry':{'name':'02_industry_02','fg':'RGB_INDUSTRY','bg':'RGB_BLACK','type':'ARTIFICIAL','marker':'RECTANGLE'},
'military':{'name':'03_military_03','fg':'RGB_MILITARY','bg':'RGB_BLACK','type':'ARTIFICIAL','marker':'RECTANGLE'},
'cargo':{'name':'04_cargo_04','fg':'RGB_CARGO','bg':'RGB_BLACK','type':'ARTIFICIAL','marker':'RECTANGLE'},
'signs':{'name':'05_signs_05','fg':'RGB_SIGNS','bg':'RGB_BLACK','type':'ARTIFICIAL','marker':'RECTANGLE'},
'walls':{'name':'06_walls_06','fg':'RGB_WALLS','bg':'RGB_BLACK','type':'ARTIFICIAL','marker':'RECTANGLE'},
'fences':{'name':'07_fences_07','fg':'RGB_FENCES','bg':'RGB_BLACK','type':'ARTIFICIAL','marker':'RECTANGLE'},
'pipelines':{'name':'08_pipelines_08','fg':'RGB_PIPELINES','bg':'RGB_BLACK','type':'ARTIFICIAL','marker':'RECTANGLE'},
'powerlines':{'name':'09_powerlines_09','fg':'RGB_POWERLINES','bg':'RGB_BLACK','type':'ARTIFICIAL','marker':'RECTANGLE'},
'roads':{'name':'10_roads_10','fg':'RGB_ROADS','bg':'RGB_BLACK','type':'ARTIFICIAL','marker':'RECTANGLE'},
'rails':{'name':'11_rails_11','fg':'RGB_RAILS','bg':'RGB_BLACK','type':'ARTIFICIAL','marker':'RECTANGLE'},
'runway':{'name':'12_runway_12','fg':'RGB_RUNWAY','bg':'RGB_BLACK','type':'ARTIFICIAL','marker':'RECTANGLE'},
'sidewalks':{'name':'13_sidewalks_13','fg':'RGB_SIDEWALKS','bg':'RGB_RED','type':'ARTIFICIAL','marker':'RECTANGLE'},
'pier':{'name':'14_pier_14','fg':'RGB_PIER','bg':'RGB_BLACK','type':'ARTIFICIAL','marker':'RECTANGLE'},
'ruins':{'name':'15_ruins_15','fg':'RGB_RUINS','bg':'RGB_BLACK','type':'ARTIFICIAL','marker':'RECTANGLE'},
'wrecks':{'name':'16_wrecks_16','fg':'RGB_WRECKS','bg':'RGB_RED','type':'ARTIFICIAL','marker':'RECTANGLE'},
# natural
'trees':{'name':'00_trees_00','fg':'RGB_TREES','bg':'RGB_BLACK','type':'NATURAL','marker':'ELLIPSE'},
'bushes':{'name':'01_bushes_01','fg':'RGB_BUSHES','bg':'RGB_BLACK','type':'NATURAL','marker':'ELLIPSE'},
'plants':{'name':'03_plants_03','fg':'RGB_PLANTS','bg':'RGB_BLACK','type':'NATURAL','marker':'ELLIPSE'},
'deadtrees':{'name':'04_deadtrees_04','fg':'RGB_DEADTREES','bg':'RGB_BLACK','type':'NATURAL','marker':'ELLIPSE'},
'water':{'name':'05_water_05','fg':'RGB_WATER','bg':'RGB_BLACK','type':'NATURAL','marker':'ELLIPSE'},
'rocks':{'name':'06_rocks_06','fg':'RGB_ROCKS','bg':'RGB_BLACK','type':'NATURAL','marker':'ELLIPSE'},
}
# Default category
# the category to assocate the model with if none of the patterns matches
default_category = 'various'
#
# no more editing required below this line
#
output=open(template_filename, 'w+')
fmt = """
class Object%d_%s
{
ulObjectType=%s;
ulMarkerType=%s;
ulOutlineColour=%s;
ulObjectColour=%s;
strModelFilename="%s";
strModelName="%s";
};"""
seqnum=0 # object classname sequence number
print >>output, """
#define NATURAL 1
#define ARTIFICIAL 2
#define ROADS 3
#define RECTANGLE 0
#define ELLIPSE 1
#define RGB_DEFAULT -1
#define RGB_BLACK 0x000000
#define RGB_BLUE 0xFF0000
#define RGB_GREEN 0x00FF00
#define RGB_RED 0x0000FF
#define RGB_GREY 0x7F7F7F
#define RGB_YELLOW 0x00FFFF
#define RGB_ORANGE 0x0055FF
#define RGB_DARK_GREEN 0x007F00
#define RGB_VARIOUS 0x00FFFF
#define RGB_CIVILIAN 0xFFFFFF
#define RGB_INDUSTRY 0x0000FF
#define RGB_MILITARY 0x004080
#define RGB_CARGO 0xFFFF80
#define RGB_SIGNS 0xFF80FF
#define RGB_WALLS 0x808080
#define RGB_FENCES 0x808080
#define RGB_PIPELINES 0x4080FF
#define RGB_POWERLINES 0xFF8080
#define RGB_ROADS 0xC0C0C0
#define RGB_RAILS 0xC0C0C0
#define RGB_RUNWAY 0x555555
#define RGB_SIDEWALKS 0xC0C0C0
#define RGB_PIER 0xC08000
#define RGB_RUINS 0x000000
#define RGB_WRECKS 0x000000
#define RGB_TREES 0x008000
#define RGB_BUSHES 0x00FF00
#define RGB_PLANTS 0x00FF00
#define RGB_DEADTREES 0x000000
#define RGB_WATER 0xFF0000
#define RGB_ROCKS 0xC0C0C0
class ObjectTemplate
{
"""
for subdir in dirs:
for dirname, dirnames, filenames in os.walk("%s\\%s" % (root, subdir)):
dname = dirname.lower()
if all([x not in dname for x in ['texture','data']]): # ignore models in data and texture dirs
for filename in filenames:
fname = filename.lower()
if fname.endswith('.p3d'):
# handle invalid characters in filename
name = fname[:-4]
name = name.replace(' ','_')
name = name.replace('-','_')
name = name.replace('!','_')
name = name.replace('.','_')
category_name = default_category
for pattern in patterns:
if pattern.has_key('name') and pattern.has_key('path'):
if pattern['path'] in dname and pattern['name'] in fname:
category_name = pattern['category']
elif pattern.has_key('path'):
if pattern['path'] in dname:
category_name = pattern['category']
elif pattern.has_key('name'):
if pattern.has_key('match') and pattern['match'] == 'exact':
if pattern['name'] == fname:
category_name = pattern['category']
elif pattern['name'] in fname:
category_name = pattern['category']
category = categories[category_name]
name = '%s_%s' % (category['name'], name)
seqnum = seqnum + 1
path = os.path.join(dirname, filename)
s = fmt % (seqnum,name,category['type'],category['marker'],category['bg'],category['fg'],path[3:],name)
print >>output, s
dirnames = filter(lambda x: x.lower() != 'data', dirnames)
print >>output,"};"
output.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment