mirror of
https://github.com/QuasarApp/Snake.git
synced 2025-04-26 09:44:40 +00:00
ref #62 fix build Android
This commit is contained in:
parent
7bae425f97
commit
7ebdf6fd48
@ -26,7 +26,7 @@ else()
|
||||
add_executable(${CURRENT_PROJECT} ${SOURCE_CPP})
|
||||
endif()
|
||||
|
||||
target_link_libraries(${CURRENT_PROJECT} PUBLIC ${PROJECT_NAME}Core)
|
||||
target_link_libraries(${CURRENT_PROJECT} PUBLIC ${PROJECT_NAME}Core TestLvl)
|
||||
|
||||
target_include_directories(${CURRENT_PROJECT} PUBLIC ${PUBLIC_INCUDE_DIR})
|
||||
target_include_directories(${CURRENT_PROJECT} PRIVATE ${PRIVATE_INCUDE_DIR})
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQmlContext>
|
||||
#include <Crawl/clientapp.h>
|
||||
#include <testlvl.h>
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
@ -21,9 +22,10 @@ int main(int argc, char *argv[])
|
||||
QQmlApplicationEngine engine;
|
||||
ClientApp client;
|
||||
|
||||
client.registerLevel<TestLvl>();
|
||||
|
||||
if (!client.init(&engine)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
@ -67,25 +67,6 @@ void ClientApp::initLang() {
|
||||
}
|
||||
}
|
||||
|
||||
void ClientApp::initLvls() {
|
||||
auto plugins = availablePlugins();
|
||||
QList<QObject*> _availableWorlds;
|
||||
for (const auto& lvl: plugins) {
|
||||
WordlData data;
|
||||
IWorld* pluginData = PluginLoader::load(lvl.absoluteFilePath());
|
||||
|
||||
if (pluginData) {
|
||||
|
||||
data.model = pluginData;
|
||||
data.viewModel = new WorldViewData(data.model);
|
||||
_availableWorlds.push_back(data.viewModel);
|
||||
_availableLvls.insert(data.model->name(), data);
|
||||
}
|
||||
}
|
||||
|
||||
_menu->setAvailableLvls(_availableWorlds);
|
||||
}
|
||||
|
||||
IWorld *ClientApp::getLastWorld() {
|
||||
for (const auto &data : qAsConst(_availableLvls)) {
|
||||
if (data.viewModel && data.viewModel->unlocked()) {
|
||||
@ -115,23 +96,6 @@ void ClientApp::start(const QString &lvl) {
|
||||
_engine->start();
|
||||
}
|
||||
|
||||
QList<QFileInfo> ClientApp::availablePlugins() const {
|
||||
QDir dir(QCoreApplication::applicationDirPath() + "/modules");
|
||||
auto list = dir.entryInfoList(QStringList() << "*.so" << "*.dll", QDir::Files);
|
||||
#ifdef Q_OS_ANDROID
|
||||
dir.setPath(QCoreApplication::applicationDirPath());
|
||||
list += dir.entryInfoList(registeredLvls(), QDir::Files);
|
||||
#endif
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
QList<QString> ClientApp::registeredLvls() const {
|
||||
return {
|
||||
"*TestLvl.*"
|
||||
};
|
||||
}
|
||||
|
||||
bool ClientApp::init(QQmlApplicationEngine *engine) {
|
||||
|
||||
qputenv("QT_QUICK_CONTROLS_MATERIAL_THEME", initTheme());
|
||||
@ -155,7 +119,6 @@ bool ClientApp::init(QQmlApplicationEngine *engine) {
|
||||
|
||||
initCrawlResources();
|
||||
initLang();
|
||||
initLvls();
|
||||
|
||||
engine->addImportPath(":/CrawlModule/");
|
||||
|
||||
@ -177,3 +140,12 @@ bool ClientApp::init(QQmlApplicationEngine *engine) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ClientApp::addLvl(IWorld *levelWordl) {
|
||||
WordlData data;
|
||||
|
||||
data.model = levelWordl;
|
||||
data.viewModel = new WorldViewData(data.model);
|
||||
_availableLvls.insert(data.model->name(), data);
|
||||
_menu->addWorldViewModel(data.viewModel);
|
||||
}
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <QFileInfo>
|
||||
#include <QStringList>
|
||||
#include "global.h"
|
||||
#include "ilevel.h"
|
||||
|
||||
class Engine;
|
||||
class IWorld;
|
||||
@ -49,30 +50,36 @@ public:
|
||||
*/
|
||||
bool init(QQmlApplicationEngine* engine);
|
||||
|
||||
template<class LevelType>
|
||||
|
||||
/**
|
||||
* @brief registerLevel This method register new levels in game.
|
||||
*/
|
||||
void registerLevel() {
|
||||
|
||||
static_assert(std::is_base_of_v<ILevel, LevelType>,
|
||||
"Plrease use the child classes of the ILevel interface for tegistering new levels in the crawl game.");
|
||||
|
||||
addLvl(LevelType().world());
|
||||
}
|
||||
|
||||
private:
|
||||
QByteArray initTheme();
|
||||
void initLang();
|
||||
void initLvls();
|
||||
IWorld* getLastWorld();
|
||||
|
||||
/**
|
||||
* @brief addLvl This method should be add level to game.
|
||||
* @param levelWordl This is world instance
|
||||
*/
|
||||
void addLvl(IWorld* levelWordl);
|
||||
|
||||
/**
|
||||
* @brief start This method star new game in @a lvl
|
||||
* @param lvl This is lvl name
|
||||
*/
|
||||
void start(const QString& lvl);
|
||||
|
||||
/**
|
||||
* @brief availablePlugins This method read all available plugins.
|
||||
* @return list of the available plugins.
|
||||
*/
|
||||
QList<QFileInfo> availablePlugins() const;
|
||||
|
||||
/**
|
||||
* @brief registeredLvls This method should be return names of the lvl plugins. This method prepare data for loading plugins on android platform.
|
||||
* @return list of the plugins names.
|
||||
*/
|
||||
QList<QString> registeredLvls() const;
|
||||
|
||||
QHash<QString, WordlData> _availableLvls;
|
||||
MainMenuModel *_menu = nullptr;
|
||||
Engine *_engine = nullptr;
|
||||
|
8
src/Core/Crawl/ilevel.cpp
Normal file
8
src/Core/Crawl/ilevel.cpp
Normal file
@ -0,0 +1,8 @@
|
||||
//#
|
||||
//# Copyright (C) 2021-2021 QuasarApp.
|
||||
//# Distributed under the GPLv3 software license, see the accompanying
|
||||
//# Everyone is permitted to copy and distribute verbatim copies
|
||||
//# of this license document, but changing it is not allowed.
|
||||
//#
|
||||
|
||||
#include "ilevel.h"
|
30
src/Core/Crawl/ilevel.h
Normal file
30
src/Core/Crawl/ilevel.h
Normal file
@ -0,0 +1,30 @@
|
||||
//#
|
||||
//# Copyright (C) 2021-2021 QuasarApp.
|
||||
//# Distributed under the GPLv3 software license, see the accompanying
|
||||
//# Everyone is permitted to copy and distribute verbatim copies
|
||||
//# of this license document, but changing it is not allowed.
|
||||
//#
|
||||
|
||||
#ifndef LEVEL_H
|
||||
#define LEVEL_H
|
||||
|
||||
class IWorld;
|
||||
|
||||
/**
|
||||
* @brief The ILevel class This interface make the world instance object.
|
||||
* All levels libraries should be override this interface.
|
||||
*/
|
||||
class ILevel
|
||||
{
|
||||
public:
|
||||
ILevel() = default;
|
||||
virtual ~ILevel() = default;
|
||||
|
||||
/**
|
||||
* @brief world This method should be return pointer to the level world.
|
||||
* @return pointer to the level world.
|
||||
*/
|
||||
virtual IWorld* world() = 0;
|
||||
};
|
||||
|
||||
#endif // LEVEL_H
|
@ -27,6 +27,10 @@ QObject *MainMenuModel::availableLvlsModel() const {
|
||||
return _availableLvlsModel;
|
||||
}
|
||||
|
||||
void MainMenuModel::addWorldViewModel(QObject * data) {
|
||||
_availableLvlsModel->addSource(data);
|
||||
}
|
||||
|
||||
void MainMenuModel::setAvailableLvls(const QList<QObject*> &newData) {
|
||||
_availableLvlsModel->setSource(newData);
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ public:
|
||||
MainMenuModel(QObject *ptr = nullptr);
|
||||
QObject* userSettingsModel() const;
|
||||
QObject* availableLvlsModel() const;
|
||||
void addWorldViewModel(QObject *);
|
||||
void setAvailableLvls(const QList<QObject *> &newData);
|
||||
Q_INVOKABLE void newGame(const QString& lvl);
|
||||
|
||||
|
@ -15,13 +15,12 @@ file(GLOB SOURCE_CPP
|
||||
"private/*.cpp"
|
||||
"*.qrc"
|
||||
"private/*.qrc"
|
||||
"CrawlTestLvlAssets/*.qrc"
|
||||
)
|
||||
|
||||
set(PUBLIC_INCUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
set(PRIVATE_INCUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/private")
|
||||
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ../Client/modules)
|
||||
|
||||
add_library(${CURRENT_PROJECT} ${SOURCE_CPP})
|
||||
|
||||
target_link_libraries(${CURRENT_PROJECT} PUBLIC ${PROJECT_NAME}Core)
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 5ebf63b94d5f1ed15edddfb0a69080340e8a6e11
|
||||
Subproject commit c213ef504c8dd5b4c658504fbb506342bc9cf307
|
@ -1,11 +1,4 @@
|
||||
<RCC>
|
||||
<qresource prefix="/mesh">
|
||||
<file>res/meshes/cube.mesh</file>
|
||||
</qresource>
|
||||
<qresource prefix="/hdr">
|
||||
<file>res/hdr/testHDR.jpg</file>
|
||||
<file>res/hdr/testHDR.hdr</file>
|
||||
</qresource>
|
||||
<qresource prefix="/qml">
|
||||
<file>TestControl.qml</file>
|
||||
</qresource>
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
|
||||
Box::Box(): IWorldItem("Box") {
|
||||
setMash("qrc:/mesh/res/meshes/cube.mesh");
|
||||
setMash("qrc:/mesh/meshes/cube.mesh");
|
||||
setSize({2,2,2});
|
||||
setColor(QColor::fromRgb(rand()).name());
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
Plate::Plate(): IGround("plate")
|
||||
{
|
||||
setMash("qrc:/mesh/res/meshes/cube.mesh");
|
||||
setMash("qrc:/mesh/meshes/cube.mesh");
|
||||
setSize({100,100,0});
|
||||
setZ(0);
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ TestSnake::TestSnake(): Snake("Snake") {
|
||||
setBreakingForce(50);
|
||||
setAngularVelocity(100);
|
||||
setColor("#90faaa");
|
||||
setMash("qrc:/mesh/res/meshes/cube.mesh");
|
||||
setMash("qrc:/mesh/meshes/cube.mesh");
|
||||
setSize({2,1,1});
|
||||
|
||||
registerBodyitem<TestSnakeItem>();
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "testsnakeitem.h"
|
||||
|
||||
TestSnakeItem::TestSnakeItem() {
|
||||
setMash("qrc:/mesh/res/meshes/cube.mesh");
|
||||
setMash("qrc:/mesh/meshes/cube.mesh");
|
||||
setColor("#20aa9a");
|
||||
setSize({1,1,1});
|
||||
|
||||
|
@ -24,7 +24,7 @@ WorldRule *World::initWorldRules() {
|
||||
}
|
||||
|
||||
QString World::initHdrBackGround() const {
|
||||
return "qrc:/hdr/res/hdr/testHDR.hdr";
|
||||
return "qrc:/hdr/hdr/testHDR.hdr";
|
||||
}
|
||||
|
||||
QString World::description() const {
|
||||
@ -32,7 +32,7 @@ QString World::description() const {
|
||||
}
|
||||
|
||||
QString World::imagePreview() const {
|
||||
return "qrc:/hdr/res/hdr/testHDR.jpg";
|
||||
return "qrc:/hdr/hdr/testHDR.jpg";
|
||||
}
|
||||
|
||||
QString World::name() const {
|
||||
|
@ -5,12 +5,14 @@
|
||||
//# of this license document, but changing it is not allowed.
|
||||
//#
|
||||
|
||||
#include "Crawl/iworld.h"
|
||||
#include "testlvl.h"
|
||||
#include "world.h"
|
||||
|
||||
inline void initResources() { Q_INIT_RESOURCE(Empty); }
|
||||
TestLvl::TestLvl() {
|
||||
|
||||
extern "C" IWorld* worldInstance() {
|
||||
initResources();
|
||||
}
|
||||
|
||||
IWorld *TestLvl::world() {
|
||||
initTestLvlResources();
|
||||
return new World();
|
||||
}
|
30
src/CrawlTestLvl/testlvl.h
Normal file
30
src/CrawlTestLvl/testlvl.h
Normal file
@ -0,0 +1,30 @@
|
||||
//#
|
||||
//# Copyright (C) 2021-2021 QuasarApp.
|
||||
//# Distributed under the GPLv3 software license, see the accompanying
|
||||
//# Everyone is permitted to copy and distribute verbatim copies
|
||||
//# of this license document, but changing it is not allowed.
|
||||
//#
|
||||
|
||||
|
||||
#ifndef TESTLVL_H
|
||||
#define TESTLVL_H
|
||||
|
||||
#include <Crawl/ilevel.h>
|
||||
#include <QObject>
|
||||
|
||||
inline void initTestLvlResources() { Q_INIT_RESOURCE(Empty);
|
||||
Q_INIT_RESOURCE(testLvl);}
|
||||
/**
|
||||
* @brief The TestLvl class This is test lvlv wraper of the crawl
|
||||
*/
|
||||
class TestLvl: public ILevel
|
||||
{
|
||||
public:
|
||||
TestLvl();
|
||||
|
||||
// ILevel interface
|
||||
public:
|
||||
IWorld *world() override;
|
||||
};
|
||||
|
||||
#endif // TESTLVL_H
|
@ -6,7 +6,6 @@
|
||||
//#
|
||||
|
||||
#include <QtTest>
|
||||
#include "pluginloadertest.h"
|
||||
#include "clasterstest.h"
|
||||
|
||||
// Use This macros for initialize your own test classes.
|
||||
@ -33,7 +32,6 @@ private slots:
|
||||
|
||||
|
||||
// BEGIN TESTS CASES
|
||||
TestCase(exampleTest, PluginLoaderTest)
|
||||
TestCase(clastersTest, ClastersTest)
|
||||
|
||||
// END TEST CASES
|
||||
|
@ -1,22 +0,0 @@
|
||||
//#
|
||||
//# Copyright (C) 2020-2021 QuasarApp.
|
||||
//# Distributed under the GPLv3 software license, see the accompanying
|
||||
//# Everyone is permitted to copy and distribute verbatim copies
|
||||
//# of this license document, but changing it is not allowed.
|
||||
//#
|
||||
|
||||
|
||||
#include "pluginloadertest.h"
|
||||
|
||||
|
||||
PluginLoaderTest::PluginLoaderTest() {
|
||||
|
||||
}
|
||||
|
||||
PluginLoaderTest::~PluginLoaderTest() {
|
||||
|
||||
}
|
||||
|
||||
void PluginLoaderTest::test() {
|
||||
QVERIFY(true);
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
//#
|
||||
//# Copyright (C) 2020-2021 QuasarApp.
|
||||
//# Distributed under the GPLv3 software license, see the accompanying
|
||||
//# Everyone is permitted to copy and distribute verbatim copies
|
||||
//# of this license document, but changing it is not allowed.
|
||||
//#
|
||||
|
||||
|
||||
|
||||
#ifndef EXAMPLE_TEST_H
|
||||
#define EXAMPLE_TEST_H
|
||||
#include "test.h"
|
||||
#include "testutils.h"
|
||||
|
||||
#include <QtTest>
|
||||
|
||||
class PluginLoaderTest: public Test, protected TestUtils
|
||||
{
|
||||
public:
|
||||
PluginLoaderTest();
|
||||
~PluginLoaderTest();
|
||||
|
||||
void test();
|
||||
|
||||
};
|
||||
|
||||
#endif // EXAMPLE_TEST_H
|
Loading…
x
Reference in New Issue
Block a user