Initial commit
This commit is contained in:
commit
9472e4c497
|
@ -0,0 +1,16 @@
|
||||||
|
# botany widget
|
||||||
|
|
||||||
|
a very simple script that allows you to host your plant on your website (lol)
|
||||||
|
|
||||||
|
rename your home directory before use and check that the path to the botany matches your server
|
||||||
|
|
||||||
|
it probably does not work completely, so i will probably update it quite often,
|
||||||
|
live demo: [tilde.team/~grizzly](https://tilde.team/~grizzly/)
|
||||||
|
|
||||||
|
are you a member of tilde.team? visit my plant and water it! `grizzly` :)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
if you want to change or improve something, clone the repo, add changes, upload to some git server and send me the link, if you are a user of tilde.institute, send me an email with the path to your repo on the server
|
||||||
|
|
||||||
|
=> grizzly/at/nand.sh
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
Loading…
Reference in New Issue