Design Document JSON Data Structures

From BOARD18 Project WIKI
Revision as of 09:08, 21 February 2018 by Rich (talk | contribs) (→‎The JSON Game Session Data Structure: added links)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
This page has been updated to comply with Release 2.5.x of BOARD18.
Design Document edit


The JSON Game Session Data Structure

Each BOARD18 game session has its own JSON data structure. This data structure is stored in the “json_text” field of the game table. The gname, and boxID keys are used to identify the JSON Game Session and specify the game box that the game session uses. These are followed by four array structures.

The following is a depiction of the top levels of this data structure:

{
  "gname":"The Name of the Game", 
  "boxID":"The numeric ID of the Game Box", 
  "brdTls": {
    
  },
  "brdTks": {

  },
  "mktTks": [
  
  ],
  "trayCounts": [
 
  ]
}

The array with the key of brdTls tracks the tiles that have been placed on the board. The array with the key of brdTks tracks the tokens that have been placed on the board. The array with the key of mktTks tracks the tokens that have been placed on the stock market. And the array with the key of trayCounts tracks the number of remaining tiles and tokens available to be played on the game board.

These arrays are stored in the global variable BD18.gm. This global variable is loaded by the gameBox.php server function and the loadSession() javascript function which is in both the board18Map2.js file and the board18Market2.js file.

The brdTls array

Functions that access brdTls
Function In File
makeBdTileList() board18Map2.js
updateGmBrdTiles() board18Map3.js

This array is built and modified dynamically. Below is a part of a brdTls array which is currently tracking 63 tiles on the game board. And to the right is a list of the functions that access this array.

brdTls:Array(63)
  0:
    rotate:2
    sheetNumber:0
    tileNumber:10
    xCoord:5
    yCoord:15

  1:
    rotate:2
    sheetNumber:0
    tileNumber:15
    xCoord:3
    yCoord:13

 . . . .

  62:
   rotate:0
   sheetNumber:0
   tileNumber:9
   xCoord:4
   yCoord:10

The brdTks array

Functions that access brdTks
Function In File
makeBdTokenList() board18Map2.js
updateGmBrdTokens() board18Map3.js

This array is built and modified dynamically. Below is a part of a brdTks array which is currently tracking 29 tokens on the game board. And to the right is a list of the functions that access this array.

brdTks:Array(29)
  0:
    flip:false
    sheetNumber:5
    tokenNumber:5
    xCoord:447
    yCoord:466

  1:
    flip:false
    sheetNumber:5
    tokenNumber:6
    xCoord:467
    yCoord:497

 . . . .

  28:
    flip:false
    sheetNumber:5
    tokenNumber:10
    xCoord:301
    yCoord:855.4444580078125

The mktTks array

Functions that access mktTks
Function In File
makeMktTokenList() board18Market2.js
updateMarketTokens() board18Market3.js

This array is built and modified dynamically. Below is a part of a mktTks array which is currently tracking 29 tokens on the stock market. And to the right is a list of the functions that access this array.

mktTks:Array(29)
  0:
    flip:false
    sheetNumber:0
    stack:0
    tokenNumber:0
    xCoord:216
    yCoord:113

  1:
    flip:false
    sheetNumber:0
    stack:0
    tokenNumber:16
    xCoord:214
    yCoord:272

 . . . .

  28:
    flip:false
    sheetNumber:0
    stack:0
    tokenNumber:2
    xCoord:1339
    yCoord:198

The trayCounts array

Functions that access trayCounts
Function In File
TileSheet(image,sheet) board18Map1.js
TokenSheet(image,sheet) board18Map1.js
loadBox(box) board18Map2.js
reduceCount(sheet,ind) board18Map3.js
increaseCount(sheet,ind) board18Map3.js
traySelect(event) board18Map6.js

This array is built and modified dynamically. It is initialized by the javascript loadBox() function only if it is found to be uninitialized. Below is a trayCounts array which is currently tracking the remaining counts for 75 token/tile items in 6 different trays. Each sub array is tracking a separate tray. And to the right is a list of the functions that access this array.

trayCounts:Array(6)
  0:(16) [2, 8, 10, 6, 4, 6, 1, 5, 4, 3, 0, 1, 1, 2, 0, 1]
  1:(14) [2, 1, 1, 2, 2, 3, 1, 3, 2, 2, 2, 1, 1, 1]
  2:(14) [2, 4, 0, 0, 1, 1, 1, 1, 1, 1, 1, 2, 4, 3]
  3:(8) [0, 0, 0, 0, 2, 1, 1, 3]
  4:(5) [3, 3, 1, 1, 1]
  5:(18) [0, 1, 2, 0, 1, 0, 0, 2, 2, 0, 2, 2, 1, 0, 1, 1, 1, 1]