diff --git a/README.txt b/README.txt index cc96250..311f414 100644 --- a/README.txt +++ b/README.txt @@ -1,4 +1,4 @@ -Bedrock Markup Language Mod v1.0 +Bedrock Markup Language Mod v1.1 By Leslie E. Krause Bedrock Markup Language is an extensible markup language and API specifically tailored diff --git a/init.lua b/init.lua index 4101915..5d58fb0 100644 --- a/init.lua +++ b/init.lua @@ -1,5 +1,5 @@ -------------------------------------------------------- --- Minetest :: Bedrock Markup Language v1.0 (markup) +-- Minetest :: Bedrock Markup Language (bedrock) -- -- See README.txt for licensing and other information. -- Copyright (c) 2016-2019, Leslie Ellen Krause @@ -9,6 +9,41 @@ markup = { } +local registered_icons = { + happy = "emoji_happy.png", + silly = "emoji_silly.png", + annoyed = "emoji_annoyed.png", + mad = "emoji_mad.png", + hungry = "emoji_hungry.png", + amused = "emoji_amused.png", + disappointed = "emoji_disappointed.png", + cool = "emoji_cool.png", + smug = "emoji_smug.png", + confused = "emoji_confused.png", + angry = "emoji_angry.png", + cheerful = "emoji_cheerful.png", + frustrated = "emoji_frustrated.png", + surprised = "emoji_surprised.png", + sad = "emoji_sad.png", + smitten = "emoji_smitten.png", + laughing = "emoji_laughing.png", + kissing = "emoji_kissing.png", + crying = "emoji_crying.png", + sleeping = "emoji_sleeping.png", + heart = "emoji_heart.png", + cupid_heart = "emoji_cupid_heart.png", + black_heart = "emoji_black_heart.png", + frozen_heart = "emoji_frozen_heart.png", + heartbreak = "emoji_heartbreak.png", + warning = "emoji_warning.png", + danger = "emoji_danger.png", + keep_out = "emoji_keep_out.png", + cone = "emoji_cone.png", + lock = "emoji_lock.png", + left_arrow = "emoji_left_arrow.png", + right_arrow = "emoji_right_arrow.png", +} + function table.get_index( self, sel_val, def_idx ) for idx, val in ipairs( self ) do if val == sel_val then return idx end @@ -21,6 +56,7 @@ markup.get_builtin_vars = function ( player_name ) return { ["$name"] = player_name, + ["$hash"] = cipher.tokenize( cipher.get_checksum( player_name ) ), ["$rank"] = default.rank_to_string( default.get_player_rank( player_name ) ), ["$item"] = player:get_wielded_item( ):get_name( ), ["$skin"] = skins.skins[ player_name ], @@ -46,12 +82,13 @@ markup.parse_message = function ( message, vars ) message = string.gsub( message, "%[c", "[ct" ) -- text message = string.gsub( message, "%[i", "[ci" ) -- item message = string.gsub( message, "%[s", "[cs" ) -- skin + message = string.gsub( message, "%[f", "[cf" ) -- form local rows = { } local input_rows = string.split( message, "[r", true ) local r_types = { n = "normal", b = "border", h = "header" } - local c_types = { t = "text", i = "item", s = "skin" } + local c_types = { t = "text", i = "item", s = "skin", f = "form" } for r_idx, r_val in ipairs( input_rows ) do @@ -96,25 +133,34 @@ markup.parse_message = function ( message, vars ) -- c_val = string.gsub( c_val, "[^\]%[.-%]", "" ) -- strip undefined tags? if type == "text" then - c_val = string.gsub( c_val, "%[q=([a-z]+)%](.-)%[/q%]", function ( code, text ) + local text = string.gsub( c_val, "%[q=([a-z]+)%](.-)%[/q%]", function ( code, text ) return text_colors[ code ] and minetest.colorize( text_colors[ code ], text ) or "?" .. text end ) + table.insert( cols, { horz = horz, text = text, type = type } ) - table.insert( cols, { horz = horz, text = c_val, type = type } ) + elseif type == "form" then + local text = string.gsub( c_val, "%[q[^%]]*%]", "" ) + table.insert( cols, { horz = horz, text = text, type = type } ) - elseif type == "item" and string.find( c_val, "%w+:%w+" ) then + elseif type == "item" and string.find( c_val, "^[a-zA-Z0-9_]+:[a-zA-Z0-9_]+$" ) then local itemdef = minetest.registered_items[ c_val ] or ":unknown" - local texture = "unknown_item.png" + local text = "unknown_item.png" if itemdef.type == "tool" or itemdef.type == "craft" then - texture = itemdef.inventory_image + text = itemdef.inventory_image elseif itemdef.tiles then - texture = itemdef.tiles[ 1 ] + text = itemdef.tiles[ 1 ] end - table.insert( cols, { horz = horz, text = texture, type = type } ) + table.insert( cols, { horz = horz, text = text, type = type } ) - elseif type == "skin" and string.find( c_val, "character_%d+" ) then - local texture = skins.meta[ c_val ] and c_val .. "_preview.png" or "character_preview.png" - table.insert( cols, { horz = horz, text = texture, type = type } ) + elseif type == "item" and string.find( c_val, "^:[a-zA-Z0-9_]+$" ) then + local text = registered_icons[ string.sub( c_val, 2 ) ] or "emoji_unknown.png" + table.insert( cols, { horz = horz, text = text, type = type } ) + + elseif type == "skin" and string.find( c_val, "^character_%d+$" ) then + local text = skins.meta[ c_val ] and c_val .. "_preview.png" or "character_preview.png" + table.insert( cols, { horz = horz, text = text, type = type } ) + + elseif type == "icon" and string.find( c_val, "^%w+$" ) then end end end @@ -191,6 +237,10 @@ markup.get_formspec_string = function ( rows, min_horz, min_vert, max_horz, max_ string.format( "textarea[%0.2f,%0.2f;%0.2f,%0.2f;;%s;]", off_horz, off_vert, width, depth + depth / 6, minetest.formspec_escape( c.text ) ) + elseif c.type == "form" then + formspec = formspec .. string.format( "field[%0.1f,%0.1f;%0.1f,1.3;userdata;;%s]", off_horz, off_vert, width, + minetest.formspec_escape( c.text ) ) + elseif c.type == "item" then -- NB: image must be shifted left to correspond with formspec text if depth >= 0.5 then @@ -204,6 +254,7 @@ markup.get_formspec_string = function ( rows, min_horz, min_vert, max_horz, max_ formspec = formspec .. string.format( "image[%0.1f,%0.1f;%0.1f,%0.1f;%s]", off_horz - 0.3, off_vert, math.min( width, depth / 2 ), math.min( width * 2, depth ), c.text ) end + end off_horz = off_horz + width