1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Merge pull request #4478 from Laserlicht/resource_generation

generate assets to file
This commit is contained in:
Ivan Savenko 2024-08-30 15:36:51 +03:00 committed by GitHub
commit 7f926fc30e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 174 additions and 93 deletions

View File

@ -83,6 +83,7 @@ set(client_SRCS
media/CSoundHandler.cpp
media/CVideoHandler.cpp
render/AssetGenerator.cpp
render/CAnimation.cpp
render/CBitmapHandler.cpp
render/CDefFile.cpp
@ -285,6 +286,7 @@ set(client_HEADERS
media/ISoundPlayer.h
media/IVideoPlayer.h
render/AssetGenerator.h
render/CAnimation.h
render/CBitmapHandler.h
render/CDefFile.h

View File

@ -18,6 +18,7 @@
#include "gui/CGuiHandler.h"
#include "gui/WindowHandler.h"
#include "render/IRenderHandler.h"
#include "render/AssetGenerator.h"
#include "ClientNetPackVisitors.h"
#include "../lib/CConfigHandler.h"
#include "../lib/gameState/CGameState.h"
@ -502,6 +503,12 @@ void ClientCommandManager::handleVsLog(std::istringstream & singleWordBuffer)
logVisual->setKey(key);
}
void ClientCommandManager::handleGenerateAssets()
{
AssetGenerator::generateAll();
printCommandMessage("All assets generated");
}
void ClientCommandManager::printCommandMessage(const std::string &commandMessage, ELogLevel::ELogLevel messageType)
{
switch(messageType)
@ -624,6 +631,9 @@ void ClientCommandManager::processCommand(const std::string & message, bool call
else if(commandName == "vslog")
handleVsLog(singleWordBuffer);
else if(message=="generate assets")
handleGenerateAssets();
else
{
if (!commandName.empty() && !vstd::iswithin(commandName[0], 0, ' ')) // filter-out debugger/IDE noise

View File

@ -84,6 +84,9 @@ class ClientCommandManager //take mantis #2292 issue about account if thinking a
// shows object graph
void handleVsLog(std::istringstream & singleWordBuffer);
// generate all assets
void handleGenerateAssets();
// Prints in Chat the given message
void printCommandMessage(const std::string &commandMessage, ELogLevel::ELogLevel messageType = ELogLevel::NOT_SET);
void giveTurn(const PlayerColor &color);

View File

@ -18,6 +18,7 @@
#include "../widgets/TextControls.h"
#include "../CServerHandler.h"
#include "../CGameInfo.h"
#include "../render/AssetGenerator.h"
#include "../../lib/StartInfo.h"
#include "../../lib/texts/CGeneralTextHandler.h"
@ -68,6 +69,8 @@ std::vector<SimturnsInfo> OptionsTabBase::getSimturnsPresets() const
OptionsTabBase::OptionsTabBase(const JsonPath & configPath)
{
AssetGenerator::createAdventureOptionsCleanBackground();
recActions = 0;
auto setTimerPresetCallback = [this](int index){

View File

@ -0,0 +1,116 @@
/*
* AssetGenerator.cpp, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#include "StdInc.h"
#include "AssetGenerator.h"
#include "../gui/CGuiHandler.h"
#include "../render/IImage.h"
#include "../render/IImageLoader.h"
#include "../render/Canvas.h"
#include "../render/IRenderHandler.h"
#include "../lib/filesystem/Filesystem.h"
void AssetGenerator::generateAll()
{
createBigSpellBook();
createAdventureOptionsCleanBackground();
}
void AssetGenerator::createAdventureOptionsCleanBackground()
{
std::string filename = "data/AdventureOptionsBackgroundClear.bmp";
if(CResourceHandler::get()->existsResource(ResourcePath(filename))) // overridden by mod, no generation
return;
if(!CResourceHandler::get("local")->createResource(filename))
return;
ResourcePath savePath(filename, EResType::IMAGE);
auto res = ImagePath::builtin("ADVOPTBK");
std::shared_ptr<IImage> img = GH.renderHandler().loadImage(res, EImageBlitMode::OPAQUE);
Canvas canvas = Canvas(Point(575, 585), CanvasScalingPolicy::IGNORE);
canvas.draw(img, Point(0, 0), Rect(0, 0, 575, 585));
canvas.draw(img, Point(54, 121), Rect(54, 123, 335, 1));
canvas.draw(img, Point(158, 84), Rect(156, 84, 2, 37));
canvas.draw(img, Point(234, 84), Rect(232, 84, 2, 37));
canvas.draw(img, Point(310, 84), Rect(308, 84, 2, 37));
canvas.draw(img, Point(53, 567), Rect(53, 520, 339, 3));
canvas.draw(img, Point(53, 520), Rect(53, 264, 339, 47));
std::shared_ptr<IImage> image = GH.renderHandler().createImage(canvas.getInternalSurface());
image->exportBitmap(*CResourceHandler::get("local")->getResourceName(savePath));
}
void AssetGenerator::createBigSpellBook()
{
std::string filename = "data/SpellBookLarge.bmp";
if(CResourceHandler::get()->existsResource(ResourcePath(filename))) // overridden by mod, no generation
return;
if(!CResourceHandler::get("local")->createResource(filename))
return;
ResourcePath savePath(filename, EResType::IMAGE);
auto res = ImagePath::builtin("SpelBack");
std::shared_ptr<IImage> img = GH.renderHandler().loadImage(res, EImageBlitMode::OPAQUE);
Canvas canvas = Canvas(Point(800, 600), CanvasScalingPolicy::IGNORE);
// edges
canvas.draw(img, Point(0, 0), Rect(15, 38, 90, 45));
canvas.draw(img, Point(0, 460), Rect(15, 400, 90, 141));
canvas.draw(img, Point(705, 0), Rect(509, 38, 95, 45));
canvas.draw(img, Point(705, 460), Rect(509, 400, 95, 141));
// left / right
Canvas tmp1 = Canvas(Point(90, 355 - 45), CanvasScalingPolicy::IGNORE);
tmp1.draw(img, Point(0, 0), Rect(15, 38 + 45, 90, 355 - 45));
canvas.drawScaled(tmp1, Point(0, 45), Point(90, 415));
Canvas tmp2 = Canvas(Point(95, 355 - 45), CanvasScalingPolicy::IGNORE);
tmp2.draw(img, Point(0, 0), Rect(509, 38 + 45, 95, 355 - 45));
canvas.drawScaled(tmp2, Point(705, 45), Point(95, 415));
// top / bottom
Canvas tmp3 = Canvas(Point(409, 45), CanvasScalingPolicy::IGNORE);
tmp3.draw(img, Point(0, 0), Rect(100, 38, 409, 45));
canvas.drawScaled(tmp3, Point(90, 0), Point(615, 45));
Canvas tmp4 = Canvas(Point(409, 141), CanvasScalingPolicy::IGNORE);
tmp4.draw(img, Point(0, 0), Rect(100, 400, 409, 141));
canvas.drawScaled(tmp4, Point(90, 460), Point(615, 141));
// middle
Canvas tmp5 = Canvas(Point(409, 141), CanvasScalingPolicy::IGNORE);
tmp5.draw(img, Point(0, 0), Rect(100, 38 + 45, 509 - 15, 400 - 38));
canvas.drawScaled(tmp5, Point(90, 45), Point(615, 415));
// carpet
Canvas tmp6 = Canvas(Point(590, 59), CanvasScalingPolicy::IGNORE);
tmp6.draw(img, Point(0, 0), Rect(15, 484, 590, 59));
canvas.drawScaled(tmp6, Point(0, 545), Point(800, 59));
// remove bookmarks
for (int i = 0; i < 56; i++)
canvas.draw(Canvas(canvas, Rect(i < 30 ? 268 : 327, 464, 1, 46)), Point(269 + i, 464));
for (int i = 0; i < 56; i++)
canvas.draw(Canvas(canvas, Rect(469, 464, 1, 42)), Point(470 + i, 464));
for (int i = 0; i < 57; i++)
canvas.draw(Canvas(canvas, Rect(i < 30 ? 564 : 630, 464, 1, 44)), Point(565 + i, 464));
for (int i = 0; i < 56; i++)
canvas.draw(Canvas(canvas, Rect(656, 464, 1, 47)), Point(657 + i, 464));
// draw bookmarks
canvas.draw(img, Point(278, 464), Rect(220, 405, 37, 47));
canvas.draw(img, Point(481, 465), Rect(354, 406, 37, 41));
canvas.draw(img, Point(575, 465), Rect(417, 406, 37, 45));
canvas.draw(img, Point(667, 465), Rect(478, 406, 37, 47));
std::shared_ptr<IImage> image = GH.renderHandler().createImage(canvas.getInternalSurface());
image->exportBitmap(*CResourceHandler::get("local")->getResourceName(savePath));
}

View File

@ -0,0 +1,18 @@
/*
* AssetGenerator.h, part of VCMI engine
*
* Authors: listed in file AUTHORS in main folder
*
* License: GNU General Public License v2.0 or later
* Full text of license available in license.txt file, in main folder
*
*/
#pragma once
class AssetGenerator
{
public:
static void generateAll();
static void createAdventureOptionsCleanBackground();
static void createBigSpellBook();
};

View File

@ -31,10 +31,7 @@
#include "../widgets/TextControls.h"
#include "../widgets/Buttons.h"
#include "../adventureMap/AdventureMapInterface.h"
#include "../render/IRenderHandler.h"
#include "../render/IImage.h"
#include "../render/IImageLoader.h"
#include "../render/Canvas.h"
#include "../render/AssetGenerator.h"
#include "../../CCallback.h"
@ -119,7 +116,8 @@ CSpellWindow::CSpellWindow(const CGHeroInstance * _myHero, CPlayerInterface * _m
if(isBigSpellbook)
{
background = std::make_shared<CPicture>(createBigSpellBook(), Point(0, 0));
AssetGenerator::createBigSpellBook();
background = std::make_shared<CPicture>(ImagePath::builtin("SpellBookLarge"), 0, 0);
updateShadow();
}
else
@ -221,55 +219,6 @@ CSpellWindow::~CSpellWindow()
{
}
std::shared_ptr<IImage> CSpellWindow::createBigSpellBook()
{
std::shared_ptr<IImage> img = GH.renderHandler().loadImage(ImagePath::builtin("SpelBack"), EImageBlitMode::OPAQUE);
Canvas canvas = Canvas(Point(800, 600), CanvasScalingPolicy::AUTO);
// edges
canvas.draw(img, Point(0, 0), Rect(15, 38, 90, 45));
canvas.draw(img, Point(0, 460), Rect(15, 400, 90, 141));
canvas.draw(img, Point(705, 0), Rect(509, 38, 95, 45));
canvas.draw(img, Point(705, 460), Rect(509, 400, 95, 141));
// left / right
Canvas tmp1 = Canvas(Point(90, 355 - 45), CanvasScalingPolicy::AUTO);
tmp1.draw(img, Point(0, 0), Rect(15, 38 + 45, 90, 355 - 45));
canvas.drawScaled(tmp1, Point(0, 45), Point(90, 415));
Canvas tmp2 = Canvas(Point(95, 355 - 45), CanvasScalingPolicy::AUTO);
tmp2.draw(img, Point(0, 0), Rect(509, 38 + 45, 95, 355 - 45));
canvas.drawScaled(tmp2, Point(705, 45), Point(95, 415));
// top / bottom
Canvas tmp3 = Canvas(Point(409, 45), CanvasScalingPolicy::AUTO);
tmp3.draw(img, Point(0, 0), Rect(100, 38, 409, 45));
canvas.drawScaled(tmp3, Point(90, 0), Point(615, 45));
Canvas tmp4 = Canvas(Point(409, 141), CanvasScalingPolicy::AUTO);
tmp4.draw(img, Point(0, 0), Rect(100, 400, 409, 141));
canvas.drawScaled(tmp4, Point(90, 460), Point(615, 141));
// middle
Canvas tmp5 = Canvas(Point(409, 141), CanvasScalingPolicy::AUTO);
tmp5.draw(img, Point(0, 0), Rect(100, 38 + 45, 509 - 15, 400 - 38));
canvas.drawScaled(tmp5, Point(90, 45), Point(615, 415));
// carpet
Canvas tmp6 = Canvas(Point(590, 59), CanvasScalingPolicy::AUTO);
tmp6.draw(img, Point(0, 0), Rect(15, 484, 590, 59));
canvas.drawScaled(tmp6, Point(0, 545), Point(800, 59));
// remove bookmarks
for (int i = 0; i < 56; i++)
canvas.draw(Canvas(canvas, Rect(i < 30 ? 268 : 327, 464, 1, 46)), Point(269 + i, 464));
for (int i = 0; i < 56; i++)
canvas.draw(Canvas(canvas, Rect(469, 464, 1, 42)), Point(470 + i, 464));
for (int i = 0; i < 57; i++)
canvas.draw(Canvas(canvas, Rect(i < 30 ? 564 : 630, 464, 1, 44)), Point(565 + i, 464));
for (int i = 0; i < 56; i++)
canvas.draw(Canvas(canvas, Rect(656, 464, 1, 47)), Point(657 + i, 464));
// draw bookmarks
canvas.draw(img, Point(278, 464), Rect(220, 405, 37, 47));
canvas.draw(img, Point(481, 465), Rect(354, 406, 37, 41));
canvas.draw(img, Point(575, 465), Rect(417, 406, 37, 45));
canvas.draw(img, Point(667, 465), Rect(478, 406, 37, 47));
return GH.renderHandler().createImage(canvas.getInternalSurface());
}
void CSpellWindow::searchInput()
{
if(searchBox)

View File

@ -113,8 +113,6 @@ class CSpellWindow : public CWindowObject
void turnPageLeft();
void turnPageRight();
std::shared_ptr<IImage> createBigSpellBook();
bool openOnBattleSpells;
std::function<void(SpellID)> onSpellSelect; //external processing of selected spell

View File

@ -6,7 +6,7 @@
{
"name": "background",
"type": "picture",
"image": "ADVOPTBK",
"image": "AdventureOptionsBackgroundClear",
"position": {"x": 0, "y": 6}
},
{
@ -35,31 +35,6 @@
"rect": {"x": 60, "y": 48, "w": 320, "h": 0},
"adoptHeight": true
},
{
"type": "transparentFilledRectangle",
"rect": {"x": 54, "y": 127, "w": 335, "h": 2},
"color": [24, 41, 90, 255]
},
{
"type": "transparentFilledRectangle",
"rect": {"x": 159, "y": 90, "w": 2, "h": 38},
"color": [24, 41, 90, 255]
},
{
"type": "transparentFilledRectangle",
"rect": {"x": 235, "y": 90, "w": 2, "h": 38},
"color": [24, 41, 90, 255]
},
{
"type": "transparentFilledRectangle",
"rect": {"x": 311, "y": 90, "w": 2, "h": 38},
"color": [24, 41, 90, 255]
},
{
"type": "transparentFilledRectangle",
"rect": {"x": 55, "y": 556, "w": 335, "h": 19},
"color": [24, 41, 90, 255]
},
{
"name": "ExtraOptionsButtons",
"type" : "verticalLayout",

View File

@ -120,13 +120,14 @@ Below a list of supported commands, with their arguments wrapped in `<>`
`bonuses` - shows bonuses of currently selected adventure map object
#### Extract commands
`translate` - save game texts into json files
`translate maps` - save map and campaign texts into json files
`get config` - save game objects data into json files
`get scripts` - dumps lua script stuff into files (currently inactive due to scripting disabled for default builds)
`get txt` - save game texts into .txt files matching original heroes 3 files
`def2bmp <.def file name>` - extract .def animation as BMP files
`extract <relative file path>` - export file into directory used by other extraction commands
`translate` - save game texts into json files
`translate maps` - save map and campaign texts into json files
`get config` - save game objects data into json files
`get scripts` - dumps lua script stuff into files (currently inactive due to scripting disabled for default builds)
`get txt` - save game texts into .txt files matching original heroes 3 files
`def2bmp <.def file name>` - extract .def animation as BMP files
`extract <relative file path>` - export file into directory used by other extraction commands
`generate assets` - generate all assets at once
#### AI commands
`setBattleAI <ai name>` - change battle AI used by neutral creatures to the one specified, persists through game quit

View File

@ -68,10 +68,8 @@ std::unique_ptr<CInputStream> CFilesystemList::load(const ResourcePath & resourc
{
// load resource from last loader that have it (last overridden version)
for(const auto & loader : boost::adaptors::reverse(loaders))
{
if (loader->existsResource(resourceName))
return loader->load(resourceName);
}
throw std::runtime_error("Resource with name " + resourceName.getName() + " and type "
+ EResTypeHelper::getEResTypeAsString(resourceName.getType()) + " wasn't found.");

View File

@ -118,10 +118,11 @@ std::unordered_map<ResourcePath, boost::filesystem::path> CFilesystemLoader::lis
EResType::ARCHIVE_SND,
EResType::ARCHIVE_ZIP };
static const std::set<EResType> initialTypes(initArray, initArray + std::size(initArray));
assert(boost::filesystem::is_directory(baseDirectory));
std::unordered_map<ResourcePath, boost::filesystem::path> fileList;
if(!boost::filesystem::is_directory(baseDirectory))
return fileList;
std::vector<boost::filesystem::path> path; //vector holding relative path to our file
boost::filesystem::recursive_directory_iterator enddir;

View File

@ -183,9 +183,16 @@ void CResourceHandler::initialize()
knownLoaders["saves"] = new CFilesystemLoader("SAVES/", VCMIDirs::get().userSavePath());
knownLoaders["config"] = new CFilesystemLoader("CONFIG/", VCMIDirs::get().userConfigPath());
if(boost::filesystem::is_directory(VCMIDirs::get().userDataPath() / "Generated"))
boost::filesystem::remove_all(VCMIDirs::get().userDataPath() / "Generated");
knownLoaders["gen_data"] = new CFilesystemLoader("DATA/", VCMIDirs::get().userDataPath() / "Generated" / "Data");
knownLoaders["gen_sprites"] = new CFilesystemLoader("SPRITES/", VCMIDirs::get().userDataPath() / "Generated" / "Sprites");
auto * localFS = new CFilesystemList();
localFS->addLoader(knownLoaders["saves"], true);
localFS->addLoader(knownLoaders["config"], true);
localFS->addLoader(knownLoaders["gen_data"], true);
localFS->addLoader(knownLoaders["gen_sprites"], true);
addFilesystem("root", "initial", createInitial());
addFilesystem("root", "data", new CFilesystemList());