-
Notifications
You must be signed in to change notification settings - Fork 0
/
savegame.adept
50 lines (36 loc) · 1.32 KB
/
savegame.adept
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
import 'main.adept'
func savegame(savefile_index int) successful {
filename String = "savegame_%.sav" % savefile_index
filename_cstr *ubyte = filename.cstr()
defer delete filename_cstr
pet_count int = gamedata.inventory.getTotalPets()
f *FILE = fopen(filename_cstr, 'w')
unless f, return false
fprintf(f, '%f %f\n', gamedata.player.x as double, gamedata.player.y as double)
repeat pet_count {
representation String = gamedata.inventory.getPetPointer(idx).toLine()
cstr *ubyte = representation.cstr()
defer delete cstr
fprintf(f, '%s\n', cstr)
}
fclose(f)
return true
}
func loadgame(savefile_index int) successful {
filename String = "savegame_%.sav" % savefile_index
filename_cstr *ubyte = filename.cstr()
defer delete filename_cstr
gamedata.inventory.clear()
f *FILE = fopen(filename_cstr, 'r')
unless f, return false
buffer 256 ubyte = undef
fscanf(f, '%f %f\n', def x_pos float, def y_pos float)
while fgets(&buffer as *ubyte, 256, f) {
if strlen(&buffer as *ubyte) == 0, continue
gamedata.inventory.addPet(petFromLine(stringConstant(&buffer as *ubyte)))
}
fclose(f)
gamedata.player.init(x_pos, y_pos)
gamedata.gotoScene(1)
return true
}