11import context from 'js-slang/context' ;
2+ import { functionDeclaration } from '../../typings/type_map' ;
23import { AnaglyphRune , HollusionRune } from './functions' ;
3- import { type DrawnRune , AnimatedRune , type Rune , NormalRune , type RuneAnimation } from './rune' ;
4+ import { AnimatedRune , NormalRune , type DrawnRune , type Rune , type RuneAnimation } from './rune' ;
45import { throwIfNotRune } from './runes_ops' ;
56
67// =============================================================================
@@ -12,103 +13,111 @@ context.moduleContexts.rune.state = {
1213 drawnRunes
1314} ;
1415
15- /**
16- * Renders the specified Rune in a tab as a basic drawing.
17- * @param rune - The Rune to render
18- * @return {Rune } The specified Rune
19- *
20- * @category Main
21- */
22- export function show ( rune : Rune ) : Rune {
23- throwIfNotRune ( show . name , rune ) ;
24- drawnRunes . push ( new NormalRune ( rune ) ) ;
25- return rune ;
26- }
16+ class RuneDisplay {
17+ /**
18+ * Renders the specified Rune in a tab as a basic drawing.
19+ * @param rune - The Rune to render
20+ * @return {Rune } The specified Rune
21+ *
22+ * @category Main
23+ */
24+ @functionDeclaration ( 'rune: Rune' , 'Rune' )
25+ static show ( rune : Rune ) : Rune {
26+ throwIfNotRune ( RuneDisplay . show . name , rune ) ;
27+ drawnRunes . push ( new NormalRune ( rune ) ) ;
28+ return rune ;
29+ }
2730
28- /**
29- * Renders the specified Rune in a tab as an anaglyph. Use 3D glasses to view the
30- * anaglyph.
31- * @param rune - The Rune to render
32- * @return {Rune } The specified Rune
33- *
34- * @category Main
35- */
36- export function anaglyph ( rune : Rune ) : Rune {
37- throwIfNotRune ( anaglyph . name , rune ) ;
38- drawnRunes . push ( new AnaglyphRune ( rune ) ) ;
39- return rune ;
40- }
31+ /**
32+ * Renders the specified Rune in a tab as an anaglyph. Use 3D glasses to view the
33+ * anaglyph.
34+ * @param rune - The Rune to render
35+ * @return {Rune } The specified Rune
36+ *
37+ * @category Main
38+ */
39+ @functionDeclaration ( 'rune: Rune' , 'Rune' )
40+ static anaglyph ( rune : Rune ) : Rune {
41+ throwIfNotRune ( RuneDisplay . anaglyph . name , rune ) ;
42+ drawnRunes . push ( new AnaglyphRune ( rune ) ) ;
43+ return rune ;
44+ }
4145
42- /**
43- * Renders the specified Rune in a tab as a hollusion, using the specified
44- * magnitude.
45- * @param rune - The Rune to render
46- * @param {number } magnitude - The hollusion's magnitude
47- * @return {Rune } The specified Rune
48- *
49- * @category Main
50- */
51- export function hollusion_magnitude ( rune : Rune , magnitude : number ) : Rune {
52- throwIfNotRune ( hollusion_magnitude . name , rune ) ;
53- drawnRunes . push ( new HollusionRune ( rune , magnitude ) ) ;
54- return rune ;
55- }
46+ /**
47+ * Renders the specified Rune in a tab as a hollusion, using the specified
48+ * magnitude.
49+ * @param rune - The Rune to render
50+ * @param {number } magnitude - The hollusion's magnitude
51+ * @return {Rune } The specified Rune
52+ *
53+ * @category Main
54+ */
55+ @functionDeclaration ( 'rune: Rune, magnitude: number' , 'Rune' )
56+ static hollusion_magnitude ( rune : Rune , magnitude : number ) : Rune {
57+ throwIfNotRune ( RuneDisplay . hollusion_magnitude . name , rune ) ;
58+ drawnRunes . push ( new HollusionRune ( rune , magnitude ) ) ;
59+ return rune ;
60+ }
5661
57- /**
58- * Renders the specified Rune in a tab as a hollusion, with a default magnitude
59- * of 0.1.
60- * @param rune - The Rune to render
61- * @return {Rune } The specified Rune
62- *
63- * @category Main
64- */
65- export function hollusion ( rune : Rune ) : Rune {
66- throwIfNotRune ( hollusion . name , rune ) ;
67- return hollusion_magnitude ( rune , 0.1 ) ;
68- }
62+ /**
63+ * Renders the specified Rune in a tab as a hollusion, with a default magnitude
64+ * of 0.1.
65+ * @param rune - The Rune to render
66+ * @return {Rune } The specified Rune
67+ *
68+ * @category Main
69+ */
70+ @functionDeclaration ( 'rune: Rune' , 'Rune' )
71+ static hollusion ( rune : Rune ) : Rune {
72+ throwIfNotRune ( RuneDisplay . hollusion . name , rune ) ;
73+ return RuneDisplay . hollusion_magnitude ( rune , 0.1 ) ;
74+ }
6975
70- /**
71- * Create an animation of runes
72- * @param duration Duration of the entire animation in seconds
73- * @param fps Duration of each frame in frames per seconds
74- * @param func Takes in the timestamp and returns a Rune to draw
75- * @returns A rune animation
76- *
77- * @category Main
78- */
79- export function animate_rune (
80- duration : number ,
81- fps : number ,
82- func : RuneAnimation
83- ) {
84- const anim = new AnimatedRune ( duration , fps , ( n ) => {
85- const rune = func ( n ) ;
86- throwIfNotRune ( animate_rune . name , rune ) ;
87- return new NormalRune ( rune ) ;
88- } ) ;
89- drawnRunes . push ( anim ) ;
90- return anim ;
91- }
76+ /**
77+ * Create an animation of runes
78+ * @param duration Duration of the entire animation in seconds
79+ * @param fps Duration of each frame in frames per seconds
80+ * @param func Takes in the timestamp and returns a Rune to draw
81+ * @returns A rune animation
82+ *
83+ * @category Main
84+ */
85+ @functionDeclaration ( 'duration: number, fps: number, func: RuneAnimation' , 'AnimatedRune' )
86+ static animate_rune ( duration : number , fps : number , func : RuneAnimation ) {
87+ const anim = new AnimatedRune ( duration , fps , ( n ) => {
88+ const rune = func ( n ) ;
89+ throwIfNotRune ( RuneDisplay . animate_rune . name , rune ) ;
90+ return new NormalRune ( rune ) ;
91+ } ) ;
92+ drawnRunes . push ( anim ) ;
93+ return anim ;
94+ }
9295
93- /**
94- * Create an animation of anaglyph runes
95- * @param duration Duration of the entire animation in seconds
96- * @param fps Duration of each frame in frames per seconds
97- * @param func Takes in the timestamp and returns a Rune to draw
98- * @returns A rune animation
99- *
100- * @category Main
101- */
102- export function animate_anaglyph (
103- duration : number ,
104- fps : number ,
105- func : RuneAnimation
106- ) {
107- const anim = new AnimatedRune ( duration , fps , ( n ) => {
108- const rune = func ( n ) ;
109- throwIfNotRune ( animate_anaglyph . name , rune ) ;
110- return new AnaglyphRune ( rune ) ;
111- } ) ;
112- drawnRunes . push ( anim ) ;
113- return anim ;
96+ /**
97+ * Create an animation of anaglyph runes
98+ * @param duration Duration of the entire animation in seconds
99+ * @param fps Duration of each frame in frames per seconds
100+ * @param func Takes in the timestamp and returns a Rune to draw
101+ * @returns A rune animation
102+ *
103+ * @category Main
104+ */
105+ @functionDeclaration ( 'duration: number, fps: number, func: RuneAnimation' , 'AnimatedRune' )
106+ static animate_anaglyph ( duration : number , fps : number , func : RuneAnimation ) {
107+ const anim = new AnimatedRune ( duration , fps , ( n ) => {
108+ const rune = func ( n ) ;
109+ throwIfNotRune ( RuneDisplay . animate_anaglyph . name , rune ) ;
110+ return new AnaglyphRune ( rune ) ;
111+ } ) ;
112+ drawnRunes . push ( anim ) ;
113+ return anim ;
114+ }
114115}
116+
117+ export const { show,
118+ anaglyph,
119+ hollusion,
120+ hollusion_magnitude,
121+ animate_rune,
122+ animate_anaglyph,
123+ } = RuneDisplay ;
0 commit comments