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
|
<?php
$json = file_get_contents("/home/grizzly/.botany/grizzly_plant_data.json");
$data = json_decode($json, true);
$art = file_get_contents("/srv/botany/botany/art/" . $data['stage'] . ".txt");
// https://github.com/jifunks/botany/blob/master/menu_screen.py#L233
function water_gauge($last) {
$water_left_pct = 1 - ((time() - $last)/86400);
# don't allow negative value
$water_left_pct = max(0, $water_left_pct);
$water_left = intval(ceil($water_left_pct * 10));
//$water_string = "(" . (")" * $water_left) . ("." * (10 - $water_left)) . ") " . strval(intval($water_left_pct * 100)) . "% ";
$water_string = strval(intval($water_left_pct * 100)) . "% ";
return $water_string;
}
?>
<div class="plant">
<div class="status <?php echo $data['is_dead'] ? "dead" : "alive" ?>"><?php echo $data['is_dead'] ? "Dead 💀" : "Alive 👍" ?></div>
<div class="stats">
plant: <?=$data['stage']?><br />
score: <?=$data['score']?><br />
age: <?=$data['age']?><br />
generation: <?=$data['generation']?><br />
water: <?=water_gauge($data['last_watered'])?>
<em class="description"><?=$data['description']?></em>
</div>
<div class="ascii">
<pre><?=getArt($data['stage'], $data['species'], $data['is_dead'])?></pre>
</div>
</div>
<style>
.plant {
display: flex;
width: 450px;
border: 4px dotted greenyellow;
padding: 10px;
border-radius: 1rem;
background-color: beige;
position: relative;
}
.stats {
display: flex;
flex-direction: column;
align-items: center;
width: 35%;
}
.ascii {
width: 65%;
}
em.description {
margin-top: 10px;
}
.status {
position: absolute;
top: 0;
right: 0;
padding: 10px;
}
.alive {
color: green;
}
.dead {
color: red;
}
</style>
<?php
function getArt($stage, $species, $is_dead) {
$stage_list = [
'seed',
'seedling',
'young',
'mature',
'flowering',
'seed-bearing',
];
$stage = array_keys($stage_list, $stage)[0] + 1;
if ($is_dead) {
echo ascii_render('rip.txt');
} else if (date("m", time()) == 10 and date("d", time()) == 31) {
echo ascii_render('jackolantern.txt');
} else if ($stage == 0) {
echo ascii_render('seed.txt');
} else if ($stage == 1) {
echo ascii_render('seedling.txt');
} else if ($stage == 2) {
$this_filename = $species . '1.txt';
echo ascii_render($this_filename);
} else if ($stage == 3 or $stage == 5) {
$this_filename = $species . '2.txt';
echo ascii_render($this_filename);
} else if ($stage == 4) {
$this_filename = $species . '3.txt';
echo ascii_render($this_filename);
} else {
}
}
function ascii_render($art) {
return file_get_contents("/srv/botany/botany/art/" . $art);
}
?>
|