Multiple Datasets: Tutorial

Gcompris

Multiple dataset Migration of an Activity

This post is a step by step tutorial for adding multiple datasets to an activity in Gcompris.
The procedure of adding multiple datasets to an activity is fairly simple in Gcompris. The steps for it are given below.
Note: In these steps we'll refer the activity in consideration as current_activity. Also we assume that we plan to add 3 datasets to current_activity.

PROCEDURE

  1. Add the following line to current_activity/ActivityInfo.qml file

    levels: "1,2,3"
    

    The above line indicates that that the activity will contain 3 datasets and will automatically create the dataset selection menu for the activity with 3 options.
    example

    import GCompris 1.0
    
    ActivityInfo {
    name: "money/Money.qml"
    difficulty: 2
    icon: "money/money.svg"
    author: "Bruno Coudoin <bruno.coudoin@gcompris.net>"
    demo: false
    //: Activity title
    title: qsTr("Money")
    //: Help title
    description: qsTr("Practice money usage")
    //  intro: "Click or tap on the money to pay."
    //: Help goal
    goal: qsTr("You must buy the different items and give the exact price. At higher levels, several items are displayed, and you must first calculate the total price.")
    //: Help prerequisite
    prerequisite: qsTr("Can count")
    //: Help manual
    manual: qsTr("Click or tap on the coins or paper money at the bottom of the screen to pay. If you want to remove a coin or note, click or tap on it on the upper screen area.")
    credit: ""
    section: "math money measures"
    createdInVersion: 0
    levels: "1,2,3"
    }
    
  2. Create a resource directory inside the current_activity folder and inside it create separate folders for separate datasets with the name of the folder representing dataset number. The resultant directory structure would be as follows.
    +-- current_activity
    | ++-- resource
    | +++-- 1
    | ++++-- Data.qml
    | +++-- 2
    | ++++-- Data.qml
    | +++-- 3
    | ++++-- Data.qml

  3. Create a Data.qml file inside each dataset folder in the following format

    • objective - It will contain the text corresponding to this dataset that would be shown in the dataset selection menu.
    • difficulty - contains the difficulty of the dataset.
    • data - contains the actual data of the dataset The following example demonstrates the layout.
    import QtQuick 2.6
    import GCompris 1.0
    import "../../../../core"
    
    Dataset {
      objective: qsTr("Set and display time on analog clock for full half and quarters of an hour.")
      difficulty: 2
      data: [
      {
          "numberOfSubLevels": 5,
          "fixedMinutes": 0,
          "displayMinutesHand": false,
          "fixedSeconds": 0,
          "displaySecondsHand": false
      },
      {
          "numberOfSubLevels": 5,
          "fixedMinutes": 15,
          "displayMinutesHand": true,
          "fixedSeconds": 0,
          "displaySecondsHand": false
      },
      {
          "numberOfSubLevels": 5,
          "fixedMinutes": 30,
          "displayMinutesHand": true,
          "fixedSeconds": 0,
          "displaySecondsHand": false
      },
      {
          "numberOfSubLevels": 5,
          "fixedMinutes": 45,
          "displayMinutesHand": true,
          "fixedSeconds": 0,
          "displaySecondsHand": false
      }
      ]
    }
    
  4. In the current_activity/CurrentActivity.qml file add the following line to get the currenlty selected dataset.

              property var levels: activity.datasetLoader.item.data
    

    example

    QtObject {
              id: items
              property Item main: activity.main
              property alias background: background
              property GCSfx audioEffects: activity.audioEffects
              property alias answerModel: answerArea.pocketModel
              property alias pocketModel: pocketArea.pocketModel
              property alias store: store
              property alias instructions: instructions
              property alias tux: tux 
              property var levels: activity.datasetLoader.item.data
              property alias tuxMoney: tuxMoney
              property alias bar: bar
              property alias bonus: bonus
              property int itemIndex
              property int pocketRows
              property var selectedArea
              property alias pocket: pocketArea.answer
              property alias answer: answerArea.answer
          }
    

    This way the variable levels will contain the data section of the selected dataset.

  5. The dataset can be extracted from the levels variable inside the js file as follows.

      dataset = items.levels
      var data = dataset[currentLevel]
    

Comments

Popular posts from this blog

Generating generic questions for calendar activity.

Overriding Wordlist component function to use Multiple Datasets.