@@ -46,14 +46,14 @@ public static void Main(string[] args)
4646 if ( fi . Extension . Equals ( ".sql" , StringComparison . OrdinalIgnoreCase ) )
4747 {
4848 // convert sql to es
49- sql2es ( fi ) ;
49+ Converter . sql2es ( fi ) ;
5050 return ;
5151 }
5252
5353 if ( fi . Extension . Equals ( ".json" , StringComparison . OrdinalIgnoreCase ) )
5454 {
5555 // convert json to es
56- json2es ( fi ) ;
56+ Converter . json2es ( fi ) ;
5757 return ;
5858 }
5959
@@ -68,7 +68,7 @@ public static void Main(string[] args)
6868 //emoteTable.BuildLinks();
6969 //emoteTable.ClearLinks();
7070
71- emoteTable . Wcid = GetObjectId ( fi ) ;
71+ emoteTable . Wcid = Converter . GetObjectId ( fi ) ;
7272 //emoteTable.Wcid = 33970;
7373
7474 //ShowSQL(emoteTable);
@@ -80,212 +80,15 @@ public static void Main(string[] args)
8080 if ( args . Length < 2 || ! args [ 1 ] . Contains ( "json" , StringComparison . OrdinalIgnoreCase ) )
8181 {
8282 // convert script to sql
83- es2sql ( emoteTable , fi ) ;
83+ Converter . es2sql ( emoteTable , fi ) ;
8484 }
8585 else
8686 {
8787 // convert script to json
88- es2json ( emoteTable , fi ) ;
88+ Converter . es2json ( emoteTable , fi ) ;
8989 }
9090 }
9191
92- public static void es2sql ( EmoteTable emoteTable , FileInfo esFile )
93- {
94- var sqlFilename = Path . ChangeExtension ( esFile . FullName , ".sql" ) ;
95- var sqlFile = new FileInfo ( sqlFilename ) ;
96-
97- // check if file already exists?
98-
99- // output sql file
100- OutputSQL ( emoteTable , sqlFile ) ;
101- }
102-
103- public static void es2json ( EmoteTable emoteTable , FileInfo esFile )
104- {
105- var jsonFilename = Path . ChangeExtension ( esFile . FullName , ".json" ) ;
106- var jsonFile = new FileInfo ( jsonFilename ) ;
107-
108- emoteTable . NormalRange ( ) ;
109-
110- var jsonTable = new EmoteScriptLib . JSON . EmoteTable ( emoteTable ) ;
111-
112- // check if file already exists?
113-
114- // output json file
115- OutputJSON ( jsonTable , jsonFile ) ;
116- }
117-
118- public static void sql2es ( FileInfo sqlFile )
119- {
120- var sqlLines = File . ReadAllLines ( sqlFile . FullName ) ;
121-
122- var sqlReader = new EmoteScriptLib . SQL . SQLReader ( ) ;
123-
124- var emoteTable = sqlReader . ReadEmoteTable ( sqlLines ) ;
125-
126- emoteTable . BuildLinks ( ) ;
127-
128- //ShowScript(emoteTable.EmoteSets);
129-
130- var esFilename = Path . ChangeExtension ( sqlFile . FullName , ".es" ) ;
131-
132- // check if file already exists?
133-
134- var esFile = new FileInfo ( esFilename ) ;
135-
136- OutputScript ( emoteTable . EmoteSets , esFile ) ;
137- }
138-
139- public static void json2es ( FileInfo jsonFile )
140- {
141- var settings = new JsonSerializerSettings ( ) ;
142- settings . ContractResolver = new EmoteScriptLib . JSON . LowercaseContractResolver ( ) ;
143-
144- var json = File . ReadAllText ( jsonFile . FullName ) ;
145-
146- var jsonEmoteTable = JsonConvert . DeserializeObject < EmoteScriptLib . JSON . EmoteTable > ( json , settings ) ;
147-
148- var emoteTable = new EmoteTable ( jsonEmoteTable ) ;
149-
150- emoteTable . SetValidBranches ( ) ;
151-
152- emoteTable . BuildLinks ( ) ;
153-
154- //ShowScript(emoteTable.EmoteSets);
155-
156- var esFilename = Path . ChangeExtension ( jsonFile . FullName , ".es" ) ;
157-
158- // check if file already exists?
159-
160- var esFile = new FileInfo ( esFilename ) ;
161-
162- OutputScript ( emoteTable . EmoteSets , esFile ) ;
163- }
164-
165- public static void OutputSQL ( EmoteTable emoteTable , FileInfo sqlFile )
166- {
167- var sqlLines = BuildSQL ( emoteTable ) ;
168-
169- File . WriteAllLines ( sqlFile . FullName , sqlLines ) ;
170-
171- Console . WriteLine ( $ "Compiled { sqlFile . FullName } ") ;
172- }
173-
174- public static uint ? GetObjectId ( FileInfo file )
175- {
176- var match = Regex . Match ( file . Name , @"^(\d+)" ) ;
177-
178- if ( match . Success )
179- return uint . Parse ( match . Groups [ 1 ] . Value ) ;
180- else
181- return null ;
182- }
183-
184- public static List < string > BuildSQL ( EmoteTable emoteTable )
185- {
186- emoteTable . NormalRange ( ) ;
187-
188- return EmoteScriptLib . SQL . SQLWriter . GetSQL ( emoteTable ) ;
189- }
190-
191- public static void ShowSQL ( EmoteTable emoteTable )
192- {
193- var sqlLines = BuildSQL ( emoteTable ) ;
194-
195- foreach ( var sqlLine in sqlLines )
196- Console . WriteLine ( sqlLines ) ;
197- }
198-
199- public static void OutputJSON ( EmoteScriptLib . JSON . EmoteTable emoteTable , FileInfo jsonFile )
200- {
201- var json = BuildJSON ( emoteTable ) ;
202-
203- File . WriteAllText ( jsonFile . FullName , json ) ;
204-
205- Console . WriteLine ( $ "Compiled { jsonFile . FullName } ") ;
206- }
207-
208- public static string BuildJSON ( EmoteScriptLib . JSON . EmoteTable emoteTable )
209- {
210- var settings = new JsonSerializerSettings ( ) ;
211- settings . NullValueHandling = NullValueHandling . Ignore ;
212- settings . Formatting = Formatting . Indented ;
213- //settings.ContractResolver = new LowercaseContractResolver();
214-
215- return JsonConvert . SerializeObject ( emoteTable , settings ) ;
216- }
217-
218- public static void ShowJSON ( EmoteTable emoteTable )
219- {
220- var jsonTable = new EmoteScriptLib . JSON . EmoteTable ( emoteTable ) ;
221-
222- var json = BuildJSON ( jsonTable ) ;
223-
224- Console . WriteLine ( json ) ;
225- }
226-
227- public static void OutputScript ( List < EmoteSet > emoteSets , FileInfo esFile )
228- {
229- var script = BuildScript ( emoteSets ) ;
230-
231- File . WriteAllLines ( esFile . FullName , script ) ;
232-
233- Console . WriteLine ( $ "Compiled { esFile . FullName } ") ;
234- }
235-
236- public static List < string > BuildScript ( List < EmoteSet > emoteSets , int depth = 0 )
237- {
238- var scriptLines = new List < string > ( ) ;
239-
240- var indent = string . Concat ( Enumerable . Repeat ( " " , depth ) ) ;
241-
242- for ( var i = 0 ; i < emoteSets . Count ; i ++ )
243- {
244- var emoteSet = emoteSets [ i ] ;
245-
246- if ( depth == 0 && emoteSet . Inline )
247- continue ;
248-
249- if ( depth > 0 && ! emoteSet . Inline )
250- continue ;
251-
252- //Console.WriteLine($"{emoteSet}");
253-
254- if ( i > 0 && depth == 0 )
255- scriptLines . Add ( string . Empty ) ;
256-
257- scriptLines . Add ( $ "{ indent } { emoteSet . ToString ( true ) } ") ;
258-
259- foreach ( var emote in emoteSet . Emotes )
260- scriptLines . AddRange ( BuildScript ( emote , depth + 1 ) ) ;
261- }
262- return scriptLines ;
263- }
264-
265- public static List < string > BuildScript ( Emote emote , int depth )
266- {
267- //Console.WriteLine($"{emote}");
268-
269- var scriptLines = new List < string > ( ) ;
270-
271- var indent = string . Concat ( Enumerable . Repeat ( " " , depth ) ) ;
272-
273- scriptLines . Add ( $ "{ indent } - { emote . ToString ( true ) } ") ;
274-
275- if ( emote . Branches != null )
276- scriptLines . AddRange ( BuildScript ( emote . Branches , depth + 1 ) ) ;
277-
278- return scriptLines ;
279- }
280-
281- public static void ShowScript ( List < EmoteSet > emoteSets )
282- {
283- var script = BuildScript ( emoteSets ) ;
284-
285- foreach ( var line in script )
286- Console . WriteLine ( line ) ;
287- }
288-
28992 public static void ShowUsage ( )
29093 {
29194 Console . WriteLine ( $ "EmoteScript - a scripting language for Asheron's Call emotes") ;
0 commit comments