-
Notifications
You must be signed in to change notification settings - Fork 34
fix(rune): address conductor migration nitpicks #835
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { mat4 } from 'gl-matrix'; | ||
| import { describe, expect, test } from 'vitest'; | ||
| import { deserializeRune, serializeRune } from '../protocol'; | ||
| import { Rune } from '../rune'; | ||
|
|
||
| describe('rune protocol', () => { | ||
| test('round-trips serialized rune structures', () => { | ||
| const transformMatrix = mat4.create(); | ||
| mat4.translate(transformMatrix, transformMatrix, [0.25, 0.5, 0]); | ||
| const childTransformMatrix = mat4.create(); | ||
| mat4.scale(childTransformMatrix, childTransformMatrix, [0.5, 0.5, 1]); | ||
|
|
||
| const rune = Rune.of({ | ||
| vertices: new Float32Array([ | ||
| 0, 0, 0, 1, | ||
| 1, 0, 0, 1, | ||
| 0, 1, 0, 1 | ||
| ]), | ||
| colors: new Float32Array([ | ||
| 1, 0, 0, 1, | ||
| 0, 1, 0, 1, | ||
| 0, 0, 1, 1 | ||
| ]), | ||
| transformMatrix, | ||
| subRunes: [ | ||
| Rune.of({ | ||
| vertices: new Float32Array([ | ||
| -1, -1, 0, 1, | ||
| 0, 1, 0, 1, | ||
| 1, -1, 0, 1 | ||
| ]), | ||
| transformMatrix: childTransformMatrix, | ||
| hollusionDistance: 0.3 | ||
| }) | ||
| ], | ||
| hollusionDistance: 0.7 | ||
| }); | ||
| const serialized = serializeRune(rune); | ||
|
|
||
| expect(serializeRune(deserializeRune(serialized))).toEqual(serialized); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ import { GeneralRuntimeError } from '@sourceacademy/modules-lib/errors'; | |
| import * as funcs from './functions'; | ||
| import { | ||
| RUNE_CHANNEL_ID, | ||
| RUNE_TAB_NAME, | ||
| serializeRune, | ||
| type RuneAnimationMessage, | ||
| type RuneChannelMessage, | ||
|
|
@@ -79,6 +80,7 @@ export default class RuneModulePlugin extends BaseModulePlugin { | |
| private readonly __runeChannel: IChannel<RuneChannelMessage>; | ||
| private readonly __tabLoader: RuneTabLoader | undefined; | ||
| private readonly __displayed: RuneDisplayMessage[] = []; | ||
| private __initialised = false; | ||
| private __tabLoaded = false; | ||
|
|
||
| /** | ||
|
|
@@ -182,12 +184,12 @@ export default class RuneModulePlugin extends BaseModulePlugin { | |
| evaluator: IInterfacableEvaluator, | ||
| tabLoader: RuneTabLoader | ||
| ) { | ||
| super(conduit, [runeChannel], evaluator); | ||
|
|
||
| if (!runeChannel) { | ||
| throw new GeneralRuntimeError('Rune channel is required but was not provided.'); | ||
| } | ||
|
|
||
| super(conduit, [runeChannel], evaluator); | ||
|
|
||
| this.__runeChannel = runeChannel as IChannel<RuneChannelMessage>; | ||
| this.__tabLoader = tabLoader; | ||
| this.__runeChannel.subscribe(message => { | ||
|
|
@@ -198,6 +200,9 @@ export default class RuneModulePlugin extends BaseModulePlugin { | |
| } | ||
|
|
||
| override async initialise() { | ||
| if (this.__initialised) return; | ||
| this.__initialised = true; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, I'd love to hear the motivation behind this PR! Do you have a code sample out of curiosity?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I just noticed the attached issue, let me get home and review this
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Quick concrete repro for the |
||
|
|
||
| await super.initialise(); | ||
| for (const name in funcs.RuneFunctions) { | ||
| const value = funcs.RuneFunctions[name as keyof typeof funcs.RuneFunctions]; | ||
|
|
@@ -219,7 +224,7 @@ export default class RuneModulePlugin extends BaseModulePlugin { | |
| private __loadRuneTab(): boolean { | ||
| if (this.__tabLoaded || this.__tabLoader === undefined) return true; | ||
|
|
||
| const tabName = this.__tabLoader.tabs[0]; | ||
| const tabName = this.__tabLoader.tabs.find(tab => tab === RUNE_TAB_NAME); | ||
| if (tabName === undefined) return true; | ||
|
|
||
| this.__tabLoader.loadTab(tabName); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there instances where an error is encountered without this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No observed user-facing runtime failure from this constructor ordering specifically. This one is a defensive/parity fix from the linked issue: with the old order,
super(conduit, [runeChannel], evaluator)receives[undefined]before Rune gets a chance to throw its own "Rune channel is required" error. Moving the guard beforesuper()keeps the invalid channel out ofBaseModulePluginentirely.