Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create generic models that will be used by all game apps. #172

Open
MaySantucci opened this issue Apr 14, 2020 · 0 comments
Open

Create generic models that will be used by all game apps. #172

MaySantucci opened this issue Apr 14, 2020 · 0 comments

Comments

@MaySantucci
Copy link
Contributor

MaySantucci commented Apr 14, 2020

Because of Mysthea, Icaion and The Fall share the same structure, it is good create some generic models that will behave correctly with all of them.
The basic idea is to load a specific Json file when an app is chosen. So in the main.qml we will have something like this:

            AppContainer {
                id: _mysthea

               appConfiguration: AppConfiguration {
                                       id: _appConfiguration
                                       file: "MystheaConfiguration.json"
                            }

                objectName: PageName.mystheaPage
                logo: "qrc:/assets/images/mysthea_logo.png"
                mainColor: Palette.mystheaMain
                whiteColor: Palette.lightPink
                accentColor: Palette.darkPink
                headerSeparatorColor: Palette.pink
                rightAction: _drawerOpenAction
                appContents: [
                    Mysthea.CardsReference {
                        id: _cardsRef
                        searchFieldBorderColor: Palette.pinkLavenderBlush
                    },
                    Mysthea.GameSetup {},
                    Mysthea.Rulebook {},
                    Mysthea.Extras {
                        id: _mystheaExtras
                    }
                ]

                onTabButtonClicked: {
                    _cardsRef.clear()
                    _mystheaExtras.clear()
                }
            }

Where AppConfiguration has a structure like this:

class AppConfiguration : public QObject {
     Q_OBJECT
     Q_PROPERTY(QJsonDocument configurationFile WRITE setConfigurationFile NOTIFY configurationFileChanged)
     Q_PROPERTY(QVector<Card> cards READ cards NOTIFY cardsChanged)
     Q_PROPERTY(QVector<Artwork> artworks READ artworks NOTIFY artworksChanged)
     Q_PROPERTY(QVector<Miniature> miniatures READ miniatures NOTIFY miniaturesChanged)

public:
     void setConfigurationFile(const QJsonDocument &doc);
     QVector<Card> cards(); 
     QVector<Artwork> artworks();
     QVector<Miniature> miniatures();

public signals:
     void cardsChanged();
     void artworksChanged();
     void miniaturesChanged();
     void configurationFIleChanged();

private:
     void processFile(const QJsonDocument &file);

    QJsonDocument *m_configurationFile;
    QVector<Card> m_cards;
    QVector<Artwork> m_artworks;
     QVector<Miniature> m_miniatures;
 };

The cards, artworks, miniatures properties defined inside AppConfiguration will be passed respectively to the constructure or to a source property of CardsModel, ArtworksModel and MiniaturesModel to init them with the correct information.

The file that we pass to AppConfiguration's load function contains all the informations related to app's cards, artworks and miniatures, so its structure will be like this:

{
   "app":"mysthea",
   "cards":[
      {
         "code":"C001",
         "type":1,
         "command":1,
         "img":"mysthea/c001.jpg",
         "back_img":"",
         "description":"Pay 2 Energy Points to Act."
      },
      {
         "..."
      },
   ],
   "artworks":[
      {
         "name":"Telron",
         "type":1,
         "author":"Travis Anderson",
         "img":"qrc:/assets/images/extras/artworks/mysthea/champ_1.jpg"
      },
      {
         "..."
      },
   ],
   "miniatures":[
      {
         "name":"Telron",
         "type":1,
         "miniature":"qrc:/assets/images/extras/artworks/mysthea/champ_1.jpg"
      },
   ],
   "card_types":[
      {
         "id":0,
         "text":"All types",
         "icon":""
      },
      {
         "id":1,
         "text":"Era X",
         "icon":"qrc:/assets/icons/era_x.svg"
      },
      {
         "id":2,
         "text":"Era I",
         "icon":"qrc:/assets/icons/era_i.svg"
      },
      .....
   ],
   "card_commands":[
      {
         "id":0,
         "text":"All commands",
         "icon":"",
         "color":"#FFFFFF"
      },
      {
         "id":1,
         "text":"Tactic",
         "icon":"qrc:/assets/icons/tactic.svg",
         "color":"#F04937"
      },
     ......
   ],
   "artwork_types":[
      {
         "id":0,
         "text":"Heros"
      },
      {
         "id":1,
         "text":"Monsters"         
      },
    ],
   miniature_types: [{id: 0, text: "Heros"}, ... ],
}"

This class will be able to load the json file and process it to obtain the list of cards, artworks, miniatures and other informations related to a specif game app.

In this way in main.qm each times we click on an game app, we will instance an AppConfiguration object and and pass to it the Json configuration file. This file will be processed and will be created the data structures that we need to use in the various app models.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant