diff options
Diffstat (limited to 'botany.php')
-rw-r--r-- | botany.php | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/botany.php b/botany.php new file mode 100644 index 0000000..989bc40 --- /dev/null +++ b/botany.php @@ -0,0 +1,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); + } + +?> \ No newline at end of file |