This commit is contained in:
Alexander Wang 2023-03-02 19:32:31 -08:00
parent 78c3f3f797
commit e13be5c09a
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE

View file

@ -752,38 +752,37 @@ func (c *compiler) validateBoardLinks(g *d2graph.Graph) {
} }
func hasBoard(root *d2graph.Graph, ida []string) bool { func hasBoard(root *d2graph.Graph, ida []string) bool {
for i := 0; i < len(ida); i += 2 { if len(ida) == 0 {
id := ida[i] return true
if i == 0 && id == "root" {
i--
continue
} }
if i == len(ida)-1 { if ida[0] == "root" {
return hasBoard(root, ida[1:])
}
id := ida[0]
if len(ida) == 1 {
return root.Name == id return root.Name == id
} }
nextID := ida[i+1] nextID := ida[1]
switch id { switch id {
case "layers": case "layers":
for _, b := range root.Layers { for _, b := range root.Layers {
if b.Name == nextID { if b.Name == nextID {
return hasBoard(b, ida[i+1:]) return hasBoard(b, ida[2:])
} }
} }
case "scenarios": case "scenarios":
for _, b := range root.Scenarios { for _, b := range root.Scenarios {
if b.Name == nextID { if b.Name == nextID {
return hasBoard(b, ida[i+1:]) return hasBoard(b, ida[2:])
} }
} }
case "steps": case "steps":
for _, b := range root.Steps { for _, b := range root.Steps {
if b.Name == nextID { if b.Name == nextID {
return hasBoard(b, ida[i+1:]) return hasBoard(b, ida[2:])
} }
} }
} }
break
}
return false return false
} }