Skip to content

Commit

Permalink
Refactor to use range (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
NonSpicyBurrito authored Dec 1, 2024
1 parent 8adb4f8 commit fe25b11
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 63 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { approach } from '../../../../../../../shared/src/engine/data/note.mjs'
import { perspectiveLayout } from '../../../../../../../shared/src/engine/data/utils.mjs'
import {
DualWindows,
toBucketWindows,
toWindows,
} from '../../../../../../../shared/src/engine/data/windows.mjs'
import { options } from '../../../../configuration/options.mjs'
import { lane } from '../../../lane.mjs'
import { note } from '../../../note.mjs'
Expand All @@ -12,10 +17,7 @@ export abstract class VisibleNote extends Note {
accuracyDiff: { name: 'accuracyDiff', type: Number },
})

abstract dualWindows: {
normal: JudgmentWindows
strict: JudgmentWindows
}
abstract dualWindows: DualWindows

abstract bucket: Bucket

Expand All @@ -29,16 +31,7 @@ export abstract class VisibleNote extends Note {
y = this.entityMemory(Number)

globalPreprocess() {
const toMs = ({ min, max }: RangeLike) => ({
min: Math.round(min * 1000),
max: Math.round(max * 1000),
})

this.bucket.set({
perfect: toMs(this.windows.perfect),
great: toMs(this.windows.great),
good: toMs(this.windows.good),
})
this.bucket.set(toBucketWindows(this.windows))

this.life.miss = -100
}
Expand Down Expand Up @@ -77,18 +70,7 @@ export abstract class VisibleNote extends Note {
}

get windows() {
const dualWindows = this.dualWindows

const toWindow = (key: 'perfect' | 'great' | 'good') => ({
min: options.strictJudgment ? dualWindows.strict[key].min : dualWindows.normal[key].min,
max: options.strictJudgment ? dualWindows.strict[key].max : dualWindows.normal[key].max,
})

return {
perfect: toWindow('perfect'),
great: toWindow('great'),
good: toWindow('good'),
}
return toWindows(this.dualWindows, options.strictJudgment)
}

get shouldScheduleSFX() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export abstract class SlideConnector extends Archetype {

visualTime = this.entityMemory({
min: Number,
hidden: Number,
})
hiddenTime = this.entityMemory(Number)

spawnTime = this.entityMemory(Number)

Expand Down Expand Up @@ -82,8 +82,7 @@ export abstract class SlideConnector extends Archetype {
this.tail.l = this.tail.lane - w
this.tail.r = this.tail.lane + w

if (options.hidden > 0)
this.visualTime.hidden = this.tail.time - note.duration * options.hidden
if (options.hidden > 0) this.hiddenTime = this.tail.time - note.duration * options.hidden

this.connector.z = getZ(layer.note.connector, this.head.time, this.headImport.lane)

Expand Down Expand Up @@ -151,7 +150,7 @@ export abstract class SlideConnector extends Archetype {
}

renderConnector() {
if (options.hidden > 0 && time.now > this.visualTime.hidden) return
if (options.hidden > 0 && time.now > this.hiddenTime) return

const hiddenDuration = options.hidden > 0 ? note.duration * options.hidden : 0

Expand Down
37 changes: 34 additions & 3 deletions shared/src/engine/data/windows.mts
Original file line number Diff line number Diff line change
@@ -1,10 +1,41 @@
type Windows = {
perfect: Range
great: Range
good: Range
}

export type DualWindows = {
normal: Windows
strict: Windows
}

export const toWindows = (dualWindows: DualWindows, strictJudgment: boolean) => {
const toWindow = (key: 'perfect' | 'great' | 'good') =>
new Range(
strictJudgment ? dualWindows.strict[key].min : dualWindows.normal[key].min,
strictJudgment ? dualWindows.strict[key].max : dualWindows.normal[key].max,
)

return {
perfect: toWindow('perfect'),
great: toWindow('great'),
good: toWindow('good'),
}
}

const toMs = ({ min, max }: Range) => new Range(Math.round(min * 1000), Math.round(max * 1000))

export const toBucketWindows = (windows: Windows) => ({
perfect: toMs(windows.perfect),
great: toMs(windows.great),
good: toMs(windows.good),
})

type Seconds = number | [min: number, max: number]

const fromSeconds = (perfect: Seconds, great: Seconds, good: Seconds) => {
const toWindow = (seconds: Seconds) =>
typeof seconds === 'number'
? { min: -seconds, max: seconds }
: { min: seconds[0], max: seconds[1] }
typeof seconds === 'number' ? Range.one.mul(seconds) : new Range(...seconds)

return {
perfect: toWindow(perfect),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { lane } from '../../../../../../../shared/src/engine/data/lane.mjs'
import { approach } from '../../../../../../../shared/src/engine/data/note.mjs'
import { perspectiveLayout } from '../../../../../../../shared/src/engine/data/utils.mjs'
import {
DualWindows,
toBucketWindows,
toWindows,
} from '../../../../../../../shared/src/engine/data/windows.mjs'
import { options } from '../../../../configuration/options.mjs'
import { note } from '../../../note.mjs'
import { particle } from '../../../particle.mjs'
import { getZ, layer } from '../../../skin.mjs'
import { Note } from '../Note.mjs'

export abstract class VisibleNote extends Note {
abstract dualWindows: {
normal: JudgmentWindows
strict: JudgmentWindows
}
abstract dualWindows: DualWindows

abstract bucket: Bucket

Expand All @@ -33,16 +35,7 @@ export abstract class VisibleNote extends Note {
y = this.entityMemory(Number)

globalPreprocess() {
const toMs = ({ min, max }: RangeLike) => ({
min: Math.round(min * 1000),
max: Math.round(max * 1000),
})

this.bucket.set({
perfect: toMs(this.windows.perfect),
great: toMs(this.windows.great),
good: toMs(this.windows.good),
})
this.bucket.set(toBucketWindows(this.windows))

this.life.miss = -100
}
Expand Down Expand Up @@ -102,18 +95,7 @@ export abstract class VisibleNote extends Note {
}

get windows() {
const dualWindows = this.dualWindows

const toWindow = (key: 'perfect' | 'great' | 'good') => ({
min: options.strictJudgment ? dualWindows.strict[key].min : dualWindows.normal[key].min,
max: options.strictJudgment ? dualWindows.strict[key].max : dualWindows.normal[key].max,
})

return {
perfect: toWindow('perfect'),
great: toWindow('great'),
good: toWindow('good'),
}
return toWindows(this.dualWindows, options.strictJudgment)
}

get hitTime() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ export abstract class SlideConnector extends Archetype {

visualTime = this.entityMemory({
min: Number,
hidden: Number,
})
hiddenTime = this.entityMemory(Number)

connector = this.entityMemory({
z: Number,
Expand Down Expand Up @@ -165,8 +165,7 @@ export abstract class SlideConnector extends Archetype {
this.tail.l = this.tail.lane - w
this.tail.r = this.tail.lane + w

if (options.hidden > 0)
this.visualTime.hidden = this.tail.time - note.duration * options.hidden
if (options.hidden > 0) this.hiddenTime = this.tail.time - note.duration * options.hidden

this.connector.z = getZ(layer.note.connector, this.head.time, this.headImport.lane)

Expand All @@ -192,7 +191,7 @@ export abstract class SlideConnector extends Archetype {
}

renderConnector() {
if (options.hidden > 0 && time.now > this.visualTime.hidden) return
if (options.hidden > 0 && time.now > this.hiddenTime) return

const hiddenDuration = options.hidden > 0 ? note.duration * options.hidden : 0

Expand Down

0 comments on commit fe25b11

Please sign in to comment.