Skip to content

Commit

Permalink
move source and minified result path
Browse files Browse the repository at this point in the history
  • Loading branch information
JRJurman committed Mar 17, 2024
1 parent 47e7b8d commit ce9a2df
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 152 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ You can test this locally by going to
Alternatively, you can clone this repo, and open the `a11y_page.html` with your browser.

## How To Use
Copy the code in the second tab from `sample/aria_test.p8` into your project (if you are viewing the file directly, search for `-- pico-8 a11y template`). That will give you access to the API, and when loaded in the `a11y_page.html`, will show text to screen readers.

You can also grab the minified version from `sample/aria_test.min.p8`, in that file, all other code has been removed, and you can copy it directly into your project.
Copy the code from `a11y_code.lua` or `a11y_code.min.lua` into your project. That will give you access to the API, and when loaded in the `a11y_page.html`, will show text to screen readers.

## PICO-8 API

Expand Down Expand Up @@ -80,12 +78,12 @@ To use this, clone the project, and from that directory run the following comman

For linting:
```sh
python shrinko8.py ../pico-a11y/sample/aria_test.p8 --lint
python shrinko8.py ../pico-a11y/a11y_code.lua --lint
```

For minification:
```sh
python shrinko8.py ../pico-a11y/sample/aria_test.p8 ../pico-a11y/sample/aria_test.min.p8 --minify-safe-only --no-minify-rename
python shrinko8.py ../pico-a11y/a11y_code.lua ../pico-a11y/a11y_code.min.lua --minify-safe-only --no-minify-rename
```

Then delete all the code before `a11y_start=24448`.
90 changes: 90 additions & 0 deletions a11y_code.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
-- pico-8 a11y template

-- this file contains functions
-- to interface with a webpage
-- and present text for screen
-- readers.
-- read more at https://github.com/jrjurman/pico-a11y-template

-- gpio addresses
a11y_start = 0x5f80
a11y_page_size = 128 - 4
a11y_end = a11y_start + a11y_page_size
-- has the window read the page? 0 or 1
a11y_read = a11y_end + 1
-- what page are we on?
a11y_page = a11y_end + 2
-- what is the last page?
a11y_last = a11y_end + 3

-- full text to read out
a11y_text = ""

-- update screen reader function
-- this should be called at the
-- end of your update function
function update_sr()
-- get current page
local has_read_page = peek(a11y_read) == 1
local page = peek(a11y_page)
local last_page = peek(a11y_last)

-- if we have read this page (and there are more)
-- reset the read counter, and update the page
if has_read_page and page < last_page then
page = page + 1
poke(a11y_read, 0)
poke(a11y_page, page)
end

if page <= last_page then
-- clear previous text
for i = a11y_start, a11y_end do
poke(i, 0)
end

-- load the text for this page
local text_start = a11y_page_size * page
for i = 1, a11y_page_size do
local char = ord(a11y_text, i + text_start)
local addr = a11y_start + i
poke(addr, char)
end
end
end

function set_sr_text(text)
printh('sr:' .. text .. '\n')

-- set text and page variables
a11y_text = text
local page_size = #text / a11y_page_size

-- reset counters and set values
poke(a11y_read, 0)
poke(a11y_page, 0)
poke(a11y_last, page_size)

-- run update_sr to populate the text
update_sr()
end

-- handle pause button
-- since this menu is not accessible
pre_paused_text = ""
function handle_pause_sr()
-- first, check if we have pre_paused_text
-- this is the text before pausing
-- this will also be true right after pause menu is closed
if pre_paused_text != "" then
set_sr_text(pre_paused_text)
pre_paused_text = ""
end

-- then, if we just paused, update the menu text
-- and save the existing a11y text (to load later)
if btn(6) then
pre_paused_text = a11y_text
set_sr_text("you've entered the pause menu, read out is not available yet, press p or enter to leave")
end
end
5 changes: 5 additions & 0 deletions a11y_code.min.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
a11y_start=24448a11y_page_size=128-4a11y_end=a11y_start+a11y_page_size a11y_read=a11y_end+1a11y_page=a11y_end+2a11y_last=a11y_end+3a11y_text=""function update_sr()local has_read_page,page,last_page=peek(a11y_read)==1,peek(a11y_page),peek(a11y_last)if(has_read_page and page<last_page)page=page+1poke(a11y_read,0)poke(a11y_page,page)
if(page<=last_page)for i=a11y_start,a11y_end do poke(i,0)end local text_start=a11y_page_size*page for i=1,a11y_page_size do local char,addr=ord(a11y_text,i+text_start),a11y_start+i poke(addr,char)end
end function set_sr_text(text)printh("sr:"..text.."\n")a11y_text=text local page_size=#text/a11y_page_size poke(a11y_read,0)poke(a11y_page,0)poke(a11y_last,page_size)update_sr()end pre_paused_text=""function handle_pause_sr()if(pre_paused_text~="")set_sr_text(pre_paused_text)pre_paused_text=""
if(btn(6))pre_paused_text=a11y_text set_sr_text"you've entered the pause menu, read out is not available yet, press p or enter to leave"
end
Loading

0 comments on commit ce9a2df

Please sign in to comment.