Switch Show to pointer slices, share objects between Show and Timeline

This commit is contained in:
Ian Gulliver
2026-02-20 17:06:43 -07:00
parent a7e831cfab
commit 69402ea2e4
2 changed files with 19 additions and 20 deletions

View File

@@ -102,16 +102,16 @@ func main() {
} }
} }
func loadMockShow() (Show, error) { func loadMockShow() (*Show, error) {
buf, err := staticFS.ReadFile("static/show.json") buf, err := staticFS.ReadFile("static/show.json")
if err != nil { if err != nil {
return Show{}, err return nil, err
} }
var show Show var show Show
if err := json.Unmarshal(buf, &show); err != nil { if err := json.Unmarshal(buf, &show); err != nil {
return Show{}, err return nil, err
} }
return show, nil return &show, nil
} }
func writeJSON(w http.ResponseWriter, v any) { func writeJSON(w http.ResponseWriter, v any) {

View File

@@ -7,9 +7,9 @@ const (
) )
type Show struct { type Show struct {
Tracks []Track `json:"tracks"` Tracks []*Track `json:"tracks"`
Blocks []Block `json:"blocks"` Blocks []*Block `json:"blocks"`
Triggers []Trigger `json:"triggers"` Triggers []*Trigger `json:"triggers"`
} }
type Track struct { type Track struct {
@@ -41,15 +41,15 @@ type TriggerTarget struct {
} }
type TimelineTrack struct { type TimelineTrack struct {
Track *Track
Cells []*TimelineCell `json:"cells"` Cells []*TimelineCell `json:"cells"`
} }
type Timeline struct { 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:"-"`
constraints []constraint `json:"-"` constraints []constraint `json:"-"`
exclusives []exclusiveGroup `json:"-"` exclusives []exclusiveGroup `json:"-"`
@@ -78,7 +78,7 @@ type exclusiveGroup struct {
members []*TimelineCell members []*TimelineCell
} }
func validateShow(show Show) error { func validateShow(show *Show) error {
startTargeted := map[string]bool{} startTargeted := map[string]bool{}
for _, trigger := range show.Triggers { for _, trigger := range show.Triggers {
for _, target := range trigger.Targets { for _, target := range trigger.Targets {
@@ -100,18 +100,18 @@ func validateShow(show Show) error {
return nil return nil
} }
func BuildTimeline(show Show) (Timeline, error) { func BuildTimeline(show *Show) (Timeline, error) {
if err := validateShow(show); err != nil { if err := validateShow(show); err != nil {
return Timeline{}, err return Timeline{}, err
} }
tl := Timeline{ tl := Timeline{
show: show, show: show,
Blocks: map[string]Block{}, Blocks: map[string]*Block{},
trackIdx: map[string]*TimelineTrack{}, trackIdx: map[string]*TimelineTrack{},
} }
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 show.Tracks {
@@ -158,7 +158,7 @@ func (track *TimelineTrack) appendCells(cells ...*TimelineCell) {
} }
} }
func getCueCells(block Block) []*TimelineCell { func getCueCells(block *Block) []*TimelineCell {
return []*TimelineCell{{ return []*TimelineCell{{
BlockID: block.ID, BlockID: block.ID,
IsStart: true, IsStart: true,
@@ -167,7 +167,7 @@ func getCueCells(block Block) []*TimelineCell {
}} }}
} }
func getBlockCells(block Block) []*TimelineCell { func getBlockCells(block *Block) []*TimelineCell {
return []*TimelineCell{ return []*TimelineCell{
{BlockID: block.ID, IsStart: true, Event: "START"}, {BlockID: block.ID, IsStart: true, Event: "START"},
{BlockID: block.ID, IsTitle: true}, {BlockID: block.ID, IsTitle: true},
@@ -187,9 +187,8 @@ func (tl *Timeline) findCell(blockID, event string) *TimelineCell {
} }
func (tl *Timeline) buildCells(endChains map[string]bool) { func (tl *Timeline) buildCells(endChains map[string]bool) {
for _, sb := range tl.show.Blocks { for _, block := range tl.show.Blocks {
block := tl.Blocks[sb.ID] track := tl.trackIdx[tl.Blocks[block.ID].Track]
track := tl.trackIdx[block.Track]
var cells []*TimelineCell var cells []*TimelineCell
switch block.Type { switch block.Type {
case "cue": case "cue":