1- using NoteEditor . Notes ;
1+ using LitJson ;
2+ using NoteEditor . Model . JSON ;
3+ using NoteEditor . Notes ;
24using NoteEditor . Utility ;
35using System . Collections . Generic ;
6+ using System . IO ;
7+ using System . Linq ;
48using UniRx ;
59
610namespace NoteEditor . Model
@@ -20,5 +24,59 @@ public class EditData : SingletonMonoBehaviour<EditData>
2024 public static ReactiveProperty < int > BPM { get { return Instance . BPM_ ; } }
2125 public static ReactiveProperty < int > OffsetSamples { get { return Instance . offsetSamples_ ; } }
2226 public static Dictionary < NotePosition , NoteObject > Notes { get { return Instance . notes_ ; } }
27+
28+ public static string SerializeEditData ( )
29+ {
30+ var data = new SaveDataModel . EditData ( ) ;
31+ data . BPM = BPM . Value ;
32+ data . maxBlock = MaxBlock . Value ;
33+ data . offset = OffsetSamples . Value ;
34+ data . name = Path . GetFileNameWithoutExtension ( Name . Value ) ;
35+
36+ var sortedNoteObjects = Notes . Values
37+ . Where ( note => ! ( note . note . type == NoteTypes . Long && Notes . ContainsKey ( note . note . prev ) ) )
38+ . OrderBy ( note => note . note . position . ToSamples ( Audio . Source . clip . frequency , BPM . Value ) ) ;
39+
40+ data . notes = new List < SaveDataModel . Note > ( ) ;
41+
42+ foreach ( var noteObject in sortedNoteObjects )
43+ {
44+ if ( noteObject . note . type == NoteTypes . Single )
45+ {
46+ data . notes . Add ( ToSaveData ( noteObject ) ) ;
47+ }
48+ else if ( noteObject . note . type == NoteTypes . Long )
49+ {
50+ var current = noteObject ;
51+ var note = ToSaveData ( noteObject ) ;
52+
53+ while ( Notes . ContainsKey ( current . note . next ) )
54+ {
55+ var nextObj = Notes [ current . note . next ] ;
56+ note . notes . Add ( ToSaveData ( nextObj ) ) ;
57+ current = nextObj ;
58+ }
59+
60+ data . notes . Add ( note ) ;
61+ }
62+ }
63+
64+ var jsonWriter = new JsonWriter ( ) ;
65+ jsonWriter . PrettyPrint = true ;
66+ jsonWriter . IndentValue = 4 ;
67+ JsonMapper . ToJson ( data , jsonWriter ) ;
68+ return jsonWriter . ToString ( ) ;
69+ }
70+
71+ static SaveDataModel . Note ToSaveData ( NoteObject noteObject )
72+ {
73+ var note = new SaveDataModel . Note ( ) ;
74+ note . num = noteObject . note . position . num ;
75+ note . block = noteObject . note . position . block ;
76+ note . LPB = noteObject . note . position . LPB ;
77+ note . type = noteObject . note . type == NoteTypes . Long ? 2 : 1 ;
78+ note . notes = new List < SaveDataModel . Note > ( ) ;
79+ return note ;
80+ }
2381 }
2482}
0 commit comments