Contextual Substitutions... but next level

Hi,

I am making a font in which every glyph has an alternative version. Without getting too much into the design of it, lets just use the letter “a” for instance. The a has two versions, one where it is flipped vertically and one version where it is flipped horizontally. For now the vertical one is named just “a” and the horizontal one is named “a.ss01”. I’m hoping to make it so that when one types a word, the glyphs alternate between .ss01 and the regular. So the letters would go vertical horizontal vertical horizontal etc. So that a vertical letter would never be next another vertical one vice versa. For example with the sentence, “typography is fun”, would be typed out as

“t” “y.ss01” “p” “o.ss01” “g” “r.ss01” “a” “p.ss01” “h” “y.ss01” “i” “s.ss01” “f” “u.ss01” “n”

OR

“t.ss01” “y” “p.ss01” “o” “g.ss01” etc…

So rather than typing out all the million gazillion combinations, I’m wondering if there is a nice simple solution. I’m sure it’s possible but my knowledge on the coding aspect of type is rather minimal…

Thank you.

This here could help you probably:
https://opentypecookbook.com/common-techniques/

There is also a tutorial about it. Look for contextual substitutions on the Learn page.