Skip to content

Commit

Permalink
Adds the dmitool icon merger from baystation12
Browse files Browse the repository at this point in the history
Credits to GinjaNinja32@bay12 for developing dmitool and
PsiOmegaDelta@bay12 for some of these scripts. Thanks also to
neersighted for reminding me that we need this.

Basically this is like the map merger, except for icons. You can install
a hook using the instructions in the dmitool folder, and it should
automatically merge your DMIs for you. This means you can solve icon
conflicts effortlessly most of the time.
  • Loading branch information
tkdrg committed Nov 28, 2015
1 parent 01edb6d commit 553ce69
Show file tree
Hide file tree
Showing 20 changed files with 1,867 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,9 @@
# needs additional setup, see tools/mapmerge/install.txt
*.dmm merge=merge-dmm

# dmi icon merger hook
# needs additional setup, see tools/dmitool/merging.txt
*.dmi merge=merge-dmi

# force changelog merging to use union
html/changelog.html merge=union
5 changes: 5 additions & 0 deletions tools/dmitool/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Uses PNGJ: https://code.google.com/p/pngj/.

For help, use "java -jar dmitool.jar help".

Requires Java 7.
16 changes: 16 additions & 0 deletions tools/dmitool/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apply plugin: 'java'

repositories {
mavenCentral()
}

dependencies {
compile group: 'ar.com.hjg', name: 'pngj', version: '2.1.0'
}

jar {
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
manifest {
attributes 'Main-Class': 'dmitool.Main'
}
}
8 changes: 8 additions & 0 deletions tools/dmitool/dmimerge.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
java -jar tools/dmitool/dmitool.jar merge $1 $2 $3 $2
if [ "$?" -gt 0 ]
then
echo "Unable to automatically resolve all icon_state conflicts, please merge manually."
exit 1
fi

exit 0
Binary file added tools/dmitool/dmitool.jar
Binary file not shown.
94 changes: 94 additions & 0 deletions tools/dmitool/dmitool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
""" Python 2.7 wrapper for dmitool.
"""

import os
from subprocess import Popen, PIPE

_JAVA_PATH = ["java"]
_DMITOOL_CMD = ["-jar", "dmitool.jar"]

def _dmitool_call(*dmitool_args, **popen_args):
return Popen(_JAVA_PATH + _DMITOOL_CMD + [str(arg) for arg in dmitool_args], **popen_args)

def _safe_parse(dict, key, deferred_value):
try:
dict[key] = deferred_value()
except Exception as e:
print "Could not parse property '%s': %s"%(key, e)
return e
return False

def version():
""" Returns the version as a string. """
stdout, stderr = _dmitool_call("version", stdout=PIPE).communicate()
return str(stdout).strip()

def help():
""" Returns the help text as a string. """
stdout, stderr = _dmitool_call("help", stdout=PIPE).communicate()
return str(stdout).strip()

def info(filepath):
""" Totally not a hack that parses the output from dmitool into a dictionary.
May break at any moment.
"""
subproc = _dmitool_call("info", filepath, stdout=PIPE)
stdout, stderr = subproc.communicate()

result = {}
data = stdout.split(os.linesep)[1:]
#for s in data: print s

#parse header line
if len(data) > 0:
header = data.pop(0).split(",")
#don't need to parse states, it's redundant
_safe_parse(result, "images", lambda: int(header[0].split()[0].strip()))
_safe_parse(result, "size", lambda: header[2].split()[1].strip())

#parse state information
states = []
for item in data:
if not len(item): continue

stateinfo = {}
item = item.split(",", 3)
_safe_parse(stateinfo, "name", lambda: item[0].split()[1].strip(" \""))
_safe_parse(stateinfo, "dirs", lambda: int(item[1].split()[0].strip()))
_safe_parse(stateinfo, "frames", lambda: int(item[2].split()[0].strip()))
if len(item) > 3:
stateinfo["misc"] = item[3]

states.append(stateinfo)

result["states"] = states
return result

def extract_state(input_path, output_path, icon_state, direction=None, frame=None):
""" Extracts an icon state as a png to a given path.
If provided direction should be a string, one of S, N, E, W, SE, SW, NE, NW.
If provided frame should be a frame number or a string of two frame number separated by a dash.
"""
args = ["extract", input_path, icon_state, output_path]
if direction is not None: args.extend(("direction" , str(direction)))
if frame is not None: args.extend(("frame" , str(frame)))
return _dmitool_call(*args)

def import_state(target_path, input_path, icon_state, replace=False, delays=None, rewind=False, loop=None, ismovement=False, direction=None, frame=None):
""" Inserts an input png given by the input_path into the target_path.
"""
args = ["import", target_path, icon_state, input_path]

if replace: args.append("nodup")
if rewind: args.append("rewind")
if ismovement: args.append("movement")
if delays: args.extend(("delays", ",".join(delays)))
if direction is not None: args.extend(("direction", direction))
if frame is not None: args.extend(("frame", frame))

if loop in ("inf", "infinity"):
args.append("loop")
elif loop:
args.extend(("loopn", loop))

return _dmitool_call(*args)
6 changes: 6 additions & 0 deletions tools/dmitool/git_merge_installer.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@echo off
set tab=
echo. >> ../../.git/config
echo [merge "merge-dmi"] >> ../../.git/config
echo %tab%name = iconfile merge driver >> ../../.git/config
echo %tab%driver = ./tools/dmitool/dmimerge.sh %%O %%A %%B >> ../../.git/config
6 changes: 6 additions & 0 deletions tools/dmitool/git_merge_installer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
F="../../.git/config"

echo '' >> $F
echo '[merge "merge-dmi"]' >> $F
echo ' name = iconfile merge driver' >> $F
echo ' driver = ./tools/dmitool/dmimerge.sh %O %A %B' >> $F
14 changes: 14 additions & 0 deletions tools/dmitool/merging.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
1. Install java(http://www.java.com/en/download/index.jsp)
2. Make sure java is in your PATH. To test this, open git bash, and type "java". If it says unknown command, you need to add JAVA/bin to your PATH variable (A guide for this can be found at https://www.java.com/en/download/help/path.xml ).

Merging
The easiest way to do merging is to install the merge driver. For this, open `-tg-station/.git/config` in a text editor, and paste the following lines to the end of it:

[merge "merge-dmi"]
name = iconfile merge driver
driver = ./tools/dmitool/dmimerge.sh %O %A %B

You may optionally instead run git_merge_installer.bat or git_merge_installer.sh which should automatically insert these lines for you at the appropriate location.

After this, merging DMI files should happen automagically unless there are conflicts (an icon_state that both you and someone else changed).
If there are conflicts, you will unfortunately still be stuck with opening both versions in the editor, and manually resolving the issues with those states.
Loading

0 comments on commit 553ce69

Please sign in to comment.