-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgamepack.awk
More file actions
135 lines (112 loc) · 2.61 KB
/
Copy pathgamepack.awk
File metadata and controls
135 lines (112 loc) · 2.61 KB
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
# Function that loads csv formatted lines into dict, with type and char as keys
function load_csv(storage_array) {
getline
split($0,headers,", ")
do {
EOF = !getline
if (EOF) {
exit
}
for (i in headers) {
headers[i] = trim(headers[i])
}
if (length($0) != 0) {
split($0,a,", ")
type = trim(a[1])
char = trim(a[2])
storage_array["CHARSET"] = storage_array["CHARSET"] char
for (i in headers) {
storage_array[type][headers[i]] = a[i]
storage_array[char][headers[i]] = a[i]
}
}
} while (trim($0) != "")
}
# Read line and check if it is an empty line
function readline() {
EOF = !getline
if (trim($0) == "") {
return 0
} else if (EOF) {
return 0
} else {
return 1
}
}
function load_script( script) {
script = ""
do {
EOF = !getline
if (EOF) {
exit
}
script = script "\n" $0
} while (trim($0) != "END_SCRIPT")
return script
}
# Function that loads lines until an empty line is found
function load_block(storage_array, y) {
y = 0
while (readline()) {
storage_array[y] = $0
y++
}
}
# Function that loads .ini formatted lines
function load_ini(storage_array, lines) {
load_block(lines)
for (i in lines) {
split(lines[i],a,"=")
key = trim(a[1])
value = trim(a[2])
storage_array[key] = value
}
}
function load_art(entity_type, storage_array, line, y, x, i) {
for (y=0;y<8;y++) {
for (x=0;x<8;x++) {
storage_array[entity_type]["art"][x][y] = "30,30,30"
}
}
while(readline()) {
line = $0
match(line, /RGB\(([0-9]+,[0-9]+,[0-9]+)\)/, groups)
split(groups[1], a, ",")
r = a[1]
g = a[2]
b = a[3]
match(line, / ([0-9],[0-9].*)/, groups)
split(groups[1], positions, " ")
nr_of_matches = length(positions)
for (i=1;i<=nr_of_matches;i++) {
split(positions[i], a, ",")
x = a[1]
y = a[2]
storage_array[entity_type]["art"][x][y] = r "," g "," b
}
}
}
function load_map(level_nr, map_width, map_height) {
map_width = 0
map_height = 0
while(readline()) {
line = $0
if (map_width == 0) {
map_width = length(line)
for (x=0; x < map_width; x++) {
world_maps[level_nr][x][map_height] = substr(line, x, 1)
}
map_height++
} else if (map_width != 0 && length(line) == map_width) {
for (x=0; x < map_width; x++) {
world_maps[level_nr][x][map_height] = substr(line, x, 1)
}
map_height++
} else {
print "Game map is jagged, please check " FILENAME " for errors"
system("sleep 5")
}
}
world_maps[level_nr]["map_width"] = map_width
world_maps[level_nr]["map_height"] = map_height
}