From a1e2109f576f608c8590fb4d20191ee9f0b960ed Mon Sep 17 00:00:00 2001 From: Kade M Date: Wed, 23 Jun 2021 01:51:37 -0700 Subject: [PATCH] fix input drops (hopefully) + work on sm support --- source/PlayState.hx | 25 +++++++++++++--- source/smTools/SMFile.hx | 59 +++++++++++++++++++++++++++++++++++++ source/smTools/SMHeader.hx | 37 +++++++++++++++++++++++ source/smTools/SMMeasure.hx | 14 +++++++++ source/smTools/SMNote.hx | 8 +++++ 5 files changed, 139 insertions(+), 4 deletions(-) create mode 100644 source/smTools/SMFile.hx create mode 100644 source/smTools/SMHeader.hx create mode 100644 source/smTools/SMMeasure.hx create mode 100644 source/smTools/SMNote.hx diff --git a/source/PlayState.hx b/source/PlayState.hx index 67cd656..f21c8a3 100644 --- a/source/PlayState.hx +++ b/source/PlayState.hx @@ -1353,20 +1353,37 @@ class PlayState extends MusicBeatState var songTime:Float = 0; + private function getKey(charCode:Int):String + { + for (key => value in FlxKey.fromStringMap) + { + if (charCode == value) + return key; + } + return null; + } + private function handleInput(evt:KeyboardEvent):Void { // this actually handles press inputs if (PlayStateChangeables.botPlay || loadRep || paused) return; - var key = String.fromCharCode(evt.charCode); + // first convert it from openfl to a flixel key code + // then use FlxKey to get the key's name based off of the FlxKey dictionary + // this makes it work for special characters + @:privateAccess + var key = FlxKey.toStringMap.get(Keyboard.__convertKeyCode(evt.keyCode)); + var binds:Array = [FlxG.save.data.leftBind,FlxG.save.data.downBind, FlxG.save.data.upBind, FlxG.save.data.rightBind]; var data = -1; - + for (i in 0...binds.length) - if (binds[i].toLowerCase() == key) + { + if (binds[i].toLowerCase() == key.toLowerCase()) data = i; + } if (data == -1) return; @@ -2821,7 +2838,7 @@ class PlayState extends MusicBeatState ss = false; shits++; if (FlxG.save.data.accuracyMod == 0) - totalNotesHit += 0.25; + totalNotesHit -= 1; case 'bad': daRating = 'bad'; score = 0; diff --git a/source/smTools/SMFile.hx b/source/smTools/SMFile.hx new file mode 100644 index 0000000..9b6ffda --- /dev/null +++ b/source/smTools/SMFile.hx @@ -0,0 +1,59 @@ +package smTools; + +import sys.io.File; + +class SMFile +{ + public static function loadFile(path):SMFile + { + return new SMFile(File.getContent(path).split('\n')); + } + + private var _fileData:Array; + + public var _readTime:Float = 0; + + public var header:SMHeader; + public var measures:Array; + + public function new(data:Array) + { + _fileData = data; + + // Gather header data + var headerData = ""; + var inc = 0; + while(!StringTools.contains(data[inc + 1],"//")) + { + headerData += data[inc] + "\n"; + inc++; + // trace(data[inc]); + } + + header = new SMHeader(headerData.split('\n')); + + // check if this is a valid file, it should be a dance double file. + inc += 3; // skip three lines down + if (!StringTools.contains(data[inc],"dance-double:")) + return; + trace('this is dance double'); + + inc += 4; // skip 5 down to where da notes @ + trace(data[inc]); + + measures = []; + + while(data[inc + 1] != ";") + { + var measure = ""; + while(data[inc + 1] != ",") + { + inc++; + var line = data[inc]; + measure += line + "\n"; + } + measures.push(new SMMeasure(measure.split('\n'))); + } + trace(measures.length + " Measures"); + } +} \ No newline at end of file diff --git a/source/smTools/SMHeader.hx b/source/smTools/SMHeader.hx new file mode 100644 index 0000000..9e4a381 --- /dev/null +++ b/source/smTools/SMHeader.hx @@ -0,0 +1,37 @@ +package smTools; + +class SMHeader +{ + private var _header:Array; + + public var TITLE = ""; + public var SUBTITLE = ""; + public var ARTIST = ""; + public var GENRE = ""; + public var CREDIT = ""; + public var MUSIC = ""; + public var BANNER = ""; + public var BACKGROUND = ""; + public var CDTITLE = ""; + public var OFFSET = ""; + public var BPMS = ""; + + public function new(headerData:Array) + { + _header = headerData; + for (i in headerData) + readHeaderLine(i); + } + + function readHeaderLine(line:String) + { + var propName = line.split('#')[1].split(':')[0]; + var value = line.split(':')[1].split(';')[0]; + var prop = Reflect.getProperty(this,propName); + + if (prop != null) + { + Reflect.setProperty(this,propName,value); + } + } +} \ No newline at end of file diff --git a/source/smTools/SMMeasure.hx b/source/smTools/SMMeasure.hx new file mode 100644 index 0000000..1dc4fc4 --- /dev/null +++ b/source/smTools/SMMeasure.hx @@ -0,0 +1,14 @@ +package smTools; + +class SMMeasure +{ + public var notes:Array; + + private var _measure:Array; + + public function new(measureData:Array) + { + _measure = measureData; + notes = []; + } +} \ No newline at end of file diff --git a/source/smTools/SMNote.hx b/source/smTools/SMNote.hx new file mode 100644 index 0000000..f5dd95a --- /dev/null +++ b/source/smTools/SMNote.hx @@ -0,0 +1,8 @@ +package smTools; + +class SMNote +{ + public var time:Float; + public var data:Int; + public var length:Float; +} \ No newline at end of file