Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: non alphabetical groups producing zero length instance #79

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions src/resolver/__tests__/resolver/groups.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,118 @@ describe('Resolver, groups', () => {
expect(state1.layers['1']).toBeFalsy()
expect(state1.layers['2']).toBeFalsy()
})
test('solid groups - non alphabetical', () => {
// "solid groups" are groups with a layer
const timeline: TimelineObject[] = [
{
id: 'group1',
layer: 'g0',
enable: {
start: 10,
end: 100,
},
content: {},
isGroup: true,
children: [
{
id: 'child0',
layer: '1',
enable: {
start: '5', // 15
},
content: {},
},
],
},
{
id: 'group0',
layer: 'g0',
enable: {
start: 50,
end: 100,
},
content: {},
isGroup: true,
children: [
{
id: 'child1',
layer: '2',
enable: {
start: '5', // 55
},
content: {},
},
],
},
]

const resolved = Resolver.resolveAllStates(Resolver.resolveTimeline(timeline, { time: 0 }))

expect(resolved.statistics.resolvedObjectCount).toEqual(4)
expect(resolved.statistics.unresolvedCount).toEqual(0)

expect(resolved.objects['group1']).toBeTruthy()
expect(resolved.objects['child0']).toBeTruthy()
expect(resolved.objects['group0']).toBeTruthy()
expect(resolved.objects['child1']).toBeTruthy()

expect(resolved.objects['group1'].resolved).toMatchObject({
resolved: true,
instances: [{ start: 10, end: 50 }], // because group 0 started
})
expect(resolved.objects['child0'].resolved).toMatchObject({
resolved: true,
instances: [{ start: 15, end: 100 }],
})
expect(resolved.objects['group0'].resolved).toMatchObject({
resolved: true,
instances: [{ start: 50, end: 100 }],
})
expect(resolved.objects['child1'].resolved).toMatchObject({
resolved: true,
instances: [{ start: 55, end: 100 }],
})

expect(Resolver.getState(resolved, 16)).toMatchObject({
layers: {
g0: {
id: 'group1',
},
'1': {
id: 'child0',
},
},
nextEvents: [
{ objId: 'group1', time: 50, type: EventType.END },
{ objId: 'group0', time: 50, type: EventType.START },
{ objId: 'child1', time: 55, type: EventType.START },
{ objId: 'child0', time: 100, type: EventType.END },
{ objId: 'child1', time: 100, type: EventType.END },
{ objId: 'group0', time: 100, type: EventType.END },
// { objId: 'group0', time: 100, type: EventType.START },
],
})
expect(Resolver.getState(resolved, 56)).toMatchObject({
layers: {
g0: {
id: 'group0',
},
'2': {
id: 'child1',
},
},
nextEvents: [
{ objId: 'child0', time: 100, type: EventType.END },
{ objId: 'child1', time: 100, type: EventType.END },
{ objId: 'group0', time: 100, type: EventType.END },
// { objId: 'group0', time: 100, type: EventType.START }
],
})
const state1 = Resolver.getState(resolved, 120)
expect(state1.layers['g0']).toBeFalsy()
expect(state1.layers['1']).toBeFalsy()
expect(state1.layers['2']).toBeFalsy()
})
test('cap in repeating parent group', () => {
const timeline: TimelineObject[] = [
{
Expand Down
33 changes: 25 additions & 8 deletions src/resolver/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,31 @@ export function resolveStates(resolved: ResolvedTimeline, onlyForTime?: Time, ca
// Update activeObjIds:
delete activeObjIds[prevObj.id]

// Add to nextEvents:
if (!onlyForTime || time > onlyForTime) {
resolvedStates.nextEvents.push({
type: EventType.END,
time: time,
objId: prevObj.id,
})
eventObjectTimes[instance.end + ''] = EventType.END
if (prevObj.instance.start === prevObj.instance.end) {
// Strip out this zero-length instance

const index = prevObj.resolved.instances.findIndex((i) => i.id === prevObj.instance.id)
if (index !== -1) {
prevObj.resolved.instances.splice(index, 1)
}

const index2 = resolvedStates.nextEvents.findIndex(
(e) => e.objId === prevObj.id && e.type === EventType.START && e.time === time
)
if (index2 !== -1) {
resolvedStates.nextEvents.splice(index2, 1)
}
console.log('ind', index2, index, prevObj.id)
} else {
// Add to nextEvents:
if (!onlyForTime || time > onlyForTime) {
resolvedStates.nextEvents.push({
type: EventType.END,
time: time,
objId: prevObj.id,
})
eventObjectTimes[instance.end + ''] = EventType.END
}
}
}
}
Expand Down