package funkin.ui.debug.charting; import flixel.addons.display.FlxSliceSprite; import flixel.addons.display.FlxTiledSprite; import flixel.addons.transition.FlxTransitionableState; import flixel.FlxCamera; import flixel.FlxSprite; import flixel.FlxSubState; import flixel.group.FlxSpriteGroup; import flixel.input.keyboard.FlxKey; import flixel.math.FlxMath; import flixel.math.FlxPoint; import flixel.math.FlxRect; import flixel.sound.FlxSound; import flixel.system.FlxAssets.FlxSoundAsset; import flixel.tweens.FlxEase; import flixel.tweens.FlxTween; import flixel.tweens.misc.VarTween; import flixel.util.FlxColor; import funkin.ui.mainmenu.MainMenuState; import flixel.util.FlxSort; import flixel.util.FlxTimer; import funkin.audio.visualize.PolygonSpectogram; import funkin.audio.VoicesGroup; import funkin.data.notestyle.NoteStyleRegistry; import funkin.data.song.SongData.SongChartData; import funkin.data.song.SongData.SongEventData; import funkin.data.song.SongData.SongMetadata; import funkin.data.song.SongData.SongNoteData; import funkin.data.song.SongDataUtils; import funkin.input.Cursor; import funkin.input.TurboKeyHandler; import funkin.modding.events.ScriptEvent; import funkin.play.character.BaseCharacter.CharacterType; import funkin.play.character.CharacterData; import funkin.play.character.CharacterData.CharacterDataParser; import funkin.play.components.HealthIcon; import funkin.play.notes.NoteSprite; import funkin.play.PlayState; import funkin.play.song.Song; import funkin.data.song.SongData.SongChartData; import funkin.data.song.SongRegistry; import funkin.data.song.SongData.SongEventData; import funkin.data.song.SongData.SongMetadata; import funkin.data.song.SongData.SongNoteData; import funkin.data.song.SongData.SongCharacterData; import funkin.data.song.SongDataUtils; import funkin.ui.debug.charting.commands.ChartEditorCommand; import funkin.ui.debug.charting.handlers.ChartEditorShortcutHandler; import funkin.play.stage.StageData; import funkin.save.Save; import funkin.ui.debug.charting.commands.AddEventsCommand; import funkin.ui.debug.charting.commands.AddNotesCommand; import funkin.ui.debug.charting.commands.ChartEditorCommand; import funkin.ui.debug.charting.commands.CutItemsCommand; import funkin.ui.debug.charting.commands.DeselectAllItemsCommand; import funkin.ui.debug.charting.commands.DeselectItemsCommand; import funkin.ui.debug.charting.commands.ExtendNoteLengthCommand; import funkin.ui.debug.charting.commands.FlipNotesCommand; import funkin.ui.debug.charting.commands.InvertSelectedItemsCommand; import funkin.ui.debug.charting.commands.MoveEventsCommand; import funkin.ui.debug.charting.commands.MoveItemsCommand; import funkin.ui.debug.charting.commands.MoveNotesCommand; import funkin.ui.debug.charting.commands.PasteItemsCommand; import funkin.ui.debug.charting.commands.RemoveEventsCommand; import funkin.ui.debug.charting.commands.RemoveItemsCommand; import funkin.ui.debug.charting.commands.RemoveNotesCommand; import funkin.ui.debug.charting.commands.SelectAllItemsCommand; import funkin.ui.debug.charting.commands.SelectItemsCommand; import funkin.ui.debug.charting.commands.SetItemSelectionCommand; import funkin.ui.debug.charting.components.ChartEditorEventSprite; import funkin.ui.debug.charting.components.ChartEditorHoldNoteSprite; import funkin.ui.debug.charting.components.ChartEditorNotePreview; import funkin.ui.debug.charting.components.ChartEditorNoteSprite; import funkin.ui.debug.charting.components.ChartEditorSelectionSquareSprite; import funkin.ui.haxeui.components.CharacterPlayer; import funkin.ui.haxeui.HaxeUIState; import funkin.util.Constants; import funkin.util.SortUtil; import funkin.util.WindowUtil; import haxe.DynamicAccess; import haxe.io.Bytes; import haxe.io.Path; import haxe.ui.components.DropDown; import haxe.ui.components.Label; import haxe.ui.components.NumberStepper; import haxe.ui.components.Slider; import haxe.ui.components.TextField; import haxe.ui.containers.dialogs.CollapsibleDialog; import haxe.ui.containers.Frame; import haxe.ui.containers.menus.Menu; import haxe.ui.containers.menus.MenuItem; import haxe.ui.containers.TreeView; import haxe.ui.containers.TreeViewNode; import haxe.ui.core.Component; import haxe.ui.core.Screen; import haxe.ui.events.DragEvent; import haxe.ui.events.UIEvent; import haxe.ui.focus.FocusManager; import haxe.ui.notifications.NotificationManager; import haxe.ui.notifications.NotificationType; import openfl.display.BitmapData; import funkin.util.FileUtil; using Lambda; /** * A state dedicated to allowing the user to create and edit song charts. * Built with HaxeUI for use by both developers and modders. * * Some functionality is moved to other classes to help maintain my sanity. * * @author MasterEric */ @:nullSafety class ChartEditorState extends HaxeUIState { /** * CONSTANTS */ // ============================== // XML Layouts public static final CHART_EDITOR_LAYOUT:String = Paths.ui('chart-editor/main-view'); public static final CHART_EDITOR_NOTIFBAR_LAYOUT:String = Paths.ui('chart-editor/components/notifbar'); public static final CHART_EDITOR_PLAYBARHEAD_LAYOUT:String = Paths.ui('chart-editor/components/playbar-head'); public static final CHART_EDITOR_TOOLBOX_NOTEDATA_LAYOUT:String = Paths.ui('chart-editor/toolbox/notedata'); public static final CHART_EDITOR_TOOLBOX_EVENTDATA_LAYOUT:String = Paths.ui('chart-editor/toolbox/eventdata'); public static final CHART_EDITOR_TOOLBOX_METADATA_LAYOUT:String = Paths.ui('chart-editor/toolbox/metadata'); public static final CHART_EDITOR_TOOLBOX_DIFFICULTY_LAYOUT:String = Paths.ui('chart-editor/toolbox/difficulty'); public static final CHART_EDITOR_TOOLBOX_PLAYER_PREVIEW_LAYOUT:String = Paths.ui('chart-editor/toolbox/player-preview'); public static final CHART_EDITOR_TOOLBOX_OPPONENT_PREVIEW_LAYOUT:String = Paths.ui('chart-editor/toolbox/opponent-preview'); // Validation public static final SUPPORTED_MUSIC_FORMATS:Array = ['ogg']; // Layout /** * The base grid size for the chart editor. */ public static final GRID_SIZE:Int = 40; /** * The width of the scroll area. */ public static final PLAYHEAD_SCROLL_AREA_WIDTH:Int = 12; /** * The height of the playhead, in pixels. */ public static final PLAYHEAD_HEIGHT:Int = Std.int(GRID_SIZE / 8); /** * The width of the border between grid squares, where the crosshair changes from "Place Notes" to "Select Notes". */ public static final GRID_SELECTION_BORDER_WIDTH:Int = 6; /** * The height of the menu bar in the layout. */ public static final MENU_BAR_HEIGHT:Int = 32; /** * The height of the playbar in the layout. */ public static final PLAYBAR_HEIGHT:Int = 48; /** * The amount of padding between the menu bar and the chart grid when fully scrolled up. */ public static final GRID_TOP_PAD:Int = 8; // Colors // Background color tint. public static final CURSOR_COLOR:FlxColor = 0xE0FFFFFF; public static final PREVIEW_BG_COLOR:FlxColor = 0xFF303030; public static final PLAYHEAD_SCROLL_AREA_COLOR:FlxColor = 0xFF682B2F; public static final SPECTROGRAM_COLOR:FlxColor = 0xFFFF0000; public static final PLAYHEAD_COLOR:FlxColor = 0xC0BD0231; // Timings /** * Duration, in seconds, for the scroll easing animation. */ public static final SCROLL_EASE_DURATION:Float = 0.2; // Other /** * Number of notes in each player's strumline. */ public static final STRUMLINE_SIZE:Int = 4; /** * How many pixels far the user needs to move the mouse before the cursor is considered to be dragged rather than clicked. */ public static final DRAG_THRESHOLD:Float = 16.0; /** * Precisions of notes you can snap to. */ public static final SNAP_QUANTS:Array = [4, 8, 12, 16, 20, 24, 32, 48, 64, 96, 192]; /** * The default note snapping value. */ public static final BASE_QUANT:Int = 16; /** * The index of thet default note snapping value in the `SNAP_QUANTS` array. */ public static final BASE_QUANT_INDEX:Int = 3; /** * INSTANCE DATA */ // ============================== // Song Length /** * The length of the current instrumental, in milliseconds. */ @:isVar var songLengthInMs(get, set):Float = 0; function get_songLengthInMs():Float { if (songLengthInMs <= 0) return 1000; return songLengthInMs; } function set_songLengthInMs(value:Float):Float { this.songLengthInMs = value; // Make sure playhead doesn't go outside the song. if (playheadPositionInMs > songLengthInMs) playheadPositionInMs = songLengthInMs; return this.songLengthInMs; } /** * The length of the current instrumental, converted to steps. * Dependant on BPM, because the size of a grid square does not change with BPM but the length of a beat does. */ var songLengthInSteps(get, set):Float; function get_songLengthInSteps():Float { return Conductor.getTimeInSteps(songLengthInMs); } function set_songLengthInSteps(value:Float):Float { // Getting a reasonable result from setting songLengthInSteps requires that Conductor.mapBPMChanges be called first. songLengthInMs = Conductor.getStepTimeInMs(value); return value; } /** * The length of the current instrumental, in PIXELS. * Dependant on BPM, because the size of a grid square does not change with BPM but the length of a beat does. */ var songLengthInPixels(get, set):Int; function get_songLengthInPixels():Int { return Std.int(songLengthInSteps * GRID_SIZE); } function set_songLengthInPixels(value:Int):Int { songLengthInSteps = value / GRID_SIZE; return value; } // Scroll Position /** * The relative scroll position in the song, in pixels. * One pixel is 1/40 of 1 step, and 1/160 of 1 beat. */ var scrollPositionInPixels(default, set):Float = -1.0; function set_scrollPositionInPixels(value:Float):Float { if (value < 0) { // If we're scrolling up, and we hit the top, // but the playhead is in the middle, move the playhead up. if (playheadPositionInPixels > 0) { var amount:Float = scrollPositionInPixels - value; playheadPositionInPixels -= amount; } value = 0; } if (value > songLengthInPixels) value = songLengthInPixels; if (value == scrollPositionInPixels) return value; // Difference in pixels. var diff:Float = value - scrollPositionInPixels; this.scrollPositionInPixels = value; // Move the grid sprite to the correct position. if (gridTiledSprite != null && gridPlayheadScrollArea != null) { if (isViewDownscroll) { gridTiledSprite.y = -scrollPositionInPixels + (MENU_BAR_HEIGHT + GRID_TOP_PAD); gridPlayheadScrollArea.y = gridTiledSprite.y; } else { gridTiledSprite.y = -scrollPositionInPixels + (MENU_BAR_HEIGHT + GRID_TOP_PAD); gridPlayheadScrollArea.y = gridTiledSprite.y; } } // Move the rendered notes to the correct position. renderedNotes.setPosition(gridTiledSprite?.x ?? 0.0, gridTiledSprite?.y ?? 0.0); renderedHoldNotes.setPosition(gridTiledSprite?.x ?? 0.0, gridTiledSprite?.y ?? 0.0); renderedEvents.setPosition(gridTiledSprite?.x ?? 0.0, gridTiledSprite?.y ?? 0.0); renderedSelectionSquares.setPosition(gridTiledSprite?.x ?? 0.0, gridTiledSprite?.y ?? 0.0); // Offset the selection box start position, if we are dragging. if (selectionBoxStartPos != null) selectionBoxStartPos.y -= diff; // Update the note preview viewport box. setNotePreviewViewportBounds(calculateNotePreviewViewportBounds()); return this.scrollPositionInPixels; } /** * The relative scroll position in the song, converted to steps. * NOT dependant on BPM, because the size of a grid square does not change with BPM. */ var scrollPositionInSteps(get, set):Float; function get_scrollPositionInSteps():Float { return scrollPositionInPixels / GRID_SIZE; } function set_scrollPositionInSteps(value:Float):Float { scrollPositionInPixels = value * GRID_SIZE; return value; } /** * The relative scroll position in the song, converted to milliseconds. * DEPENDANT on BPM, because the duration of a grid square changes with BPM. */ var scrollPositionInMs(get, set):Float; function get_scrollPositionInMs():Float { return Conductor.getStepTimeInMs(scrollPositionInSteps); } function set_scrollPositionInMs(value:Float):Float { scrollPositionInSteps = Conductor.getTimeInSteps(value); return value; } // Playhead (on the grid) /** * The position of the playhead, in pixels, relative to the `scrollPositionInPixels`. * `0` means playhead is at the top of the grid. * `40` means the playhead is 1 grid length below the base position. * `-40` means the playhead is 1 grid length above the base position. */ var playheadPositionInPixels(default, set):Float = 0.0; function set_playheadPositionInPixels(value:Float):Float { // Make sure playhead doesn't go outside the song. if (value + scrollPositionInPixels < 0) value = -scrollPositionInPixels; if (value + scrollPositionInPixels > songLengthInPixels) value = songLengthInPixels - scrollPositionInPixels; this.playheadPositionInPixels = value; // Move the playhead sprite to the correct position. gridPlayhead.y = this.playheadPositionInPixels + (MENU_BAR_HEIGHT + GRID_TOP_PAD); return this.playheadPositionInPixels; } /** * playheadPosition, converted to steps. * NOT dependant on BPM, because the size of a grid square does not change with BPM. */ var playheadPositionInSteps(get, set):Float; function get_playheadPositionInSteps():Float { return playheadPositionInPixels / GRID_SIZE; } function set_playheadPositionInSteps(value:Float):Float { playheadPositionInPixels = value * GRID_SIZE; return value; } /** * playheadPosition, converted to milliseconds. * DEPENDANT on BPM, because the duration of a grid square changes with BPM. */ var playheadPositionInMs(get, set):Float; function get_playheadPositionInMs():Float { return Conductor.getStepTimeInMs(playheadPositionInSteps); } function set_playheadPositionInMs(value:Float):Float { playheadPositionInSteps = Conductor.getTimeInSteps(value); return value; } // Playbar (at the bottom) /** * Whether a skip button has been pressed on the playbar, and which one. * `null` if no button has been pressed. * This will be used to update the scrollPosition (in the same function that handles the scroll wheel), then cleared. */ var playbarButtonPressed:Null = null; /** * Whether the head of the playbar is currently being dragged with the mouse by the user. */ var playbarHeadDragging:Bool = false; /** * Whether music was playing before we started dragging the playbar head. * If so, then when we stop dragging the playbar head, we should resume song playback. */ var playbarHeadDraggingWasPlaying:Bool = false; // Tools Status /** * The note kind to use for notes being placed in the chart. Defaults to `''`. */ var selectedNoteKind:String = ''; /** * The event type to use for events being placed in the chart. Defaults to `''`. */ var selectedEventKind:String = 'FocusCamera'; /** * The event data to use for events being placed in the chart. */ var selectedEventData:DynamicAccess = {}; /** * The internal index of what note snapping value is in use. * Increment to make placement more preceise and decrement to make placement less precise. */ var noteSnapQuantIndex:Int = BASE_QUANT_INDEX; /** * The current note snapping value. * For example, `32` when snapping to 32nd notes. */ var noteSnapQuant(get, never):Int; function get_noteSnapQuant():Int { return SNAP_QUANTS[noteSnapQuantIndex]; } /** * The ratio of the current note snapping value to the default. * For example, `32` becomes `0.5` when snapping to 16th notes. */ var noteSnapRatio(get, never):Float; function get_noteSnapRatio():Float { return BASE_QUANT / noteSnapQuant; } /** * The currently selected live input style. */ var currentLiveInputStyle:ChartEditorLiveInputStyle = None; /** * If true, playtesting a chart will skip to the current playhead position. */ var playtestStartTime:Bool = false; // Visuals /** * Whether the current view is in downscroll mode. */ var isViewDownscroll(default, set):Bool = false; function set_isViewDownscroll(value:Bool):Bool { isViewDownscroll = value; // Make sure view is updated when we change view modes. noteDisplayDirty = true; notePreviewDirty = true; notePreviewViewportBoundsDirty = true; this.scrollPositionInPixels = this.scrollPositionInPixels; // Characters have probably changed too. healthIconsDirty = true; return isViewDownscroll; } /** * The current theme used by the editor. * Dictates the appearance of many UI elements. * Currently hardcoded to just Light and Dark. */ var currentTheme(default, set):ChartEditorTheme = ChartEditorTheme.Light; function set_currentTheme(value:ChartEditorTheme):ChartEditorTheme { if (value == null || value == currentTheme) return currentTheme; currentTheme = value; this.updateTheme(); return value; } /** * The character sprite in the Player Preview window. * `null` until accessed. */ var currentPlayerCharacterPlayer:Null = null; /** * The character sprite in the Opponent Preview window. * `null` until accessed. */ var currentOpponentCharacterPlayer:Null = null; // HaxeUI /** * Whether the user is focused on an input in the Haxe UI, and inputs are being fed into it. * If the user clicks off the input, focus will leave. */ var isHaxeUIFocused(get, never):Bool; function get_isHaxeUIFocused():Bool { return FocusManager.instance.focus != null; } /** * Set by ChartEditorDialogHandler, used to prevent background interaction while the dialog is open. */ var isHaxeUIDialogOpen:Bool = false; /** * The Dialog components representing the currently available tool windows. * Dialogs are retained here even when collapsed or hidden. */ var activeToolboxes:Map = new Map(); // Audio /** * Whether to play a metronome sound while the playhead is moving. */ var isMetronomeEnabled:Bool = true; /** * Whether hitsounds are enabled for the player. */ var hitsoundsEnabledPlayer:Bool = true; /** * Whether hitsounds are enabled for the opponent. */ var hitsoundsEnabledOpponent:Bool = true; /** * Whether hitsounds are enabled for at least one character. */ var hitsoundsEnabled(get, never):Bool; function get_hitsoundsEnabled():Bool { return hitsoundsEnabledPlayer || hitsoundsEnabledOpponent; } // Auto-save /** * A timer used to auto-save the chart after a period of inactivity. */ var autoSaveTimer:Null = null; // Scrolling /** * Whether the user's last mouse click was on the playhead scroll area. */ var gridPlayheadScrollAreaPressed:Bool = false; /** * Where the user's last mouse click was on the note preview scroll area. * `null` if the user isn't clicking on the note preview. */ var notePreviewScrollAreaStartPos:Null = null; /** * The current process that is lerping the scroll position. * Used to cancel the previous lerp if the user scrolls again. */ var currentScrollEase:Null; // Note Placement /** * The SongNoteData which is currently being placed. * `null` if the user isn't currently placing a note. * As the user drags, we will update this note's sustain length, and finalize the note when they release. */ var currentPlaceNoteData:Null = null; // Note Movement /** * The note sprite we are currently moving, if any. */ var dragTargetNote:Null = null; /** * The song event sprite we are currently moving, if any. */ var dragTargetEvent:Null = null; /** * The amount of vertical steps the note sprite has moved by since the user started dragging. */ var dragTargetCurrentStep:Float = 0; /** * The amount of horizontal columns the note sprite has moved by since the user started dragging. */ var dragTargetCurrentColumn:Int = 0; // Hold Note Dragging /** * The current length of the hold note we are dragging, in steps. * Play a sound when this value changes. */ var dragLengthCurrent:Float = 0; /** * Flip-flop to alternate between two stretching sounds. */ var stretchySounds:Bool = false; // Selection /** * The notes which are currently in the user's selection. */ var currentNoteSelection:Array = []; /** * The events which are currently in the user's selection. */ var currentEventSelection:Array = []; /** * The position where the user clicked to start a selection. * `null` if the user isn't currently selecting anything. * The selection box extends from this point to the current mouse position. */ var selectionBoxStartPos:Null = null; // History /** * The list of command previously performed. Used for undoing previous actions. */ var undoHistory:Array = []; /** * The list of commands that have been undone. Used for redoing previous actions. */ var redoHistory:Array = []; // Dirty Flags /** * Whether the note display render group has been modified and needs to be updated. * This happens when we scroll or add/remove notes, and need to update what notes are displayed and where. */ var noteDisplayDirty:Bool = true; /** * Whether the selected charactesr have been modified and the health icons need to be updated. */ var healthIconsDirty:Bool = true; /** * Whether the note preview graphic needs to be FULLY rebuilt. */ var notePreviewDirty(default, set):Bool = true; function set_notePreviewDirty(value:Bool):Bool { trace('Note preview dirtied!'); return notePreviewDirty = value; } var notePreviewViewportBoundsDirty:Bool = true; /** * Whether the chart has been modified since it was last saved. * Used to determine whether to auto-save, etc. */ var saveDataDirty(default, set):Bool = false; function set_saveDataDirty(value:Bool):Bool { if (value == saveDataDirty) return value; if (value) { // Start the auto-save timer. autoSaveTimer = new FlxTimer().start(Constants.AUTOSAVE_TIMER_DELAY_SEC, (_) -> autoSave()); } else { if (autoSaveTimer != null) { // Stop the auto-save timer. autoSaveTimer.cancel(); autoSaveTimer.destroy(); autoSaveTimer = null; } } saveDataDirty = value; applyWindowTitle(); return saveDataDirty; } /** * Whether the difficulty tree view in the toolbox has been modified and needs to be updated. * This happens when we add/remove difficulties. */ var difficultySelectDirty:Bool = true; /** * Whether the character select view in the toolbox has been modified and needs to be updated. * This happens when we add/remove characters. */ var characterSelectDirty:Bool = true; /** * Whether the player preview toolbox have been modified and need to be updated. * This happens when we switch characters. */ var playerPreviewDirty:Bool = true; /** * Whether the opponent preview toolbox have been modified and need to be updated. * This happens when we switch characters. */ var opponentPreviewDirty:Bool = true; /** * Whether the undo/redo histories have changed since the last time the UI was updated. */ var commandHistoryDirty:Bool = true; // Input /** * Handler used to track how long the user has been holding the undo keybind. */ var undoKeyHandler:TurboKeyHandler = TurboKeyHandler.build([FlxKey.CONTROL, FlxKey.Z]); /** * Variable used to track how long the user has been holding the redo keybind. */ var redoKeyHandler:TurboKeyHandler = TurboKeyHandler.build([FlxKey.CONTROL, FlxKey.Y]); /** * Variable used to track how long the user has been holding the up keybind. */ var upKeyHandler:TurboKeyHandler = TurboKeyHandler.build(FlxKey.UP); /** * Variable used to track how long the user has been holding the down keybind. */ var downKeyHandler:TurboKeyHandler = TurboKeyHandler.build(FlxKey.DOWN); /** * Variable used to track how long the user has been holding the W keybind. */ var wKeyHandler:TurboKeyHandler = TurboKeyHandler.build(FlxKey.W); /** * Variable used to track how long the user has been holding the S keybind. */ var sKeyHandler:TurboKeyHandler = TurboKeyHandler.build(FlxKey.S); /** * Variable used to track how long the user has been holding the page-up keybind. */ var pageUpKeyHandler:TurboKeyHandler = TurboKeyHandler.build(FlxKey.PAGEUP); /** * Variable used to track how long the user has been holding the page-down keybind. */ var pageDownKeyHandler:TurboKeyHandler = TurboKeyHandler.build(FlxKey.PAGEDOWN); /** * AUDIO AND SOUND DATA */ // ============================== /** * The chill audio track that plays when you open the Chart Editor. */ var welcomeMusic:FlxSound = new FlxSound(); /** * The audio track for the instrumental. * Replaced when switching instrumentals. * `null` until an instrumental track is loaded. */ var audioInstTrack:Null = null; /** * The raw byte data for the instrumental audio tracks. * Key is the instrumental name. * `null` until an instrumental track is loaded. */ var audioInstTrackData:Map = []; /** * The audio track for the vocals. * `null` until vocal track(s) are loaded. * When switching characters, the elements of the VoicesGroup will be swapped to match the new character. */ var audioVocalTrackGroup:Null = null; /** * A map of the audio tracks for each character's vocals. * - Keys are `characterId-variation` (with `characterId` being the default variation). * - Values are the byte data for the audio track. */ var audioVocalTrackData:Map = []; /** * CHART DATA */ // ============================== /** * The song metadata. * - Keys are the variation IDs. At least one (`default`) must exist. * - Values are the relevant metadata, ready to be serialized to JSON. */ var songMetadata:Map = []; /** * Retrieves the list of variations for the current song. */ var availableVariations(get, never):Array; function get_availableVariations():Array { var variations:Array = [for (x in songMetadata.keys()) x]; variations.sort(SortUtil.defaultThenAlphabetically.bind('default')); return variations; } /** * Retrieves the list of difficulties for the current variation of the current song. * ONLY CONTAINS DIFFICULTIES FOR THE CURRENT VARIATION so if on the default variation, erect/nightmare won't be included. */ var availableDifficulties(get, never):Array; function get_availableDifficulties():Array { var m:Null = songMetadata.get(selectedVariation); return m?.playData?.difficulties ?? []; } /** * Retrieves the list of difficulties for ALL variations of the current song. */ var allDifficulties(get, never):Array; function get_allDifficulties():Array { var result:Array> = [ for (x in availableVariations) { var m:Null = songMetadata.get(x); m?.playData?.difficulties ?? []; } ]; return result.flatten(); } /** * The song chart data. * - Keys are the variation IDs. At least one (`default`) must exist. * - Values are the relevant chart data, ready to be serialized to JSON. */ var songChartData:Map = []; /** * Convenience property to get the chart data for the current variation. */ var currentSongMetadata(get, set):SongMetadata; function get_currentSongMetadata():SongMetadata { var result:Null = songMetadata.get(selectedVariation); if (result == null) { result = new SongMetadata('DadBattle', 'Kawai Sprite', selectedVariation); songMetadata.set(selectedVariation, result); } return result; } function set_currentSongMetadata(value:SongMetadata):SongMetadata { songMetadata.set(selectedVariation, value); return value; } /** * Convenience property to get the chart data for the current variation. */ var currentSongChartData(get, set):SongChartData; function get_currentSongChartData():SongChartData { var result:Null = songChartData.get(selectedVariation); if (result == null) { result = new SongChartData(["normal" => 1.0], [], ["normal" => []]); songChartData.set(selectedVariation, result); } return result; } function set_currentSongChartData(value:SongChartData):SongChartData { songChartData.set(selectedVariation, value); return value; } /** * Convenience property to get (and set) the scroll speed for the current difficulty. */ var currentSongChartScrollSpeed(get, set):Float; function get_currentSongChartScrollSpeed():Float { var result:Null = currentSongChartData.scrollSpeed.get(selectedDifficulty); if (result == null) { // Initialize to the default value if not set. currentSongChartData.scrollSpeed.set(selectedDifficulty, 1.0); return 1.0; } return result; } function set_currentSongChartScrollSpeed(value:Float):Float { currentSongChartData.scrollSpeed.set(selectedDifficulty, value); return value; } /** * Convenience property to get the note data for the current difficulty. */ var currentSongChartNoteData(get, set):Array; function get_currentSongChartNoteData():Array { var result:Null> = currentSongChartData.notes.get(selectedDifficulty); if (result == null) { // Initialize to the default value if not set. result = []; trace('Initializing blank note data for difficulty ' + selectedDifficulty); currentSongChartData.notes.set(selectedDifficulty, result); currentSongMetadata.playData.difficulties.pushUnique(selectedDifficulty); return result; } return result; } function set_currentSongChartNoteData(value:Array):Array { currentSongChartData.notes.set(selectedDifficulty, value); currentSongMetadata.playData.difficulties.pushUnique(selectedDifficulty); return value; } /** * Convenience property to get the event data for the current difficulty. */ var currentSongChartEventData(get, set):Array; function get_currentSongChartEventData():Array { if (currentSongChartData.events == null) { // Initialize to the default value if not set. currentSongChartData.events = []; } return currentSongChartData.events; } function set_currentSongChartEventData(value:Array):Array { return currentSongChartData.events = value; } var currentSongNoteStyle(get, set):String; function get_currentSongNoteStyle():String { if (currentSongMetadata.playData.noteStyle == null) { // Initialize to the default value if not set. currentSongMetadata.playData.noteStyle = Constants.DEFAULT_NOTE_STYLE; } return currentSongMetadata.playData.noteStyle; } function set_currentSongNoteStyle(value:String):String { return currentSongMetadata.playData.noteStyle = value; } var currentSongStage(get, set):String; function get_currentSongStage():String { if (currentSongMetadata.playData.stage == null) { // Initialize to the default value if not set. currentSongMetadata.playData.stage = 'mainStage'; } return currentSongMetadata.playData.stage; } function set_currentSongStage(value:String):String { return currentSongMetadata.playData.stage = value; } var currentSongName(get, set):String; function get_currentSongName():String { if (currentSongMetadata.songName == null) { // Initialize to the default value if not set. currentSongMetadata.songName = 'New Song'; } return currentSongMetadata.songName; } function set_currentSongName(value:String):String { return currentSongMetadata.songName = value; } var currentSongId(get, never):String; function get_currentSongId():String { return currentSongName.toLowerKebabCase().replace('.', '').replace(' ', '-'); } var currentSongArtist(get, set):String; function get_currentSongArtist():String { if (currentSongMetadata.artist == null) { // Initialize to the default value if not set. currentSongMetadata.artist = 'Unknown'; } return currentSongMetadata.artist; } function set_currentSongArtist(value:String):String { return currentSongMetadata.artist = value; } /** * The variation ID for the difficulty which is currently being edited. */ var selectedVariation(default, set):String = Constants.DEFAULT_VARIATION; /** * Setter called when we are switching variations. * We will likely need to switch instrumentals as well. */ function set_selectedVariation(value:String):String { // Don't update if we're already on the variation. if (selectedVariation == value) return selectedVariation; selectedVariation = value; // Make sure view is updated when the variation changes. noteDisplayDirty = true; notePreviewDirty = true; notePreviewViewportBoundsDirty = true; switchToCurrentInstrumental(); return selectedVariation; } /** * The difficulty ID for the difficulty which is currently being edited. */ var selectedDifficulty(default, set):String = Constants.DEFAULT_DIFFICULTY; function set_selectedDifficulty(value:String):String { selectedDifficulty = value; // Make sure view is updated when the difficulty changes. noteDisplayDirty = true; notePreviewDirty = true; notePreviewViewportBoundsDirty = true; // Make sure the difficulty we selected is in the list of difficulties. currentSongMetadata.playData.difficulties.pushUnique(selectedDifficulty); return selectedDifficulty; } /** * The instrumental ID which is currently selected. */ var currentInstrumentalId(get, set):String; function get_currentInstrumentalId():String { var instId:Null = currentSongMetadata.playData.characters.instrumental; if (instId == null || instId == '') instId = (selectedVariation == Constants.DEFAULT_VARIATION) ? '' : selectedVariation; return instId; } function set_currentInstrumentalId(value:String):String { return currentSongMetadata.playData.characters.instrumental = value; } /** * RENDER OBJECTS */ // ============================== /** * The IMAGE used for the grid. Updated by ChartEditorThemeHandler. */ var gridBitmap:Null = null; /** * The IMAGE used for the selection squares. Updated by ChartEditorThemeHandler. * Used two ways: * 1. A sprite is given this bitmap and placed over selected notes. * 2. The image is split and used for a 9-slice sprite for the selection box. */ var selectionSquareBitmap:Null = null; /** * The IMAGE used for the note preview bitmap. Updated by ChartEditorThemeHandler. * The image is split and used for a 9-slice sprite for the box over the note preview. */ var notePreviewViewportBitmap:Null = null; /** * The tiled sprite used to display the grid. * The height is the length of the song, and scrolling is done by simply the sprite. */ var gridTiledSprite:Null = null; /** * The playhead representing the current position in the song. * Can move around on the grid independently of the view. */ var gridPlayhead:FlxSpriteGroup = new FlxSpriteGroup(); /** * The sprite for the scroll area under */ var gridPlayheadScrollArea:Null = null; /** * A sprite used to indicate the note that will be placed on click. */ var gridGhostNote:Null = null; /** * A sprite used to indicate the note that will be placed on click. */ var gridGhostHoldNote:Null = null; /** * A sprite used to indicate the event that will be placed on click. */ var gridGhostEvent:Null = null; /** * The sprite used to display the note preview area. * We move this up and down to scroll the preview. */ var notePreview:Null = null; /** * The rectangular sprite used for representing the current viewport on the note preview. * We move this up and down and resize it to represent the visible area. */ var notePreviewViewport:Null = null; /** * The rectangular sprite used for rendering the selection box. * Uses a 9-slice to stretch the selection box to the correct size without warping. */ var selectionBoxSprite:Null = null; /** * The opponent's health icon. */ var healthIconDad:Null = null; /** * The player's health icon. */ var healthIconBF:Null = null; /** * The purple background sprite. */ var menuBG:Null = null; /** * The layout containing the playbar head slider. */ var playbarHeadLayout:Null = null; /** * The submenu in the menubar containing recently opened files. */ var menubarOpenRecent:Null = null; /** * The item in the menubar to save the currently opened chart. */ var menubarItemSaveChart:Null = null; /** * The playbar head slider. */ var playbarHead:Null = null; /** * The label by the playbar telling the song position. */ var playbarSongPos:Null