-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata.v
129 lines (113 loc) · 2.32 KB
/
data.v
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
// Copyright(C) 2023 Lars Pontoppidan. All rights reserved.
// Use of this source code is governed by an MIT license
// that can be found in the LICENSE file.
module main
import shy.lib as shy
const default_image = 'images/classical_ruin_tiles.png'
const image_db = parse_image_db($embed_file('assets/images/images.txt').to_string())
const music_db = parse_music_db($embed_file('assets/music/music.txt').to_string())
const sfx_db = parse_sfx_db($embed_file('assets/sfx/sfx.txt').to_string())
struct Music {
info MusicInfo
sound shy.Sound
}
struct ImageInfo {
name string
file string
url string
comment string
}
fn (i []ImageInfo) get_name(n string) ?ImageInfo {
for e in i {
if e.name == n {
return e
}
}
return none
}
struct MusicInfo {
name string
file string
url string
comment string
}
fn (i []MusicInfo) get_name(n string) ?MusicInfo {
for e in i {
if e.name == n {
return e
}
}
return none
}
struct SFXInfo {
name string
file string
url string
comment string
}
fn (i []SFXInfo) get_name(n string) ?SFXInfo {
for e in i {
if e.name == n {
return e
}
}
return none
}
fn parse_image_db(raw string) []ImageInfo {
lines := parse_db(raw)
mut db := []ImageInfo{}
for line in lines {
fields := line.split('|').map(it.trim_space())
if fields.len < 4 {
$if debug {
eprintln('Skipping image DB line "${line}"...')
}
continue
}
// dump(fields)
db << ImageInfo{
name: fields[0]
file: fields[1]
url: fields[2]
comment: fields[2]
}
}
return db
}
fn parse_music_db(raw string) []MusicInfo {
lines := parse_db(raw)
mut db := []MusicInfo{}
for line in lines {
fields := line.split('|').map(it.trim_space())
if fields.len < 4 {
continue
}
db << MusicInfo{
name: fields[0]
file: fields[1]
url: fields[2]
comment: fields[2]
}
}
return db
}
fn parse_sfx_db(raw string) []SFXInfo {
lines := parse_db(raw)
mut db := []SFXInfo{}
for line in lines {
fields := line.split('|').map(it.trim_space())
if fields.len < 4 {
continue
}
db << SFXInfo{
name: fields[0]
file: fields[1]
url: fields[2]
comment: fields[2]
}
}
return db
}
fn parse_db(raw string) []string {
return raw.replace('\r', '').split('\n').filter(!it.trim_space().starts_with('#')).filter(it.trim_space() != '')
}