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

41 lines
1.3 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-17 01:14:31 +02:00
## This class is used to create entities based on their type
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")
2024-04-11 17:51:30 +03:00
const LineGraphEntity = preload ("res://content/entities/line_chart/line_chart.tscn")
2024-04-11 17:51:30 +03:00
static func create_entity(id: String, type=null):
var entity = null
2024-04-11 17:51:30 +03:00
if type == null:
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()
2024-04-11 17:51:30 +03:00
"line_chart":
entity = LineGraphEntity.instantiate()
_:
return null
2023-12-10 01:34:54 +02:00
entity.entity_id = id
return entity