-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
126 lines (113 loc) · 3.44 KB
/
main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
require "ParseLib"
print("***********************PARSELIB TESTS*****************\n")
Test = Core.class()
function Test:init(testName)
self.testName = testName
self.parse = ParseLib.new(appId, apiKey, "ScoreTest", "PlayerTest")
end
--Ctor
TestCtor = Core.class(Test)
function TestCtor:init(testName)
self.parse = nil
self.parse = ParseLib.new(appId, apiKey)
if (self.parse.scoreClass == "Score" and self.parse.playerClass == "Player") then
print(self.testName.." SUCCESS")
else
print(self.testName.." FAILURE: ", "("..self.parse.scoreClass.." == Score and "..self.parse.playerClass.." == Player)")
end
end
test = TestCtor.new("TestCtor")
--Ctor Params
TestCtorParams = Core.class(Test)
function TestCtorParams:init(testName)
self.parse = nil
self.parse = ParseLib.new(appId, apiKey, "ScoreTest", "PlayerTest")
if (self.parse.scoreClass == "ScoreTest" and self.parse.playerClass == "PlayerTest") then
print(self.testName.." SUCCESS")
else
print(self.testName.." FAILURE: ", "("..self.parse.scoreClass.." == ScoreTest and "..self.parse.playerClass.." == PlayerTest)")
end
end
test = TestCtorParams.new("TestCtorParams")
--Login
TestLogin = Core.class(Test)
function TestLogin:init(testName)
local function callback(success, userId)
if (success and self.parse.userObjectId ~= nil and self.parse.currentFacebookId == self.facebookId) then
print(self.testName.." SUCCESS")
else
print(self.testName.." FAILURE: ", "("..tostring(success).." and "..tostring(self.parse.userObjectId).." ~= nil and "..tostring(self.parse.currentFacebookId).." == "..self.facebookId..")")
end
end
self.facebookId = "10152817179103304"
self.parse:login(self.facebookId, callback)
end
--test = TestLogin.new("TestLogin")
--addScore
local function testAddScore(success)
if (success) then
print("Scores added successfully")
else
print("Unable to add score")
end
end
--Add score at specified level for logged in user.
--local l = {
--{level = 1, score = 1200},
--{level = 2, score = 3000},
--{level = 3, score = 1240},
--{level = 4, score = 2300}}
--print("do")
--for k, v in ipairs(l) do
-- print(v.level, v.score)
--end
--parse = ParseLib.new(appId, apiKey, "ScoreTest", "PlayerTest")
--parse:login("10204480970048216",
-- function(success) print("HELLO")
-- if (success) then print("addScore") parse:addScore(l, testAddScore) end
-- end)
--Get score
local function testGetScore(success, scoreList)
if (success) then
for i, score in ipairs(scoreList) do
print("User", score.owner.facebookId, "Get score ", score.score, "for level ", score.level)
end
else
print("Unable to get scores")
end
end
--Get score for current user at specified level
--print("getScore")
parse = ParseLib.new(appId, apiKey, "ScoreTest", "PlayerTest")
parse.userObjectId = "7RsNg1uzPe"
parse.currentFacebookId = "10204480970048216"
--parse:getScore(nil, nil, testGetScore)
test = {
"10152817417013304",
"10152837124006527",
"10152643550940589",
"10152785245570439",
"10152388518528443",
"10152817179103304",
"10152978619666855",
"10152869798117730",
"10205229717006422",
"10153157597253968"}
local backup = ScoreLocalBackup.new()
backup:clear()
Timer.delayedCall(1000, function()
backup:loadFromParse(parse, test, function()
end)
end)
Timer.delayedCall(10000, function()
--backup:save()
backup:print()
local i = 0
for index, bmp in pairs(backup.pictures) do
local tex = Texture.new(bmp["path"])
local bitmap = Bitmap.new(tex)
bitmap:setPosition(100,i * 100)
stage:addChild(bitmap)
i = i+1
end
end)