Add cellTypeAt helper to simplify repeated type checks in timeline solver
This commit is contained in:
@@ -39,6 +39,18 @@ type TimelineCell struct {
|
|||||||
track *TimelineTrack `json:"-"`
|
track *TimelineTrack `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *TimelineTrack) cellTypeAt(index int, types ...CellType) bool {
|
||||||
|
if index < 0 || index >= len(t.Cells) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, typ := range types {
|
||||||
|
if t.Cells[index].Type == typ {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (c *TimelineCell) String() string {
|
func (c *TimelineCell) String() string {
|
||||||
return fmt.Sprintf("%s/%s@%s:r%d", c.BlockID, c.Event, c.track.ID, c.row)
|
return fmt.Sprintf("%s/%s@%s:r%d", c.BlockID, c.Event, c.track.ID, c.row)
|
||||||
}
|
}
|
||||||
@@ -86,15 +98,10 @@ func (g exclusiveGroup) satisfied(tracks []*TimelineTrack) bool {
|
|||||||
if memberTracks[t] {
|
if memberTracks[t] {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if row >= len(t.Cells) {
|
if t.cellTypeAt(row, CellEvent, CellTitle, CellSignal) {
|
||||||
continue
|
|
||||||
}
|
|
||||||
c := t.Cells[row]
|
|
||||||
if c.Type != CellEvent && c.Type != CellTitle && c.Type != CellSignal {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -302,11 +309,7 @@ func (tl *Timeline) enforceExclusives() bool {
|
|||||||
if memberTracks[t] {
|
if memberTracks[t] {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if row >= len(t.Cells) {
|
if !t.cellTypeAt(row, CellEvent, CellTitle, CellSignal) {
|
||||||
continue
|
|
||||||
}
|
|
||||||
c := t.Cells[row]
|
|
||||||
if c.Type != CellEvent && c.Type != CellTitle && c.Type != CellSignal {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
tl.insertGap(t, row)
|
tl.insertGap(t, row)
|
||||||
@@ -324,12 +327,11 @@ func (tl *Timeline) isAllRemovableGapRow(row int, except *TimelineTrack) bool {
|
|||||||
if row >= len(t.Cells) {
|
if row >= len(t.Cells) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
c := t.Cells[row]
|
if !t.cellTypeAt(row, CellGap, CellChain, CellContinuation) {
|
||||||
if c.Type != CellGap && c.Type != CellChain && c.Type != CellContinuation {
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
hasBefore := row > 0 && (t.Cells[row-1].Type == CellEvent || t.Cells[row-1].Type == CellTitle || t.Cells[row-1].Type == CellSignal)
|
hasBefore := t.cellTypeAt(row-1, CellEvent, CellTitle, CellSignal)
|
||||||
hasAfter := row+1 < len(t.Cells) && (t.Cells[row+1].Type == CellEvent || t.Cells[row+1].Type == CellTitle || t.Cells[row+1].Type == CellSignal)
|
hasAfter := t.cellTypeAt(row+1, CellEvent, CellTitle, CellSignal)
|
||||||
if hasBefore && hasAfter {
|
if hasBefore && hasAfter {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user