File indexing completed on 2024-04-28 15:07:44
0001 /* GCompris - balancebox_common.js 0002 * 0003 * SPDX-FileCopyrightText: 2015 Holger Kaelberer <holger.k@elberer.de> 0004 * 0005 * Authors: 0006 * Holger Kaelberer <holger.k@elberer.de> 0007 * 0008 * SPDX-License-Identifier: GPL-3.0-or-later 0009 */ 0010 0011 /** 0012 * Level description format: 0013 * 0014 * Example: 0015 * [ { "level": 1, 0016 * "map": [ [ 0x0000, 0x0308, ... ], 0017 * [ 0x0010, 0x0008, ... ], 0018 * ... 0019 * ], 0020 * "targets": [ 1, 2, 3, 5, 10, ... ] 0021 * }, 0022 * { "level": 2, ... } 0023 * ... 0024 * ] 0025 * 0026 * "level": Number of the level. 0027 * "map": Definition of the map inside the balancebox. 0028 * The map is a 2-dimensional array of map cells. A cell is 0029 * described by a bitmask of 16 bit with the lower 8bit defining walls, 0030 * objects, etc. (cf. below) and the higher 8 bit defining the order of 0031 * buttons present on the map. The values of the buttons are described 0032 * in the "targets" property. 0033 * "targets": Values of the buttons present on the map. Most likely these will 0034 * be numbers, but letters are also possible. The order in which they 0035 * need to be pressed by the ball is defined in the higher 8 bits of 0036 * the map fields. 0037 */ 0038 0039 var EMPTY = 0x0000; 0040 var NORTH = 0x0001; 0041 var EAST = 0x0002; 0042 var SOUTH = 0x0004; 0043 var WEST = 0x0008; 0044 // all the following are mutually exclusive: 0045 var START = 0x0010; 0046 var GOAL = 0x0020; 0047 var HOLE = 0x0040; 0048 var CONTACT = 0x0080; 0049 0050 var baseUrl = "qrc:/gcompris/src/activities/balancebox/resource"; 0051 var builtinFile = baseUrl + "/levels-default.json"; 0052 0053 function validateLevels(doc) 0054 { 0055 // minimal syntax check: 0056 if (undefined === doc || !Array.isArray(doc) || doc.length < 1) 0057 return false; 0058 for (var i = 0; i < doc.length; i++) { 0059 if (undefined === doc[i].map || !Array.isArray(doc[i].map) || 0060 doc[i].map.length < 1) 0061 return false; 0062 } 0063 return true; 0064 }