Extract init methods and clean up sortedBlocks references
This commit is contained in:
@@ -19,6 +19,8 @@ type Block struct {
|
|||||||
Track string `json:"track,omitempty"`
|
Track string `json:"track,omitempty"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Loop bool `json:"loop,omitempty"`
|
Loop bool `json:"loop,omitempty"`
|
||||||
|
|
||||||
|
weight int
|
||||||
}
|
}
|
||||||
|
|
||||||
type Trigger struct {
|
type Trigger struct {
|
||||||
|
|||||||
@@ -18,12 +18,12 @@ type Timeline struct {
|
|||||||
Tracks []*TimelineTrack `json:"tracks"`
|
Tracks []*TimelineTrack `json:"tracks"`
|
||||||
Blocks map[string]*Block `json:"blocks"`
|
Blocks map[string]*Block `json:"blocks"`
|
||||||
|
|
||||||
show *Show `json:"-"`
|
show *Show `json:"-"`
|
||||||
trackIdx map[string]*TimelineTrack `json:"-"`
|
trackIdx map[string]*TimelineTrack `json:"-"`
|
||||||
cellIdx map[cellKey]*TimelineCell `json:"-"`
|
cellIdx map[cellKey]*TimelineCell `json:"-"`
|
||||||
sameRows []sameRowConstraint `json:"-"`
|
sameRows []sameRowConstraint `json:"-"`
|
||||||
exclusives []exclusiveGroup `json:"-"`
|
exclusives []exclusiveGroup `json:"-"`
|
||||||
debugW io.Writer `json:"-"`
|
debugW io.Writer `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CellType string
|
type CellType string
|
||||||
@@ -168,25 +168,41 @@ func BuildTimelineDebug(show *Show, debugW io.Writer) (Timeline, error) {
|
|||||||
debugW: debugW,
|
debugW: debugW,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tl.buildTracks()
|
||||||
|
tl.indexBlocks()
|
||||||
|
tl.buildCells()
|
||||||
|
tl.buildConstraints()
|
||||||
|
if err := tl.assignRows(); err != nil {
|
||||||
|
return Timeline{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return tl, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (tl *Timeline) buildTracks() {
|
||||||
cueTrack := &TimelineTrack{Track: &Track{ID: cueTrackID, Name: "Cue"}}
|
cueTrack := &TimelineTrack{Track: &Track{ID: cueTrackID, Name: "Cue"}}
|
||||||
tl.Tracks = append(tl.Tracks, cueTrack)
|
tl.Tracks = append(tl.Tracks, cueTrack)
|
||||||
tl.trackIdx[cueTrackID] = cueTrack
|
tl.trackIdx[cueTrackID] = cueTrack
|
||||||
for _, track := range show.Tracks {
|
|
||||||
|
for _, track := range tl.show.Tracks {
|
||||||
tt := &TimelineTrack{Track: track}
|
tt := &TimelineTrack{Track: track}
|
||||||
tl.Tracks = append(tl.Tracks, tt)
|
tl.Tracks = append(tl.Tracks, tt)
|
||||||
tl.trackIdx[track.ID] = tt
|
tl.trackIdx[track.ID] = tt
|
||||||
}
|
}
|
||||||
for _, block := range show.Blocks {
|
}
|
||||||
|
|
||||||
|
func (tl *Timeline) indexBlocks() {
|
||||||
|
for _, block := range tl.show.Blocks {
|
||||||
if block.Type == "cue" {
|
if block.Type == "cue" {
|
||||||
block.Track = cueTrackID
|
block.Track = cueTrackID
|
||||||
}
|
}
|
||||||
tl.Blocks[block.ID] = block
|
tl.Blocks[block.ID] = block
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sortedBlocks := tl.show.Blocks
|
func (tl *Timeline) findEndChains() map[string]bool {
|
||||||
|
|
||||||
endChains := map[string]bool{}
|
endChains := map[string]bool{}
|
||||||
for _, trigger := range show.Triggers {
|
for _, trigger := range tl.show.Triggers {
|
||||||
if trigger.Source.Signal != "END" {
|
if trigger.Source.Signal != "END" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -197,17 +213,9 @@ func BuildTimelineDebug(show *Show, debugW io.Writer) (Timeline, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return endChains
|
||||||
tl.buildCells(endChains, sortedBlocks)
|
|
||||||
tl.buildConstraints()
|
|
||||||
if err := tl.assignRows(); err != nil {
|
|
||||||
return Timeline{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return tl, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (tl *Timeline) addSameRow(a, b *TimelineCell) {
|
func (tl *Timeline) addSameRow(a, b *TimelineCell) {
|
||||||
tl.sameRows = append(tl.sameRows, sameRowConstraint{a: a, b: b})
|
tl.sameRows = append(tl.sameRows, sameRowConstraint{a: a, b: b})
|
||||||
}
|
}
|
||||||
@@ -244,13 +252,14 @@ func (tl *Timeline) findCell(blockID, event string) *TimelineCell {
|
|||||||
panic("cell not found: " + blockID + " " + event)
|
panic("cell not found: " + blockID + " " + event)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tl *Timeline) buildCells(endChains map[string]bool, sortedBlocks []*Block) {
|
func (tl *Timeline) buildCells() {
|
||||||
|
endChains := tl.findEndChains()
|
||||||
lastOnTrack := map[string]*Block{}
|
lastOnTrack := map[string]*Block{}
|
||||||
for _, block := range sortedBlocks {
|
for _, block := range tl.show.Blocks {
|
||||||
lastOnTrack[block.Track] = block
|
lastOnTrack[block.Track] = block
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, block := range sortedBlocks {
|
for _, block := range tl.show.Blocks {
|
||||||
track := tl.trackIdx[block.Track]
|
track := tl.trackIdx[block.Track]
|
||||||
var cells []*TimelineCell
|
var cells []*TimelineCell
|
||||||
switch block.Type {
|
switch block.Type {
|
||||||
|
|||||||
Reference in New Issue
Block a user