| OLD | NEW |
| 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 --- Utility functions and constants shared by nacltoons lua code | 5 --- Utility functions and constants shared by nacltoons lua code |
| 6 | 6 |
| 7 local yaml = require 'yaml' | 7 local yaml = require 'yaml' |
| 8 | 8 |
| 9 local util = {} | 9 local util = {} |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 print('LUA: ' .. string.format(...)) | 24 print('LUA: ' .. string.format(...)) |
| 25 end | 25 end |
| 26 | 26 |
| 27 function util.PointToString(point) | 27 function util.PointToString(point) |
| 28 return string.format('%dx%d', point.x, point.y) | 28 return string.format('%dx%d', point.x, point.y) |
| 29 end | 29 end |
| 30 | 30 |
| 31 --- Create CCPoint from a lua table containing 2 elements. | 31 --- Create CCPoint from a lua table containing 2 elements. |
| 32 -- This is used to convert point data from .def files into | 32 -- This is used to convert point data from .def files into |
| 33 -- the cocos2dx coordinate space. | 33 -- the cocos2dx coordinate space. |
| 34 function util.PointFromLua(point) | 34 function util.PointFromLua(point, absolute) |
| 35 return CCPointMake(point[1] + game_obj.origin.x, point[2] + game_obj.origin.
y) | 35 if absolute == nil then |
| 36 absolute = true |
| 37 end |
| 38 if abolute then |
| 39 return ccp(point[1] + game_obj.origin.x, point[2] + game_obj.origin.y) |
| 40 else |
| 41 return ccp(point[1], point[2]) |
| 42 end |
| 36 end | 43 end |
| 37 | 44 |
| 38 --- Convert CCPoint to b2Vec. | 45 --- Convert CCPoint to b2Vec. |
| 39 function util.b2VecFromCocos(cocos_vec) | 46 function util.b2VecFromCocos(cocos_vec) |
| 40 return b2Vec2:new_local(util.ScreenToWorld(cocos_vec.x), | 47 return b2Vec2:new_local(util.ScreenToWorld(cocos_vec.x), |
| 41 util.ScreenToWorld(cocos_vec.y)) | 48 util.ScreenToWorld(cocos_vec.y)) |
| 42 end | 49 end |
| 43 | 50 |
| 44 --- Load a yaml file and return a lua table that represents the data | 51 --- Load a yaml file and return a lua table that represents the data |
| 45 -- in the file. | 52 -- in the file. |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 table.insert(sb, string.format("%s,\n", tostring(value))) | 206 table.insert(sb, string.format("%s,\n", tostring(value))) |
| 200 else | 207 else |
| 201 table.insert(sb, string.format("'%s',\n", tostring(value))) | 208 table.insert(sb, string.format("'%s',\n", tostring(value))) |
| 202 end | 209 end |
| 203 end | 210 end |
| 204 end | 211 end |
| 205 | 212 |
| 206 table.insert(sb, string.rep (' ', indent - 2)) | 213 table.insert(sb, string.rep (' ', indent - 2)) |
| 207 table.insert(sb, '}\n') | 214 table.insert(sb, '}\n') |
| 208 return table.concat(sb) | 215 return table.concat(sb) |
| 209 | |
| 210 end | 216 end |
| 211 | 217 |
| 212 return util | 218 return util |
| OLD | NEW |