Setting for laser patterns (for colorblindness)

This commit is contained in:
Wuzzy 2024-08-13 00:17:47 +02:00
parent 20abe6aabd
commit 70d642008b
8 changed files with 77 additions and 14 deletions

View File

@ -1,22 +1,79 @@
local S = minetest.get_translator("lzr_laser")
-- List of laser hex codes. Affects the actual laser color in the game!
lzr_laser.DEFAULT_LASER_COLORS = {
[lzr_globals.COLOR_RED] = "#FF0000",
[lzr_globals.COLOR_GREEN] = "#00FF00",
[lzr_globals.COLOR_BLUE] = "#0000FF",
[lzr_globals.COLOR_YELLOW] = "#FFFF00",
[lzr_globals.COLOR_CYAN] = "#00FFFF",
[lzr_globals.COLOR_MAGENTA] = "#FF00FF",
[lzr_globals.COLOR_WHITE] = "#FFFFFF",
}
-- List of patterns to apply on lasers to distinguish them by some other
-- way than just color. Implemented to deal with colorblindness.
local LASER_PATTERNS = {
[lzr_globals.COLOR_RED] = nil, -- no pattern, use a solid line
[lzr_globals.COLOR_GREEN] = { name = "lzr_laser_pattern_lines.png", size = 16 },
[lzr_globals.COLOR_BLUE] = { name = "lzr_laser_pattern_dots.png", size = 16 },
[lzr_globals.COLOR_YELLOW] = { name = "lzr_laser_pattern_checkers.png", size = 16 },
[lzr_globals.COLOR_CYAN] = { name = "lzr_laser_pattern_long_checkers.png", size = 16 },
[lzr_globals.COLOR_MAGENTA] = { name = "lzr_laser_pattern_alternating.png", size = 16 },
[lzr_globals.COLOR_WHITE] = { name = "lzr_laser_pattern_holes.png", size = 32 },
}
-- Hex alpha value for translucent lasers, as a string
local LALPHA = "EE"
-- Shorthand to generate a laser tile. We don't use texture files,
-- we generate them on the fly!
local maketile = function(colorcode, alpha)
local use_patterns = minetest.settings:get_bool("lzr_patterned_lasers", false)
local alpha_append = ""
local pattern_append = ""
if alpha then
alpha_append = LALPHA
end
local texsize = 16
if use_patterns then
local pattern = LASER_PATTERNS[colorcode]
if pattern ~= nil then
pattern_append = "^[mask:"..pattern.name
texsize = pattern.size
end
end
local texture =
-- Generate the texture base color
"([fill:"..texsize.."x"..texsize..":"..
lzr_laser.DEFAULT_LASER_COLORS[colorcode]..alpha_append..")"
-- Apply a pattern on the laser, if enabled (allows to distinguish
-- lasers other than by color to circumvent colorblindness)
.. pattern_append
return { name = texture, backface_culling = true }
end
-- List of all possible laser tiles
if lzr_globals.OPAQUE_LASERS then
lzr_laser.TILE_LASER_R = { name = "lzr_laser_laser_opaque.png", backface_culling = true }
lzr_laser.TILE_LASER_G = { name = "lzr_laser_laser_green_opaque.png", backface_culling = true }
lzr_laser.TILE_LASER_B = { name = "lzr_laser_laser_blue_opaque.png", backface_culling = true }
lzr_laser.TILE_LASER_Y = { name = "lzr_laser_laser_yellow_opaque.png", backface_culling = true }
lzr_laser.TILE_LASER_C = { name = "lzr_laser_laser_cyan_opaque.png", backface_culling = true }
lzr_laser.TILE_LASER_M = { name = "lzr_laser_laser_magenta_opaque.png", backface_culling = true }
lzr_laser.TILE_LASER_W = { name = "lzr_laser_laser_white_opaque.png", backface_culling = true }
lzr_laser.TILE_LASER_R = maketile(lzr_globals.COLOR_RED)
lzr_laser.TILE_LASER_G = maketile(lzr_globals.COLOR_GREEN)
lzr_laser.TILE_LASER_B = maketile(lzr_globals.COLOR_BLUE)
lzr_laser.TILE_LASER_Y = maketile(lzr_globals.COLOR_YELLOW)
lzr_laser.TILE_LASER_C = maketile(lzr_globals.COLOR_CYAN)
lzr_laser.TILE_LASER_M = maketile(lzr_globals.COLOR_MAGENTA)
lzr_laser.TILE_LASER_W = maketile(lzr_globals.COLOR_WHITE)
lzr_laser.ALPHA_LASER = "clip"
else
lzr_laser.TILE_LASER_R = { name = "lzr_laser_laser.png", backface_culling = true }
lzr_laser.TILE_LASER_G = { name = "lzr_laser_laser_green.png", backface_culling = true }
lzr_laser.TILE_LASER_B = { name = "lzr_laser_laser_blue.png", backface_culling = true }
lzr_laser.TILE_LASER_Y = { name = "lzr_laser_laser_yellow.png", backface_culling = true }
lzr_laser.TILE_LASER_C = { name = "lzr_laser_laser_cyan.png", backface_culling = true }
lzr_laser.TILE_LASER_M = { name = "lzr_laser_laser_magenta.png", backface_culling = true }
lzr_laser.TILE_LASER_W = { name = "lzr_laser_laser_white.png", backface_culling = true }
lzr_laser.TILE_LASER_R = maketile(lzr_globals.COLOR_RED, true)
lzr_laser.TILE_LASER_G = maketile(lzr_globals.COLOR_GREEN, true)
lzr_laser.TILE_LASER_B = maketile(lzr_globals.COLOR_BLUE, true)
lzr_laser.TILE_LASER_Y = maketile(lzr_globals.COLOR_YELLOW, true)
lzr_laser.TILE_LASER_C = maketile(lzr_globals.COLOR_CYAN, true)
lzr_laser.TILE_LASER_M = maketile(lzr_globals.COLOR_MAGENTA, true)
lzr_laser.TILE_LASER_W = maketile(lzr_globals.COLOR_WHITE, true)
lzr_laser.ALPHA_LASER = "blend"
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 B

View File

@ -1,6 +1,12 @@
# If true, laser beams are opaque instead of translucent.
lzr_opaque_lasers (Opaque lasers) bool false
# If true, each laser color will be represented by an unique pattern
# so they can be distinguished not just by color alone.
# If false, lasers will be flat and smooth.
# This should be helpful in case of colorblindness.
lzr_patterned_lasers (Represent laser colors by patterns [colorblind support]) bool false
# If true, background ambience sounds will be played.
# Note: You can always toggle ambience sounds in-game with the '/ambience' command.
lzr_ambience_start_with_ambience (Ambience sounds) bool true