ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/kgsueme/kgsueme/util.pl
Revision: 1.15
Committed: Sat Jun 5 16:01:53 2004 UTC (19 years, 11 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.14: +3 -3 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 pcg 1.1 package util;
2    
3     use Storable ();
4     use Scalar::Util ();
5    
6     my $staterc = "$ENV{HOME}/.kgsueme";
7    
8 pcg 1.4 $stateversion = 1;
9    
10 pcg 1.3 our $state = -r $staterc ? Storable::retrieve($staterc) : {};
11 pcg 1.4
12     if ($state->{version} != $stateversion) {
13     warn "$staterc has wrong version - ignoring it.\n";
14     $state = {};
15     }
16    
17     $state->{version} = $stateversion;
18 pcg 1.1
19     $::config = $state->{config} ||= {};
20    
21 root 1.15 $::config->{speed} = 0; #d# optimize for speed or memory? (0,1)
22     $::config->{conserve_memory} = 0; # try to conserve memory at the expense of speed (0,1,2)
23     $::config->{randomize} = 0; # randomize placement of stones (BROKEN)
24 elmex 1.14 $::config->{suppress_userpic} = 0; # for omitting the userpic in the game window
25 pcg 1.1
26     sub save_config {
27 pcg 1.3 &gtk::save_state;
28 root 1.12 Storable::nstore ($state, $staterc);
29     app::status ("save_state", "layout saved");
30 pcg 1.1 }
31    
32 pcg 1.8 sub format_time($) {
33     my ($time) = @_;
34    
35     $time > 60*60
36     ? sprintf "%d:%02d:%02d", $time / (60 * 60), $time / 60 % 60, $time % 60
37     : sprintf "%d:%02d", $time / 60 % 60, $time % 60;
38     }
39    
40 root 1.13 sub parse_time($) {
41    
42     my $time;
43     $time = $time * 60 + $_ for split /:/, $_[0];
44    
45     $time;
46     }
47    
48 pcg 1.7 # text to xml
49 pcg 1.6 sub toxml($) {
50     local $_ = shift;
51     s/&/&/g;
52     s/</&lt;/g;
53     s/]]>/]]&gt;/g;
54 pcg 1.7 $_;
55     }
56    
57     # pseudo-"xml" to text
58     sub xmlto($) {
59     local $_ = shift;
60     s/&lt;/</g;
61     s/&amp;/&/g;
62 pcg 1.6 $_;
63     }
64    
65 pcg 1.1 1;
66