wok rev 24127

sokojs: get slc levels
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sat Oct 16 16:30:13 2021 +0000 (2021-10-16)
parents 83927a09d38d
children c207e28d59ee
files sokojs/receipt sokojs/stuff/levels.sh sokojs/stuff/multiset.sh sokojs/stuff/slc2htm.sh
line diff
     1.1 --- a/sokojs/receipt	Thu Oct 14 06:54:52 2021 +0000
     1.2 +++ b/sokojs/receipt	Sat Oct 16 16:30:13 2021 +0000
     1.3 @@ -23,13 +23,13 @@
     1.4  genpkg_rules()
     1.5  {
     1.6  	mkdir -p $fs/var/www $fs/usr/share/applications $install/usr/share/doc
     1.7 -	cp -a $src $fs/var/www/sokojs
     1.8 +	cp -a $src $stuff/*.sh $fs/var/www/sokojs
     1.9  	mv $fs/var/www/sokojs/*.txt $install/usr/share/doc
    1.10  	cat > $fs/usr/share/applications/Sokoban.desktop <<EOT
    1.11  [Desktop Entry]
    1.12  Type=Application
    1.13  Name=Sokoban
    1.14 -Comment=Plateform game
    1.15 +Comment=Plateform game (get 39000 levels with /var/www/sokojs/levels.sh)
    1.16  Exec=sh -c "url=http://127.0.0.1/sokojs/main.htm ; tazweb --notoolbar \\\$url || browser \\\$url"
    1.17  Icon=/var/www/sokojs/4.gif
    1.18  Terminal=false
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/sokojs/stuff/levels.sh	Sat Oct 16 16:30:13 2021 +0000
     2.3 @@ -0,0 +1,9 @@
     2.4 +#!/bin/sh
     2.5 +
     2.6 +cd $(dirname $0)
     2.7 +for i in main.htm multiset.sh slc2htm.sh ; do [ ! -s "$i" ] && echo "$PWD/$i not found" && exit 1; done
     2.8 +[ -s Levels.zip ] || wget https://www.sourcecode.se/sokoban/download/Levels.zip
     2.9 +unzip Levels.zip
    2.10 +./multiset.sh
    2.11 +./slc2htm.sh *.slc
    2.12 +rm -f *.slc
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/sokojs/stuff/multiset.sh	Sat Oct 16 16:30:13 2021 +0000
     3.3 @@ -0,0 +1,169 @@
     3.4 +#!/bin/sh
     3.5 +
     3.6 +grep -q 'text/html' level.htm || patch -p0 <<EOT
     3.7 +--- level.htm
     3.8 ++++ level.htm
     3.9 +@@ -22,12 +22,14 @@
    3.10 + <html>
    3.11 + <head>
    3.12 + <title></title>
    3.13 ++<META HTTP-EQUIV="Content Type" CONTENT="text/html;charset=utf-8">
    3.14 + <script type="text/javascript">
    3.15 + <!--
    3.16 + if (parent.frames[0] == null) { document.location = "sokojs.htm"  }
    3.17 +-Row=16
    3.18 +-Col=16
    3.19 +-document.write("<body style=\"margin:0\" bgcolor=\"black\">&nbsp;<b><FONT FACE=\"Comic Sans MS\" SIZE=4 COLOR=\"red\">LEVEL ",
    3.20 ++Row = eval(parent.frames[0].document.forms[1].elements[0].value)
    3.21 ++Col = eval(parent.frames[0].document.forms[1].elements[1].value)
    3.22 ++document.write("<body style=\"margin:0\" bgcolor=\"black\">&nbsp;<b><FONT FACE=\"Comic Sans MS\" SIZE=4 COLOR=\"red\">",
    3.23 ++  parent.frames[0].document.forms[1].elements[2].value," LEVEL ",
    3.24 +   eval(parent.frames[0].document.forms[0].elements[(Row*Col)+1].value) + 1);
    3.25 + 
    3.26 + 
    3.27 +--- main.htm
    3.28 ++++ main.htm
    3.29 +@@ -11,8 +11,9 @@
    3.30 + -->
    3.31 + <html>
    3.32 + <head>
    3.33 ++<META HTTP-EQUIV="Content Type" CONTENT="text/html;charset=utf-8">
    3.34 + <meta name="viewport" content="width=device-width, initial-scale=1">
    3.35 +-<style>
    3.36 ++<style type="text/css">
    3.37 + <!--
    3.38 + img.r{
    3.39 + width:30px;
    3.40 +@@ -76,19 +77,19 @@
    3.41 + var ie4= (navigator.appName == "Microsoft Internet Explorer")?1:0;
    3.42 + var ns4= (navigator.appName=="Netscape")?1:0;
    3.43 + 
    3.44 +-Row    = 16
    3.45 +-Col    = 16
    3.46 ++Row = eval(parent.frames[0].document.forms[1].elements[0].value)
    3.47 ++Col = eval(parent.frames[0].document.forms[1].elements[1].value)
    3.48 + 
    3.49 + function Nmajevent(evenement)
    3.50 + {
    3.51 +            if (evenement.which == 52 || evenement.which == 37) {
    3.52 +         Move(eval(manpos) - 1)
    3.53 +     } else if (evenement.which == 56 || evenement.which == 38) {
    3.54 +-        Move(eval(manpos) - Row)
    3.55 ++        Move(eval(manpos) - Col)
    3.56 +     } else if (evenement.which == 54 || evenement.which == 39) {
    3.57 +         Move(eval(manpos) + 1)
    3.58 +     } else if (evenement.which == 50 || evenement.which == 40) {
    3.59 +-        Move(eval(manpos) + Row)
    3.60 ++        Move(eval(manpos) + Col)
    3.61 +     }
    3.62 + }
    3.63 + 
    3.64 +@@ -108,7 +109,7 @@
    3.65 +          if (window.event.keyCode == 37) {
    3.66 +      Move(eval(manpos) - 1)
    3.67 +   } else if (window.event.keyCode == 38) {
    3.68 +-     Move(eval(manpos) - Row)
    3.69 ++     Move(eval(manpos) - Col)
    3.70 +   } else if (window.event.keyCode == 39) {
    3.71 +      Move(eval(manpos) + 1)
    3.72 +   } else if (window.event.keyCode == 40) {
    3.73 +@@ -150,7 +151,7 @@
    3.74 + manD  = new Image(30, 30); manD.src = "9.gif"; // down
    3.75 + 
    3.76 + level = new Array()
    3.77 +-maxLevel = 97
    3.78 ++maxLevel = eval(parent.frames[0].document.forms[1].elements[3].value)
    3.79 + moves = 0
    3.80 + 
    3.81 + function ReloadLevel() {
    3.82 +@@ -168,14 +169,18 @@
    3.83 + 
    3.84 + function GoLevel(n) {
    3.85 +   if (n == nbLevel) ReloadLevel()
    3.86 +-  parent.frames[0].document.location = "level" + n + ".htm"
    3.87 ++  parent.frames[0].document.location = parent.frames[0].document.forms[1].elements[2].value + "/level" + n + ".htm"
    3.88 ++}
    3.89 ++
    3.90 ++function GoSet() {
    3.91 ++  parent.frames[0].document.location = document.getElementById('set').value + "/level0.htm"
    3.92 + }
    3.93 + 
    3.94 + function dir(d) {
    3.95 +   if (d ==   -1) return "L";
    3.96 +   if (d ==    1) return "R";  
    3.97 +-  if (d ==  Row) return "D";    
    3.98 +-  if (d == -Row) return "U";      
    3.99 ++  if (d ==  Col) return "D";    
   3.100 ++  if (d == -Col) return "U";      
   3.101 + }
   3.102 + 
   3.103 + function print_moves(m) {
   3.104 +@@ -226,7 +231,7 @@
   3.105 +     if (nbBoxin == 0) {
   3.106 +       if (nbLevel < maxLevel) {
   3.107 +         alert("You have done a good job !")
   3.108 +-        parent.frames[0].location = "level" + (++nbLevel) + ".htm"
   3.109 ++        parent.frames[0].document.location = parent.frames[0].document.forms[1].elements[2].value + "/level" + (++nbLevel) + ".htm"
   3.110 +         GoLevel(nbLevel)
   3.111 +       } else {
   3.112 +         alert("Congratulations !")
   3.113 +@@ -246,14 +251,14 @@
   3.114 +   for (y = 0 ; y < Row; y++) {
   3.115 +     document.write ("<TR>")
   3.116 +     for (x = 0; x < Col; x++) {
   3.117 +-      level[x + Row * y] = parent.frames[0].document.forms[0].elements[x + Row * y].value
   3.118 +-      if (level[x + Row * y] == dest) nbBoxin++
   3.119 +-      if (level[x + Row * y] == land || level[x + Row * y] == wall)
   3.120 ++      level[x + Col * y] = parent.frames[0].document.forms[0].elements[x + Col * y].value
   3.121 ++      if (level[x + Col * y] == dest) nbBoxin++
   3.122 ++      if (level[x + Col * y] == land || level[x + Col * y] == wall)
   3.123 +         document.write("<TD VALIGN=TOP>",
   3.124 +-          "<IMG align=middle class=r border=0 src=\"", level[x + Row * y], ".gif\"<\/TD>")
   3.125 ++          "<IMG align=middle class=r border=0 src=\"", level[x + Col * y], ".gif\"<\/TD>")
   3.126 +       else
   3.127 +-        document.write("<TD VALIGN=TOP><A HREF=\"JavaScript:Move(", x + Row * y, ")\">",
   3.128 +-          "<IMG align=middle class=r border=0 src=\"", level[x + Row * y], ".gif\"</A><\/TD>")      
   3.129 ++        document.write("<TD VALIGN=TOP><A HREF=\"JavaScript:Move(", x + Col * y, ")\">",
   3.130 ++          "<IMG align=middle class=r border=0 src=\"", level[x + Col * y], ".gif\"</A><\/TD>")      
   3.131 +     }
   3.132 +     document.write("<\/TR>")
   3.133 +   }
   3.134 +@@ -266,8 +271,12 @@
   3.135 +  document.write("<FORM>",
   3.136 +   "<INPUT TYPE=button onClick=\"Javascript:ReloadLevel();\" value=\"Restart\">",
   3.137 +   "<INPUT TYPE=button onClick=\"Javascript:UndoMove();\" value=\"Undo\"><p id=\"moves\" style=\"color:white\">0 moves</p></center>")
   3.138 ++  style="style='font-family:Courier New;font-size:14px;font-weight:bold;border:1;border-color:0;padding:0;margin:0px;background-color:#c0c0c0;color:#404040..'"
   3.139 ++  document.write("<select id='set' "+style+" onChange=\"Javascript:GoSet();\">")
   3.140 ++  document.write("<option>sokojs</option>");
   3.141 ++    document.write("</select><br />")
   3.142 +   for (i = 0; i <= maxLevel; i++) {
   3.143 +-    document.write("<INPUT style='font-family:Courier New;font-size:14px;font-weight:bold;border:1;border-color:0;padding:0;margin:0px;background-color:#c0c0c0;color:#404040รน' TYPE=\"button\" onClick=\"Javascript:GoLevel(", i, ");\" value=\"", (i<9?"&nbsp;":"")+(i+1), "\">")
   3.144 ++    document.write("<INPUT "+style+" TYPE=\"button\" onClick=\"Javascript:GoLevel(", i, ");\" value=\"", (i<9?"&nbsp;":"")+(i+1), "\">")
   3.145 +   }
   3.146 +   document.write("<\/FORM></table>")
   3.147 + 
   3.148 +--- sokojs.htm
   3.149 ++++ sokojs.htm
   3.150 +@@ -22,13 +22,13 @@
   3.151 + <html>
   3.152 + <head>
   3.153 + <TITLE>Sokoban (C) Michel Buze</TITLE>
   3.154 +-<META HTTP-EQUIV="Keywords" CONTENT="boxworld,javascript,sokoban,jeu,jeux,game,buze,web">
   3.155 ++<META HTTP-EQUIV="Content Type" CONTENT="text/html;charset=utf-8">
   3.156 + <META NAME="Keywords" CONTENT="boxworld,javascript,sokoban,jeu,jeux,game,buze,web">
   3.157 + <meta name="viewport" content="width=device-width, initial-scale=1">
   3.158 + </head>
   3.159 + 
   3.160 + <frameset border="0" rows="0,700,*">
   3.161 +-<frame src="level0.htm">
   3.162 ++<frame src="sokojs/level0.htm">
   3.163 + <frame src="0.gif">
   3.164 + <frame src="0.gif">
   3.165 + <noframes>
   3.166 +EOT
   3.167 +[ -s level0.htm ] && mkdir sokojs && mv level?*.htm sokojs &&
   3.168 +sed -i 's|location = "|&../|;/.*main.htm/i document.write("<FORM ACTION=\\"\\">")\
   3.169 +document.write("<INPUT TYPE=\\"button\\" value=\\""+Row+"\\">",\
   3.170 +               "<INPUT TYPE=\\"button\\" value=\\""+Col+"\\">",\
   3.171 +               "<INPUT TYPE=\\"button\\" value=\\"sokojs\\">",\
   3.172 +               "<INPUT TYPE=\\"button\\" value=\\"97\\"><\\/FORM>")' sokojs/level*.htm
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/sokojs/stuff/slc2htm.sh	Sat Oct 16 16:30:13 2021 +0000
     4.3 @@ -0,0 +1,103 @@
     4.4 +#!/bin/sh
     4.5 +
     4.6 +[ -z "$1" ] && echo "$0 set1.slc ..." && exit 1
     4.7 +[ ! -s "main.htm" ] && echo "$PWD/main.htm not found" && exit 2
     4.8 +
     4.9 +while [ "$1" ]; do
    4.10 +	file="$1"
    4.11 +	set="$(basename $1 .slc)"
    4.12 +	shift
    4.13 +	[ -d "$set" ] && continue
    4.14 +	echo "$set"
    4.15 +	grep -q "<option>$set</option>" main.htm || sed -i "s|</select>|<option>$set</option>\");\n    document.write(\"&|" main.htm
    4.16 +	mkdir "$set"
    4.17 +	comment=""; state=""; level=0
    4.18 +	while read line; do
    4.19 +		case "$line" in
    4.20 +		*\<Url\>*) echo "$line" | sed 's|.*<Url>||;s|</Url>.*||' >> "$set/description.txt" ;;
    4.21 +		*\<Title\>*) echo "$line" | sed 's|.*<Title>||;s|</Title>.*||' >> "$set/description.txt" ;;
    4.22 +		*\<Description\>) state="Description"; continue ;;
    4.23 +		*\</Description\>) state="" ;;
    4.24 +		*\<LevelCollection*)
    4.25 +                        maxwidth="$(echo "$line" | sed 's|.*MaxWidth="||;s|".*||')"
    4.26 +			col=16; [ $maxwidth -gt $col ] && col=$maxwidth
    4.27 +                        maxheight="$(echo "$line" | sed 's|.*MaxHeight="||;s|".*||')"
    4.28 +			row=16; [ $maxheight -gt $row ] && row=$maxheight
    4.29 +                        echo "$line" | sed '/Copyright=/!d;s|.*Copyright="|copyright |;s|".*||' >> "$set/description.txt" ;;
    4.30 +		*\<Level*) state="Level"
    4.31 +                        id="$(echo "$line" | sed 's|.*Id="||;s|".*||')"
    4.32 +                        width="$(echo "$line" | sed 's|.*Width="||;s|".*||')"
    4.33 +			fmt="                                               "
    4.34 +			fmt="${fmt:0:$((($col-$width)/2))}%-$(($col-($col-$width)/2))s"
    4.35 +                        height="$(echo "$line" | sed 's|.*Height="||;s|".*||')"
    4.36 +			height=$((($row-$height)/2))
    4.37 +			l=0
    4.38 +			cat > "$set/level$level.htm" <<EOT
    4.39 +<html>
    4.40 +<head>
    4.41 +</head>
    4.42 +<body>
    4.43 +<form action="">
    4.44 +<script type="text/javascript">
    4.45 +<!--
    4.46 +if (parent.frames[0] == null) { document.location = "../sokojs.htm"  }
    4.47 +l = new Array(
    4.48 +EOT
    4.49 +			prev=""
    4.50 +			continue ;;
    4.51 +		*\</Level\>) state=""
    4.52 +			while [ $row -gt $l ]; do
    4.53 +				printf "\"$fmt\",\n" "$prev" >> "$set/level$level.htm"
    4.54 +				prev=""
    4.55 +				l=$(($l+1))
    4.56 +			done
    4.57 +			cat >> "$set/level$level.htm" <<EOT
    4.58 +$(printf "\"$fmt\"" "$prev"));
    4.59 +
    4.60 +Row=$row
    4.61 +Col=$col
    4.62 +for  (x = 0; x < Row; x++)
    4.63 +  for  (y = 0; y < Col; y++)
    4.64 +    document.write("<INPUT TYPE=\"button\" value=\"",
    4.65 +      ' _#*$.'.indexOf(l[x].substring(y, y + 1)), "\">")
    4.66 +document.write("<INPUT TYPE=\"button\" value=\"$x\">",
    4.67 +               "<INPUT TYPE=\"button\" value=\"$level\"><\/FORM>")
    4.68 +
    4.69 +document.write("<FORM ACTION=\"\">")
    4.70 +document.write("<INPUT TYPE=\"button\" value=\""+Row+"\">",
    4.71 +               "<INPUT TYPE=\"button\" value=\""+Col+"\">",
    4.72 +               "<INPUT TYPE=\"button\" value=\"$set\">",
    4.73 +               "<INPUT TYPE=\"button\" value=\"COUNT\"><\/FORM>")
    4.74 +parent.frames[1].location = "../main.htm"
    4.75 +parent.frames[2].location = "../level.htm"
    4.76 +//-->
    4.77 +</script></form>
    4.78 +</body>
    4.79 +</html>
    4.80 +EOT
    4.81 +			level=$(($level+1))
    4.82 +			continue ;;
    4.83 +		esac
    4.84 +		case "$state" in
    4.85 +		Description)
    4.86 +			echo "$line" >> "$set/description.txt" ;;
    4.87 +		Level)
    4.88 +			[ "$prev" ] && printf "\"$fmt\",$comment\n" "$prev" >> "$set/level$level.htm" ||
    4.89 +			echo "// $id ${maxwidth}x$maxheight+$((($col-$width)/2))+$height" >> "$set/level$level.htm"
    4.90 +			while [ $height -gt 0 ]; do
    4.91 +				printf "\"$fmt\",\n" "" >> "$set/level$level.htm"
    4.92 +				height=$(($height-1))
    4.93 +				l=$(($l+1))
    4.94 +			done
    4.95 +			prev="$(echo "$line" | sed 's|.*<L>||;s|</L>||;:a;s|\([#.+@$\*]_*\) |\1_|;ta')"
    4.96 +			comment=""
    4.97 +			if echo "$prev" | grep -Eq '@|\+'; then
    4.98 +				x=$(($(echo "$prev" | sed 's|[@+].*||' | wc -c)+($l*$col)+($col-$width)/2-1))
    4.99 +				comment=" // $(printf "\"$fmt\"," "$prev") $x"
   4.100 +				prev="$(echo "$prev" | sed 's|\+|.|;s|@|_|')"
   4.101 +			fi
   4.102 +			l=$(($l+1))
   4.103 +		esac
   4.104 +	done < "$file"
   4.105 +	sed -i "s|COUNT|$(($level-1))|" "$set"/level*.htm
   4.106 +done