@@ -2,7 +2,10 @@ package;
2
2
3
3
import flixel .FlxG ;
4
4
import flixel .FlxState ;
5
+ import flixel .group .FlxGroup .FlxTypedGroup ;
5
6
import flixel .ui .FlxButton ;
7
+ import flixel .ui .FlxSpriteButton ;
8
+ import flixel .util .FlxColor ;
6
9
import haxe .Json ;
7
10
import openfl .events .Event ;
8
11
import openfl .events .IOErrorEvent ;
@@ -13,34 +16,77 @@ import openfl.net.FileReference;
13
16
class ChartingState extends MusicBeatState
14
17
{
15
18
var _file : FileReference ;
19
+ var sequencer : FlxTypedGroup <FlxSpriteButton >;
20
+ var notes : Array <Dynamic > = [];
16
21
17
22
override function create ()
18
23
{
19
24
var saveButton : FlxButton = new FlxButton (0 , 0 , " Save" , function ()
20
25
{
21
- // bullshit
26
+ saveLevel ();
27
+ });
28
+ saveButton .screenCenter ();
29
+ add (saveButton );
22
30
23
- var json = {
24
- " song" : " Bopeebo" ,
25
- " bpm" : 100 ,
26
- " sections" : 15
27
- };
31
+ createStepChart ();
28
32
29
- var data : String = Json .stringify (json );
33
+ super .create ();
34
+ }
30
35
31
- if ((data != null ) && (data .length > 0 ))
36
+ function createStepChart ()
37
+ {
38
+ sequencer = new FlxTypedGroup <FlxSpriteButton >();
39
+ add (sequencer );
40
+
41
+ for (r in 0 ... 2 )
42
+ {
43
+ notes .push ([]);
44
+ for (i in 0 ... 16 )
32
45
{
33
- _file = new FileReference ();
34
- _file .addEventListener (Event .COMPLETE , onSaveComplete );
35
- _file .addEventListener (Event .CANCEL , onSaveCancel );
36
- _file .addEventListener (IOErrorEvent .IO_ERROR , onSaveError );
37
- _file .save (data , json .song + " .json" );
46
+ notes [r ].push (false );
47
+ var seqBtn : FlxSpriteButton = new FlxSpriteButton ((35 * r ) + 10 , (35 * i ) + 50 , null , function ()
48
+ {
49
+ notes [r ][i ] = ! notes [r ][i ];
50
+ });
51
+
52
+ seqBtn .makeGraphic (30 , 30 , FlxColor .WHITE );
53
+ seqBtn. ID = i + (16 * r );
54
+ sequencer .add (seqBtn );
38
55
}
56
+ }
57
+ }
58
+
59
+ override function update (elapsed : Float )
60
+ {
61
+ sequencer .forEach (function (spr : FlxSpriteButton )
62
+ {
63
+ if (notes [Std .int (spr. ID / 16 )][spr. ID % 16 ])
64
+ spr .alpha = 1 ;
65
+ else
66
+ spr .alpha = 0.5 ;
39
67
});
40
- saveButton .screenCenter ();
41
- add (saveButton );
42
68
43
- super .create ();
69
+ super .update (elapsed );
70
+ }
71
+
72
+ private function saveLevel ()
73
+ {
74
+ var json = {
75
+ " song" : " Bopeebo" ,
76
+ " bpm" : 100 ,
77
+ " sections" : 15
78
+ };
79
+
80
+ var data : String = Json .stringify (json );
81
+
82
+ if ((data != null ) && (data .length > 0 ))
83
+ {
84
+ _file = new FileReference ();
85
+ _file .addEventListener (Event .COMPLETE , onSaveComplete );
86
+ _file .addEventListener (Event .CANCEL , onSaveCancel );
87
+ _file .addEventListener (IOErrorEvent .IO_ERROR , onSaveError );
88
+ _file .save (data , json .song + " .json" );
89
+ }
44
90
}
45
91
46
92
function onSaveComplete (_ ): Void
0 commit comments