immersive-home/lib/utils/entity_factory.gd
2023-12-20 01:54:22 +01:00

32 lines
921 B
GDScript

extends RefCounted
class_name EntityFactory
const Switch = preload("res://content/entities/switch/switch.tscn")
const Light = preload("res://content/entities/light/light.tscn")
const Sensor = preload("res://content/entities/sensor/sensor.tscn")
const MediaPlayer = preload("res://content/entities/media_player/media_player.tscn")
const Camera = preload("res://content/entities/camera/camera.tscn")
const ButtonEntity = preload("res://content/entities/button/button.tscn")
static func create_entity(id: String):
var entity = null
var type = id.split(".")[0]
match type:
"switch":
entity = Switch.instantiate()
"light":
entity = Light.instantiate()
"sensor":
entity = Sensor.instantiate()
"media_player":
entity = MediaPlayer.instantiate()
"camera":
entity = Camera.instantiate()
"button":
entity = ButtonEntity.instantiate()
_:
return null
entity.entity_id = id
return entity