mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
Separate vcmiqt lib
This commit is contained in:
parent
0299c5a133
commit
40576e9bb9
@ -666,6 +666,10 @@ if(NOT TARGET minizip::minizip)
|
||||
add_library(minizip::minizip ALIAS minizip)
|
||||
endif()
|
||||
|
||||
if(ENABLE_LAUNCHER OR ENABLE_EDITOR)
|
||||
add_subdirectory(vcmiqt)
|
||||
endif()
|
||||
|
||||
if(ENABLE_LAUNCHER)
|
||||
add_subdirectory(launcher)
|
||||
endif()
|
||||
|
@ -20,8 +20,6 @@ set(launcher_SRCS
|
||||
innoextract.cpp
|
||||
mainwindow_moc.cpp
|
||||
languages.cpp
|
||||
launcherdirs.cpp
|
||||
jsonutils.cpp
|
||||
updatedialog_moc.cpp
|
||||
prepare.cpp
|
||||
)
|
||||
@ -49,8 +47,6 @@ set(launcher_HEADERS
|
||||
firstLaunch/firstlaunch_moc.h
|
||||
mainwindow_moc.h
|
||||
languages.h
|
||||
launcherdirs.h
|
||||
jsonutils.h
|
||||
updatedialog_moc.h
|
||||
main.h
|
||||
helper.h
|
||||
@ -206,7 +202,7 @@ elseif(NOT APPLE_IOS)
|
||||
target_link_libraries(vcmilauncher SDL2::SDL2)
|
||||
endif()
|
||||
|
||||
target_link_libraries(vcmilauncher vcmi Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Network)
|
||||
target_link_libraries(vcmilauncher vcmi vcmiqt Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Network)
|
||||
target_include_directories(vcmilauncher
|
||||
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
@ -20,22 +20,6 @@
|
||||
#include <QFile>
|
||||
#include <QTemporaryDir>
|
||||
|
||||
#include "../vcmiqt/convpathqstring.h"
|
||||
|
||||
VCMI_LIB_USING_NAMESPACE
|
||||
|
||||
inline QString pathToQString(const boost::filesystem::path & path)
|
||||
{
|
||||
#ifdef VCMI_WINDOWS
|
||||
return QString::fromStdWString(path.wstring());
|
||||
#else
|
||||
return QString::fromStdString(path.string());
|
||||
#endif
|
||||
}
|
||||
|
||||
inline boost::filesystem::path qstringToPath(const QString & path)
|
||||
{
|
||||
#ifdef VCMI_WINDOWS
|
||||
return boost::filesystem::path(path.toStdWString());
|
||||
#else
|
||||
return boost::filesystem::path(path.toUtf8().data());
|
||||
#endif
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
#include "StdInc.h"
|
||||
#include "cdownloadmanager_moc.h"
|
||||
|
||||
#include "../launcherdirs.h"
|
||||
#include "../vcmiqt/launcherdirs.h"
|
||||
|
||||
#include "../../lib/CConfigHandler.h"
|
||||
|
||||
|
@ -22,8 +22,8 @@
|
||||
#include "cdownloadmanager_moc.h"
|
||||
#include "chroniclesextractor.h"
|
||||
#include "../settingsView/csettingsview_moc.h"
|
||||
#include "../launcherdirs.h"
|
||||
#include "../jsonutils.h"
|
||||
#include "../vcmiqt/launcherdirs.h"
|
||||
#include "../vcmiqt/jsonutils.h"
|
||||
#include "../helper.h"
|
||||
|
||||
#include "../../lib/VCMIDirs.h"
|
||||
|
@ -17,8 +17,8 @@
|
||||
#include "../../lib/modding/CModInfo.h"
|
||||
#include "../../lib/modding/IdentifierStorage.h"
|
||||
|
||||
#include "../jsonutils.h"
|
||||
#include "../launcherdirs.h"
|
||||
#include "../vcmiqt/jsonutils.h"
|
||||
#include "../vcmiqt/launcherdirs.h"
|
||||
|
||||
#include <future>
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
*/
|
||||
#include "StdInc.h"
|
||||
#include "prepare.h"
|
||||
#include "launcherdirs.h"
|
||||
#include "../vcmiqt/launcherdirs.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
#include "../modManager/cmodlistview_moc.h"
|
||||
#include "../helper.h"
|
||||
#include "../jsonutils.h"
|
||||
#include "../vcmiqt/jsonutils.h"
|
||||
#include "../languages.h"
|
||||
|
||||
#include <QFileInfo>
|
||||
|
@ -1,8 +1,6 @@
|
||||
set(editor_SRCS
|
||||
StdInc.cpp
|
||||
main.cpp
|
||||
launcherdirs.cpp
|
||||
jsonutils.cpp
|
||||
mainwindow.cpp
|
||||
BitmapHandler.cpp
|
||||
maphandler.cpp
|
||||
@ -45,8 +43,6 @@ set(editor_SRCS
|
||||
|
||||
set(editor_HEADERS
|
||||
StdInc.h
|
||||
launcherdirs.h
|
||||
jsonutils.h
|
||||
mainwindow.h
|
||||
BitmapHandler.h
|
||||
maphandler.h
|
||||
@ -221,7 +217,7 @@ if(APPLE)
|
||||
set_property(GLOBAL PROPERTY AUTOGEN_TARGETS_FOLDER vcmieditor)
|
||||
endif()
|
||||
|
||||
target_link_libraries(vcmieditor vcmi Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Network)
|
||||
target_link_libraries(vcmieditor vcmi vcmiqt Qt${QT_VERSION_MAJOR}::Widgets Qt${QT_VERSION_MAJOR}::Network)
|
||||
target_include_directories(vcmieditor
|
||||
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
@ -22,6 +22,8 @@
|
||||
#include <QString>
|
||||
#include <QFile>
|
||||
|
||||
#include "../vcmiqt/convpathqstring.h"
|
||||
|
||||
VCMI_LIB_USING_NAMESPACE
|
||||
|
||||
using NumericPointer = typename std::conditional_t<sizeof(void *) == sizeof(unsigned long long),
|
||||
@ -44,21 +46,3 @@ Type * data_cast(NumericPointer _numeric)
|
||||
|
||||
return reinterpret_cast<Type *>(_numeric);
|
||||
}
|
||||
|
||||
inline QString pathToQString(const boost::filesystem::path & path)
|
||||
{
|
||||
#ifdef VCMI_WINDOWS
|
||||
return QString::fromStdWString(path.wstring());
|
||||
#else
|
||||
return QString::fromStdString(path.string());
|
||||
#endif
|
||||
}
|
||||
|
||||
inline boost::filesystem::path qstringToPath(const QString & path)
|
||||
{
|
||||
#ifdef VCMI_WINDOWS
|
||||
return boost::filesystem::path(path.toStdWString());
|
||||
#else
|
||||
return boost::filesystem::path(path.toUtf8().data());
|
||||
#endif
|
||||
}
|
||||
|
@ -1,124 +0,0 @@
|
||||
/*
|
||||
* jsonutils.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 "jsonutils.h"
|
||||
|
||||
#include "../lib/json/JsonNode.h"
|
||||
|
||||
static QVariantMap JsonToMap(const JsonMap & json)
|
||||
{
|
||||
QVariantMap map;
|
||||
for(auto & entry : json)
|
||||
{
|
||||
map.insert(QString::fromStdString(entry.first), JsonUtils::toVariant(entry.second));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
static QVariantList JsonToList(const JsonVector & json)
|
||||
{
|
||||
QVariantList list;
|
||||
for(auto & entry : json)
|
||||
{
|
||||
list.push_back(JsonUtils::toVariant(entry));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
static JsonVector VariantToList(QVariantList variant)
|
||||
{
|
||||
JsonVector vector;
|
||||
for(auto & entry : variant)
|
||||
{
|
||||
vector.push_back(JsonUtils::toJson(entry));
|
||||
}
|
||||
return vector;
|
||||
}
|
||||
|
||||
static JsonMap VariantToMap(QVariantMap variant)
|
||||
{
|
||||
JsonMap map;
|
||||
for(auto & entry : variant.toStdMap())
|
||||
{
|
||||
map[entry.first.toUtf8().data()] = JsonUtils::toJson(entry.second);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
namespace JsonUtils
|
||||
{
|
||||
|
||||
QVariant toVariant(const JsonNode & node)
|
||||
{
|
||||
switch(node.getType())
|
||||
{
|
||||
case JsonNode::JsonType::DATA_NULL:
|
||||
return QVariant();
|
||||
case JsonNode::JsonType::DATA_BOOL:
|
||||
return QVariant(node.Bool());
|
||||
case JsonNode::JsonType::DATA_FLOAT:
|
||||
return QVariant(node.Float());
|
||||
case JsonNode::JsonType::DATA_INTEGER:
|
||||
return QVariant{static_cast<qlonglong>(node.Integer())};
|
||||
case JsonNode::JsonType::DATA_STRING:
|
||||
return QVariant(QString::fromStdString(node.String()));
|
||||
case JsonNode::JsonType::DATA_VECTOR:
|
||||
return JsonToList(node.Vector());
|
||||
case JsonNode::JsonType::DATA_STRUCT:
|
||||
return JsonToMap(node.Struct());
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QVariant JsonFromFile(QString filename)
|
||||
{
|
||||
QFile file(filename);
|
||||
if(!file.open(QFile::ReadOnly))
|
||||
{
|
||||
logGlobal->error("Failed to open file %s. Reason: %s", qUtf8Printable(filename), qUtf8Printable(file.errorString()));
|
||||
return {};
|
||||
}
|
||||
|
||||
const auto data = file.readAll();
|
||||
JsonNode node(reinterpret_cast<const std::byte*>(data.data()), data.size(), filename.toStdString());
|
||||
return toVariant(node);
|
||||
}
|
||||
|
||||
JsonNode toJson(QVariant object)
|
||||
{
|
||||
JsonNode ret;
|
||||
|
||||
if(object.userType() == QMetaType::QString)
|
||||
ret.String() = object.toString().toUtf8().data();
|
||||
else if(object.userType() == QMetaType::Bool)
|
||||
ret.Bool() = object.toBool();
|
||||
else if(object.canConvert<QVariantMap>())
|
||||
ret.Struct() = VariantToMap(object.toMap());
|
||||
else if(object.canConvert<QVariantList>())
|
||||
ret.Vector() = VariantToList(object.toList());
|
||||
else if(object.canConvert<int>())
|
||||
ret.Integer() = object.toInt();
|
||||
else if(object.canConvert<double>())
|
||||
ret.Float() = object.toFloat();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void JsonToFile(QString filename, QVariant object)
|
||||
{
|
||||
std::fstream file(qstringToPath(filename).c_str(), std::ios::out | std::ios_base::binary);
|
||||
file << toJson(object).toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
@ -1,27 +0,0 @@
|
||||
/*
|
||||
* jsonutils.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
|
||||
|
||||
#include <QVariant>
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
class JsonNode;
|
||||
|
||||
namespace JsonUtils
|
||||
{
|
||||
QVariant toVariant(const JsonNode & node);
|
||||
QVariant JsonFromFile(QString filename);
|
||||
|
||||
JsonNode toJson(QVariant object);
|
||||
void JsonToFile(QString filename, QVariant object);
|
||||
}
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* launcherdirs.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 "launcherdirs.h"
|
||||
|
||||
#include "../lib/VCMIDirs.h"
|
||||
|
||||
static CLauncherDirs launcherDirsGlobal;
|
||||
|
||||
CLauncherDirs::CLauncherDirs()
|
||||
{
|
||||
QDir().mkdir(downloadsPath());
|
||||
QDir().mkdir(modsPath());
|
||||
}
|
||||
|
||||
CLauncherDirs & CLauncherDirs::get()
|
||||
{
|
||||
return launcherDirsGlobal;
|
||||
}
|
||||
|
||||
QString CLauncherDirs::downloadsPath()
|
||||
{
|
||||
return pathToQString(VCMIDirs::get().userCachePath() / "downloads");
|
||||
}
|
||||
|
||||
QString CLauncherDirs::modsPath()
|
||||
{
|
||||
return pathToQString(VCMIDirs::get().userDataPath() / "Mods");
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
/*
|
||||
* launcherdirs.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
|
||||
|
||||
/// similar to lib/VCMIDirs, controls where all launcher-related data will be stored
|
||||
class CLauncherDirs
|
||||
{
|
||||
public:
|
||||
CLauncherDirs();
|
||||
|
||||
static CLauncherDirs & get();
|
||||
|
||||
QString downloadsPath();
|
||||
QString modsPath();
|
||||
};
|
@ -21,7 +21,7 @@
|
||||
#include "../lib/serializer/JsonSerializer.h"
|
||||
#include "../lib/serializer/JsonDeserializer.h"
|
||||
|
||||
#include "jsonutils.h"
|
||||
#include "../vcmiqt/jsonutils.h"
|
||||
#include "windownewmap.h"
|
||||
#include "ui_windownewmap.h"
|
||||
#include "mainwindow.h"
|
||||
|
46
vcmiqt/CMakeLists.txt
Normal file
46
vcmiqt/CMakeLists.txt
Normal file
@ -0,0 +1,46 @@
|
||||
set(vcmiqt_SRCS
|
||||
StdInc.cpp
|
||||
|
||||
jsonutils.cpp
|
||||
launcherdirs.cpp
|
||||
)
|
||||
|
||||
set(vcmiqt_HEADERS
|
||||
StdInc.h
|
||||
|
||||
jsonutils.h
|
||||
launcherdirs.h
|
||||
convpathqstring.h
|
||||
vcmiqt.h
|
||||
)
|
||||
|
||||
assign_source_group(${vcmiqt_SRCS} ${vcmiqt_HEADERS})
|
||||
|
||||
if(ENABLE_STATIC_LIBS OR NOT (ENABLE_EDITOR AND ENABLE_LAUNCHER))
|
||||
add_library(vcmiqt STATIC ${vcmiqt_SRCS} ${vcmiqt_HEADERS})
|
||||
target_compile_definitions(vcmiqt PRIVATE VCMIQT_STATIC)
|
||||
else()
|
||||
add_library(vcmiqt SHARED ${vcmiqt_SRCS} ${vcmiqt_HEADERS})
|
||||
target_compile_definitions(vcmiqt PRIVATE VCMIQT_SHARED)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
set_target_properties(vcmiqt
|
||||
PROPERTIES
|
||||
OUTPUT_NAME "VCMI_vcmiqt"
|
||||
PROJECT_LABEL "VCMI_vcmiqt"
|
||||
)
|
||||
endif()
|
||||
|
||||
target_link_libraries(vcmiqt vcmi Qt${QT_VERSION_MAJOR}::Core)
|
||||
|
||||
target_include_directories(vcmiqt PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}
|
||||
)
|
||||
|
||||
if(NOT ENABLE_STATIC_LIBS OR (ENABLE_EDITOR AND ENABLE_LAUNCHER))
|
||||
install(TARGETS vcmiqt RUNTIME DESTINATION ${LIB_DIR} LIBRARY DESTINATION ${LIB_DIR})
|
||||
endif()
|
||||
|
||||
vcmi_set_output_dir(vcmiqt "")
|
||||
enable_pch(vcmiqt)
|
12
vcmiqt/StdInc.cpp
Normal file
12
vcmiqt/StdInc.cpp
Normal file
@ -0,0 +1,12 @@
|
||||
/*
|
||||
* StdInc.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
|
||||
*
|
||||
*/
|
||||
// Creates the precompiled header
|
||||
#include "StdInc.h"
|
||||
|
20
vcmiqt/StdInc.h
Normal file
20
vcmiqt/StdInc.h
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* StdInc.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
|
||||
|
||||
#include "../Global.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QString>
|
||||
|
||||
#include "convpathqstring.h"
|
||||
|
||||
VCMI_LIB_USING_NAMESPACE
|
29
vcmiqt/convpathqstring.h
Normal file
29
vcmiqt/convpathqstring.h
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* convpathqstring.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
|
||||
|
||||
inline QString pathToQString(const boost::filesystem::path & path)
|
||||
{
|
||||
#ifdef VCMI_WINDOWS
|
||||
return QString::fromStdWString(path.wstring());
|
||||
#else
|
||||
return QString::fromStdString(path.string());
|
||||
#endif
|
||||
}
|
||||
|
||||
inline boost::filesystem::path qstringToPath(const QString & path)
|
||||
{
|
||||
#ifdef VCMI_WINDOWS
|
||||
return boost::filesystem::path(path.toStdWString());
|
||||
#else
|
||||
return boost::filesystem::path(path.toUtf8().data());
|
||||
#endif
|
||||
}
|
@ -9,6 +9,8 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "vcmiqt.h"
|
||||
|
||||
#include <QVariant>
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
@ -17,11 +19,11 @@ class JsonNode;
|
||||
|
||||
namespace JsonUtils
|
||||
{
|
||||
QVariant toVariant(const JsonNode & node);
|
||||
QVariant JsonFromFile(QString filename);
|
||||
VCMIQT_LINKAGE QVariant toVariant(const JsonNode & node);
|
||||
VCMIQT_LINKAGE QVariant JsonFromFile(QString filename);
|
||||
|
||||
JsonNode toJson(QVariant object);
|
||||
void JsonToFile(QString filename, QVariant object);
|
||||
VCMIQT_LINKAGE JsonNode toJson(QVariant object);
|
||||
VCMIQT_LINKAGE void JsonToFile(QString filename, QVariant object);
|
||||
}
|
||||
|
||||
VCMI_LIB_NAMESPACE_END
|
@ -9,12 +9,14 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "vcmiqt.h"
|
||||
|
||||
/// similar to lib/VCMIDirs, controls where all launcher-related data will be stored
|
||||
namespace CLauncherDirs
|
||||
{
|
||||
void prepare();
|
||||
VCMIQT_LINKAGE void prepare();
|
||||
|
||||
QString downloadsPath();
|
||||
QString modsPath();
|
||||
QString mapsPath();
|
||||
VCMIQT_LINKAGE QString downloadsPath();
|
||||
VCMIQT_LINKAGE QString modsPath();
|
||||
VCMIQT_LINKAGE QString mapsPath();
|
||||
}
|
19
vcmiqt/vcmiqt.h
Normal file
19
vcmiqt/vcmiqt.h
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* vcmiqt.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
|
||||
*
|
||||
*/
|
||||
|
||||
#include <QtCore/QtGlobal>
|
||||
|
||||
#if VCMIQT_STATIC
|
||||
# define VCMIQT_LINKAGE
|
||||
#elif defined(VCMIQT_SHARED)
|
||||
# define VCMIQT_LINKAGE Q_DECL_EXPORT
|
||||
#else
|
||||
# define VCMIQT_LINKAGE Q_DECL_IMPORT
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user