41 lines
1.1 KiB
GDScript
41 lines
1.1 KiB
GDScript
class_name GameEventMatcher extends Resource
|
|
|
|
# match event under certain conditions
|
|
|
|
# regex matcher, "[chapter]_[section]", * means any
|
|
# e.g. 3_* means any section in chapter 3
|
|
# empty means any ground
|
|
@export var grounds: Array[String]
|
|
# can't be empty
|
|
@export var entity: String
|
|
# empty means any action
|
|
@export var entity_actions: Array[String]
|
|
|
|
|
|
# check if the event matches the conditions
|
|
func match(event: GameEvent) -> bool:
|
|
if !entity or entity != event.entity:
|
|
return false
|
|
if entity_actions.size() > 0 and !entity_actions.has(event.entity_action):
|
|
return false
|
|
if grounds.size() > 0:
|
|
var chapter := str(event.packed_time.chapter)
|
|
var section := str(event.packed_time.section)
|
|
var matched := false
|
|
for ground_matcher in grounds:
|
|
# regex match
|
|
var parts = ground_matcher.split("_")
|
|
if parts.size() != 2:
|
|
continue
|
|
var chapter_matcher = parts[0].strip_edges()
|
|
var section_matcher = parts[1].strip_edges()
|
|
if (
|
|
(chapter_matcher == "*" or chapter_matcher == chapter)
|
|
and (section_matcher == "*" or section_matcher == section)
|
|
):
|
|
matched = true
|
|
break
|
|
if !matched:
|
|
return false
|
|
return true
|