freefowl [Lexaloffle Blog Feed]https://www.lexaloffle.com/bbs/?uid=51009 Quick cart loader <p> <table><tr><td> <a href="/bbs/?pid=124327#p"> <img src="/bbs/thumbs/pico8_quickerloader_slowboot-2.png" style="height:256px"></a> </td><td width=10></td><td valign=top> <a href="/bbs/?pid=124327#p"> quickerloader 0.1</a><br><br> by <a href="/bbs/?uid=51009"> freefowl</a> <br><br><br> <a href="/bbs/?pid=124327#p"> [Click to Play]</a> </td></tr></table> <br /> Made a menu to navigate picowesome while running pico.pi by gamaral. Using splore to navigate large directories of carts was tedious. Mainly because there was no way to back out of a directory besides scrolling to the top.</p> <p>One challenge I ran into was there was no way to use ls() on a nested directory or run cd from the cart (that I could find). So my initial version had the entire gamelist in the menu cart. This worked well but the file was to big to upload here and felt not in the spirit of writing this app as a pico-8 cart.</p> <p>So I wrote a python script to move and rename all the carts to one directory so they could all be accessible by ls(). This caused a notable slower initial menu cart load time on a raspberry pi 3. Pico.pi takes ~18s to boot and then ~12s after pico-8 does its boot chime. With those carts nested in directories that 12s is saved.</p> <p>So I'm going to refactor back to nested directories but I wanted to post this version because it is a minimum viable product. Now I'm just going to focus on writing the new version of the quick menu.</p> <p>Here's my python script. If there's interest I can explain how to use it in the comment below.</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre> from os import walk, path from pathlib import Path import string from shutil import copy2 def main(): catagories = \ ['action adventure', 'beat em up', 'gun fps', 'misc', 'platform', \ 'race', 'shoot em up', 'sport', 'adventure visual', \ 'celeste hacks', 'hacks', 'music rythm', 'puzzle', 'rpg', \ 'simulation', 'strategy gestion', 'vs fighting', 'tools'] carts = list_files(&quot;./carts&quot;) new_carts = add_prefix_to_files(carts, catagories) copy_to_output('./carts/', './output/carts/', carts, new_carts) def copy_to_output(base_directory, output_directory, filenames, new_filenames): # mkdir $output_directory Path(output_directory).mkdir(parents=True, exist_ok=True) dir_index = 0 #print(filenames.keys()) for directory in filenames.keys(): file_index = 0 for filename in filenames[directory]: # Source directory src = base_directory + directory +'/' # Source filename src += filenames[directory][file_index] # Destination directory dst = output_directory # Destination filename dst += new_filenames[directory][file_index].lower() copy2(src, dst) file_index += 1 dir_index += 1 def add_prefix_to_files(filenames, directories): new_filenames = {} dir_index = 0 for directory in directories: file_index = 0 new_filenames[directory] = [] for filename in filenames[directory]: prefix = '.' prefix += alphanumeric_formatted(dir_index, 1) # directory code prefix += alphanumeric_formatted(file_index, 2) # file number code new_filenames[directory].append(prefix + filename) file_index += 1 dir_index += 1 return new_filenames letters = &quot;-&quot; + string.digits + string.ascii_uppercase + &quot;_&quot; + string.ascii_lowercase def alphanumeric_formatted(n, digits): &quot;&quot;&quot; Return string of int as 64 bit alphanumeric with a specific number of digits &gt;&gt;&gt; alphanumeric_formatted(4098, 4) '-0-1' &gt;&gt;&gt; alphanumeric_formatted(4098,2) '-1' &quot;&quot;&quot; s = int_to_64bit_alphanumeric(n) if len(s) &gt; digits: return s[len(s)-digits:] return s.rjust(digits, letters[0]) def int_to_64bit_alphanumeric(n): &quot;&quot;&quot; Return string of int as a 64 bit alphanumeric &gt;&gt;&gt; int_to_64bit_alphanumeric(65) '00' &gt;&gt;&gt; int_to_64bit_alphanumeric(0) '-' &gt;&gt;&gt; int_to_64bit_alphanumeric(1) '0' &gt;&gt;&gt; int_to_64bit_alphanumeric(4097) '0-0' &quot;&quot;&quot; if n &gt; 63: return int_to_64bit_alphanumeric(n&gt;&gt;6) + int_to_64bit_alphanumeric(n&amp;63) return letters[n] def list_files(startpath): carts = {} for root, dirs, files in walk(startpath): # Only grab files if directory has no files if dirs == []: carts[path.basename(root)] = sorted(files) return carts if __name__==&quot;__main__&quot;: main() </pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> https://www.lexaloffle.com/bbs/?tid=51173 https://www.lexaloffle.com/bbs/?tid=51173 Sun, 15 Jan 2023 00:31:29 UTC Git intergration <p>I wanted to commit to a git repo without leaving pico 8 so wrote bash script and about 30 tokens to add to the p8 file. Both are here (or at the bottom of the post):</p> <p><a href="https://gist.github.com/cutecprog/827ef8a82d65a1a27f133fd89392f1b0">https://gist.github.com/cutecprog/827ef8a82d65a1a27f133fd89392f1b0</a></p> <p>Start pico8 by running the bash script. Then to use. First load your p8 file.</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>&gt; load your_file.p8 &gt; run all text after will be in the commit message no quotes needed commit message set</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>Game runs.<br /> Exit the game.</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>&gt; save</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <p>All p8 files are auto added to repo. This command runs in the terminal</p> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>$ git commit -am &quot;commit message set at run&quot; # Runs when a file is saved</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <h3>Put in p8 file</h3> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>-- &gt; run breadcrumb text -- write stat(6) to file to use -- as git commit message -- call in _init() function add_commit_message() -- this saves 1 token local msg = stat(6) -- check if message entered if msg ~= &quot;~~~&quot; and msg ~= &quot;&quot; then -- write message to file printh(msg, &quot;msg&quot;, true) -- report success (opt) ?&quot;commit message set&quot; -- sleep for 30 frames (opt) for i=1, 30 do flip() end -- reset breadcrumb run(&quot;~~~&quot;) end end</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> <h3>Bash script</h3> <div> <div class=scrollable_with_touch style="width:100%; max-width:800px; overflow:auto; margin-bottom:12px"> <table style="width:100%" cellspacing=0 cellpadding=0> <tr><td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> <td background=/gfx/code_bg0.png> <div style="font-family : courier; color: #000000; display:absolute; padding-left:10px; padding-top:4px; padding-bottom:4px; "> <pre>#! /bin/bash # Run script to call pico8 ~/pico-8/pico8 &amp; while true; do inotifywait -qq -e CLOSE_WRITE ~/.lexaloffle/pico-8/carts/*.p8 cd ~/.lexaloffle/pico-8/carts git add *.p8 if test -f msg.p8l; then git commit -a -F msg.p8l rm msg.p8l else git commit -am &quot;autocommit&quot; fi done</pre></div></td> <td background=/gfx/code_bg1.png width=16><div style="width:16px;display:block"></div></td> </tr></table></div></div> https://www.lexaloffle.com/bbs/?tid=46161 https://www.lexaloffle.com/bbs/?tid=46161 Fri, 14 Jan 2022 02:12:13 UTC