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")
|
2024-04-11 17:51:30 +03:00
|
|
|
const LineGraphEntity = preload ("res://content/entities/line_chart/line_chart.tscn")
|
2024-05-01 20:08:09 +03:00
|
|
|
const TimerEntity = preload ("res://content/entities/timer/timer.tscn")
|
2023-11-26 01:02:03 +02:00
|
|
|
|
2024-04-11 17:51:30 +03:00
|
|
|
static func create_entity(id: String, type=null):
|
2023-11-26 01:02:03 +02:00
|
|
|
var entity = null
|
2024-04-11 17:51:30 +03:00
|
|
|
|
|
|
|
if type == null:
|
|
|
|
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()
|
2024-04-11 17:51:30 +03:00
|
|
|
"line_chart":
|
|
|
|
entity = LineGraphEntity.instantiate()
|
2024-05-01 20:08:09 +03:00
|
|
|
"timer":
|
|
|
|
entity = TimerEntity.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
|
2024-04-25 14:19:12 +03:00
|
|
|
return entity
|
|
|
|
|
|
|
|
static func get_entity_icon(type: String) -> String:
|
|
|
|
match type:
|
|
|
|
"switch":
|
|
|
|
return "toggle_on"
|
|
|
|
"light":
|
|
|
|
return "lightbulb"
|
|
|
|
"sensor":
|
|
|
|
return "sensors"
|
|
|
|
"media_player":
|
|
|
|
return "play_circle"
|
|
|
|
"camera":
|
|
|
|
return "photo_camera"
|
|
|
|
"button":
|
|
|
|
return "radio_button_checked"
|
|
|
|
"number":
|
|
|
|
return "sliders"
|
|
|
|
"line_chart":
|
|
|
|
return "finance"
|
2024-05-01 20:08:09 +03:00
|
|
|
"timer":
|
|
|
|
return "timer"
|
2024-04-25 14:19:12 +03:00
|
|
|
_:
|
|
|
|
return "question_mark"
|