Skip to content

Commit

Permalink
Fixed serialization bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jean-bovet committed Nov 18, 2022
1 parent 94de91f commit b774ed6
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion BTrain.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,7 @@
children = (
A7F779E2272E20F500E73275 /* TrainControlListView.swift */,
A7CA5EBE2795D05A00171398 /* TrainControlActionsView.swift */,
A700B21E292741AF001CC33E /* TrainControlScriptView.swift */,
A747967E291EA869001DF7FA /* TrainControlHeaderView.swift */,
A7F779F72732407E00E73275 /* TrainControlContainerView.swift */,
A76507E7275AD1FE0079C71A /* TrainControlLocationView.swift */,
Expand All @@ -1121,7 +1122,6 @@
A76FD43728FD07A000E1A295 /* TrainControlMoveSheet.swift */,
A76FD43928FD07AA00E1A295 /* TrainControlRemoveSheet.swift */,
A744D13427659330005C2F37 /* TrainControlRouteView.swift */,
A700B21E292741AF001CC33E /* TrainControlScriptView.swift */,
);
path = "Train Controls";
sourceTree = "<group>";
Expand Down
4 changes: 2 additions & 2 deletions BTrain/Scripts/LayoutScript/LayoutScriptCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ extension LayoutScriptCommand: Codable {
self.action = try container.decode(Action.self, forKey: CodingKeys.action)
self.children = try container.decode([LayoutScriptCommand].self, forKey: CodingKeys.children)

self.trainId = try container.decode(Identifier<Train>.self, forKey: CodingKeys.train)
self.routeScriptId = try container.decode(Identifier<RouteScript>.self, forKey: CodingKeys.route)
self.trainId = try container.decodeIfPresent(Identifier<Train>.self, forKey: CodingKeys.train)
self.routeScriptId = try container.decodeIfPresent(Identifier<RouteScript>.self, forKey: CodingKeys.route)
}

func encode(to encoder: Encoder) throws {
Expand Down
2 changes: 1 addition & 1 deletion BTrain/Views/Document/DocumentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ struct DocumentView: View {
}

var displaySheetView: some View {
ConfigurationSheet(title: document.displaySheetType.rawValue) {
ConfigurationSheet(title: document.displaySheetType.label) {
switch document.displaySheetType {
case .layoutScripts:
LayoutScriptEditingView(doc: document, layout: document.layout)
Expand Down
23 changes: 22 additions & 1 deletion BTrain/Views/Scripts/LayoutScript/LayoutScriptEditorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ struct LayoutScriptEditorView: View {

let doc: LayoutDocument
let layout: Layout

@ObservedObject var script: LayoutScript

@State private var invalidCommandIds = Set<UUID>()
@State private var verifyStatus: RouteScriptValidator.VerifyStatus = .none

var body: some View {
VStack {
Expand Down Expand Up @@ -48,24 +51,42 @@ struct LayoutScriptEditorView: View {
Button("Verify") {
verify()
}
Spacer()

switch verifyStatus {
case .none:
Spacer()

case .failure:
Text("􀇾")
Spacer()

case .success:
Text("􀁢")

Spacer()
}

}
}
}
}

func verify() {
invalidCommandIds.removeAll()
verifyStatus = .success

for command in script.commands {
guard let routeScript = layout.routeScripts[command.routeScriptId] else {
invalidCommandIds.insert(command.id)
verifyStatus = .failure
return
}

var validator = RouteScriptValidator()
validator.validate(script: routeScript, layout: layout)
if validator.verifyStatus == .failure {
invalidCommandIds.insert(command.id)
verifyStatus = .failure
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ struct RouteScriptEditorView: View {
Button("Verify") {
validator.validate(script: script, layout: layout)
}

switch validator.verifyStatus {
case .none:
Spacer()
Expand Down
4 changes: 2 additions & 2 deletions BTrain/Views/Train Controls/TrainControlActionsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ struct TrainControlActionsView: View {

Button("􀛷 Stop All") {
document.stopAll()
}.disabled(!document.trainsThatCanBeStopped)
}.disabled(!document.trainsThatCanBeStopped || !document.power)

Spacer().fixedSpace()

Button("􀊆 Finish All") {
document.finishAll()
}.disabled(!document.trainsThatCanBeFinished)
}.disabled(!document.trainsThatCanBeFinished || !document.power)

Spacer()

Expand Down

0 comments on commit b774ed6

Please sign in to comment.