PICO-8 Text Editor with Effects, #2

A prototype of per-letter effects using one table to hold all the letters.

I’m working on the text editor and I need to change my system of storing text to enable per-letter effects and a cursor. Right now, I’m storing the text as a table of strings, with each string storing one line of text. The problem is this system can’t do anything different per-letter because it stores lines as the smallest element.

Here’s some alternative systems and their pros and cons:

  • Table with one string per line (current system):
    • Pros: Line breaks are baked into the data structure. Intuitive. Easy to get letters’ positions.
    • Cons: No easy way to add per-letter effects, have to manage strings.
  • Table with each letter as an element:
    • Pros: Easy to add per-letter effects.
    • Cons: Have to handle line breaks and it’s not as easy to get letters’ positions.
  • Table with sub tables for each line:
    • Pros: Easy to add per-letter effects.
    • Cons: Have to manage the arrays like with strings.

About the letters’ screen position: To draw the particle burst when a new letter is added, I need to know the new letter’s X and Y screen position. The string-per-line method makes this easy, the others are harder. One option would be to store the letter’s screen position as it’s drawn and then create the burst effect afterward.

I’m also considering how to do things like selections and how to position the cursor with the mouse.

Making this text editor is an interesting exercise; I don’t normally think about how text editors work under the hood.

Leave a comment

Your email address will not be published. Required fields are marked *

Your data is processed in accordance with my privacy policy. Comments are manually approved and may take a while to appear.