- 1,748
- Posts
- 15
- Years
- Age 28
- Nearby my feet.
- Seen Apr 18, 2021
Well recently I decided I wanted to use braille, but I was too lazy to create an image for each and every braille tablet, so I came up with the idea to input a string and convert that into a displayable braille tablet!
To use call (with a script command): Braille.show("Text Here")
Also, you'll need these too if you want the script to work: "image removed"
To use call (with a script command): Braille.show("Text Here")
Code:
################################################################################
# Braille Script
# By Rei
# Credits Required
################################################################################
# Turns a normal string into a Braille string and displays it.
#
# NOTICE: Yes, I know the braille graphics aren't the best, but they work.
#
# How to use:
# - Insert the graphics provided to: YourGameFolder/Graphics/Pictures OR add
# your own graphics (to the same folder)
# - Customize the settings to make sure everything works the way it should
# - Test it out
# - Report any problems
#
#
# Call with: Braille.show("Text Here")
################################################################################
class Braille
BackgroundFile = "BrailleBackground" # Background of the Braille (EG a stone tablet)
FilePrefix = "Braille" # The prefix of the Braille characters (EG if the prefix
# is "Braille_" then it will look for "Braille_A",
# "Braille_B", "Braille_C", ect.)
# THESE OPTIONS ARE MEASURED IN PIXELS!
BrailleStartX = 32 # The Starting X (per line) on which a Braille character is shown
BrailleStartY = 32 # The Starting Y point on which Braille is shown
BrailleNewLineAt = Graphics.width - BrailleStartX # The maximum X before we go to
# a new line
# THESE OPTIONS ARE MEASURED IN PIXELS!
BraillePaddingX = 10 # Padding between each Braille character (Left to Right)
BraillePaddingY = 10 # Padding between each Braille character (Top to Bottom)
def self.show(text)
scene = Braille.new(text)
scene.main
end
def initialize(text)
@text = brailAlphabetString(text)
@exit = false
end
# Converts a normal string into an braille alphabetical string
# Removes all uneeded characters, converts numbers into the correct format
# ect.
def brailAlphabetString(input)
input[/([A-Za-z0-9# ]*)/]
input = $1
output = ""
char = "A"
for i in 0...input.length
prev_char = char
charI = input[i]
char = " "
char[0] = charI
# Check to see if we are at the start of an integer
if (char == "0" || char.to_i != 0) &&
(prev_char != "0" && prev_char.to_i == 0 && prev_char != "#")
output += "#" # Add a number sign to the start of numbers
end
# Convert each integer into a letter, because this is how it is in braille
if char == "1"
output += "A"
elsif char == "2"
output += "B"
elsif char == "3"
output += "C"
elsif char == "4"
output += "D"
elsif char == "5"
output += "E"
elsif char == "6"
output += "F"
elsif char == "7"
output += "G"
elsif char == "8"
output += "H"
elsif char == "9"
output += "I"
elsif char == "0"
output += "J"
else # If it's not a letter, just add the character.
output += char
end
end
return output
end
def create_spriteset
@sprites = {}
@sprites["background"] = IconSprite.new
@sprites["background"].setBitmap("Graphics/Pictures/" + BackgroundFile)
x = BrailleStartX + BraillePaddingX
y = BrailleStartY + BraillePaddingY
for i in [email protected]
file = "Graphics/Pictures/" + FilePrefix + "A"
t = @text[i]
if t == "#"[0]
t = "NS"
elsif t == " "[0]
t = "Space"
end
file[file.length - 1] = t
if FileTest.image_exist?(file)
@sprites["letter#{i}"] = IconSprite.new(x, y)
@sprites["letter#{i}"].setBitmap(file)
x += @sprites["letter#{i}"].bitmap.width + BraillePaddingX
if x >= BrailleNewLineAt - BraillePaddingX
x = BrailleStartX + BraillePaddingX
y += @sprites["letter#{i}"].bitmap.height + BraillePaddingX
end
else
c = "A"
c[0] = @text[i]
c = c.upcase
t = "Could not find the file Braille file for the character: #{c}!"
raise t
end
end
end
def main
create_spriteset
loop do
Graphics.update
Input.update
update
break if @exit
end
pbDisposeSpriteHash(@sprites)
end
def update
pbUpdateSpriteHash(@sprites)
if Input.trigger?(Input::C) || Input.trigger?(Input::B)
@exit = true
end
end
end
Also, you'll need these too if you want the script to work: "image removed"
Last edited: