Added Glitch Room Source code to Gitty
This commit is contained in:
commit
1ac9eb5644
505 files changed
+28504
No files matched your search
@@ -0,0 +1,223 @@
|
||||
class_name RoomValidator
|
||||
|
||||
|
||||
static func validate(
|
||||
room: RoomDefinition,
|
||||
database: ProjectDatabase
|
||||
) -> ValidationResult:
|
||||
|
||||
var result := ValidationResult.new()
|
||||
|
||||
if room == null:
|
||||
result.add_error(
|
||||
"RoomDefinition is null."
|
||||
)
|
||||
return result
|
||||
|
||||
_validate_cabinet_placements(
|
||||
room,
|
||||
database,
|
||||
result
|
||||
)
|
||||
|
||||
_validate_devices(
|
||||
room,
|
||||
result
|
||||
)
|
||||
|
||||
_validate_bindings(
|
||||
room,
|
||||
database,
|
||||
result
|
||||
)
|
||||
|
||||
return result
|
||||
|
||||
static func _validate_cabinet_placements(
|
||||
room: RoomDefinition,
|
||||
database: ProjectDatabase,
|
||||
result: ValidationResult
|
||||
) -> void:
|
||||
|
||||
var seen_ids: Dictionary = {}
|
||||
|
||||
for placement in room.cabinet_placements:
|
||||
|
||||
if placement == null:
|
||||
result.add_warning(
|
||||
"Room contains a null cabinet placement."
|
||||
)
|
||||
continue
|
||||
|
||||
var cabinet_id := placement.cabinet_id
|
||||
|
||||
if cabinet_id == &"":
|
||||
result.add_error(
|
||||
"Room contains a cabinet placement with no cabinet_id."
|
||||
)
|
||||
continue
|
||||
|
||||
if seen_ids.has(cabinet_id):
|
||||
result.add_error(
|
||||
"Cabinet '%s' is placed in the room more than once."
|
||||
% cabinet_id
|
||||
)
|
||||
else:
|
||||
seen_ids[cabinet_id] = true
|
||||
|
||||
if database != null:
|
||||
if database.get_cabinet(
|
||||
cabinet_id
|
||||
) == null:
|
||||
|
||||
result.add_error(
|
||||
"Room references unknown cabinet '%s'."
|
||||
% cabinet_id
|
||||
)
|
||||
|
||||
static func _validate_devices(
|
||||
room: RoomDefinition,
|
||||
result: ValidationResult
|
||||
) -> void:
|
||||
|
||||
var seen_ids: Dictionary = {}
|
||||
|
||||
for device in room.devices:
|
||||
|
||||
if device == null:
|
||||
result.add_warning(
|
||||
"Room contains a null device."
|
||||
)
|
||||
continue
|
||||
|
||||
if device.device_id == &"":
|
||||
result.add_error(
|
||||
"Room contains a device with no device_id."
|
||||
)
|
||||
continue
|
||||
|
||||
if seen_ids.has(
|
||||
device.device_id
|
||||
):
|
||||
result.add_error(
|
||||
"Room device '%s' appears more than once."
|
||||
% device.device_id
|
||||
)
|
||||
else:
|
||||
seen_ids[
|
||||
device.device_id
|
||||
] = true
|
||||
|
||||
static func _validate_bindings(
|
||||
room: RoomDefinition,
|
||||
database: ProjectDatabase,
|
||||
result: ValidationResult
|
||||
) -> void:
|
||||
|
||||
var seen_bindings: Dictionary = {}
|
||||
|
||||
for binding in room.bindings:
|
||||
|
||||
if binding == null:
|
||||
result.add_warning(
|
||||
"Room contains a null device binding."
|
||||
)
|
||||
continue
|
||||
|
||||
var cabinet_id := binding.cabinet_id
|
||||
var action_id := binding.hardware_action_id
|
||||
var device_id := binding.device_id
|
||||
|
||||
if cabinet_id == &"":
|
||||
result.add_error(
|
||||
"A room binding has no cabinet_id."
|
||||
)
|
||||
continue
|
||||
|
||||
if action_id == &"":
|
||||
result.add_error(
|
||||
"A room binding for cabinet '%s' has no hardware action."
|
||||
% cabinet_id
|
||||
)
|
||||
continue
|
||||
|
||||
if device_id == &"":
|
||||
result.add_error(
|
||||
"A room binding for cabinet '%s' has no device_id."
|
||||
% cabinet_id
|
||||
)
|
||||
continue
|
||||
|
||||
if room.get_cabinet_placement(
|
||||
cabinet_id
|
||||
) == null:
|
||||
|
||||
result.add_error(
|
||||
(
|
||||
"Binding references cabinet '%s', "
|
||||
+ "but that cabinet is not placed in the room."
|
||||
)
|
||||
% cabinet_id
|
||||
)
|
||||
|
||||
if room.get_device(
|
||||
device_id
|
||||
) == null:
|
||||
|
||||
result.add_error(
|
||||
"Binding references unknown room device '%s'."
|
||||
% device_id
|
||||
)
|
||||
|
||||
var cabinet: CabinetProfile = null
|
||||
|
||||
if database != null:
|
||||
cabinet = database.get_cabinet(
|
||||
cabinet_id
|
||||
)
|
||||
|
||||
if cabinet == null:
|
||||
result.add_error(
|
||||
"Binding references unknown cabinet '%s'."
|
||||
% cabinet_id
|
||||
)
|
||||
else:
|
||||
if cabinet.hardware_config == null:
|
||||
result.add_error(
|
||||
"Cabinet '%s' has no HardwareConfig."
|
||||
% cabinet_id
|
||||
)
|
||||
elif not cabinet.hardware_config.has_action(
|
||||
action_id
|
||||
):
|
||||
result.add_error(
|
||||
(
|
||||
"Room binding references unknown hardware action '%s' "
|
||||
+ "on cabinet '%s'."
|
||||
)
|
||||
% [
|
||||
action_id,
|
||||
cabinet_id
|
||||
]
|
||||
)
|
||||
|
||||
var binding_key := (
|
||||
"%s::%s::%s"
|
||||
% [
|
||||
cabinet_id,
|
||||
action_id,
|
||||
device_id
|
||||
]
|
||||
)
|
||||
|
||||
if seen_bindings.has(
|
||||
binding_key
|
||||
):
|
||||
result.add_warning(
|
||||
"Duplicate room binding '%s'."
|
||||
% binding_key
|
||||
)
|
||||
else:
|
||||
seen_bindings[
|
||||
binding_key
|
||||
] = true
|
||||
Reference in new issue
Block a user