Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(990)

Side by Side Diff: nacltoons/data/res/validate.lua

Issue 15070003: [nacltoons] Add compound shapes. (Closed) Base URL: https://nativeclient-sdk.googlecode.com/svn/trunk/src
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 -- Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 -- Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 -- Use of this source code is governed by a BSD-style license that can be 2 -- Use of this source code is governed by a BSD-style license that can be
3 -- found in the LICENSE file. 3 -- found in the LICENSE file.
4 4
5 -- Functions for validating game data files (.def files). 5 -- Functions for validating game data files (.def files).
6 -- This module provides a single global called 'validate' which 6 -- This module provides a single global called 'validate' which
7 -- contains two function: 7 -- contains two function:
8 -- ValidateGameDef 8 -- ValidateGameDef
9 -- ValidateLevelDef 9 -- ValidateLevelDef
10 -- 10 --
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 -- @param the level.def lua table (result of dofile()) 86 -- @param the level.def lua table (result of dofile())
87 validate.ValidateLevelDef = function(filename, gamedef, leveldef) 87 validate.ValidateLevelDef = function(filename, gamedef, leveldef)
88 local function Err(message) 88 local function Err(message)
89 Error(filename, message) 89 Error(filename, message)
90 end 90 end
91 91
92 if type(leveldef) ~= 'table' then 92 if type(leveldef) ~= 'table' then
93 return Err("file does not evaluate to an object of type 'table'") 93 return Err("file does not evaluate to an object of type 'table'")
94 end 94 end
95 95
96 CheckValidKeys(filename, leveldef, { 'num_stars', 'shapes', 'sprites', 'scri pt' }) 96 CheckValidKeys(filename, leveldef, { 'num_stars', 'shapes', 'script' })
97 97
98 if leveldef.shapes then 98 if leveldef.shapes then
99 local valid_keys = { 'start', 'finish', 'color', 'type', 'anchor', 'tag' , 'dynamic' } 99 local valid_keys = { 'script', 'pos', 'children', 'sensor', 'image', 'st art', 'finish', 'color', 'type', 'anchor', 'tag', 'dynamic' }
100 local valid_types = { 'line', 'edge' } 100 local valid_types = { 'compound', 'line', 'edge', 'image' }
101 local required_keys = { 'type' } 101 local required_keys = { 'type' }
102 for _, shape in pairs(leveldef.shapes) do 102
103 CheckValidKeys(filename, shape, valid_keys) 103 local function ValidateShapeList(shapes)
104 CheckRequiredKeys(filename, shape, required_keys, 'shape') 104 for _, shape in pairs(shapes) do
105 if not ListContains(valid_types, shape.type) then 105 if #shape > 0 then
106 Err('invalid shape type: ' .. shape.type) 106 ValidateShapeList(shape)
107 else
108 CheckValidKeys(filename, shape, valid_keys)
109 CheckRequiredKeys(filename, shape, required_keys, 'shape')
110 if not ListContains(valid_types, shape.type) then
111 Err('invalid shape type: ' .. shape.type)
112 end
113 end
107 end 114 end
108 end 115 end
116
117 ValidateShapeList(leveldef.shapes)
109 end 118 end
110
111 if leveldef.sprites then
112 local valid_keys = { 'pos', 'tag', 'image', 'script', 'sensor' }
113 local required_keys = { 'pos', 'image' }
114 for _, sprite in pairs(leveldef.sprites) do
115 CheckValidKeys(filename, sprite, valid_keys)
116 CheckRequiredKeys(filename, sprite, required_keys, 'sprite')
117 if gamedef.assets[sprite.image] == nil then
118 Err('invalid image asset: ' .. sprite.image)
119 end
120 end
121 end
122
123 end 119 end
124 120
125 if arg and #arg >= 1 then 121 if arg and #arg >= 1 then
126 -- When run from the command line run validation on passed in game.def file. 122 -- When run from the command line run validation on passed in game.def file.
127 local filename = arg[1] 123 local filename = arg[1]
128 if string.sub(filename, -4) == '.def' then 124 if string.sub(filename, -4) == '.def' then
129 local gamedef = util.LoadYaml(filename) 125 local gamedef = util.LoadYaml(filename)
130 gamedef.root = path.dirname(filename) 126 gamedef.root = path.dirname(filename)
131 validate.ValidateGameDef(filename, gamedef) 127 validate.ValidateGameDef(filename, gamedef)
132 128
133 -- Now validate all the levels in the game. 129 -- Now validate all the levels in the game.
134 for _, level in ipairs(gamedef.levels) do 130 for _, level in ipairs(gamedef.levels) do
135 filename = path.join(gamedef.root, level) 131 filename = path.join(gamedef.root, level)
136 level = util.LoadYaml(filename) 132 level = util.LoadYaml(filename)
137 validate.ValidateLevelDef(filename, gamedef, level) 133 validate.ValidateLevelDef(filename, gamedef, level)
138 end 134 end
139 135
140 print("Validation successful!") 136 print("Validation successful!")
141 end 137 end
binji 2013/05/21 21:11:36 warn on no match? or do you do this to allow globb
Sam Clegg 2013/05/21 22:51:46 The problem is that thee is no way to do "if __nam
142 end 138 end
143 139
144 return validate 140 return validate
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698