-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsavemanage.lua
510 lines (464 loc) · 17.6 KB
/
savemanage.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
--savemanage.lua
local json = require("json")
local music = require("music")
local SM = {}
SM.PlayCollInventGame = system.pathForFile( "PlayCollInvent.json", system.DocumentsDirectory )
SM.PlayCollInventFile = io.open( SM.PlayCollInventGame )
local function loadTablePlayCollInvent(filename)
local path = system.pathForFile( "PlayCollInvent.json", system.DocumentsDirectory)
local contents = ""
local myTable = {}
local file = io.open( path, "r" )
if file then
local contents = file:read( "*a" )
myTable = json.decode(contents);
io.close( file )
return myTable
end
return nil
end
local function loadTableOne(filename)
local path = system.pathForFile( "SavedGameOneSettings.json", system.DocumentsDirectory)
local contents = ""
local myTable = {}
local file = io.open( path, "r" )
if file then
local contents = file:read( "*a" )
myTable = json.decode(contents);
io.close( file )
return myTable
end
return nil
end
local function saveTableGame(t, filename)
local path = system.pathForFile( "GameSettings.json", system.DocumentsDirectory)
local file = io.open(path, "w")
if file then
local contents = json.encode(t)
file:write( contents )
io.close( file )
return true
else
return false
end
end
local function saveTableOne(t, filename)
--print("SAVING FIRST GAME")
local path = system.pathForFile( "SavedGameOneSettings.json", system.DocumentsDirectory)
local file = io.open(path, "w")
if file then
local contents = json.encode(t)
file:write( contents )
io.close( file )
return true
else
return false
end
end
local function loadTableGame(filename)
local path = system.pathForFile( "GameSettings.json", system.DocumentsDirectory)
local contents = ""
local myTable = {}
local file = io.open( path, "r" )
if file then
local contents = file:read( "*a" )
myTable = json.decode(contents);
io.close( file )
return myTable
end
return nil
end
local function saveTablePlayCollInvent(t, filename)
local path = system.pathForFile( "PlayCollInvent.json", system.DocumentsDirectory)
local file = io.open(path, "w")
if file then
local contents = json.encode(t)
file:write( contents )
io.close( file )
return true
else
return false
end
end
local function chargePointIncrease()
checkSavedGameOneSettingsActive()
if SavedGameOneSettings.chargePoints <= 19 then
SavedGameOneSettings.chargePoints = SavedGameOneSettings.chargePoints+1
elseif SavedGameOneSettings.chargePoints >= 20 then
SavedGameOneSettings.chargePoints = SavedGameOneSettings.chargePoints
end
end
local function savePlayLoc()
checkSavedGameOneSettingsActive()
SavedGameOneSettings.isOnLevel = sceneIn
saveActiveGame()
end
local function refillHitPoints()
print("POINTS REFILL")
SavedGameOneSettings.hitPoints = 10
SavedGameOneSettings.Speed = 14
SavedGameOneSettings.chargePoints = 0
saveTableOne(SavedGameOneSettings, "SavedGameOneSettings.json")
end
local function createGameOne()
print("NEW FILE CREATION ATTEMPTED")
if SavedGameOneSettings.hasStarted == nil then
print("NEW FILE ONE CREATE SUCCESS")
SavedGameOneSettings.orientSet = "right"
SavedGameOneSettings.isOnLevel = ""
SavedGameOneSettings.levelAttained = 1
SavedGameOneSettings.hasStarted = 0
SavedGameOneSettings.moneyAmount = 0
SavedGameOneSettings.Speed = 14
SavedGameOneSettings.damageAmount = 1
SavedGameOneSettings.hitPoints = 10
SavedGameOneSettings.scoreAmount = 0
SavedGameOneSettings.enemDefeated = 0
SavedGameOneSettings.ScoreAmnted = 0
SavedGameOneSettings.jumpLength = 200
SavedGameOneSettings.hitCount = 0
SavedGameOneSettings.statExtend = 1
SavedGameOneSettings.statusIdent = 1
SavedGameOneSettings.iapPurch = 0
SavedGameOneSettings.countShot = {
1,
0,
0,
0,
0,
0,
}
SavedGameOneSettings.ammoInfinite = false
SavedGameOneSettings.showAllControls = false
SavedGameOneSettings.showAds = true
SavedGameOneSettings.SoundOn = true
SavedGameOneSettings.MusicOn = true
SavedGameOneSettings.VibeOn = true
SavedGameOneSettings.glockShot = 1
SavedGameOneSettings.shotgunShot = 0
SavedGameOneSettings.machinegunShot = 0
SavedGameOneSettings.sniperShot = 0
SavedGameOneSettings.grenadelauncherShot = 0
SavedGameOneSettings.rocketShot = 0
SavedGameOneSettings.mainWeapon = "glock"
SavedGameOneSettings.glockClipSz = 8
SavedGameOneSettings.glockAmmo = 89451234567489746515235687
SavedGameOneSettings.machinegunAmmo = GameSettings.machinegunDebugTotal
SavedGameOneSettings.machinegunClipSz = GameSettings.machinegunDebugAmount
SavedGameOneSettings.rocketAmmo = GameSettings.rocketDebugTotal
SavedGameOneSettings.rocketClipSz = GameSettings.rocketDebugAmount
SavedGameOneSettings.sniperAmmo = GameSettings.sniperDebugTotal
SavedGameOneSettings.sniperClipSz = GameSettings.sniperDebugAmount
SavedGameOneSettings.shotgunAmmo = GameSettings.shotgunDebugTotal
SavedGameOneSettings.shotgunClipSz = GameSettings.shotgunDebugAmount
SavedGameOneSettings.empAmmo = GameSettings.empDebugTotal
SavedGameOneSettings.empClipSz = GameSettings.empDebugAmount
SavedGameOneSettings.grenadelauncherAmmo = GameSettings.grenadelauncherDebugTotal
SavedGameOneSettings.grenadelauncherClipSz = GameSettings.grenadelauncherDebugAmount
SavedGameOneSettings.grenadefireAmmo = GameSettings.grenadefireDebugTotal
SavedGameOneSettings.grenadefireClipSz = GameSettings.grenadefireDebugAmount
if GameSettings.isDebug then
-- inventoried amount
SavedGameOneSettings.ammoListing = {
SavedGameOneSettings.glockAmmo,
SavedGameOneSettings.shotgunAmmo,
SavedGameOneSettings.machinegunAmmo,
SavedGameOneSettings.sniperAmmo,
SavedGameOneSettings.grenadelauncherAmmo,
SavedGameOneSettings.rocketAmmo,
}
-- clip amount
SavedGameOneSettings.clipListing = {
SavedGameOneSettings.glockClipSz,
SavedGameOneSettings.shotgunClipSz,
SavedGameOneSettings.machinegunClipSz,
SavedGameOneSettings.sniperClipSz,
SavedGameOneSettings.grenadelauncherClipSz,
SavedGameOneSettings.rocketClipSz,
}
SavedGameOneSettings.itemInventContents = {
"glock",
"shotgun",
"machinegun",
"sniper",
"grenadelauncher",
"rocket",
}
else
-- inventoried amount
SavedGameOneSettings.ammoListing = {
SavedGameOneSettings.glockAmmo,
}
-- clip amount
SavedGameOneSettings.clipListing = {
SavedGameOneSettings.glockClipSz,
}
SavedGameOneSettings.itemInventContents = {
"glock",
}
end
end
end
function SM.incIAPcount()
SavedGameOneSettings.iapPurch = SavedGameOneSettings.iapPurch+1
saveTableOne(SavedGameOneSettings, "SavedGameOneSettings.json")
end
function SM.iap10KPurch()
print(" ++++++++ PURCHASING THE 10K IN-GAME CURRENCY! +++++++++ ")
SavedGameOneSettings.moneyAmount = SavedGameOneSettings.moneyAmount+100000
saveTableOne(SavedGameOneSettings, "SavedGameOneSettings.json")
end
function SM.markenhan()
print(" ++++++++ PURCHASING THE MARKSMAN ENHANCEMENT! +++++++++ ")
SavedGameOneSettings.damageAmount = SavedGameOneSettings.damageAmount+2
SM.incIAPcount()
end
function SM.bodyarm()
print(" ++++++++ PURCHASING THE BODY ARMOR! +++++++++ ")
SavedGameOneSettings.hitCount = SavedGameOneSettings.hitCount+.5
SM.incIAPcount()
end
function SM.armory()
print(" ++++++++ PURCHASING INFINITE AMMO! +++++++++ ")
SavedGameOneSettings.ammoInfinite = true
SM.incIAPcount()
end
function SM.fatigues()
print(" ++++++++ PURCHASING EXTEND STATUS'! +++++++++ ")
SavedGameOneSettings.statExtend = SavedGameOneSettings.statExtend+1
SM.incIAPcount()
end
function SM.showads()
print(" ++++++++ PURCHASING SHOW ADS'! +++++++++ ")
SavedGameOneSettings.showAds = false
ads.hide()
SM.incIAPcount()
end
function SM.fullcontrol()
print(" ++++++++ PURCHASING FULL CONTROL'! +++++++++ ")
SavedGameOneSettings.showAllControls = true
SM.incIAPcount()
end
local function clearStatusOptions()
GameSettings.levelIsCleared = false
GameSettings.isPaused = false
GameSettings.lockStatus = false
GameSettings.playerHasDied = false
GameSettings.enemiesInLevel = 0
GameSettings.playerIsMoving = 0
GameSettings.ChargeChain = 0
GameSettings.enemDefeatChain = 0
GameSettings.enemInLevel = 0
GameSettings.quitGameNow = false
GameSettings.MoneyAmountChain = 0
GameSettings.ScoreAmntChain = 0
GameSettings.currLevNum = 0
saveTableGame(GameSettings, "GameSettings.json")
end
local function oneFileClear()
SM.pathOne = system.pathForFile( "SavedGameOneSettings.json", system.DocumentsDirectory )
SM.oneFile = io.open( SM.pathOne )
createGameOne()
saveTableOne(SavedGameOneSettings, "SavedGameOneSettings.json")
SM.oneFile.close(SM.oneFile)
print( "File SavedGameOneSettings didn't exist, but now IT DOES!" )
end
local function oneFileCheck()
SM.pathOne = system.pathForFile( "SavedGameOneSettings.json", system.DocumentsDirectory )
SM.oneFile = io.open( SM.pathOne )
if SM.oneFile then
print( "File SavedGameOneSettings exists" )
SM.oneFile.close(SM.oneFile)
else
createGameOne()
saveTableOne(SavedGameOneSettings, "SavedGameOneSettings.json")
print( "File SavedGameOneSettings didn't exist, but now IT DOES!" )
end
end
local function gameFileCheck()
SM.pathGame = system.pathForFile( "GameSettings.json", system.DocumentsDirectory )
SM.gameFile = io.open( SM.pathGame )
if SM.gameFile then
print( "File exists" )
SM.gameFile.close(SM.gameFile)
else
saveTableGame(GameSettings, "GameSettings.json")
print( "File didn't exist, but now IT DOES!" )
end
end
local function playCollFileCheck()
if SM.PlayCollInventFile then
print( "File exists" )
SM.PlayCollInventFile.close(SM.PlayCollInventFile)
else
saveTablePlayCollInvent(PlayCollInvent, "PlayCollInvent.json")
print( "File didn't exist, but now IT DOES!" )
end
end
function SM.callAdsNow()
-- Create a text object to display ad status
local showAd
-- Set up ad listener.
local function adListener( event )
-- event table includes:
-- event.provider
-- event.isError (e.g. true/false )
local msg = event.response
-- just a quick debug message to check what response we got from the library
print("Message received from the ads library: ", msg)
if event.isError then
showAd( "banner" )
--showAd( "interstitial" )
else
end
end
-- Initialize the 'ads' library with the provider you wish to use.
if appID then
ads.init( provider, appID, adListener )
end
--------------------------------------------------------------------------------
-- UI
--------------------------------------------------------------------------------
-- initial variables
local sysModel = system.getInfo("model")
local sysEnv = system.getInfo("environment")
-- create a background for the app
-- Shows a specific type of ad
showAd = function( adType )
--local adX, adY = display.contentCenterX, (display.actualContentHeight)-25
local adX, adY = display.screenOriginX, (display.actualContentHeight)-70
ads.show( adType, { x=adX, y=adY } )
end
-- if on simulator, let user know they must build for device
if sysEnv == "simulator" then
print("ON SIMULATOR NOW")
else
print("ON "..sysModel.." NOW")
-- start with banner ad
showAd( "banner" )
--showAd( "interstitial" )
end
end
local function inputWeapon(weapPickup)
SavedGameOneSettings.itemInventContents[#SavedGameOneSettings.itemInventContents+1] = weapPickup
SavedGameOneSettings.ammoListing[#SavedGameOneSettings.itemInventContents+1] = GameSettings.ammoConf[6]
SavedGameOneSettings.clipListing[#SavedGameOneSettings.itemInventContents+1] = GameSettings.clipConf[6]
--SavedGameOneSettings.VMac1Killed = SavedGameOneSettings.VMac1Killed+1
--print("SavedGameOneSettings.VMac1Killed = "..SavedGameOneSettings.VMac1Killed)
return true
end
function SM.popWeapEq(weapPickup)
music.collectSoundPlay()
for e=1, #SavedGameOneSettings.itemInventContents+1 do
--if weapPickup == SavedGameOneSettings.itemInventContents[e] then
if SavedGameOneSettings.itemInventContents[e] == weapPickup then
print("INVENTORY IS ALREADY LOADED WITH "..tostring(weapPickup))
GameSettings.purchSuccess = false
print("---------------------------------------------------------------")
return true
end
if SavedGameOneSettings.itemInventContents[e] == nil then
print("---------------------------------------------------------------")
print("INVENTORY IS NOT CURRENTLY LOADED WITH "..tostring(weapPickup))
for q=1, 6 do
--print("GameSettings.weaponList[q] = "..tostring(GameSettings.weaponList[q]))
if GameSettings.weaponList[q] == weapPickup then
GameSettings.purchSuccess = true
SavedGameOneSettings.itemInventContents[#SavedGameOneSettings.itemInventContents+1] = weapPickup
SavedGameOneSettings.ammoListing[#SavedGameOneSettings.itemInventContents] = GameSettings.ammoConf[q]
SavedGameOneSettings.clipListing[#SavedGameOneSettings.itemInventContents] = GameSettings.clipConf[q]
--print("GameSettings.weaponList "..q.." = "..tostring(GameSettings.weaponList[q]))
--print("SavedGameOneSettings.itemInventContents"..e.." = "..tostring(SavedGameOneSettings.itemInventContents[e]))
--print("SavedGameOneSettings.ammoListing"..e.." = "..tostring(SavedGameOneSettings.ammoListing[e]))
--SavedGameOneSettings.VMac1Killed = SavedGameOneSettings.VMac1Killed+1
--print("SavedGameOneSettings.VMac1Killed = "..SavedGameOneSettings.VMac1Killed)
--inputWeapon(weapPickup)
saveTableOne(SavedGameOneSettings, "SavedGameOneSettings.json")
end
end
end
end
end
function SM.popInventSG(itemPickup)
music.collectSoundPlay()
for r=1, #GameSettings.weaponList do
if itemPickup == GameSettings.weaponList[r]then
print("itemPickup = "..tostring(itemPickup))
print("GameSettings.weaponList["..r.."] = "..tostring(GameSettings.weaponList[r]))
for e=1, #SavedGameOneSettings.itemInventContents+1 do
--if itemPickup == SavedGameOneSettings.itemInventContents[e] then
if SavedGameOneSettings.itemInventContents[e] == itemPickup then
--print("e = "..e)
--print("GameSettings.weaponList[q] = "..tostring(GameSettings.weaponList[q]))
SavedGameOneSettings.ammoListing[e] = SavedGameOneSettings.ammoListing[e]+1
print("SavedGameOneSettings.ammoListing["..e.."] = "..SavedGameOneSettings.ammoListing[e])
print("INVENTORY IS ALREADY LOADED WITH "..tostring(itemPickup))
print("---------------------------------------------------------------")
saveTableOne(SavedGameOneSettings, "SavedGameOneSettings.json")
return true
end
if SavedGameOneSettings.itemInventContents[e] == nil then
print("---------------------------------------------------------------")
print("INVENTORY IS NOT CURRENTLY LOADED WITH "..tostring(itemPickup))
for q=1, #GameSettings.weaponList do
--print("GameSettings.weaponList[q] = "..tostring(GameSettings.weaponList[q]))
if GameSettings.weaponList[q] == itemPickup then
SavedGameOneSettings.itemInventContents[#SavedGameOneSettings.itemInventContents+1] = itemPickup
if SavedGameOneSettings.ammoListing[#SavedGameOneSettings.ammoListing+1] == nil then
SavedGameOneSettings.ammoListing[#SavedGameOneSettings.ammoListing+1] = 1
end
if SavedGameOneSettings.clipListing[#SavedGameOneSettings.clipListing+1] == nil then
SavedGameOneSettings.clipListing[#SavedGameOneSettings.clipListing+1] = 1
end
--print("GameSettings.weaponList "..q.." = "..tostring(GameSettings.weaponList[q]))
print("SavedGameOneSettings.itemInventContents"..e.." = "..tostring(SavedGameOneSettings.itemInventContents[e]))
--print("SavedGameOneSettings.ammoListing"..e.." = "..tostring(SavedGameOneSettings.ammoListing[e]))
--SavedGameOneSettings.VMac1Killed = SavedGameOneSettings.VMac1Killed+1
--print("SavedGameOneSettings.VMac1Killed = "..SavedGameOneSettings.VMac1Killed)
--inputWeapon(itemPickup)
saveTableOne(SavedGameOneSettings, "SavedGameOneSettings.json")
return true
end
end
end
end
end
end
end
--[[
SavedGameOneSettings = savemanage.loadTableOne("SavedGameOneSettings.json")
SavedGameTwoSettings = savemanage.loadTableTwo("SavedGameTwoSettings.json")
SavedGameThreeSettings = savemanage.loadTableThree("SavedGameThreeSettings.json")
savemanage.saveTableGame(GameSettings, "GameSettings.json")
savemanage.saveTableOne(SavedGameOneSettings, "SavedGameOneSettings.json")
savemanage.saveTableTwo(SavedGameTwoSettings, "SavedGameTwoSettings.json")
savemanage.saveTableThree(SavedGameThreeSettings, "SavedGameThreeSettings.json")
]]
SM.oneFileClear = oneFileClear
SM.oneFileCheck = oneFileCheck
SM.twoFileCheck = twoFileCheck
SM.threeFileCheck = threeFileCheck
SM.gameFileCheck = gameFileCheck
SM.playCollFileCheck = playCollFileCheck
SM.enemyFileCheck = enemyFileCheck
SM.checkSavedGameOneSettingsActive = checkSavedGameOneSettingsActive
SM.clearStatusOptions = clearStatusOptions
SM.collectProj1a = collectProj1a
SM.loadTableGame = loadTableGame
SM.loadTableEnemies = loadTableEnemies
SM.loadTableOne = loadTableOne
SM.loadTableTwo = loadTableTwo
SM.endLevelAdd = endLevelAdd
SM.loadTableThree = loadTableThree
SM.loadTablePractice = loadTablePractice
SM.saveTableGame = saveTableGame
SM.saveTableOne = saveTableOne
SM.createGameOne = createGameOne
SM.saveTable = saveTable
SM.loadTable = loadTable
SM.saveActiveGame = saveActiveGame
SM.savePlayLoc = savePlayLoc
SM.chargePointIncrease = chargePointIncrease
SM.confirmStarAmount = confirmStarAmount
SM.refillHitPoints = refillHitPoints
return SM