public void ImportChartFromJSONFile(int diff) { byte[] bytes = File.ReadAllBytes(directorySelectorController.selectedItemFullName); //JSON file bytes char[] bytechars = new char[bytes.Length + 1]; string str; //JSON string int length = bytes.Length, i = 0, offset = 0; while (bytes[i] != 0x7B) { i++; } offset = i; for (; i < length && bytes[i] != 0x00; i++) { bytechars[i - offset] = (char)bytes[i]; } str = new string(bytechars); JSONChart jchart = Utility.JSONtoJChart(str); string level = project.charts[diff].level; List <float> beats = project.charts[diff].beats; project.charts[diff] = Utility.JCharttoChart(jchart); project.charts[diff].level = level; project.charts[diff].beats = beats; directorySelectorController.DeactivateSelection(); }
public void ImportChartFromCytusChart(int diff) { string[] cychart = File.ReadAllLines(directorySelectorController.selectedItemFullName); JSONChart jchart = Utility.CytusChartToJChart(cychart); string level; level = project.charts[diff].level; project.charts[diff] = Utility.JCharttoChart(jchart); project.charts[diff].level = level; directorySelectorController.DeactivateSelection(); }
public static Chart JCharttoChart(JSONChart jchart) { Chart chart = new Chart { speed = jchart.speed }; while (chart.notes.Count > 0) { chart.notes.RemoveAt(0); } foreach (JSONChart.note jnote in jchart.notes) { Note note = new Note { position = jnote.pos, size = jnote.size, time = jnote.time, shift = jnote.shift }; foreach (JSONChart.sound jsound in jnote.sounds) { PianoSound sound = new PianoSound { delay = jsound.w, duration = jsound.d, pitch = jsound.p, volume = jsound.v }; note.sounds.Add(sound); } chart.notes.Add(note); } foreach (JSONChart.link jlink in jchart.links) { int prev = -1; foreach (int noteref in jlink.noteRef) { if (prev != -1) { chart.notes[prev].nextLink = noteref - 1; //Note number in Chart starts by 0 } chart.notes[noteref - 1].isLink = true; chart.notes[noteref - 1].prevLink = prev; prev = noteref - 1; } if (prev != -1) { chart.notes[prev].nextLink = -1; } } return(chart); }
public static JSONChart CytusChartToJChart(string[] cytusChart) { JSONChart jchart = new JSONChart(); int n = cytusChart.Length; jchart.speed = 5.0f; for (int i = 4; i < n; i++) { int j = 0; int ivalue; if (cytusChart[i][0] == 'N') { ivalue = GetInt(cytusChart[i], ref j); JSONChart.note note = new JSONChart.note { id = ivalue - 3 }; float fvalue = GetFloat(cytusChart[i], ref j); //note.time = fvalue - 0.08f; note.time = fvalue; fvalue = GetFloat(cytusChart[i], ref j); note.pos = fvalue * 4 - 2; jchart.notes.Add(note); } else { JSONChart.link link = new JSONChart.link(); while (j < cytusChart[i].Length) { ivalue = GetInt(cytusChart[i], ref j); if (ivalue == -2147483648) { continue; } link.noteRef.Add(ivalue + 1); jchart.notes[ivalue].size = 0.8f; } jchart.links.Add(link); } } return(jchart); }
public static JSONChart JSONtoJChart(string str) { JSONChart jchart = new JSONChart(); /* * The json files in the official charts have variables name with "$id" * WT* are you using variables named with some strange characters?!! * So C# would be messed up with those strange variable names... * I'm parsing these values manually... */ string substr; int i = 0, temp = 0; while (str[i] != '{') { i++; } substr = GetSubStr(str, ref i); //"speed" jchart.speed = GetFloat(str, ref i); substr = GetSubStr(str, ref i); //"notes" while (str[i] != ']') { substr = GetSubStr(str, ref i); //"$id" JSONChart.note note = new JSONChart.note(); temp = 0; note.id = GetInt(GetSubStr(str, ref i), ref temp); while (str[i] != '}') { substr = GetSubStr(str, ref i); if (substr == "sounds") { while (str[i] != ']') { JSONChart.sound sound = new JSONChart.sound(); while (str[i] != '}') { substr = GetSubStr(str, ref i); if (substr == "d") { sound.d = GetFloat(str, ref i); } else if (substr == "p") { sound.p = GetInt(str, ref i); } else if (substr == "v") { sound.v = GetInt(str, ref i); } else if (substr == "w") { sound.w = GetFloat(str, ref i); } } i++; note.sounds.Add(sound); } } else if (substr == "pos") { note.pos = GetFloat(str, ref i); } else if (substr == "size") { note.size = GetFloat(str, ref i); } else if (substr == "_time") { note.time = GetFloat(str, ref i); } else if (substr == "shift") { note.shift = GetFloat(str, ref i); } else { while (str[i] != ',' && str[i] != '}') { i++; } } } i++; jchart.notes.Add(note); }//"notes" complete substr = GetSubStr(str, ref i); //"links" i += 2; while (str[i] != ']') { JSONChart.link link = new JSONChart.link(); substr = GetSubStr(str, ref i); //"notes" while (str[i] != ']') { substr = GetSubStr(str, ref i); //"$ref" temp = 0; link.noteRef.Add(GetInt(GetSubStr(str, ref i), ref temp)); i++; } i += 2; jchart.links.Add(link); } return(jchart); }
public static JSONChart JSONtoJChart(string str) { JSONChart jchart = new JSONChart(); /* * The json files in the official charts have variables name with "$id" * WT* are you using variables named with some strange characters?!! * So C# would be messed up with those strange variable names... * I'm parsing these values manually... */ int i = 0, temp; while (str[i] != '{') { i++; } string firstSubStr = GetSubStr(str, ref i); bool isSpeed = (firstSubStr == "speed"); if (isSpeed) { jchart.speed = GetFloat(str, ref i); GetSubStr(str, ref i); //"notes" } while (str[i] != ']') { string noteSubStr = GetSubStr(str, ref i); bool isId = (noteSubStr == "id"); JSONChart.note note = new JSONChart.note(); if (!isId) { note.time = GetFloat(str, ref i); GetSubStr(str, ref i); //"$id" } note.id = GetIntFromIntOrSubStr(str, ref i); while (str[i] != '}') { string substr = GetSubStr(str, ref i); switch (substr) { case "sounds": { while (str[i] != ']') { JSONChart.sound sound = new JSONChart.sound(); while (str[i] != '}') { substr = GetSubStr(str, ref i); switch (substr) { case "d": sound.d = GetFloat(str, ref i); break; case "p": sound.p = GetInt(str, ref i); break; case "v": sound.v = GetInt(str, ref i); break; case "w": sound.w = GetFloat(str, ref i); break; } } i++; note.sounds.Add(sound); } break; } case "pos": note.pos = GetFloat(str, ref i); break; case "size": note.size = GetFloat(str, ref i); break; case "_time": note.time = GetFloat(str, ref i); break; case "shift": note.shift = GetFloat(str, ref i); break; default: { while (str[i] != ',' && str[i] != '}') { i++; } break; } } } i++; jchart.notes.Add(note); } // "notes" complete GetSubStr(str, ref i); // "links" i += 2; while (str[i] != ']') { JSONChart.link link = new JSONChart.link(); GetSubStr(str, ref i); // "notes" while (str[i] != ']') { GetSubStr(str, ref i); // "$ref" link.noteRef.Add(GetIntFromIntOrSubStr(str, ref i)); i++; } i += 2; jchart.links.Add(link); } if (!isSpeed) { GetSubStr(str, ref i); // "speed" jchart.speed = GetFloat(str, ref i); } return(jchart); }