… | |
… | |
26 | use Carp (); |
26 | use Carp (); |
27 | use AnyEvent (); |
27 | use AnyEvent (); |
28 | use BerkeleyDB; |
28 | use BerkeleyDB; |
29 | use Pod::POM (); |
29 | use Pod::POM (); |
30 | use Scalar::Util (); |
30 | use Scalar::Util (); |
|
|
31 | use YAML (); |
31 | use Storable (); # finally |
32 | use Storable (); # finally |
32 | |
33 | |
33 | our %STAT_TOOLTIP = ( |
34 | our %STAT_TOOLTIP = ( |
34 | Str => "<b>Physical Strength</b>, determines damage dealt with weapons, how much you can carry, and how often you can attack", |
35 | Str => "<b>Physical Strength</b>, determines damage dealt with weapons, how much you can carry, and how often you can attack", |
35 | Dex => "<b>Dexterity</b>, your physical agility. Determines chance of being hit and affects armor class and speed", |
36 | Dex => "<b>Dexterity</b>, your physical agility. Determines chance of being hit and affects armor class and speed", |
… | |
… | |
104 | } |
105 | } |
105 | |
106 | |
106 | die "FATAL: can't find required file $_[0]\n"; |
107 | die "FATAL: can't find required file $_[0]\n"; |
107 | } |
108 | } |
108 | |
109 | |
|
|
110 | sub parse_yaml { |
|
|
111 | my $text = shift; |
|
|
112 | |
|
|
113 | utf8::decode $text; |
|
|
114 | |
|
|
115 | YAML::Load $text |
|
|
116 | } |
|
|
117 | |
109 | sub read_cfg { |
118 | sub read_cfg { |
110 | my ($file) = @_; |
119 | my ($file) = @_; |
111 | |
120 | |
112 | open CFG, $file |
121 | open my $fh, $file |
113 | or return; |
122 | or return; |
114 | |
123 | |
115 | my $CFG; |
|
|
116 | |
|
|
117 | local $/; |
124 | local $/; |
118 | $CFG = eval <CFG>; |
125 | my $CFG = <$fh>; |
119 | |
126 | |
|
|
127 | if ($CFG =~ /^---/) { |
|
|
128 | $::CFG = parse_yaml $CFG; |
|
|
129 | } else { |
120 | $::CFG = $CFG; |
130 | $::CFG = eval $CFG; |
121 | |
131 | } |
122 | close CFG; |
|
|
123 | } |
132 | } |
124 | |
133 | |
125 | sub write_cfg { |
134 | sub write_cfg { |
126 | my ($file) = @_; |
135 | my ($file) = @_; |
127 | |
136 | |
128 | open CFG, ">$file" |
137 | $::CFG->{VERSION} = $::VERSION; |
|
|
138 | |
|
|
139 | open my $fh, ">:utf8", $file |
129 | or return; |
140 | or return; |
130 | |
141 | print $fh YAML::Dump $::CFG; |
131 | { |
|
|
132 | require Data::Dumper; |
|
|
133 | local $Data::Dumper::Purity = 1; |
|
|
134 | $::CFG->{VERSION} = $::VERSION; |
|
|
135 | print CFG Data::Dumper->Dump ([$::CFG], [qw/CFG/]); |
|
|
136 | } |
|
|
137 | |
|
|
138 | close CFG; |
|
|
139 | } |
142 | } |
140 | |
143 | |
141 | our $DB_ENV; |
144 | our $DB_ENV; |
142 | |
145 | |
143 | { |
146 | { |