Merge pull request #5072 from X123M3-256/g2_offsets
Add support for x/y offsets in g2.dat
@@ -406,7 +406,7 @@ else (WIN32)
|
||||
endif (NOT DISABLE_RCT2)
|
||||
add_custom_command(
|
||||
OUTPUT g2.dat
|
||||
COMMAND ./openrct2 sprite build ${CMAKE_BINARY_DIR}/g2.dat ${CMAKE_CURRENT_SOURCE_DIR}/resources/g2/
|
||||
COMMAND ./openrct2 sprite build ${CMAKE_BINARY_DIR}/g2.dat ${CMAKE_CURRENT_SOURCE_DIR}/resources/g2/sprites.json
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||
)
|
||||
add_custom_target(g2 DEPENDS ${PROJECT} g2.dat)
|
||||
|
||||
@@ -2504,7 +2504,7 @@
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "\"${TARGET_BUILD_DIR}/${EXECUTABLE_PATH}\" sprite build \"${SRCROOT}/data/g2.dat\" \"${SRCROOT}/resources/g2/\"";
|
||||
shellScript = "\"${TARGET_BUILD_DIR}/${EXECUTABLE_PATH}\" sprite build \"${SRCROOT}/data/g2.dat\" \"${SRCROOT}/resources/g2/sprites.json\"";
|
||||
};
|
||||
D4CA88671D4E962100060C11 /* Get Git Variables */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
|
||||
@@ -199,7 +199,7 @@
|
||||
<Target Name="g2" DependsOnTargets="Build" AfterTargets="Build" Inputs="@(g2Inputs)" Outputs="$(g2Output)"
|
||||
Condition="'$(TestConfig)'!='true'">
|
||||
<Message Text="Building g2.dat..." />
|
||||
<Exec Command=""$(OutputExe)" sprite build "$(g2Output)" "$(RootDir)resources\g2""
|
||||
<Exec Command=""$(OutputExe)" sprite build "$(g2Output)" "$(RootDir)resources\g2\sprites.json""
|
||||
StandardOutputImportance="low" />
|
||||
</Target>
|
||||
|
||||
|
||||
|
Before Width: | Height: | Size: 202 B After Width: | Height: | Size: 202 B |
|
Before Width: | Height: | Size: 203 B After Width: | Height: | Size: 203 B |
|
Before Width: | Height: | Size: 191 B After Width: | Height: | Size: 191 B |
|
Before Width: | Height: | Size: 208 B After Width: | Height: | Size: 208 B |
|
Before Width: | Height: | Size: 387 B After Width: | Height: | Size: 387 B |
|
Before Width: | Height: | Size: 506 B After Width: | Height: | Size: 506 B |
|
Before Width: | Height: | Size: 170 B After Width: | Height: | Size: 170 B |
|
Before Width: | Height: | Size: 352 B After Width: | Height: | Size: 352 B |
|
Before Width: | Height: | Size: 219 B After Width: | Height: | Size: 219 B |
|
Before Width: | Height: | Size: 229 B After Width: | Height: | Size: 229 B |
|
Before Width: | Height: | Size: 912 B After Width: | Height: | Size: 912 B |
|
Before Width: | Height: | Size: 585 B After Width: | Height: | Size: 585 B |
|
Before Width: | Height: | Size: 443 B After Width: | Height: | Size: 443 B |
|
Before Width: | Height: | Size: 497 B After Width: | Height: | Size: 497 B |
|
Before Width: | Height: | Size: 2.9 KiB After Width: | Height: | Size: 2.9 KiB |
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 446 B After Width: | Height: | Size: 446 B |
|
Before Width: | Height: | Size: 232 B After Width: | Height: | Size: 232 B |
|
Before Width: | Height: | Size: 229 B After Width: | Height: | Size: 229 B |
|
Before Width: | Height: | Size: 271 B After Width: | Height: | Size: 271 B |
|
Before Width: | Height: | Size: 268 B After Width: | Height: | Size: 268 B |
|
Before Width: | Height: | Size: 240 B After Width: | Height: | Size: 240 B |
|
Before Width: | Height: | Size: 236 B After Width: | Height: | Size: 236 B |
|
Before Width: | Height: | Size: 282 B After Width: | Height: | Size: 282 B |
|
Before Width: | Height: | Size: 282 B After Width: | Height: | Size: 282 B |
|
Before Width: | Height: | Size: 242 B After Width: | Height: | Size: 242 B |
|
Before Width: | Height: | Size: 235 B After Width: | Height: | Size: 235 B |
|
Before Width: | Height: | Size: 280 B After Width: | Height: | Size: 280 B |
|
Before Width: | Height: | Size: 280 B After Width: | Height: | Size: 280 B |
|
Before Width: | Height: | Size: 176 B After Width: | Height: | Size: 176 B |
|
Before Width: | Height: | Size: 720 B After Width: | Height: | Size: 720 B |
|
Before Width: | Height: | Size: 201 B After Width: | Height: | Size: 201 B |
|
Before Width: | Height: | Size: 113 B After Width: | Height: | Size: 113 B |
|
Before Width: | Height: | Size: 403 B After Width: | Height: | Size: 403 B |
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 557 B After Width: | Height: | Size: 557 B |
|
Before Width: | Height: | Size: 335 B After Width: | Height: | Size: 335 B |
|
Before Width: | Height: | Size: 531 B After Width: | Height: | Size: 531 B |
|
Before Width: | Height: | Size: 328 B After Width: | Height: | Size: 328 B |
|
Before Width: | Height: | Size: 4.5 KiB After Width: | Height: | Size: 4.5 KiB |
|
Before Width: | Height: | Size: 5.2 KiB After Width: | Height: | Size: 5.2 KiB |
281
resources/g2/sprites.json
Normal file
@@ -0,0 +1,281 @@
|
||||
[
|
||||
{
|
||||
"path": "logo.png"
|
||||
},
|
||||
{
|
||||
"path": "logo_text.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/fast_forward.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/game_speed_indicator.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/game_speed_indicator_double.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/twitch.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/map_gen_land.png"
|
||||
},
|
||||
{
|
||||
"path": "7.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/zoom_in.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/zoom_in_background.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/zoom_out.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/zoom_out_background.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/map_gen_trees.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/map_gen_noise.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/large_scenery.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/small_scenery.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/paths.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/rct1_close_off.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/rct1_close_off_pressed.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/rct1_close_on.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/rct1_close_off_pressed.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/rct1_test_off.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/rct1_test_off_pressed.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/rct1_test_on.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/rct1_test_on_pressed.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/rct1_open_off.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/rct1_open_off_pressed.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/rct1_open_on.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/rct1_open_on_pressed.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/29.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/30.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/31.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/32.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/cheats.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/flat_to_steep_1.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/flat_to_steep_2_1.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/flat_to_steep_3_1.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/flat_to_steep_4.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/flat_to_steep_2_2.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/flat_to_steep_3_2.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/steep_to_flat_1.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/steep_to_flat_2_1.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/steep_to_flat_3_1.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/steep_to_flat_4.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/steep_to_flat_2_2.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/steep_to_flat_3_2.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/flat_to_steep_lift_1.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/flat_to_steep_lift_2_1.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/flat_to_steep_lift_3_1.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/flat_to_steep_lift_4.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/flat_to_steep_lift_2_2.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/flat_to_steep_lift_3_2.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/steep_to_flat_lift_1.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/steep_to_flat_lift_2_1.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/steep_to_flat_lift_3_1.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/steep_to_flat_lift_4.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/steep_to_flat_lift_2_2.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/steep_to_flat_lift_3_2.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/58.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/server_password.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/multiplayer.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/flat_to_steep_diagonal_1.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/flat_to_steep_diagonal_2.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/flat_to_steep_diagonal_3.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/flat_to_steep_diagonal_4.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/steep_to_flat_diagonal_1.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/steep_to_flat_diagonal_2.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/steep_to_flat_diagonal_3.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/steep_to_flat_diagonal_4.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/flat_to_steep_diagonal_lift_1.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/flat_to_steep_diagonal_lift_2.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/flat_to_steep_diagonal_lift_3.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/flat_to_steep_diagonal_lift_4.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/steep_to_flat_diagonal_lift_1.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/steep_to_flat_diagonal_lift_2.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/steep_to_flat_diagonal_lift_3.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/steep_to_flat_diagonal_lift_4.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/sort.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/copy.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/paste.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/tab_disabled.png"
|
||||
},
|
||||
{
|
||||
"path": "track/intamin/booster_1.png"
|
||||
},
|
||||
{
|
||||
"path": "track/intamin/booster_2.png"
|
||||
},
|
||||
{
|
||||
"path": "track/bm/booster_1.png"
|
||||
},
|
||||
{
|
||||
"path": "track/bm/booster_2.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/booster_1.png"
|
||||
},
|
||||
{
|
||||
"path": "track/junior/booster_2.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/mute.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/mute_pressed.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/unmute.png"
|
||||
},
|
||||
{
|
||||
"path": "icons/unmute_pressed.png"
|
||||
},
|
||||
{
|
||||
"path": "track/mini/booster_1.png"
|
||||
},
|
||||
{
|
||||
"path": "track/mini/booster_2.png"
|
||||
}
|
||||
]
|
||||
|
Before Width: | Height: | Size: 433 B After Width: | Height: | Size: 433 B |
|
Before Width: | Height: | Size: 388 B After Width: | Height: | Size: 388 B |
|
Before Width: | Height: | Size: 428 B After Width: | Height: | Size: 428 B |
|
Before Width: | Height: | Size: 438 B After Width: | Height: | Size: 438 B |
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 518 B After Width: | Height: | Size: 518 B |
|
Before Width: | Height: | Size: 255 B After Width: | Height: | Size: 255 B |
|
Before Width: | Height: | Size: 264 B After Width: | Height: | Size: 264 B |
|
Before Width: | Height: | Size: 272 B After Width: | Height: | Size: 272 B |
|
Before Width: | Height: | Size: 254 B After Width: | Height: | Size: 254 B |
|
Before Width: | Height: | Size: 605 B After Width: | Height: | Size: 605 B |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 970 B After Width: | Height: | Size: 970 B |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 1004 B After Width: | Height: | Size: 1004 B |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 595 B After Width: | Height: | Size: 595 B |
|
Before Width: | Height: | Size: 326 B After Width: | Height: | Size: 326 B |
|
Before Width: | Height: | Size: 270 B After Width: | Height: | Size: 270 B |
|
Before Width: | Height: | Size: 280 B After Width: | Height: | Size: 280 B |
|
Before Width: | Height: | Size: 275 B After Width: | Height: | Size: 275 B |
|
Before Width: | Height: | Size: 721 B After Width: | Height: | Size: 721 B |
|
Before Width: | Height: | Size: 542 B After Width: | Height: | Size: 542 B |
|
Before Width: | Height: | Size: 250 B After Width: | Height: | Size: 250 B |
|
Before Width: | Height: | Size: 261 B After Width: | Height: | Size: 261 B |
|
Before Width: | Height: | Size: 238 B After Width: | Height: | Size: 238 B |
|
Before Width: | Height: | Size: 265 B After Width: | Height: | Size: 265 B |
|
Before Width: | Height: | Size: 577 B After Width: | Height: | Size: 577 B |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 956 B After Width: | Height: | Size: 956 B |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 976 B After Width: | Height: | Size: 976 B |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
|
Before Width: | Height: | Size: 614 B After Width: | Height: | Size: 614 B |
|
Before Width: | Height: | Size: 265 B After Width: | Height: | Size: 265 B |
|
Before Width: | Height: | Size: 299 B After Width: | Height: | Size: 299 B |
|
Before Width: | Height: | Size: 238 B After Width: | Height: | Size: 238 B |
|
Before Width: | Height: | Size: 306 B After Width: | Height: | Size: 306 B |
|
Before Width: | Height: | Size: 691 B After Width: | Height: | Size: 691 B |
|
Before Width: | Height: | Size: 297 B After Width: | Height: | Size: 297 B |
|
Before Width: | Height: | Size: 283 B After Width: | Height: | Size: 283 B |
@@ -299,9 +299,6 @@ extern "C"
|
||||
OpenRCT2::RunGameLoop();
|
||||
}
|
||||
openrct2_dispose();
|
||||
|
||||
// HACK Some threads are still running which causes the game to not terminate. Investigation required!
|
||||
exit(gExitCode);
|
||||
}
|
||||
|
||||
void openrct2_dispose()
|
||||
|
||||
@@ -568,6 +568,12 @@ extern "C"
|
||||
argEnumerator.TryPop();
|
||||
|
||||
const CommandLineCommand * command = CommandLine::FindCommandFor(CommandLine::RootCommands, &argEnumerator);
|
||||
|
||||
if (command == nullptr)
|
||||
{
|
||||
return EXITCODE_FAIL;
|
||||
}
|
||||
|
||||
if (command->Options != nullptr)
|
||||
{
|
||||
auto argEnumeratorForOptions = CommandLineArgEnumerator(argEnumerator);
|
||||
@@ -576,6 +582,7 @@ extern "C"
|
||||
return EXITCODE_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
if (command == CommandLine::RootCommands && command->Func == nullptr)
|
||||
{
|
||||
return CommandLine::HandleCommandDefault();
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
extern "C"
|
||||
{
|
||||
sint32 gSpriteMode = 0;
|
||||
sint32 gSpriteMode = 0;
|
||||
}
|
||||
|
||||
static const char * _mode;
|
||||
@@ -40,12 +40,12 @@ static exitcode_t HandleSprite(CommandLineArgEnumerator *argEnumerator);
|
||||
const CommandLineCommand CommandLine::SpriteCommands[]
|
||||
{
|
||||
// Main commands
|
||||
DefineCommand("append", "<spritefile> <input>", SpriteOptions, HandleSprite),
|
||||
DefineCommand("build", "<spritefile> <resourcedir> [silent]", SpriteOptions, HandleSprite),
|
||||
DefineCommand("create", "<spritefile>", SpriteOptions, HandleSprite),
|
||||
DefineCommand("details", "<spritefile> [idx]", SpriteOptions, HandleSprite),
|
||||
DefineCommand("export", "<spritefile> <idx> <output>", SpriteOptions, HandleSprite),
|
||||
DefineCommand("exportall", "<spritefile> <outputdir>", SpriteOptions, HandleSprite),
|
||||
DefineCommand("append", "<spritefile> <input> [x_offset y_offset]", SpriteOptions, HandleSprite),
|
||||
DefineCommand("build", "<spritefile> <json path> [silent]", SpriteOptions, HandleSprite),
|
||||
DefineCommand("create", "<spritefile>", SpriteOptions, HandleSprite),
|
||||
DefineCommand("details", "<spritefile> [idx]", SpriteOptions, HandleSprite),
|
||||
DefineCommand("export", "<spritefile> <idx> <output>", SpriteOptions, HandleSprite),
|
||||
DefineCommand("exportall", "<spritefile> <output directory>", SpriteOptions, HandleSprite),
|
||||
CommandTableEnd
|
||||
};
|
||||
|
||||
|
||||
@@ -14,6 +14,9 @@
|
||||
*****************************************************************************/
|
||||
#pragma endregion
|
||||
|
||||
#pragma warning(disable : 4706) // assignment within conditional expression
|
||||
|
||||
#include <jansson.h>
|
||||
#include "cmdline_sprite.h"
|
||||
#include "drawing/drawing.h"
|
||||
#include "Imaging.h"
|
||||
@@ -289,7 +292,8 @@ static sint32 get_palette_index(sint16 *colour)
|
||||
return -1;
|
||||
}
|
||||
|
||||
static bool sprite_file_import(const char *path, rct_g1_element *outElement, uint8 **outBuffer, sint32 *outBufferLength, sint32 mode)
|
||||
|
||||
static bool sprite_file_import(const char *path, sint16 x_offset, sint16 y_offset, rct_g1_element *outElement, uint8 **outBuffer, int *outBufferLength, sint32 mode)
|
||||
{
|
||||
uint8 *pixels;
|
||||
uint32 width, height;
|
||||
@@ -433,8 +437,8 @@ static bool sprite_file_import(const char *path, rct_g1_element *outElement, uin
|
||||
outElement->width = width;
|
||||
outElement->height = height;
|
||||
outElement->flags = G1_FLAG_RLE_COMPRESSION;
|
||||
outElement->x_offset = 0;
|
||||
outElement->y_offset = 0;
|
||||
outElement->x_offset = x_offset;
|
||||
outElement->y_offset = y_offset;
|
||||
outElement->zoomed_offset = 0;
|
||||
|
||||
*outBuffer = buffer;
|
||||
@@ -595,18 +599,42 @@ sint32 cmdline_for_sprite(const char **argv, sint32 argc)
|
||||
sprite_file_close();
|
||||
return 1;
|
||||
} else if (_strcmpi(argv[0], "append") == 0) {
|
||||
if (argc < 3) {
|
||||
fprintf(stderr, "usage: sprite append <spritefile> <input>\n");
|
||||
if (argc != 3 && argc != 5) {
|
||||
fprintf(stderr, "usage: sprite append <spritefile> <input> [<x offset> <y offset>]\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
const char *spriteFilePath = argv[1];
|
||||
const char *imagePath = argv[2];
|
||||
sint16 x_offset = 0;
|
||||
sint16 y_offset = 0;
|
||||
|
||||
if (argc == 5)
|
||||
{
|
||||
char *endptr;
|
||||
|
||||
x_offset = strtol(argv[3], &endptr, 0);
|
||||
if (*endptr != 0)
|
||||
{
|
||||
fprintf(stderr, "X offset must be an integer\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
y_offset = strtol(argv[4], &endptr, 0);
|
||||
if (*endptr != 0)
|
||||
{
|
||||
fprintf(stderr, "Y offset must be an integer\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
rct_g1_element spriteElement;
|
||||
uint8 *buffer;
|
||||
|
||||
sint32 bufferLength;
|
||||
if (!sprite_file_import(imagePath, &spriteElement, &buffer, &bufferLength, gSpriteMode))
|
||||
if (!sprite_file_import(imagePath, x_offset, y_offset, &spriteElement, &buffer, &bufferLength, gSpriteMode))
|
||||
|
||||
return -1;
|
||||
|
||||
if (!sprite_file_open(spriteFilePath)) {
|
||||
@@ -633,75 +661,118 @@ sint32 cmdline_for_sprite(const char **argv, sint32 argc)
|
||||
return 1;
|
||||
} else if (_strcmpi(argv[0], "build") == 0) {
|
||||
if (argc < 3) {
|
||||
fprintf(stdout, "usage: sprite build <spritefile> <resourcedir> [silent]\n");
|
||||
fprintf(stdout, "usage: sprite build <spritefile> <sprite description file> [silent]\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
const char *spriteFilePath = argv[1];
|
||||
const char *resourcePath = argv[2];
|
||||
char imagePath[MAX_PATH];
|
||||
size_t resourceLength = strlen(resourcePath);
|
||||
const char *spriteDescriptionPath = argv[2];
|
||||
char* directoryPath = path_get_directory(spriteDescriptionPath);
|
||||
|
||||
json_error_t error;
|
||||
json_t* sprite_list=json_load_file(spriteDescriptionPath, JSON_REJECT_DUPLICATES, &error);
|
||||
|
||||
if (sprite_list == NULL)
|
||||
{
|
||||
fprintf(stderr, "Error parsing sprite description file: %s at line %d column %d\n", error.text, error.line, error.column);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!json_is_array(sprite_list))
|
||||
{
|
||||
fprintf(stderr, "Error: expected array\n");
|
||||
json_decref(sprite_list);
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool silent = (argc >= 4 && strcmp(argv[3], "silent") == 0);
|
||||
SDL_RWops *file;
|
||||
|
||||
spriteFileHeader.num_entries = 0;
|
||||
spriteFileHeader.total_size = 0;
|
||||
sprite_file_save(spriteFilePath);
|
||||
|
||||
fprintf(stdout, "Building: %s\n", spriteFilePath);
|
||||
sint32 i = 0;
|
||||
do {
|
||||
// Create image path
|
||||
safe_strcpy(imagePath, resourcePath, MAX_PATH);
|
||||
if (resourcePath[resourceLength - 1] == '/' || resourcePath[resourceLength - 1] == '\\')
|
||||
imagePath[resourceLength - 1] = 0;
|
||||
char filename[16];
|
||||
snprintf(filename, 16, "%d.png", i);
|
||||
safe_strcat_path(imagePath, filename, MAX_PATH);
|
||||
|
||||
file = SDL_RWFromFile(imagePath, "r");
|
||||
if (file != NULL) {
|
||||
SDL_RWclose(file);
|
||||
rct_g1_element spriteElement;
|
||||
uint8 *buffer;
|
||||
sint32 bufferLength;
|
||||
if (!sprite_file_import(imagePath, &spriteElement, &buffer, &bufferLength, gSpriteMode)) {
|
||||
fprintf(stderr, "Could not import image file: %s\nCanceling\n", imagePath);
|
||||
return -1;
|
||||
}
|
||||
size_t i;
|
||||
json_t* sprite_description;
|
||||
|
||||
if (!sprite_file_open(spriteFilePath)) {
|
||||
fprintf(stderr, "Unable to open sprite file: %s\nCanceling\n", spriteFilePath);
|
||||
return -1;
|
||||
}
|
||||
|
||||
spriteFileHeader.num_entries++;
|
||||
spriteFileHeader.total_size += bufferLength;
|
||||
spriteFileEntries = realloc(spriteFileEntries, spriteFileHeader.num_entries * sizeof(rct_g1_element));
|
||||
|
||||
sprite_entries_make_relative();
|
||||
spriteFileData = realloc(spriteFileData, spriteFileHeader.total_size);
|
||||
sprite_entries_make_absolute();
|
||||
|
||||
spriteFileEntries[spriteFileHeader.num_entries - 1] = spriteElement;
|
||||
memcpy(spriteFileData + (spriteFileHeader.total_size - bufferLength), buffer, bufferLength);
|
||||
spriteFileEntries[spriteFileHeader.num_entries - 1].offset = spriteFileData + (spriteFileHeader.total_size - bufferLength);
|
||||
|
||||
free(buffer);
|
||||
|
||||
if (!sprite_file_save(spriteFilePath)) {
|
||||
fprintf(stderr, "Could not save sprite file: %s\nCanceling\n", imagePath);
|
||||
return -1;
|
||||
}
|
||||
if (!silent)
|
||||
fprintf(stdout, "Added: %s\n", imagePath);
|
||||
sprite_file_close();
|
||||
json_array_foreach(sprite_list, i, sprite_description)
|
||||
{
|
||||
if(!json_is_object(sprite_description))
|
||||
{
|
||||
fprintf(stderr, "Error: expected object for sprite %lu\n", (unsigned long)i);
|
||||
json_decref(sprite_list);
|
||||
return -1;
|
||||
}
|
||||
i++;
|
||||
} while (file != NULL);
|
||||
|
||||
json_t* path = json_object_get(sprite_description,"path");
|
||||
if(!path || !json_is_string(path))
|
||||
{
|
||||
fprintf(stderr, "Error: no path provided for sprite %lu\n", (unsigned long)i);
|
||||
json_decref(sprite_list);
|
||||
return -1;
|
||||
}
|
||||
//Get x and y offsets, if present
|
||||
json_t* x_offset = json_object_get(sprite_description, "x_offset");
|
||||
json_t* y_offset = json_object_get(sprite_description, "y_offset");
|
||||
|
||||
|
||||
//Resolve absolute sprite path
|
||||
char *imagePath = platform_get_absolute_path(json_string_value(path), directoryPath);
|
||||
|
||||
rct_g1_element spriteElement;
|
||||
uint8 *buffer;
|
||||
int bufferLength;
|
||||
|
||||
if (!sprite_file_import(imagePath, x_offset==NULL ? 0 : json_integer_value(x_offset), y_offset==NULL ? 0 : json_integer_value(y_offset), &spriteElement, &buffer, &bufferLength, gSpriteMode))
|
||||
{
|
||||
fprintf(stderr, "Could not import image file: %s\nCanceling\n", imagePath);
|
||||
json_decref(sprite_list);
|
||||
free(imagePath);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!sprite_file_open(spriteFilePath))
|
||||
{
|
||||
fprintf(stderr, "Unable to open sprite file: %s\nCanceling\n", spriteFilePath);
|
||||
json_decref(sprite_list);
|
||||
free(imagePath);
|
||||
return -1;
|
||||
}
|
||||
|
||||
spriteFileHeader.num_entries++;
|
||||
spriteFileHeader.total_size += bufferLength;
|
||||
spriteFileEntries = realloc(spriteFileEntries, spriteFileHeader.num_entries * sizeof(rct_g1_element));
|
||||
|
||||
sprite_entries_make_relative();
|
||||
spriteFileData = realloc(spriteFileData, spriteFileHeader.total_size);
|
||||
sprite_entries_make_absolute();
|
||||
|
||||
spriteFileEntries[spriteFileHeader.num_entries - 1] = spriteElement;
|
||||
memcpy(spriteFileData + (spriteFileHeader.total_size - bufferLength), buffer, bufferLength);
|
||||
spriteFileEntries[spriteFileHeader.num_entries - 1].offset = spriteFileData + (spriteFileHeader.total_size - bufferLength);
|
||||
|
||||
free(buffer);
|
||||
|
||||
if (!sprite_file_save(spriteFilePath))
|
||||
{
|
||||
fprintf(stderr, "Could not save sprite file: %s\nCanceling\n", imagePath);
|
||||
json_decref(sprite_list);
|
||||
free(imagePath);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!silent)
|
||||
fprintf(stdout, "Added: %s\n", imagePath);
|
||||
|
||||
free(imagePath);
|
||||
sprite_file_close();
|
||||
|
||||
}
|
||||
|
||||
json_decref(sprite_list);
|
||||
free(directoryPath);
|
||||
|
||||
fprintf(stdout, "Finished\n");
|
||||
return 1;
|
||||
} else {
|
||||
|
||||