Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for namespaces and clashing names in skin io #223

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions release/scripts/mgear/core/skin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
FILE_JSON_EXT = ".jSkin"
PACK_EXT = ".gSkinPack"

NAMESPACE_REPLACER = "~"
CLASH_REPLACER = "!"

######################################
# Skin getters
######################################
Expand Down Expand Up @@ -200,6 +203,22 @@ def collectData(skinCls, dataDic):
# Skin export
######################################

def clash_and_namespace_fixer(filepath, toFile=True):
# This is a gross approach, but it does work as Windows
# supports ! (or CLASH_REPLACER if changed) but not |
# Same with : Namespaces and NAMESPACE_REPLACER
filedir = os.path.dirname(filepath)
if filedir:
filedir = filedir + "/"
filename = os.path.basename(filepath)
raw_name, extension = os.path.splitext(filename)
if toFile:
filepath = filedir + raw_name.replace(":", NAMESPACE_REPLACER).replace("|", CLASH_REPLACER) + extension
else:
filepath = filedir + raw_name.replace(NAMESPACE_REPLACER, ":").replace(CLASH_REPLACER, "|") + extension

return filepath

def exportSkin(filePath=None, objs=None, *args):
if not objs:
if pm.selected():
Expand All @@ -222,8 +241,7 @@ def exportSkin(filePath=None, objs=None, *args):
filePath = pm.fileDialog2(fileMode=0,
fileFilter=fileFilters)
if filePath:
filePath = filePath[0]

filePath = clash_and_namespace_fixer(filepath=filePath[0], toFile=True)
else:
return False

Expand Down Expand Up @@ -317,7 +335,7 @@ def exportSkinPack(packPath=None, objs=None, use_json=False, *args):
packDic["rootPath"], packName = os.path.split(packPath)

for obj in objs:
fileName = obj.stripNamespace() + file_ext
fileName = clash_and_namespace_fixer(filepath=obj.name(), toFile=True) + file_ext
filePath = os.path.join(packDic["rootPath"], fileName)
if exportSkin(filePath, [obj], use_json):
packDic["packFiles"].append(fileName)
Expand Down Expand Up @@ -448,7 +466,7 @@ def getObjsFromSkinFile(filePath=None, *args):


def importSkin(filePath=None, *args):

filePath = clash_and_namespace_fixer(filepath=filePath, toFile=True)
if not filePath:
f1 = 'mGear Skin (*{0} *{1})'.format(FILE_EXT, FILE_JSON_EXT)
f2 = ";;gSkin Binary (*{0});;jSkin ASCII (*{1})".format(
Expand Down Expand Up @@ -557,7 +575,7 @@ def importSkinPack(filePath=None, *args):
packDic = json.load(fp)
for pFile in packDic["packFiles"]:
filePath = os.path.join(os.path.split(filePath)[0], pFile)
importSkin(filePath, True)
importSkin(clash_and_namespace_fixer(filepath=filePath, toFile=True), True)

######################################
# Skin Copy
Expand Down