2019-08-17 17:35:48 +02:00
|
|
|
tool
|
2019-08-12 15:58:42 +02:00
|
|
|
extends Object
|
|
|
|
class_name MMGenContext
|
|
|
|
|
2019-11-06 22:33:01 +01:00
|
|
|
|
2019-08-12 15:58:42 +02:00
|
|
|
var variants : Dictionary = {}
|
2019-12-12 23:11:43 +01:00
|
|
|
var parent_context : MMGenContext = null
|
2019-08-12 15:58:42 +02:00
|
|
|
|
2019-12-12 23:11:43 +01:00
|
|
|
func _init(p = null) -> void:
|
|
|
|
parent_context = p
|
2019-08-17 17:35:48 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func has_variant(generator) -> bool:
|
2019-12-12 23:11:43 +01:00
|
|
|
return variants.has(generator) or parent_context != null and parent_context.has_variant(generator)
|
|
|
|
|
|
|
|
func touch_variant(generator) -> void:
|
|
|
|
if !variants.has(generator):
|
|
|
|
variants[generator] = []
|
|
|
|
if parent_context != null:
|
|
|
|
parent_context.touch_variant(generator)
|
2019-08-12 15:58:42 +02:00
|
|
|
|
2019-10-20 16:22:06 +02:00
|
|
|
func get_variant(generator, variant) -> int:
|
2019-08-12 15:58:42 +02:00
|
|
|
var rv = -1
|
|
|
|
if variants.has(generator):
|
2019-10-10 07:42:38 +02:00
|
|
|
rv = variants[generator].find(variant)
|
2019-08-12 15:58:42 +02:00
|
|
|
if rv == -1:
|
2019-10-10 07:42:38 +02:00
|
|
|
variants[generator].push_back(variant)
|
2019-08-12 15:58:42 +02:00
|
|
|
else:
|
2019-10-10 07:42:38 +02:00
|
|
|
variants[generator] = [variant]
|
2019-12-12 23:11:43 +01:00
|
|
|
touch_variant(generator)
|
2019-08-12 15:58:42 +02:00
|
|
|
return rv
|