Mon Jun 3 15:21:17 PDT 2002
[netwalk.git] / config_data.e
blobe9b6ce21ec6523d002c642bf7528c457283e38b2
1 class CONFIG_DATA
2 creation make
3 feature
4 config_file : STRING is "config"
5 score_file : STRING
7 preset_list : LINKED_LIST[PRESET]
9 mainttf : STRING
10 bigttf : STRING
12 mainfont : TTF_FONT
13 bigfont : TTF_FONT
15 default_preset : STRING
17 has_preset(s : STRING) : BOOLEAN is
18 local
19 it : ITERATOR[PRESET]
21 it := preset_list.get_new_iterator
22 from it.start
23 until it.is_off
24 loop
25 if it.item.name.is_equal(s) then
26 Result := True
27 end
28 it.next
29 end
30 end
32 get_preset(s : STRING) : PRESET is
33 local
34 it : ITERATOR[PRESET]
36 it := preset_list.get_new_iterator
37 from it.start
38 until it.is_off
39 loop
40 if it.item.name.is_equal(s) then
41 Result := it.item
42 end
43 it.next
44 end
45 end
47 make is
49 !!preset_list.make
50 load_config
51 end
53 load_config is
54 local
55 in : TEXT_FILE_READ
57 !!in.connect_to(config_file)
58 if not in.is_connected then
59 io.put_string("couldn't read config file%N")
60 die_with_code(1)
61 else
62 read_config(in)
63 end
64 in.disconnect
65 end
67 state_none : INTEGER is 0
68 state_unknown : INTEGER is 1
69 state_preset : INTEGER is 2
71 read_config(in : TEXT_FILE_READ) is
72 local
73 s1, s2 : STRING
74 state : INTEGER
76 from in.read_word
77 until in.end_of_input
78 loop
79 s1 := clone(in.last_string)
80 in.read_line
81 if not in.end_of_input then
82 s2 := clone(in.last_string)
83 in.read_word
84 else
85 !!s2.copy("")
86 end
88 if s1.first = '#' then
89 elseif s1.is_equal("begin") then
90 state := state_unknown
91 if s2.is_equal("preset") then
92 state := state_preset
93 end
94 elseif s1.is_equal("end") then
95 state := state_none
96 else
97 inspect state
98 when state_none then
99 if s1.is_equal("main_font") then
100 mainttf := s2
101 elseif s1.is_equal("big_font") then
102 bigttf := s2
103 elseif s1.is_equal("default_preset") then
104 default_preset := s2
105 elseif s1.is_equal("hiscores") then
106 score_file := s2
108 when state_preset then
109 parse_preset(s1, s2)
110 else
115 !!mainfont.load(mainttf, 12)
116 !!bigfont.load(bigttf, 24)
119 parse_preset(s1, s2 : STRING) is
120 local
121 p : PRESET
122 args : ARRAY[STRING]
123 width, height : INTEGER
124 wrap : BOOLEAN
126 args := s2.split
127 width := args.item(1).to_integer
128 height := args.item(2).to_integer
129 wrap := args.item(3).to_integer /= 0
130 !!p.make(s1, width, height, wrap)
131 preset_list.add_last(p)