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

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 Error(filename, message) 86 Error(filename, message)
87 end 87 end
88 88
89 if type(leveldef) ~= 'table' then 89 if type(leveldef) ~= 'table' then
90 return Err("file does not evaluate to an object of type 'table'") 90 return Err("file does not evaluate to an object of type 'table'")
91 end 91 end
92 92
93 CheckValidKeys(filename, leveldef, { 'num_stars', 'shapes', 'sprites', 'scri pt' }) 93 CheckValidKeys(filename, leveldef, { 'num_stars', 'shapes', 'sprites', 'scri pt' })
94 94
95 if leveldef.shapes then 95 if leveldef.shapes then
96 local valid_keys = { 'start', 'finish', 'color', 'type', 'anchor', 'tag' , 'dynamic' } 96 local valid_keys = { 'pos', 'children', 'start', 'finish', 'color', 'typ e', 'anchor', 'tag', 'dynamic' }
97 local valid_types = { 'line', 'edge' } 97 local valid_types = { 'compound', 'line', 'edge' }
98 local required_keys = { 'type' } 98 local required_keys = { 'type' }
99 for _, shape in pairs(leveldef.shapes) do 99
100 CheckValidKeys(filename, shape, valid_keys) 100 local function ValidateShapeList(shapes)
101 CheckRequiredKeys(filename, shape, required_keys, 'shape') 101 for _, shape in pairs(shapes) do
102 if not ListContains(valid_types, shape.type) then 102 if #shape > 0 then
103 Err('invalid shape type: ' .. shape.type) 103 ValidateShapeList(shape)
104 else
105 CheckValidKeys(filename, shape, valid_keys)
106 CheckRequiredKeys(filename, shape, required_keys, 'shape')
107 if not ListContains(valid_types, shape.type) then
108 Err('invalid shape type: ' .. shape.type)
109 end
110 end
104 end 111 end
105 end 112 end
113
114 ValidateShapeList(leveldef.shapes)
106 end 115 end
107 116
108 if leveldef.sprites then 117 if leveldef.sprites then
109 local valid_keys = { 'pos', 'tag', 'image', 'script', 'sensor' } 118 local valid_keys = { 'pos', 'tag', 'image', 'script', 'sensor' }
110 local required_keys = { 'pos', 'image' } 119 local required_keys = { 'pos', 'image' }
111 for _, sprite in pairs(leveldef.sprites) do 120 for _, sprite in pairs(leveldef.sprites) do
112 CheckValidKeys(filename, sprite, valid_keys) 121 CheckValidKeys(filename, sprite, valid_keys)
113 CheckRequiredKeys(filename, sprite, required_keys, 'sprite') 122 CheckRequiredKeys(filename, sprite, required_keys, 'sprite')
114 if gamedef.assets[sprite.image] == nil then 123 if gamedef.assets[sprite.image] == nil then
115 Err('invalid image asset: ' .. sprite.image) 124 Err('invalid image asset: ' .. sprite.image)
(...skipping 14 matching lines...) Expand all
130 for _, level in ipairs(gamedef.levels) do 139 for _, level in ipairs(gamedef.levels) do
131 filename = path.join(gamedef.root, level) 140 filename = path.join(gamedef.root, level)
132 level = util.LoadYaml(filename) 141 level = util.LoadYaml(filename)
133 validate.ValidateLevelDef(filename, gamedef, level) 142 validate.ValidateLevelDef(filename, gamedef, level)
134 end 143 end
135 144
136 print("Validation successful!") 145 print("Validation successful!")
137 end 146 end
138 147
139 return validate 148 return validate
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698