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
|
2023-11-26 01:02:03 +02:00
|
|
|
|
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-11-26 01:02:03 +02:00
|
|
|
|
2023-12-20 02:54:22 +02:00
|
|
|
static func create_entity(id: String):
|
2023-11-26 01:02:03 +02:00
|
|
|
var entity = null
|
2023-12-20 02:54:22 +02:00
|
|
|
var type = id.split(".")[0]
|
2023-11-26 01:02:03 +02:00
|
|
|
|
|
|
|
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()
|
2023-11-26 01:02:03 +02:00
|
|
|
_:
|
|
|
|
return null
|
2023-12-10 01:34:54 +02:00
|
|
|
|
2023-11-26 01:02:03 +02:00
|
|
|
entity.entity_id = id
|
|
|
|
return entity
|