forked from tgstation/tgstation
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds the dmitool icon merger from baystation12
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
Showing
20 changed files
with
1,867 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Oops, something went wrong.