30 lines
608 B
GDScript
30 lines
608 B
GDScript
extends Object
|
|
|
|
class_name Message
|
|
|
|
var command: String
|
|
var args: Array
|
|
|
|
func _init(text: String = ""):
|
|
if text == "":
|
|
command = ""
|
|
args = []
|
|
return
|
|
var match_re = RegEx.new();
|
|
# r"((\\,|[^,])+)"
|
|
match_re.compile("(\\\\,|[^,])+")
|
|
|
|
var radix = text.find(':')
|
|
command = text.substr(0, radix)
|
|
var args_raw = text.substr(radix+1)
|
|
args = []
|
|
for match_ in match_re.search_all(args_raw):
|
|
var arg = match_.strings[0].strip_edges().replace("\\,", ",")
|
|
args.push_back(arg)
|
|
|
|
func _to_string():
|
|
var text = "%s:" % self.command
|
|
for arg in self.args:
|
|
text += arg.replace(",", "\\,")
|
|
return text
|