File indexing completed on 2024-05-12 05:40:40

0001 /***************************************************************************
0002  *   Copyright (C) 2015 by Renaud Guezennec                                *
0003  *   https://rolisteam.org/contact                   *
0004  *                                                                         *
0005  *   rolisteam is free software; you can redistribute it and/or modify     *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
0019  ***************************************************************************/
0020 
0021 #ifndef NAMEGENERATORWIDGET_H
0022 #define NAMEGENERATORWIDGET_H
0023 
0024 #include "rwidgets/gmtoolbox/gamemastertool.h"
0025 #include "rwidgets_global.h"
0026 #include <QHash>
0027 #include <QRandomGenerator>
0028 #include <QWidget>
0029 
0030 namespace Ui
0031 {
0032 class NameGeneratorWidget;
0033 }
0034 
0035 struct DataBase;
0036 /**
0037  * @page NameGenerator Name Generator
0038  * @tableofcontents
0039  * @section Intro Introduction
0040  * NameGenerator provides a way to get ramdom name from different culture.<br/>
0041  * This tool is dedicated to GM.<br/>
0042  *
0043  *
0044  * @section algo Let's have a look to the algo:
0045  *
0046  * @section todo Todo:
0047  * @todo Add new country
0048  */
0049 
0050 /**
0051  * @brief The NameGeneratorWidget class
0052  */
0053 class RWIDGET_EXPORT NameGeneratorWidget : public QWidget, public GameMasterTool
0054 {
0055     Q_OBJECT
0056 
0057 public:
0058     enum AVAILABLE_GENDER
0059     {
0060         Female,
0061         Male,
0062         BOTH,
0063         NONE
0064     };
0065     enum TypeOfGeneration
0066     {
0067         Chinese,
0068         Elves,
0069         English,
0070         French,
0071         Japanese,
0072         StarWars,
0073         Russian
0074     };
0075 
0076     explicit NameGeneratorWidget(QWidget* parent= nullptr);
0077     ~NameGeneratorWidget();
0078 
0079 protected:
0080     void buildAllNames(int count, QHash<QString, DataBase> data);
0081 protected slots:
0082     void checkFeatureAvailability();
0083 private slots:
0084     void generateName();
0085     bool nextCharacterCanEnd(const QJsonObject& json, QString key);
0086     bool nextIsPossible(const QJsonObject& json, QString key, bool last);
0087 
0088 private:
0089     QString buildName(const QJsonObject& json);
0090     QString pickUpName(QStringList data);
0091 
0092 private:
0093     Ui::NameGeneratorWidget* ui;
0094     QStringList m_model;
0095     QHash<TypeOfGeneration, QHash<QString, DataBase>> m_complexName;
0096     QRandomGenerator m_generator;
0097 };
0098 
0099 /**
0100  * @brief The DataBase struct stored data for database
0101  */
0102 struct RWIDGET_EXPORT DataBase
0103 {
0104     NameGeneratorWidget::AVAILABLE_GENDER gender;
0105     QString filepath;
0106     int id;
0107     bool generate;
0108 };
0109 #endif // NAMEGENERATORWIDGET_H