Compare commits
No commits in common. "master" and "0.1" have entirely different histories.
@ -2,12 +2,3 @@
|
|||||||
----
|
----
|
||||||
initial release
|
initial release
|
||||||
|
|
||||||
0.1.1
|
|
||||||
----
|
|
||||||
- fix \[lb], \[rb], and \[text between brackets]
|
|
||||||
- add img tag support & stripping
|
|
||||||
- fix message logging
|
|
||||||
|
|
||||||
0.1.2
|
|
||||||
----
|
|
||||||
- fix newline handling
|
|
||||||
|
@ -5,8 +5,7 @@ var DEBUG: bool = false
|
|||||||
enum TAG_TYPE { NULL=0, ROOT=1,
|
enum TAG_TYPE { NULL=0, ROOT=1,
|
||||||
color,
|
color,
|
||||||
u, s, i, b, center, right,
|
u, s, i, b, center, right,
|
||||||
rainbow, tornado, shake, wave, font,
|
rainbow, tornado, shake, wave, font
|
||||||
img
|
|
||||||
}
|
}
|
||||||
const DEFAULT_ALLOWED_TYPES := [TAG_TYPE.color, TAG_TYPE.u, TAG_TYPE.s, TAG_TYPE.b, TAG_TYPE.i]
|
const DEFAULT_ALLOWED_TYPES := [TAG_TYPE.color, TAG_TYPE.u, TAG_TYPE.s, TAG_TYPE.b, TAG_TYPE.i]
|
||||||
|
|
||||||
@ -27,11 +26,10 @@ class BBCodeTag extends Reference:
|
|||||||
elif n is BBCodeTag: r += n.get_full(allowed_types)
|
elif n is BBCodeTag: r += n.get_full(allowed_types)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
func get_stripped(preserve_escape:bool=false) -> String:
|
func get_stripped() -> String:
|
||||||
var r := ""
|
var r := ""
|
||||||
for n in inner:
|
for n in inner:
|
||||||
if n is String and preserve_escape: r += n
|
if n is String: r += n
|
||||||
elif n is String and not preserve_escape: r += n.replace("[lb]","[").replace("[rb]","]")
|
|
||||||
elif n is BBCodeTag: r += n.get_stripped()
|
elif n is BBCodeTag: r += n.get_stripped()
|
||||||
return r
|
return r
|
||||||
|
|
||||||
@ -75,15 +73,6 @@ class BBCodeUnsafeTag extends BBCodeTag:
|
|||||||
return "[" + tag_str + stuff + "]" + .get_full(allowed_types) + "[/" + tag_str + "]"
|
return "[" + tag_str + stuff + "]" + .get_full(allowed_types) + "[/" + tag_str + "]"
|
||||||
else: return .get_full(allowed_types)
|
else: return .get_full(allowed_types)
|
||||||
|
|
||||||
class BBCodeImgTag extends BBCodeUnsafeTag:
|
|
||||||
func get_full(allowed_types: Array) -> String:
|
|
||||||
if TAG_TYPE.img in allowed_types:
|
|
||||||
return .get_full(allowed_types)
|
|
||||||
else: return ""
|
|
||||||
# get stripped for image adds nothing!
|
|
||||||
func get_stripped(preserve_escape:bool=false) -> String:
|
|
||||||
return ""
|
|
||||||
|
|
||||||
class BBCodeSimpleTag extends BBCodeTag:
|
class BBCodeSimpleTag extends BBCodeTag:
|
||||||
func get_full(allowed_types: Array) -> String:
|
func get_full(allowed_types: Array) -> String:
|
||||||
var tag_str = TAG_TYPE.keys()[tag_type]
|
var tag_str = TAG_TYPE.keys()[tag_type]
|
||||||
@ -100,7 +89,6 @@ static func tag_creator(tag_type: int, junk: String) -> BBCodeTag:
|
|||||||
var n: BBCodeTag
|
var n: BBCodeTag
|
||||||
match tag_type:
|
match tag_type:
|
||||||
TAG_TYPE.color: n = BBCodeColorTag.new()
|
TAG_TYPE.color: n = BBCodeColorTag.new()
|
||||||
TAG_TYPE.img: n = BBCodeImgTag.new()
|
|
||||||
TAG_TYPE.s, TAG_TYPE.u, TAG_TYPE.i, TAG_TYPE.b,\
|
TAG_TYPE.s, TAG_TYPE.u, TAG_TYPE.i, TAG_TYPE.b,\
|
||||||
TAG_TYPE.center, TAG_TYPE.right: n = BBCodeSimpleTag.new()
|
TAG_TYPE.center, TAG_TYPE.right: n = BBCodeSimpleTag.new()
|
||||||
TAG_TYPE.rainbow, TAG_TYPE.shake, TAG_TYPE.tornado, TAG_TYPE.wave,\
|
TAG_TYPE.rainbow, TAG_TYPE.shake, TAG_TYPE.tornado, TAG_TYPE.wave,\
|
||||||
@ -121,7 +109,7 @@ func parse_bbcode_text(text: String) -> BBCodeTag:
|
|||||||
|
|
||||||
if not tag_matcher:
|
if not tag_matcher:
|
||||||
tag_matcher = RegEx.new()
|
tag_matcher = RegEx.new()
|
||||||
tag_matcher.compile("(?s)(.*?)(\\[(\\w+)([^\\[\\]]*?)\\]|\\[/(\\w+)\\])")
|
tag_matcher.compile("(.*?)(\\[(\\w+)([^\\[\\]]*?)\\]|\\[/(\\w+)\\])")
|
||||||
|
|
||||||
var linear_matches: Array = tag_matcher.search_all(text)
|
var linear_matches: Array = tag_matcher.search_all(text)
|
||||||
# no tags - plaintext
|
# no tags - plaintext
|
||||||
@ -164,17 +152,6 @@ func parse_bbcode_text(text: String) -> BBCodeTag:
|
|||||||
# add leading text to current tag
|
# add leading text to current tag
|
||||||
cur_tag.inner.push_back(before.replace('[','[lb]'))
|
cur_tag.inner.push_back(before.replace('[','[lb]'))
|
||||||
|
|
||||||
# special case for [lb] [rb] escapes
|
|
||||||
if not is_close and tag == "lb" or tag == "rb":
|
|
||||||
cur_tag.inner.push_back("["+tag+"]")
|
|
||||||
continue
|
|
||||||
|
|
||||||
# unsupported bbcode - treat as text
|
|
||||||
if tag_type == TAG_TYPE.NULL:
|
|
||||||
var opener = "[lb]" if not is_close else "[lb]/"
|
|
||||||
cur_tag.inner.push_back(opener+tag+junk+"[rb]")
|
|
||||||
continue
|
|
||||||
|
|
||||||
# we got a closing tag, unroll the stack
|
# we got a closing tag, unroll the stack
|
||||||
# until we get a matching open or root
|
# until we get a matching open or root
|
||||||
if is_close:
|
if is_close:
|
||||||
@ -265,13 +242,10 @@ static func find_in_strings(bbcode: BBCodeTag, find: String) -> bool:
|
|||||||
|
|
||||||
func test():
|
func test():
|
||||||
var tests := [
|
var tests := [
|
||||||
"Choose how the lobby operates.\n[color=#6a4420]PUBLIC[/color]: Public and visible in the Game Browser for all to join.\n[color=#6a4420]CODE-ONLY[/color]: Public, but not visible in the Game Browser, while still allowing players to join via.\n[color=#6a4420]FRIENDS-ONLY[/color]: Codeless Lobby that is hidden and inaccessible to all players except Steam friends.\n[color=#6a4420]OFFLINE/SOLO[/color]: Start a game alone, with players unable to join you.",
|
"foo bar",
|
||||||
"[haha i am very cool]",
|
|
||||||
"[b]foo[img=500]test1[/img]bar[img]test2[i]a[/i][/img][/b]",
|
|
||||||
"foo [lb]bar[rb]",
|
|
||||||
"foo [u]foobar[/u] bar",
|
"foo [u]foobar[/u] bar",
|
||||||
"foo [color=red]foobar[/u] bar",
|
"foo [color=red]foobar[/u] bar",
|
||||||
"foo [color=#10ffffff]fo[lb]obar[/u] bar",
|
"foo [color=#10ffffff]foobar[/u] bar",
|
||||||
"foo [color=#ffffff]foobar[/u] bar",
|
"foo [color=#ffffff]foobar[/u] bar",
|
||||||
"foo [color=#1111111111111]foobar[/u] bar",
|
"foo [color=#1111111111111]foobar[/u] bar",
|
||||||
"foo [color=transparent]foobar[/u] bar",
|
"foo [color=transparent]foobar[/u] bar",
|
||||||
@ -293,7 +267,6 @@ func test():
|
|||||||
print("[BB TEST FULL ALL] ", r.get_full(TAG_TYPE.values()))
|
print("[BB TEST FULL ALL] ", r.get_full(TAG_TYPE.values()))
|
||||||
print("[BB TEST U] ", r.get_full([TAG_TYPE.u]))
|
print("[BB TEST U] ", r.get_full([TAG_TYPE.u]))
|
||||||
print("[BB TEST STRIPPED] ", r.get_stripped())
|
print("[BB TEST STRIPPED] ", r.get_stripped())
|
||||||
print("[BB TEST STRIPPED(true)] ", r.get_stripped(true))
|
|
||||||
print("[BB TEST LEN 10] ", parsed_to_text(r, DEFAULT_ALLOWED_TYPES, 10))
|
print("[BB TEST LEN 10] ", parsed_to_text(r, DEFAULT_ALLOWED_TYPES, 10))
|
||||||
clamp_alpha(r, 0.5)
|
clamp_alpha(r, 0.5)
|
||||||
print("[BB TEST ALPHA] ", r.get_full([TAG_TYPE.color]))
|
print("[BB TEST ALPHA] ", r.get_full([TAG_TYPE.color]))
|
||||||
|
@ -19,16 +19,13 @@ func set_hlogmsg(val): pass
|
|||||||
func _enter_tree():
|
func _enter_tree():
|
||||||
NetManager = NetManager_t.new()
|
NetManager = NetManager_t.new()
|
||||||
BBCode = BBCode_t.new()
|
BBCode = BBCode_t.new()
|
||||||
|
#NetManager.DEBUG = true
|
||||||
|
#BBCode.DEBUG = true
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
print("[LUCYSLIB] LucysLib 0.1.2 ready")
|
print("[LUCYSLIB] LucysLib 0.1.0 ready")
|
||||||
#BBCode.DEBUG = true
|
|
||||||
#BBCode.test()
|
#BBCode.test()
|
||||||
|
|
||||||
#func packet_dump(PACKET):
|
|
||||||
# print("[PACKET] ", PACKET)
|
|
||||||
# print("[PACKET DECOMPRESSED DATA] ", PACKET.data.decompress_dynamic( - 1, Network.COMPRESSION_TYPE))
|
|
||||||
|
|
||||||
func register_bb_msg_support():
|
func register_bb_msg_support():
|
||||||
if HAS_BB_MSG: return
|
if HAS_BB_MSG: return
|
||||||
print("[LUCYSLIB] registering bbcode message receive support...")
|
print("[LUCYSLIB] registering bbcode message receive support...")
|
||||||
@ -43,13 +40,13 @@ func register_log_msg_support():
|
|||||||
|
|
||||||
# future use
|
# future use
|
||||||
func process_packet_lucy_packet(DATA, PACKET_SENDER, from_host) -> bool:
|
func process_packet_lucy_packet(DATA, PACKET_SENDER, from_host) -> bool:
|
||||||
print("[LUCY PACKET] [" + str(PACKET_SENDER) + " " + str(Network._get_username_from_id(PACKET_SENDER)) + "]")
|
print("[LUCY PACKET] [" + PACKET_SENDER + " " + Network._get_username_from_id(PACKET_SENDER) + "]")
|
||||||
return true
|
return true
|
||||||
|
|
||||||
# message logging
|
# message logging
|
||||||
func process_packet_message_log(DATA, PACKET_SENDER, from_host) -> bool:
|
func process_packet_message_log(DATA, PACKET_SENDER, from_host) -> bool:
|
||||||
if LOG_MESSAGES:
|
if LOG_MESSAGES:
|
||||||
print("[MSG] [" + str(PACKET_SENDER) + " " + str(Network._get_username_from_id(PACKET_SENDER)) + "] " + str(DATA))
|
print("[MSG] [" + PACKET_SENDER + " " + Network._get_username_from_id(PACKET_SENDER) + "] " + DATA)
|
||||||
return false
|
return false
|
||||||
|
|
||||||
# bbcode support in messages
|
# bbcode support in messages
|
||||||
|
Loading…
Reference in New Issue
Block a user