Note types use strings instead of ints

This commit is contained in:
lunarcleint
2023-08-20 15:28:00 -07:00
parent 9918b83efa
commit 17e177a695
8 changed files with 60 additions and 73 deletions
@@ -65,22 +65,22 @@ class BaseGameParser {
var daStrumTime:Float = note[0];
var daNoteData:Int = Std.int(note[1] % 8);
var daNoteType:Int = Std.int(note[1] / 8);
var gottaHitNote:Bool = daNoteData >= 4 ? !section.mustHitSection : section.mustHitSection;
var noteTypeStr:String = null;
if (note.length > 2) {
if (note[3] is Int)
daNoteType = Chart.addNoteType(result, data.noteTypes[Std.int(note[3])-1]);
else if (note[3] is String)
daNoteType = Chart.addNoteType(result, note[3]);
} else {
daNoteType = Chart.addNoteType(result, data.noteTypes[daNoteType-1]);
if (note[3] is Int) noteTypeStr = data.noteTypes[Std.int(((note[3])-1) > 0 ? ((note[3])-1) : 0)];
else if (note[3] is String) noteTypeStr = note[3].trim();
}
if (noteTypeStr == "Default Note" || noteTypeStr == "")
noteTypeStr = null;
result.strumLines[gottaHitNote ? 1 : 0].notes.push({
time: daStrumTime,
id: daNoteData % 4,
type: daNoteType,
type: noteTypeStr,
sLen: note[2]
});
}
+35 -30
View File
@@ -78,7 +78,6 @@ class Chart {
var chartPath = Paths.chart(songName, difficulty);
var base:ChartData = {
strumLines: [],
noteTypes: [],
events: [],
meta: {
name: null
@@ -108,24 +107,8 @@ class Chart {
*/
#if REGION
if (Reflect.hasField(data, "codenameChart") && Reflect.field(data, "codenameChart") == true) {
// backward compat on events since its caused problems
var eventTypesToString:Map<Int, String> = [
-1 => "HScript Call",
0 => "Unknown",
1 => "Camera Movement",
2 => "BPM Change",
3 => "Alt Animation Toggle",
];
for (event in cast(data.events, Array<Dynamic>)) {
if (Reflect.hasField(event, "type")) {
if(event.type != null)
event.name = eventTypesToString[event.type];
Reflect.deleteField(event, "type");
}
}
// codename chart
// cne chart
backwardCompatCNEChart(cast data); // remove this when the engine comes out
base = data;
} else {
// base game chart
@@ -148,17 +131,15 @@ class Chart {
return base;
}
public static function addNoteType(chart:ChartData, noteTypeName:String):Int {
switch(noteTypeName.trim()) {
case "Default Note" | null | "":
return 0;
default:
var index = chart.noteTypes.indexOf(noteTypeName);
if (index > -1)
return index+1;
chart.noteTypes.push(noteTypeName);
return chart.noteTypes.length;
}
public static function getChartNoteTypes(chart:ChartData):Array<String> {
var types:Array<String> = [null];
for (strL in chart.strumLines)
for (note in strL.notes)
if (note.type != null && !types.contains(note.type))
types.push(note.type);
return types;
}
/**
@@ -210,6 +191,30 @@ class Chart {
}
return sortedData;
}
public static function backwardCompatCNEChart(data:Dynamic) {
// Events
var eventTypesToString:Map<Int, String> = [
-1 => "HScript Call",
0 => "Unknown",
1 => "Camera Movement",
2 => "BPM Change",
3 => "Alt Animation Toggle",
];
for (event in cast(data.events, Array<Dynamic>)) {
if (Reflect.hasField(event, "type")) {
if(event.type != null)
event.name = eventTypesToString[event.type];
Reflect.deleteField(event, "type");
}
}
// Notes
for (strL in cast(data.strumLines, Array<Dynamic>))
for (note in cast(strL.notes, Array<Dynamic>))
if (note.type is Int) note.type = note.type == 0 ? null : data.noteTypes[note.type];
}
}
typedef ChartSaveSettings = {
+2 -3
View File
@@ -9,8 +9,7 @@ typedef ChartData = {
public var codenameChart:Bool;
public var stage:String;
public var scrollSpeed:Float;
public var noteTypes:Array<String>;
public var ?fromMods:Bool;
}
@@ -47,7 +46,7 @@ typedef ChartStrumLine = {
typedef ChartNote = {
var time:Float; // time at which the note will be hit (ms)
var id:Int; // strum id of the note
var type:Int; // type (int) of the note
var type:Null<String>; // type of the note (deafult is null)
var sLen:Float; // sustain length of the note (ms)
}
@@ -14,15 +14,10 @@ final class NoteCreationEvent extends CancellableEvent {
public var strumID:Int;
/**
* Note Type (ex: "My Super Cool Note", or "Mine")
* Note Type (ex: "My Super Cool Note", or "Mine", null as default)
*/
public var noteType:String;
/**
* ID of the note type.
*/
public var noteTypeID:Int;
/**
* ID of the player.
*/
+8 -8
View File
@@ -639,7 +639,7 @@ class Charter extends UIState {
var id = Math.floor(mousePos.x / 40);
if (id >= 0 && id < 4 * gridBackdrop.strumlinesAmount && mousePos.y >= 0) {
var note = new CharterNote();
note.updatePos(FlxG.keys.pressed.SHIFT ? (mousePos.y / 40) : Math.floor(mousePos.y / 40), id, 0, 0);
note.updatePos(FlxG.keys.pressed.SHIFT ? (mousePos.y / 40) : Math.floor(mousePos.y / 40), id, 0, null);
notesGroup.add(note);
selection = [note];
sortNotes();
@@ -1061,12 +1061,12 @@ class Charter extends UIState {
clipboard = [
for (s in selection)
if (s is CharterNote) {
var note:CharterNote = cast(s, CharterNote);
CNote(note.step - minStep, note.id, note.susLength, note.type);
} else if (s is CharterEvent) {
var event = cast(s,CharterEvent);
CEvent(event.step - minStep, event.events);
}
var note:CharterNote = cast(s, CharterNote);
CNote(note.step - minStep, note.id, note.susLength, note.type);
} else if (s is CharterEvent) {
var event = cast(s,CharterEvent);
CEvent(event.step - minStep, event.events);
}
];
}
function _edit_paste(_) {
@@ -1334,7 +1334,7 @@ enum CharterChange {
}
enum CharterCopyboardObject {
CNote(step:Float, id:Int, susLength:Float, type:Int);
CNote(step:Float, id:Int, susLength:Float, type:String);
CEvent(step:Float, events:Array<ChartEvent>);
}
+2 -2
View File
@@ -54,9 +54,9 @@ class CharterNote extends UISprite implements ICharterSelectable {
public var step:Float;
public var id:Int;
public var susLength:Float;
public var type:Int;
public var type:String;
public function updatePos(step:Float, id:Int, susLength:Float = 0, type:Int = 0) {
public function updatePos(step:Float, id:Int, susLength:Float = 0, type:String = null) {
this.step = step;
this.id = id;
this.susLength = susLength;
+3 -10
View File
@@ -72,23 +72,16 @@ class Note extends FlxSprite
public var isSustainNote:Bool = false;
public var flipSustain:Bool = true;
public var noteTypeID:Int = 0;
// TO APPLY THOSE ON A SINGLE NOTE
public var scrollSpeed:Null<Float> = null;
public var noteAngle:Null<Float> = null;
public var noteType(get, null):String;
public var noteType:Null<String> = null;
@:dox(hide) public var __strumCameras:Array<FlxCamera> = null;
@:dox(hide) public var __strum:Strum = null;
@:dox(hide) public var __noteAngle:Float = 0;
private function get_noteType() {
if (PlayState.instance == null) return null;
return PlayState.instance.getNoteType(noteTypeID);
}
public static var swagWidth:Float = 160 * 0.7;
private static var __customNoteTypeExists:Map<String, Bool> = [];
@@ -111,9 +104,9 @@ class Note extends FlxSprite
this.prevNote = prev;
else
this.prevNote = strumLine.notes.members.last();
this.noteTypeID = noteData.type.getDefault(0);
this.isSustainNote = sustain;
this.sustainLength = sustainLength;
this.noteType = noteData.type;
this.strumLine = strumLine;
x += 50;
@@ -124,7 +117,7 @@ class Note extends FlxSprite
this.noteData = noteData.id.getDefault(0);
var customType = Paths.image('game/notes/${this.noteType}');
var event = EventManager.get(NoteCreationEvent).recycle(this, strumID, this.noteType, noteTypeID, PlayState.instance.strumLines.members.indexOf(strumLine), mustPress,
var event = EventManager.get(NoteCreationEvent).recycle(this, strumID, this.noteType, PlayState.instance.strumLines.members.indexOf(strumLine), mustPress,
(this.noteType != null && customTypePathExists(customType)) ? 'game/notes/${this.noteType}' : 'game/notes/default', 0.7, animSuffix);
if (PlayState.instance != null)
+1 -6
View File
@@ -593,7 +593,7 @@ class PlayState extends MusicBeatState
generateSong(SONG);
for(noteType in SONG.noteTypes) {
for(noteType in Chart.getChartNoteTypes(SONG)) {
var scriptPath = Paths.script('data/notes/${noteType}');
if (Assets.exists(scriptPath) && !scripts.contains(scriptPath)) {
var script = Script.create(scriptPath);
@@ -1414,11 +1414,6 @@ class PlayState extends MusicBeatState
strumLine.deleteNote(note);
}
@:dox(hide)
public function getNoteType(id:Int):String {
return SONG.noteTypes[id-1];
}
/**
* Hits a note
* @param note Note to hit.