immersive-home/app/lib/utils/entity_factory.gd

35 lines
1.0 KiB
GDScript3
Raw Normal View History

2023-11-28 00:46:05 +02:00
extends RefCounted
2023-12-20 02:54:22 +02:00
class_name EntityFactory
2024-03-12 15:51:09 +02:00
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")
const NumberEntity = preload ("res://content/entities/number/number.tscn")
2023-12-20 02:54:22 +02:00
static func create_entity(id: String):
var entity = null
2023-12-20 02:54:22 +02:00
var type = id.split(".")[0]
match type:
"switch":
entity = Switch.instantiate()
"light":
entity = Light.instantiate()
"sensor":
entity = Sensor.instantiate()
2023-11-26 03:01:27 +02:00
"media_player":
entity = MediaPlayer.instantiate()
2023-12-10 00:47:17 +02:00
"camera":
entity = Camera.instantiate()
2023-12-10 01:34:54 +02:00
"button":
entity = ButtonEntity.instantiate()
2024-03-12 15:51:09 +02:00
"number":
entity = NumberEntity.instantiate()
_:
return null
2023-12-10 01:34:54 +02:00
entity.entity_id = id
return entity