Skip to content

Commit

Permalink
Fixup all command scripts - namespace handling
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jul 21, 2017
1 parent 26ab95e commit a506ed3
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 30 deletions.
14 changes: 8 additions & 6 deletions install/scripts/commands/ase_export.py
Expand Up @@ -28,13 +28,15 @@ def execute():
author = "Richard Bartlett, some additions by greebo and tels"
version = "0.9"

import darkradiant as dr

# Check if we have a valid selection

selectionInfo = GlobalSelectionSystem.getSelectionInfo()

# Don't allow empty selections or selected components only
if selectionInfo.totalCount == 0 or selectionInfo.totalCount == selectionInfo.componentCount:
errMsg = GlobalDialogManager.createMessageBox('No selection', 'Nothing selected, cannot run exporter.', Dialog.ERROR)
errMsg = GlobalDialogManager.createMessageBox('No selection', 'Nothing selected, cannot run exporter.', dr.Dialog.ERROR)
errMsg.run()
return

Expand Down Expand Up @@ -117,7 +119,7 @@ def processPrimitive(scenenode):
return

# Traversor class to visit child primitives of entities
class nodeVisitor(SceneNodeVisitor):
class nodeVisitor(dr.SceneNodeVisitor):
def pre(self, scenenode):
# Brush?
if scenenode.isBrush():
Expand All @@ -129,7 +131,7 @@ def pre(self, scenenode):
# Traverse all child nodes, regardless of type
return 1

class dataCollector(SelectionVisitor):
class dataCollector(dr.SelectionVisitor):
def visit(self, scenenode):

if scenenode.isBrush() or scenenode.isPatch():
Expand Down Expand Up @@ -161,7 +163,7 @@ def visit(self, scenenode):
exportCaulkHandle = dialog.addCheckbox("Export caulked faces")
dialog.setElementValue(exportCaulkHandle, GlobalRegistry.get('user/scripts/aseExport/exportcaulk'))

if dialog.run() == Dialog.OK:
if dialog.run() == dr.Dialog.OK:
fullpath = dialog.getElementValue(pathHandle) + '/' + dialog.getElementValue(fileHandle)
if not fullpath.endswith('.ase'):
fullpath = fullpath + '.ase'
Expand All @@ -175,8 +177,8 @@ def visit(self, scenenode):
try:
file = open(fullpath, 'r')
file.close()
prompt = GlobalDialogManager.createMessageBox('Warning', 'The file ' + fullpath + ' already exists. Do you wish to overwrite it?', Dialog.ASK)
if prompt.run() == Dialog.YES:
prompt = GlobalDialogManager.createMessageBox('Warning', 'The file ' + fullpath + ' already exists. Do you wish to overwrite it?', dr.Dialog.ASK)
if prompt.run() == dr.Dialog.YES:
overwrite = True
else:
overwrite = False
Expand Down
14 changes: 8 additions & 6 deletions install/scripts/commands/ase_export_blend.py
Expand Up @@ -28,13 +28,15 @@ def execute():
author = "Richard Bartlett, some additions by greebo and tels"
version = "0.71"

import darkradiant as dr

# Check if we have a valid selection
#import time
selectionInfo = GlobalSelectionSystem.getSelectionInfo()

# Don't allow empty selections or selected components only
if selectionInfo.totalCount == 0 or selectionInfo.totalCount == selectionInfo.componentCount:
errMsg = GlobalDialogManager.createMessageBox('No selection', 'Nothing selected, cannot run exporter.', Dialog.ERROR)
errMsg = GlobalDialogManager.createMessageBox('No selection', 'Nothing selected, cannot run exporter.', dr.Dialog.ERROR)
errMsg.run()
return

Expand Down Expand Up @@ -192,7 +194,7 @@ def processPrimitive(scenenode):
return

# Traversor class to visit child primitives of entities
class nodeVisitor(SceneNodeVisitor):
class nodeVisitor(dr.SceneNodeVisitor):
def pre(self, scenenode):
# Brush?
if scenenode.isBrush():
Expand All @@ -204,7 +206,7 @@ def pre(self, scenenode):
# Traverse all child nodes, regardless of type
return 1

class dataCollector(SelectionVisitor):
class dataCollector(dr.SelectionVisitor):
def visit(self, scenenode):

if scenenode.isBrush() or scenenode.isPatch():
Expand Down Expand Up @@ -238,7 +240,7 @@ def visit(self, scenenode):
# Add a Spin Button for blending and one for random height
#blendHeightHandle = dialog.addSpinButton("Level of blending in percent",0,1,0.05,2)
#blendRandomnessHandle = dialog.addSpinButton("Randomness",0,1,0.05,2)
if dialog.run() == Dialog.OK:
if dialog.run() == dr.Dialog.OK:
fullpath = dialog.getElementValue(pathHandle) + '/' + dialog.getElementValue(fileHandle)
if not fullpath.endswith('.ase'):
fullpath = fullpath + '.ase'
Expand All @@ -252,8 +254,8 @@ def visit(self, scenenode):
try:
file = open(fullpath, 'r')
file.close()
prompt = GlobalDialogManager.createMessageBox('Warning', 'The file ' + fullpath + ' already exists. Do you wish to overwrite it?', Dialog.ASK)
if prompt.run() == Dialog.YES:
prompt = GlobalDialogManager.createMessageBox('Warning', 'The file ' + fullpath + ' already exists. Do you wish to overwrite it?', dr.Dialog.ASK)
if prompt.run() == dr.Dialog.YES:
overwrite = True
else:
overwrite = False
Expand Down
6 changes: 4 additions & 2 deletions install/scripts/commands/check_for_invalid_visportals.py
Expand Up @@ -32,7 +32,9 @@ class VisportalResults(object):
results = VisportalResults()
visportalShader = 'textures/editor/visportal'

class VisportalChecker(SceneNodeVisitor):
import darkradiant as dr

class VisportalChecker(dr.SceneNodeVisitor):
def pre(self, node):
if node.isBrush():
brush = node.getBrush()
Expand Down Expand Up @@ -73,7 +75,7 @@ def pre(self, node):

msg += 'The problematic visportals have been highlighted.'

GlobalDialogManager.createMessageBox('Visportal Test Results', msg, Dialog.CONFIRM).run()
GlobalDialogManager.createMessageBox('Visportal Test Results', msg, dr.Dialog.CONFIRM).run()

if __executeCommand__:
execute()
20 changes: 12 additions & 8 deletions install/scripts/commands/convert_to_ase_and_replace.py
Expand Up @@ -28,24 +28,26 @@ def execute():
author = "Richard Bartlett, some additions by greebo"
version = "0.7"

import darkradiant as dr

# Check if we have a valid selection

selectionInfo = GlobalSelectionSystem.getSelectionInfo()

# Don't allow empty selections or selected components only
if selectionInfo.totalCount == 0 or selectionInfo.totalCount == selectionInfo.componentCount:
errMsg = GlobalDialogManager.createMessageBox('No selection', 'Nothing selected, cannot run exporter.', Dialog.ERROR)
errMsg = GlobalDialogManager.createMessageBox('No selection', 'Nothing selected, cannot run exporter.', dr.Dialog.ERROR)
errMsg.run()
return

if selectionInfo.entityCount != 1:
errMsg = GlobalDialogManager.createMessageBox('Wrong selection', 'Please select exactly one func_static.', Dialog.ERROR)
errMsg = GlobalDialogManager.createMessageBox('Wrong selection', 'Please select exactly one func_static.', dr.Dialog.ERROR)
errMsg.run()
return

if not GlobalRegistry.get('user/scripts/aseExport/initialUserWarning') == '1':
GlobalRegistry.set('user/scripts/aseExport/initialUserWarning', '1')
warningMsg = GlobalDialogManager.createMessageBox('Careful', 'This option will export the selected func_static to ASE and replace your entity with the newly created model.\nThe currently selected func_static will be DELETED. You can undo this operation, but know what you''re doing!', Dialog.WARNING)
warningMsg = GlobalDialogManager.createMessageBox('Careful', 'This option will export the selected func_static to ASE and replace your entity with the newly created model.\nThe currently selected func_static will be DELETED. You can undo this operation, but know what you''re doing!', dr.Dialog.WARNING)
warningMsg.run()

shaderlist = []
Expand Down Expand Up @@ -117,7 +119,7 @@ def processPrimitive(scenenode):
return

# Traversor class to visit child primitives of entities
class nodeVisitor(SceneNodeVisitor):
class nodeVisitor(dr.SceneNodeVisitor):
def pre(self, scenenode):
# Brush?
if scenenode.isBrush():
Expand All @@ -129,7 +131,8 @@ def pre(self, scenenode):
# Traverse all child nodes, regardless of type
return 1

class dataCollector(SelectionVisitor):
class dataCollector(dr.SelectionVisitor):
from darkradiant import Vector3
fs_origin = Vector3(0,0,0)
fs = 0

Expand All @@ -138,6 +141,7 @@ def visit(self, scenenode):
processPrimitive(scenenode)
elif scenenode.isEntity():
import re
from darkradiant import Vector3

# greebo: Found an entity, this could be a func_static or similar
# Traverse children of this entity using a new walker
Expand Down Expand Up @@ -175,7 +179,7 @@ def visit(self, scenenode):
pathHandle = dialog.addPathEntry("Save path:", True)
dialog.setElementValue(pathHandle, GlobalRegistry.get('user/scripts/aseExport/recentPath'))

if dialog.run() == Dialog.OK:
if dialog.run() == dr.Dialog.OK:
fullpath = dialog.getElementValue(pathHandle) + '/' + dialog.getElementValue(fileHandle)
if not fullpath.endswith('.ase'):
fullpath = fullpath + '.ase'
Expand All @@ -187,8 +191,8 @@ def visit(self, scenenode):
try:
file = open(fullpath, 'r')
file.close()
prompt = GlobalDialogManager.createMessageBox('Warning', 'The file ' + fullpath + ' already exists. Do you wish to overwrite it?', Dialog.ASK)
if prompt.run() == Dialog.YES:
prompt = GlobalDialogManager.createMessageBox('Warning', 'The file ' + fullpath + ' already exists. Do you wish to overwrite it?', dr.Dialog.ASK)
if prompt.run() == dr.Dialog.YES:
overwrite = True
else:
overwrite = False
Expand Down
5 changes: 5 additions & 0 deletions install/scripts/commands/example.py
Expand Up @@ -7,6 +7,11 @@ def execute():
shader = GlobalShaderSystem.getShaderForName('bc_rat')
print(shader.getName())

# the "Global*" variables like GlobalShaderSystem are already exposed to this scripts
# The rest needs to imported from the darkradiant module and referred to by the prefix "dr"
import darkradiant as dr
GlobalDialogManager.createMessageBox('Example Box', str(e), dr.Dialog.ERROR).run()

# __executeCommand__ evaluates to true after DarkRadiant has successfully initialised
if __executeCommand__:
execute()
5 changes: 4 additions & 1 deletion install/scripts/commands/patchsplitter.py
Expand Up @@ -12,6 +12,7 @@ class TooFewVerts(Exception): pass
class Vert:
"""Holds coords for one patch control vertex."""
def __init__(self, vertex, texcoord):
from darkradiant import Vector3, Vector2
self.vertex = Vector3(vertex)
self.texcoord = Vector2(texcoord)

Expand Down Expand Up @@ -252,8 +253,10 @@ def getSelectedVertsLine(patch, patchdata):
patch.setSelected(True)
newpatch.setSelected(True)

import darkradiant as dr

if __executeCommand__:
try:
execute()
except Exception as e:
GlobalDialogManager.createMessageBox('Patch Splitter', str(e), Dialog.ERROR).run()
GlobalDialogManager.createMessageBox('Patch Splitter', str(e), dr.Dialog.ERROR).run()
6 changes: 4 additions & 2 deletions install/scripts/commands/select_all_models_of_type.py
Expand Up @@ -8,7 +8,9 @@ def execute():
# Collect all currently selected models
selectedModelNames = {}

class Walker(SelectionVisitor) :
import darkradiant as dr

class Walker(dr.SelectionVisitor) :
def visit(self, node):
# Try to "cast" the node to an entity
entity = node.getEntity()
Expand All @@ -23,7 +25,7 @@ def visit(self, node):
print('Unique models currently selected: ' + str(len(selectedModelNames)))

# Now traverse the scenegraph, selecting all of the same names
class SceneWalker(SceneNodeVisitor) :
class SceneWalker(dr.SceneNodeVisitor) :
def pre(self, node):

# Try to "cast" the node to an entity
Expand Down
13 changes: 8 additions & 5 deletions install/scripts/commands/test_targets.py
Expand Up @@ -14,12 +14,15 @@
def execute():
g_targets = {} # entityname : [targets]
g_missing = {} # entityname : [missingtargets]
class TargetFinder(SceneNodeVisitor):

import darkradiant as dr

class TargetFinder(dr.SceneNodeVisitor):
def pre(self, node):
if node.isEntity():
n = node.getEntity()
name = n.getKeyValue('name')
targs = [t.second for t in n.getKeyValuePairs('target')]
targs = [t[1] for t in n.getKeyValuePairs('target')]
g_targets[name] = targs
return 1
# Instantiate a new walker object and get list of entities/targets
Expand All @@ -40,7 +43,7 @@ def pre(self, node):
msg = '%d entities found with %d targets' % (len(entities), targetcount) + '\n\n'
if not g_missing:
msg += 'No missing targets found'
GlobalDialogManager.createMessageBox('Missing targets', msg, Dialog.CONFIRM).run()
GlobalDialogManager.createMessageBox('Missing targets', msg, dr.Dialog.CONFIRM).run()
else:
msg += 'Missing targets:\n'
for ent in g_missing.keys():
Expand All @@ -49,8 +52,8 @@ def pre(self, node):
print(msg) # output to console
msg += "\nThe list of missing targets has been printed to the console."
msg += "\n\nDo you want to select all entities with missing targets?"
response = GlobalDialogManager.createMessageBox('Missing targets', msg, Dialog.ASK).run()
if response == Dialog.YES:
response = GlobalDialogManager.createMessageBox('Missing targets', msg, dr.Dialog.ASK).run()
if response == dr.Dialog.YES:
class Selector(SceneNodeVisitor):
def pre(self, node):
if node.isEntity() and node.getEntity().getKeyValue('name') in g_missing.keys():
Expand Down

0 comments on commit a506ed3

Please sign in to comment.