-Added regexs for High Contrast

-Fixed regext for black & white text squares (so it actually works out of Discord, _ not -)

-Updated html template, fixing textareas so 2nd one didn't get squished for unknown reason.

-Updated text in Template, still too wordy!

-Fixed RLE to end on ! instead of $ which is why the next item wasn't working

-Added a [[..]] section to end of generated RLE file to set generations per second, zoom, and colors to
custom values to generally be better defaults.
This commit is contained in:
peteyboy 2022-02-16 08:35:53 +00:00
parent eb6b8d0887
commit 8fe95c88b6

View File

@ -1,7 +1,9 @@
#!/usr/pkg/bin/perl
#Above is the particular location for system binaries in SDF's metaarray, not the usual spot
use strict;
use warnings;
use utf8;
#add my user perl library path, this is particular to each person's setup
use lib qw( /usr/pkg/lib/perl5/5.24.0 /meta/p/peteyboy/perl5/lib/perl5 );
#make request for all of the following
use CGI::Tiny;
@ -15,7 +17,7 @@ use Readonly;
#
#===
my $ORIGIN_PAGE = "/wordle-life.cgi";
my $defaulttext = "Paste your wordle share here";
my $defaulttext = "Paste your wordle share here (replace this text)";
cgi {
@ -88,6 +90,7 @@ sub generate_rle {
Readonly my $headline_prefix => "#C "; #Part of RLE spec https://conwaylife.com/wiki/Run_Length_Encoded
Readonly my $row_prefix => "x = 5"; #for wordle always 5
Readonly my $col_prefix => ",y = ";
Readonly my $lifeviewer_settings => "\n[[\n GPS 3\n ZOOM 23\n COLOR ALIVE LIME\n COLOR BACKGROUND BLUE\n STOP 100\n GRID\n]]"; #Part of Viewer Spec
my $wordle = shift; # this is how you get variables in your function call!
$rowcount = 0;
@ -99,15 +102,25 @@ sub generate_rle {
$headline = $headline_prefix . $myline;
}else{
#in case of text mode
#remove all line endings with magic perl identifier R
$myline =~ s/\R//;
$myline =~ s/^(.*)$/$1\$/;
#these replaces are logicless, so they need to be done in this order!
#in case of text mode (Discord)
$myline =~ s/:yellow_square:/o/g;
$myline =~ s/:green_square:/o/g;
$myline =~ s/:[a-z-]*square:/b/g;
$myline =~ s/:blue_square:/o/g; #HC equiv yellow
$myline =~ s/:orange_square:/o/g; #HC equiv green
$myline =~ s/:[a-z_]*square:/b/g;
# for normal unicode
$myline =~ s/\N{U+1f7e8}/o/g; #yellow
$myline =~ s/\N{U+1f7e9}/o/g; #green
$myline =~ s/\N{U+1f7e8}/o/g; #yellow hit
$myline =~ s/\N{U+1f7e9}/o/g; #green hit
$myline =~ s/\N{U+1F7E6}/o/g; #blue
$myline =~ s/\N{U+1F7E7}/o/g; #orange
$myline =~ s/\N{U+2B1B}/b/g; #black
$myline =~ s/\N{U+2B1C}/b/g; #white
@ -117,6 +130,9 @@ sub generate_rle {
$myline =~ s/white_large_square/b/g;
$myline =~ s/yellow_square/o/g;
$myline =~ s/green_square/o/g;
$myline =~ s/blue_square/o/g;
$myline =~ s/orange_square/o/g;
#skip blank lines, count rows added
@ -127,7 +143,8 @@ sub generate_rle {
}
}
#this is the format with b,o, and $. Done lazily because I don't compress the repeated b or o.
return "$headline\n$row_prefix$col_prefix$rowcount\n$rleline";
$rleline =~ s/\$$/\!/; #Correct termination of last line of RLE is !, not $, so replace it.
return "$headline\n$row_prefix$col_prefix$rowcount\n$rleline\n$lifeviewer_settings";
}
@ -140,7 +157,11 @@ __DATA__
<link rel="stylesheet" href="https://unpkg.com/some-nice-basic-css/global.css" />
<style>
.lv-rle{
min-height:140px;
}
</style>
<meta name="LifeViewer" content="viewer textarea"> <!--required tag-->
<script src="lv-plugin.js"></script>
@ -161,31 +182,32 @@ __DATA__
<form id="wordle-form" name="wordle-form" action="<%= $ORIGIN_PAGE =%>" method="POST" class="flow">
<label for="wordle">Wordle Share Chart:</label>
<textarea id="wordle" name="wordle-result" rows="9" cols="50" placeholder="<%= $defaulttext =%>" style="vertical-align: middle">
<textarea id="wordle" name="wordle-result" rows="9" cols="50" placeholder="<%= $defaulttext =%>" style="vertical-align: middle class="lv-rle"">
<%= $wordle %>
</textarea>
</p>
<br>
</li>
<li>
<p>Click "Submit" and and RLE format file for Conway's Game of Life will appear in the box below and get loaded into the Life Viewer.</p>
<p>Click "Submit" and an RLE format file made for Conway's Game of Life will appear in the box below and get loaded into the Life Viewer.</p>
<input type="submit" value="Submit">
<!--viewer container-->
</li>
<li>
<p>Watch your Wordle score play LIFE!</p>
<!--viewer container-->
<div class="viewer" class="flow">
<label for="wordle">
<p>If the conversion is successful, you should see your Wordle converted to a Run Length Encoded Conway Life file in this box:</p>
</label>
<textarea id="life" name="Life file" rows="9" cols="50" style="vertical-align: middle">
<textarea id="life" name="life-file" rows="9" cols="50" style="vertical-align: middle" class="lv-rle" class="flow">
<%= $rle %>
</textarea>
<p>If the RLE is correct, it should be loaded in the Life Viewer, and so you are ready to go!</p>
<ul>
<li><p>For best results with the Life Viewer, adjust the Zoom and the playback speed (from "1x", slide left to "3/s" or so) and press the Play button:</p>
<li><p>For best results with the Life Viewer, you may adjust the default Zoom and the playback speed, then press the Play button:</p>
<canvas height=400 width=400></canvas></li>
<li><p>Press "[Pause]" when it seems stable. </p>
</li>
@ -208,10 +230,21 @@ __DATA__
<pre code>
#C Wordle 235 3/6
x = 5,y = 3
boobo$bobbo$ooooo$
boobo$bobbo$ooooo!
[[GPS 3
ZOOM 23
COLOR ALIVE LIME
COLOR BACKGROUND BLUE
STOP 100
GRID
]]
</pre code>
<p>For details about the Life RLE file format above, read <a href=https://conwaylife.com/wiki/Run_Length_Encoded>this</a>.
<p>(the main thing that needs to be right are the first 3 lines. If the 3rd line has any : symbols, just try deleting them. The stuff between double brackets aren't part of the RLE but are comments that set some defaults for the Life Viewer)</p>
<p>For details about the Life RLE file format above, read <a href=https://conwaylife.com/wiki/Run_Length_Encoded>this</a>.</p>
</li>