| 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, relative) |
| 35 return CCPointMake(point[1] + game_obj.origin.x, point[2] + game_obj.origin.
y) | 35 if relative then |
| 36 return ccp(point[1], point[2]) |
| 37 else |
| 38 return ccp(point[1] + game_obj.origin.x, point[2] + game_obj.origin.y) |
| 39 end |
| 36 end | 40 end |
| 37 | 41 |
| 38 --- Convert CCPoint to b2Vec. | 42 --- Convert CCPoint to b2Vec. |
| 39 function util.b2VecFromCocos(cocos_vec) | 43 function util.b2VecFromCocos(cocos_vec) |
| 40 return b2Vec2:new_local(util.ScreenToWorld(cocos_vec.x), | 44 return b2Vec2:new_local(util.ScreenToWorld(cocos_vec.x), |
| 41 util.ScreenToWorld(cocos_vec.y)) | 45 util.ScreenToWorld(cocos_vec.y)) |
| 42 end | 46 end |
| 43 | 47 |
| 44 --- Load a yaml file and return a lua table that represents the data | 48 --- Load a yaml file and return a lua table that represents the data |
| 45 -- in the file. | 49 -- in the file. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 72 table.insert(sb, string.format("%s,\n", tostring(value))) | 76 table.insert(sb, string.format("%s,\n", tostring(value))) |
| 73 else | 77 else |
| 74 table.insert(sb, string.format("'%s',\n", tostring(value))) | 78 table.insert(sb, string.format("'%s',\n", tostring(value))) |
| 75 end | 79 end |
| 76 end | 80 end |
| 77 end | 81 end |
| 78 | 82 |
| 79 table.insert(sb, string.rep (' ', indent - 2)) | 83 table.insert(sb, string.rep (' ', indent - 2)) |
| 80 table.insert(sb, '}\n') | 84 table.insert(sb, '}\n') |
| 81 return table.concat(sb) | 85 return table.concat(sb) |
| 82 | |
| 83 end | 86 end |
| 84 | 87 |
| 85 if arg then | 88 if arg then |
| 86 print(util.TableToString({mylist = { 1, 2, 3 }, foo = 'bar', hello = 123})) | 89 print(util.TableToString({mylist = { 1, 2, 3 }, foo = 'bar', hello = 123})) |
| 87 end | 90 end |
| 88 | 91 |
| 89 return util | 92 return util |
| OLD | NEW |