4
0
mirror of https://github.com/QuasarApp/Hanoi-Towers.git synced 2025-05-13 18:09:33 +00:00

257 lines
6.7 KiB
C
Raw Normal View History

2020-05-23 02:31:12 +03:00
/*
* Copyright (C) 2018-2021 QuasarApp.
2020-05-23 02:31:12 +03:00
* Distributed under the lgplv3 software license, see the accompanying
* Everyone is permitted to copy and distribute verbatim copies
* of this license document, but changing it is not allowed.
*/
2018-01-20 17:44:28 +03:00
#ifndef SAVER_H
#define SAVER_H
2019-09-17 15:40:48 +03:00
#include "gamestate.h"
2019-11-10 21:46:27 +03:00
#include "hanoiclient.h"
2021-01-15 19:09:07 +03:00
#include "localuser.h"
2019-11-10 21:46:27 +03:00
#include "profiledata.h"
2020-11-03 12:19:01 +03:00
#include "settingsdata.h"
2019-11-10 14:11:50 +03:00
#include <quasarapp.h>
2018-01-20 17:44:28 +03:00
#include <QObject>
#include <QFile>
#include "onlinestatusqml.h"
2020-05-24 02:24:49 +03:00
//#include <listviewmodel.h>
2018-04-13 22:24:52 +03:00
#define SAVE "data"
2019-07-04 18:06:25 +03:00
#define MAIN_FOLDER QDir::homePath() + "/.HanoiTowers"
#define MAIN_FOLDER_KEY "HanoiTowersFolder"
2019-11-11 23:36:18 +03:00
#define MAIN_SETINGS_FILE MAIN_FOLDER + "/" + SAVE
2019-07-04 18:06:25 +03:00
2020-05-24 02:24:49 +03:00
namespace LoginView {
class LVMainModel;
2020-05-27 01:02:05 +03:00
class UserData;
2020-05-24 02:24:49 +03:00
}
class QQmlApplicationEngine;
2020-10-31 19:07:28 +03:00
class RecordListModel;
class HanoiImageProvider;
2021-01-18 23:20:37 +03:00
class DataConverter;
2021-03-15 18:04:09 +03:00
class RecordsProxyModel;
2020-05-24 02:24:49 +03:00
2021-05-04 12:36:43 +03:00
class HanoiTowers: public QObject
2018-01-20 17:44:28 +03:00
{
Q_OBJECT
2018-07-03 17:45:02 +03:00
Q_PROPERTY(bool randomColor READ randomColor WRITE setRandomColor NOTIFY randomColorChanged)
Q_PROPERTY(bool animation READ animation WRITE setAnimation NOTIFY animationChanged)
Q_PROPERTY(bool fog READ fog WRITE setFog NOTIFY fogChanged)
Q_PROPERTY(bool fogAnimation READ fogAnimation WRITE setFogAnimation NOTIFY fogAnimationChanged)
2021-05-19 19:10:33 +03:00
Q_PROPERTY(bool showCredits READ showCredits WRITE setShowCredits NOTIFY showCreditsChanged)
2021-06-01 20:30:43 +03:00
Q_PROPERTY(unsigned int launchCount READ launchCount WRITE setLaunchCount NOTIFY launchCountChanged)
2021-03-15 16:58:03 +03:00
Q_PROPERTY(GameState* gameState READ gameState WRITE setGameState NOTIFY profileChanged)
2020-10-29 20:25:28 +03:00
Q_PROPERTY(QObject* client READ client)
2018-04-11 22:13:34 +03:00
2021-03-07 20:38:38 +03:00
// local
2020-10-31 19:07:28 +03:00
Q_PROPERTY(QObject* profileList READ profileList NOTIFY profileListChanged)
Q_PROPERTY(QObject* profileObject READ profileObject NOTIFY profileChanged)
2021-03-07 20:38:38 +03:00
// global
Q_PROPERTY(QObject* worldList READ worldList NOTIFY worldListChanged)
2021-03-03 19:20:13 +03:00
Q_PROPERTY(QObject* bestUser READ bestUser NOTIFY bestUserChanged)
2021-03-07 20:38:38 +03:00
Q_PROPERTY(QObject* selectedUser READ selectedUser NOTIFY selectedUserChanged)
2019-11-20 17:55:13 +03:00
Q_PROPERTY(QString profile READ profile WRITE setProfile NOTIFY profileChanged)
2021-02-12 18:02:18 +03:00
Q_PROPERTY(int onlineStatus READ onlineStatus NOTIFY onlineStatusChanged)
2021-05-05 11:30:40 +03:00
Q_PROPERTY(QString onlineStatusColor READ onlineStatusColor NOTIFY onlineStatusChanged)
2019-11-10 14:11:50 +03:00
2019-11-11 23:36:18 +03:00
2018-01-20 17:44:28 +03:00
public:
2021-05-04 12:36:43 +03:00
HanoiTowers(QQmlApplicationEngine *engine);
~HanoiTowers();
2019-09-17 15:40:48 +03:00
2019-11-11 23:36:18 +03:00
Q_INVOKABLE QString profile() const;
2020-10-31 19:07:28 +03:00
Q_INVOKABLE QObject* profileList();
2021-03-02 19:34:53 +03:00
Q_INVOKABLE QObject* worldList();
2019-11-11 23:36:18 +03:00
2020-11-01 23:59:37 +03:00
Q_INVOKABLE bool createProfile(const QString &userId, const QString& userName);
2019-11-10 14:11:50 +03:00
2020-11-03 12:19:01 +03:00
/**
* @brief isFirst
* @return true if is first start
*/
Q_INVOKABLE bool isFirst()const;
/**
* @brief setShowHelp set new state for show help message
* @param state - a new state of show help message
*/
Q_INVOKABLE void setShowHelp(bool state);
2021-03-07 20:38:38 +03:00
/**
* @brief setNewAvatar This method sets new avatar for current user.
* @param pathToAvatar
*/
Q_INVOKABLE void setNewAvatar(QString pathToAvatar);
2020-05-24 02:24:49 +03:00
2021-03-07 20:38:38 +03:00
/**
* @brief selectUserFromWorldTable This method changes selectedUser object.
* @param userId
*/
Q_INVOKABLE void selectUserFromWorldTable(const QString &userId);
bool fog() const;
bool fogAnimation() const;
2021-01-22 17:23:19 +03:00
Q_INVOKABLE void onlineRequest(const QString& userId);
2021-03-26 17:20:41 +03:00
Q_INVOKABLE void updateProfile();
int onlineStatus() const;
2021-05-05 11:30:40 +03:00
QString onlineStatusColor() const;
2021-01-22 17:23:19 +03:00
2021-03-07 20:38:38 +03:00
QObject *bestUser();
QObject *selectedUser();
2021-03-03 19:20:13 +03:00
2021-05-07 22:36:47 +03:00
Q_INVOKABLE bool isAndroid() const;
2021-05-11 11:30:39 +03:00
Q_INVOKABLE bool isAdMod() const;
2021-05-05 11:30:40 +03:00
2021-05-19 19:10:33 +03:00
bool showCredits() const;
void setShowCredits(bool newShowCredits);
2021-06-01 20:30:43 +03:00
unsigned int launchCount() const;
void setLaunchCount(unsigned int newLaunchCount);
2018-01-20 17:44:28 +03:00
public slots:
2019-09-17 15:40:48 +03:00
2018-04-11 22:13:34 +03:00
/**
* @brief getMinSteps
* @param lvl
* @return minimum step of current lvl
*/
unsigned short getMinSteps(const unsigned short lvl) const;
2018-07-03 17:45:02 +03:00
/**
* @brief randomColor
* @return return true if enable random color of plate;
*/
bool randomColor()const;
/**
* @brief animation
* @return name of render animation;
*/
bool animation() const;
/**
* @brief setAnimation
* @param name of new animation;
*/
2020-11-03 12:19:01 +03:00
void setAnimation(bool valeu);
2018-07-03 17:45:02 +03:00
/**
* @brief setRandomColor
* enabfle or disable random colors.
*/
void setRandomColor(bool );
2020-05-24 02:24:49 +03:00
/**
* @brief gameState
* @return
*/
2021-01-17 12:12:39 +03:00
GameState* gameState();
2019-11-11 23:36:18 +03:00
2020-05-24 02:24:49 +03:00
/**
2020-10-29 20:25:28 +03:00
* @brief client
2020-05-24 02:24:49 +03:00
* @return
*/
2020-10-29 20:25:28 +03:00
QObject *client();
2020-05-24 02:24:49 +03:00
/**
* @brief profileObject
* @return
*/
2021-01-15 19:09:07 +03:00
QObject* profileObject();
2020-05-24 02:24:49 +03:00
2021-01-15 19:09:07 +03:00
void removeUser(const QString &userId);
2020-11-01 23:59:37 +03:00
void setProfile(QString userId);
2019-11-20 18:12:18 +03:00
void setReward(int);
void setFog(bool fog);
void setFogAnimation(bool fogAnimation);
2019-11-20 18:12:18 +03:00
2021-01-17 12:12:39 +03:00
void setGameState(GameState* gameState);
2021-01-22 17:23:19 +03:00
2018-04-11 22:13:34 +03:00
signals:
2018-07-03 17:45:02 +03:00
void animationChanged();
void randomColorChanged();
2019-11-10 21:46:27 +03:00
void profileListChanged();
2021-03-15 16:58:03 +03:00
void profileChanged();
2020-05-24 02:24:49 +03:00
void usersListModelChanged(QObject* usersListModel);
2020-05-27 01:02:05 +03:00
void showOnlinePage();
2020-11-01 14:28:13 +03:00
void fogChanged(bool fog);
void fogAnimationChanged(bool fogAnimation);
void onlineStatusChanged(int onlineStatus);
2021-03-02 19:34:53 +03:00
void worldListChanged(QObject* worldList);
2021-03-03 19:20:13 +03:00
void bestUserChanged(QObject* bestUser);
2021-03-07 20:38:38 +03:00
void selectedUserChanged(QObject* selectedUser);
2021-05-19 19:10:33 +03:00
void showCreditsChanged();
2021-06-01 20:30:43 +03:00
void launchCountChanged();
2020-11-01 14:28:13 +03:00
private slots:
void handleChangeName(const QString&);
2021-03-11 12:48:04 +03:00
void handleBestUserIdChanged(const QString&userId);
2021-01-17 14:11:10 +03:00
void handleCreateNewProfile(const LoginView::UserData&);
2020-11-01 14:28:13 +03:00
void handleOnlineRequest(const LoginView::UserData&);
2021-01-22 17:23:19 +03:00
void handleOnlineRegisterRequest(const LoginView::UserData&);
2021-02-09 21:21:30 +03:00
void handleOnlineRequestError(QH::ErrorCodes::Code, const QString&Errr);
2020-11-01 14:28:13 +03:00
2021-03-07 20:38:38 +03:00
void handleAcceptUserData(QSharedPointer<LocalUser> profileId);
2021-02-12 18:02:18 +03:00
void setOnlineStatus(QH::ClientStatus onlineStatus);
2021-03-02 19:34:53 +03:00
void handleWorldChanged(QSharedPointer<WorldUpdate>);
2021-03-11 17:47:44 +03:00
void handleWorldInited(QHash<QString, UserPreview> initWorldList);
2020-11-01 14:28:13 +03:00
private:
void init();
2021-05-13 10:42:32 +03:00
void loadOldSaves();
2020-11-01 14:28:13 +03:00
QuasarAppUtils::Settings *_settings = nullptr;
2021-01-17 14:11:10 +03:00
2020-11-01 14:28:13 +03:00
LoginView::LVMainModel *_loginModel = nullptr;
2021-01-17 14:11:10 +03:00
LoginView::LVMainModel *_createNewOfflineUser = nullptr;
2020-11-01 14:28:13 +03:00
RecordListModel * _recordsTable = nullptr;
2021-03-02 19:34:53 +03:00
RecordListModel * _world = nullptr;
2021-03-15 18:04:09 +03:00
RecordsProxyModel * _worldProxy = nullptr;
2021-05-05 11:00:44 +03:00
RecordsProxyModel * _recordsTableProxy = nullptr;
2020-11-01 14:28:13 +03:00
2021-01-15 19:09:07 +03:00
LocalUser _profile;
2021-03-03 19:20:13 +03:00
LocalUser _bestUser;
2021-03-07 20:38:38 +03:00
LocalUser _selectedUser;
2021-03-03 19:20:13 +03:00
2021-01-15 19:09:07 +03:00
HanoiClient *_client = nullptr;
2020-11-01 14:28:13 +03:00
2020-11-03 12:19:01 +03:00
SettingsData _settingsData;
2021-01-17 12:12:39 +03:00
HanoiImageProvider *_imageProvider = nullptr;
2021-01-18 23:20:37 +03:00
DataConverter *_dataConverter = nullptr;
2021-02-12 18:02:18 +03:00
OnlineStatus _onlineStatus = OnlineStatus::Dissconnected;
2018-01-20 17:44:28 +03:00
};
2021-01-17 12:12:39 +03:00
2018-01-20 17:44:28 +03:00
#endif // SAVER_H