Revert "Note types use strings instead of ints"

This reverts commit 17e177a695.
This commit is contained in:
NeeEoo
2023-08-21 22:18:21 +02:00
parent 17e177a695
commit 008ad05bf1
8 changed files with 73 additions and 60 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) noteTypeStr = data.noteTypes[Std.int(((note[3])-1) > 0 ? ((note[3])-1) : 0)];
else if (note[3] is String) noteTypeStr = note[3].trim();
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 (noteTypeStr == "Default Note" || noteTypeStr == "")
noteTypeStr = null;
result.strumLines[gottaHitNote ? 1 : 0].notes.push({
time: daStrumTime,
id: daNoteData % 4,
type: noteTypeStr,
type: daNoteType,
sLen: note[2]
});
}
+30 -35
View File
@@ -78,6 +78,7 @@ class Chart {
var chartPath = Paths.chart(songName, difficulty);
var base:ChartData = {
strumLines: [],
noteTypes: [],
events: [],
meta: {
name: null
@@ -107,8 +108,24 @@ class Chart {
*/
#if REGION
if (Reflect.hasField(data, "codenameChart") && Reflect.field(data, "codenameChart") == true) {
// cne chart
backwardCompatCNEChart(cast data); // remove this when the engine comes out
// 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
base = data;
} else {
// base game chart
@@ -131,15 +148,17 @@ class Chart {
return base;
}
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;
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;
}
}
/**
@@ -191,30 +210,6 @@ 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 = {
+3 -2
View File
@@ -9,7 +9,8 @@ typedef ChartData = {
public var codenameChart:Bool;
public var stage:String;
public var scrollSpeed:Float;
public var noteTypes:Array<String>;
public var ?fromMods:Bool;
}
@@ -46,7 +47,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:Null<String>; // type of the note (deafult is null)
var type:Int; // type (int) of the note
var sLen:Float; // sustain length of the note (ms)
}
@@ -14,10 +14,15 @@ final class NoteCreationEvent extends CancellableEvent {
public var strumID:Int;
/**
* Note Type (ex: "My Super Cool Note", or "Mine", null as default)
* Note Type (ex: "My Super Cool Note", or "Mine")
*/
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, null);
note.updatePos(FlxG.keys.pressed.SHIFT ? (mousePos.y / 40) : Math.floor(mousePos.y / 40), id, 0, 0);
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:String);
CNote(step:Float, id:Int, susLength:Float, type:Int);
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:String;
public var type:Int;
public function updatePos(step:Float, id:Int, susLength:Float = 0, type:String = null) {
public function updatePos(step:Float, id:Int, susLength:Float = 0, type:Int = 0) {
this.step = step;
this.id = id;
this.susLength = susLength;
+10 -3
View File
@@ -72,16 +72,23 @@ 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:Null<String> = null;
public var noteType(get, null):String;
@: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> = [];
@@ -104,9 +111,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;
@@ -117,7 +124,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, PlayState.instance.strumLines.members.indexOf(strumLine), mustPress,
var event = EventManager.get(NoteCreationEvent).recycle(this, strumID, this.noteType, noteTypeID, 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)
+6 -1
View File
@@ -593,7 +593,7 @@ class PlayState extends MusicBeatState
generateSong(SONG);
for(noteType in Chart.getChartNoteTypes(SONG)) {
for(noteType in SONG.noteTypes) {
var scriptPath = Paths.script('data/notes/${noteType}');
if (Assets.exists(scriptPath) && !scripts.contains(scriptPath)) {
var script = Script.create(scriptPath);
@@ -1414,6 +1414,11 @@ 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.