GraphSplit/api.go

46 lines
1.0 KiB
Go

package main
import (
"errors"
"fmt"
)
// CompleteSplit marks a split as finished and unlocks its dependent splits if they have no other dependencies
func CompleteSplit(session *Session, split *Split) error {
fmt.Printf("Splitting split %s (%s)\n", split.Name, split.State)
if split.State == Locked {
fmt.Println("Death!!")
return errors.New("cannot complete a split that is locked")
}
// Set provided split to finished
split.State = Finished
// Iterate over dependencies
for _, dep := range split.Dependencies {
// Check if dependency has no other dependencies
hasOtherDependencies := false
for _, otherDep := range session.Graph.Splits {
if otherDep == dep || otherDep.State == Finished {
continue
}
for _, otherDep2 := range otherDep.Dependencies {
if otherDep2 == dep {
hasOtherDependencies = true
break
}
}
if hasOtherDependencies {
break
}
}
// If no other dependencies, set dependency to unlocked
if !hasOtherDependencies {
dep.State = Unlocked
}
}
return nil
}