MCPcopy Create free account
hub / github.com/amakaseev/sprite-sheet-packer / commandLine

Function commandLine

SpriteSheetPacker/command-line.cpp:6–264  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4#include "SpritePackerProjectFile.h"
5
6int commandLine(QCoreApplication& app) {
7 QCommandLineParser parser;
8 parser.setApplicationDescription("");
9 parser.addHelpOption();
10 parser.addVersionOption();
11 parser.addPositionalArgument("source", "Sprites for packing or project file (You can override project file options with [options]).");
12 parser.addPositionalArgument("destination", "Destination folder where you're saving the sprite sheet. Optional when using project file");
13
14 parser.addOptions({
15 {{"f", "format"}, "Format for export sprite sheet data. Default is cocos2d.", "format"},
16 {"trimMode", "Rect - Removes the transparency around a sprite. The sprites appear to have their original size when using them.\n\
17Polygon - The amount of rendered transparency can be reduced by creating a tight fitting polygon around the solid pixels of a sprite. But: The vertices must be transformed by the CPU — introducing new costs.\n\
18Default is Rect", "mode", "Rect"},
19 {"trim", "Allowed values: 1 to 255, default is 1. Pixels with an alpha value below this value will be considered transparent when trimming the sprite. Very useful for sprites with nearly invisible alpha pixels at the borders.", "int", "1"},
20 {"epsilon", "Lower values create a tighter fitting mesh with less transparency but with more vertices.\nHigher values on the other hand reduce the number of vertices at the cost of adding more transparency.", "float", "5"},
21 {"texture-border", "Border of the sprite sheet, value adds transparent pixels around the borders of the sprite sheet. Default value is 0.", "int", "0"},
22 {"sprite-border", "Sprite border is the space between sprites. Value adds transparent pixels between sprites to avoid artifacts from neighbor sprites. The transparent pixels are not added to the sprites, default is 2.", "int", "2"},
23 {"powerOf2", "Forces the texture to have power of 2 size (32, 64, 128...). Default is disable."},
24 {"max-size", "Sets the maximum size for the texture, default is 8192.", "size", "8192"},
25 {"png-opt-mode", "Optimizes the png's file size.\n\
26None - No optimization at all(fastest).\n\
27Lossless - Uses optipng to optimize the filesize. The reduction is mostly small but doesn't harm image quality.\n\
28Lossy - Uses pngquant to optimize the filesize. The reduction is mostly about 70%, but the image quality gets a bit worse.", "int", "0"},
29 {"png-opt-level", "Optimizes the image's file size. Only useful in combination with opt-mode Lossless. Allowed values: 1 to 7 (Using a high value might take some time to optimize.", "int", "0"},
30 {"scale", "Scales all images before creating the sheet. E.g. use 0.5 for half size, default is 1 (Scale has no effect when source is a project file).", "float", "1"},
31 });
32
33 //--texture-border 10 /Users/alekseymakaseev/Documents/Work/run-and-jump/Assets/ART/Character /Users/alekseymakaseev/Documents/Work/run-and-jump/RunAndJump/testResources --trim 2
34 parser.process(app);
35
36 bool destinationSet = true;
37 SpritePackerProjectFile* projectFile = nullptr;
38
39 if (parser.positionalArguments().size() > 2) {
40 qDebug() << "Too many arguments, see help for information.";
41 parser.showHelp();
42 return -1;
43 } else if ((parser.positionalArguments().size() == 1) || (parser.positionalArguments().size() == 2)) {
44 QFileInfo src(parser.positionalArguments().at(0));
45 if (!src.isDir()) {
46 std::string suffix = src.suffix().toStdString();
47 projectFile = SpritePackerProjectFile::factory().get(suffix)();
48 }
49
50 if (parser.positionalArguments().size() == 1) {
51 if (!projectFile) {
52 qDebug() << "Arguments must have source and destination, see help for information.";
53 parser.showHelp();
54 return -1;
55 } else {
56 destinationSet = false; // we should already have our destination saved in our project file
57 }
58 } else if (parser.positionalArguments().size() == 2) {
59 destinationSet = true;
60 }
61
62 } else {
63 qDebug() << "Arguments must have source and destination, see help for information.";

Callers 1

mainFunction · 0.85

Calls 13

getMethod · 0.80
readMethod · 0.80
trimModeMethod · 0.80
trimThresholdMethod · 0.80
epsilonMethod · 0.80
textureBorderMethod · 0.80
spriteBorderMethod · 0.80
pngOptLevelMethod · 0.80
enablePolygonModeMethod · 0.80
generateMethod · 0.80
addSpriteSheetMethod · 0.80
setPngQualityMethod · 0.80

Tested by

no test coverage detected