Skip to content

Commit

Permalink
Add shift up/down options
Browse files Browse the repository at this point in the history
  • Loading branch information
tillvit committed Oct 9, 2024
1 parent 94f47e0 commit 3c82de9
Show file tree
Hide file tree
Showing 4 changed files with 421 additions and 195 deletions.
83 changes: 82 additions & 1 deletion app/src/chart/ChartManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1869,7 +1869,10 @@ export class ChartManager {
}
}

modifySelection(modify: (note: NotedataEntry) => PartialNotedataEntry) {
modifySelection(
modify: (note: NotedataEntry) => PartialNotedataEntry,
clear = false
) {
if (!this.loadedChart) return
const selectionNotes = this.selection.notes
const newNotes = structuredClone(this.selection.notes)
Expand Down Expand Up @@ -1898,6 +1901,84 @@ export class ChartManager {
selectionNotes
)

if (clear) {
// Remove all notes in the range that would be replaced
const endBeats = uniqueNotes.map(note => getNoteEnd(note))
let maxBeat = 0
for (const endBeat of endBeats) {
if (endBeat > maxBeat) {
maxBeat = endBeat
}
}

// We can treat this as just all holds from start to end
const clearNotes: PartialHoldNotedataEntry[] = new Array(
this.loadedChart.gameType.numCols
)
.fill(0)
.map((_, i) => {
return {
type: "Hold",
hold: maxBeat - uniqueNotes[0].beat,
col: i,
beat: uniqueNotes[0].beat,
}
})
const {
removedNotes: removedNotesCleared,
truncatedHolds: truncatedHoldsCleared,
} = this.checkConflicts(clearNotes, selectionNotes)

// Merge both conflicts together
removedNotesCleared.forEach(note => {
if (!removedNotes.includes(note)) removedNotes.push(note)
})

truncatedHoldsCleared.forEach(note => {
// Find a match with the same old note
const match = truncatedHolds.find(
truncated => truncated.oldNote == note.oldNote
)
if (match) {
// Take the shorter of the two
const oldHoldLength = isHoldNote(match.newNote)
? match.newNote.hold
: 0
const newHoldLength = isHoldNote(match.newNote)
? match.newNote.hold
: 0
const newLength = Math.min(oldHoldLength, newHoldLength)
if (newLength == 0) {
match.newNote = {
beat: match.newNote.beat,
col: match.newNote.col,
type: "Tap",
}
} else {
match.newNote = {
beat: match.newNote.beat,
col: match.newNote.col,
type: match.newNote.type,
hold: newLength,
}
}
}
})

// Sort both arrays

removedNotes.sort((a, b) => {
if (a.beat == b.beat) return a.col - b.col
return a.beat - b.beat
})

truncatedHolds.sort((a, b) => {
if (a.newNote.beat == b.newNote.beat)
return a.newNote.col - b.newNote.col
return a.newNote.beat - b.newNote.beat
})
}

this.app.actionHistory.run({
action: () => {
this.loadedChart!.removeNotes(
Expand Down
Loading

0 comments on commit 3c82de9

Please sign in to comment.