r1754 - trunk/data/maps

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Tue Jul 11 13:38:52 EDT 2006


Author: div0
Date: 2006-07-11 13:38:52 -0400 (Tue, 11 Jul 2006)
New Revision: 1754

Added:
   trunk/data/maps/entmerge.rb
Log:
ent file to map file merger added. USE WITH CAUTION. IF YOU PLAN TO COMMIT ANY MAP FILE EDITED WITH THIS, COMPILE IT FIRST AND TRY IT OUT BEFORE. THIS SCRIPT HASN'T BEEN TESTED MUCH AND IS LIKELY TO BE BROKEN. YOU HAVE BEEN WARNED.


Added: trunk/data/maps/entmerge.rb
===================================================================
--- trunk/data/maps/entmerge.rb	2006-07-11 16:07:42 UTC (rev 1753)
+++ trunk/data/maps/entmerge.rb	2006-07-11 17:38:52 UTC (rev 1754)
@@ -0,0 +1,155 @@
+#!/usr/bin/ruby
+
+require 'yaml'
+
+def preprocess(s)
+	return s.split(/\r?\n/).find_all() do |l| l[0, 2] != '//' end
+end
+
+base = ARGV[0]
+
+mapstr = File.read("#{base}.map")
+entstr = File.read("#{base}.ent")
+
+# backup
+File.open("#{base}.map~", "w") do |fh|
+	fh.write(mapstr)
+end
+File.open("#{base}.ent~", "w") do |fh|
+	fh.write(entstr)
+end
+
+def brushparse(l, index)
+	brush = []
+	nest = 0
+	while index < l.length()
+		case l[index]
+			when '}'
+				nest -= 1
+				if nest < 0
+					break
+				else
+					brush << '}'
+				end
+			when '{'
+				nest += 1
+				brush << '{'
+			when %r{^(.*)$}
+				brush << $1
+			when ''
+				true
+			else
+				raise SyntaxError, "in brush: " + l[index]
+		end
+		index += 1
+	end
+	return index, brush
+end
+
+def entparse(l, index)
+	entity = {}
+	brushes = []
+	while index < l.length()
+		case l[index]
+			when '}'
+				break
+			when '{'
+				index, brush = brushparse(l, index + 1)
+				brushes << brush
+			when %r{^"([^"]*)" "(.*)"$}
+				entity[$1] = $2
+			when ''
+				true
+			else
+				raise SyntaxError, "in entity: " + l[index]
+		end
+		index += 1
+	end
+	if brushes != []
+		entity[:brushes] = brushes
+	end
+	return index, entity
+end
+
+def mapparse(l)
+	allents = []
+	index = 0
+	while index < l.length()
+		case l[index]
+			when '{'
+				index, entity = entparse(l, index + 1)
+				allents << entity
+			when ''
+				true
+			else
+				raise SyntaxError, "in map: " + l[index]
+		end
+		index += 1
+	end
+	return allents
+end
+
+
+
+def brushout(b)
+	yield '{'
+	b.each() do |l|
+		yield l
+	end
+	yield '}'
+end
+
+def entout(e)
+	yield '{'
+	e.each() do |k, v|
+		next if k == :brushes
+		yield '"%s" "%s"' % [k, v]
+	end
+	if e[:brushes]
+		e[:brushes].each() do |b|
+			brushout(b) do |l|
+				yield l
+			end
+		end
+	end
+	yield '}'
+end
+
+def mapout(entities)
+	entities.each() do |e|
+		entout(e) do |l|
+			yield l
+		end
+	end
+end
+
+map = mapparse(preprocess(mapstr))
+ent = mapparse(preprocess(entstr))
+
+submodels = []
+lights = []
+
+map.each() do |e|
+	case
+		when e['classname'] == 'light'
+			lights << e
+		when e[:brushes]
+			submodels << e[:brushes]
+	end
+end
+
+ent.each() do |e|
+	case
+		when (e['classname'] == 'worldspawn') || (e['model'] && e['model'][0, 1] == '*')
+			e.delete('model')
+			e[:brushes] = submodels.shift()
+	end
+end
+
+File.open("#{base}.map", "w") do |fh|
+	mapout(ent + lights) do |l|
+		fh.puts(l)
+	end
+end
+
+File.unlink("#{base}.ent")


Property changes on: trunk/data/maps/entmerge.rb
___________________________________________________________________
Name: svn:executable
   + *




More information about the nexuiz-commits mailing list