Skip to content

Commit

Permalink
Merge pull request #430 from Reco1I/fixes-1-8
Browse files Browse the repository at this point in the history
More corrections prior 1.8
  • Loading branch information
Rian8337 authored Oct 28, 2024
2 parents 6b729ea + d5a1d31 commit eb7da1a
Show file tree
Hide file tree
Showing 24 changed files with 265 additions and 218 deletions.
26 changes: 10 additions & 16 deletions schemas/com.reco1l.osu.data.DroidDatabase/1.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "49e3a368b321869b51790d730406bd5d",
"identityHash": "1f4b2f2358a9efc2bfef64bd9d0e3a33",
"entities": [
{
"tableName": "BeatmapInfo",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`filename` TEXT NOT NULL, `md5` TEXT NOT NULL, `id` INTEGER, `audioFilename` TEXT NOT NULL, `backgroundFilename` TEXT, `status` INTEGER, `setDirectory` TEXT NOT NULL, `setId` INTEGER, `title` TEXT NOT NULL, `titleUnicode` TEXT NOT NULL, `artist` TEXT NOT NULL, `artistUnicode` TEXT NOT NULL, `creator` TEXT NOT NULL, `version` TEXT NOT NULL, `tags` TEXT NOT NULL, `source` TEXT NOT NULL, `dateImported` INTEGER NOT NULL, `approachRate` REAL NOT NULL, `overallDifficulty` REAL NOT NULL, `circleSize` REAL NOT NULL, `hpDrainRate` REAL NOT NULL, `droidStarRating` REAL, `standardStarRating` REAL, `bpmMax` REAL NOT NULL, `bpmMin` REAL NOT NULL, `length` INTEGER NOT NULL, `previewTime` INTEGER NOT NULL, `hitCircleCount` INTEGER NOT NULL, `spinnerCount` INTEGER NOT NULL, `sliderCount` INTEGER NOT NULL, `maxCombo` INTEGER NOT NULL, PRIMARY KEY(`filename`, `setDirectory`))",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`filename` TEXT NOT NULL, `md5` TEXT NOT NULL, `id` INTEGER, `audioFilename` TEXT NOT NULL, `backgroundFilename` TEXT, `status` INTEGER, `setDirectory` TEXT NOT NULL, `setId` INTEGER, `title` TEXT NOT NULL, `titleUnicode` TEXT NOT NULL, `artist` TEXT NOT NULL, `artistUnicode` TEXT NOT NULL, `creator` TEXT NOT NULL, `version` TEXT NOT NULL, `tags` TEXT NOT NULL, `source` TEXT NOT NULL, `dateImported` INTEGER NOT NULL, `approachRate` REAL NOT NULL, `overallDifficulty` REAL NOT NULL, `circleSize` REAL NOT NULL, `hpDrainRate` REAL NOT NULL, `droidStarRating` REAL, `standardStarRating` REAL, `bpmMax` REAL NOT NULL, `bpmMin` REAL NOT NULL, `mostCommonBPM` REAL NOT NULL, `length` INTEGER NOT NULL, `previewTime` INTEGER NOT NULL, `hitCircleCount` INTEGER NOT NULL, `spinnerCount` INTEGER NOT NULL, `sliderCount` INTEGER NOT NULL, `maxCombo` INTEGER NOT NULL, PRIMARY KEY(`filename`, `setDirectory`))",
"fields": [
{
"fieldPath": "filename",
Expand Down Expand Up @@ -158,6 +158,12 @@
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "mostCommonBPM",
"columnName": "mostCommonBPM",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "length",
"columnName": "length",
Expand Down Expand Up @@ -268,7 +274,7 @@
},
{
"tableName": "ScoreInfo",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `beatmapFilename` TEXT NOT NULL, `beatmapSetDirectory` TEXT NOT NULL, `playerName` TEXT NOT NULL, `replayFilename` TEXT NOT NULL, `mods` TEXT NOT NULL, `score` INTEGER NOT NULL, `maxCombo` INTEGER NOT NULL, `mark` TEXT NOT NULL, `hit300k` INTEGER NOT NULL, `hit300` INTEGER NOT NULL, `hit100k` INTEGER NOT NULL, `hit100` INTEGER NOT NULL, `hit50` INTEGER NOT NULL, `misses` INTEGER NOT NULL, `accuracy` REAL NOT NULL, `time` INTEGER NOT NULL, `isPerfect` INTEGER NOT NULL)",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `beatmapFilename` TEXT NOT NULL, `beatmapSetDirectory` TEXT NOT NULL, `playerName` TEXT NOT NULL, `replayFilename` TEXT NOT NULL, `mods` TEXT NOT NULL, `score` INTEGER NOT NULL, `maxCombo` INTEGER NOT NULL, `mark` TEXT NOT NULL, `hit300k` INTEGER NOT NULL, `hit300` INTEGER NOT NULL, `hit100k` INTEGER NOT NULL, `hit100` INTEGER NOT NULL, `hit50` INTEGER NOT NULL, `misses` INTEGER NOT NULL, `time` INTEGER NOT NULL)",
"fields": [
{
"fieldPath": "id",
Expand Down Expand Up @@ -360,23 +366,11 @@
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "accuracy",
"columnName": "accuracy",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "time",
"columnName": "time",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "isPerfect",
"columnName": "isPerfect",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
Expand Down Expand Up @@ -494,7 +488,7 @@
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '49e3a368b321869b51790d730406bd5d')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '1f4b2f2358a9efc2bfef64bd9d0e3a33')"
]
}
}
4 changes: 4 additions & 0 deletions src/com/reco1l/andengine/ExtendedEntity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,10 @@ abstract class ExtendedEntity(
}

override fun contains(x: Float, y: Float): Boolean {
if (width == 0f || height == 0f) {
return false
}

return RectangularShapeCollisionChecker.checkContains(this, x - totalOffsetX, y - totalOffsetY)
}

Expand Down
110 changes: 62 additions & 48 deletions src/com/reco1l/andengine/sprite/AnimatedSprite.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package com.reco1l.andengine.sprite

import org.anddev.andengine.opengl.texture.region.*
import ru.nsu.ccfit.zuev.osu.*
import kotlin.math.*




open class AnimatedSprite(frames: Array<TextureRegion?>) : ExtendedSprite() {
Expand All @@ -11,17 +14,11 @@ open class AnimatedSprite(frames: Array<TextureRegion?>) : ExtendedSprite() {
*
* @param textureName The base name of the texture (do not include the frame number or the hyphen if it has).
* @param withHyphen Whether the texture name has a hyphen before the frame number.
* @param fps The frame rate of the animation.
* @param framePerSecond The frame rate of the animation, or 0 to use the amount of frames as the frame rate.
*/
@JvmOverloads
constructor(textureName: String, withHyphen: Boolean, fps: Float = DEFAULT_FPS) : this(mutableListOf<TextureRegion?>().also { frames ->
constructor(textureName: String, withHyphen: Boolean, framePerSecond: Float): this(mutableListOf<TextureRegion?>().also { frames ->

var frameCount = if (fps < 0) ResourceManager.getInstance().getFrameCount(textureName) else fps.toInt()

// ResourceManager can return -1 if the textures are not present.
if (frameCount < 0) {
frameCount = DEFAULT_FPS.toInt()
}
val frameCount = ResourceManager.getInstance().getFrameCount(textureName)

for (i in 0 until frameCount) {
val frameName = textureName + (if (withHyphen) "-" else "") + i
Expand All @@ -34,8 +31,16 @@ open class AnimatedSprite(frames: Array<TextureRegion?>) : ExtendedSprite() {
if (frames.isEmpty()) {
frames.add(ResourceManager.getInstance().getTexture(textureName))
}

}.toTypedArray()) {
this.fps = fps

// When the frame rate is 0, use the amount of frames as the frame rate.
// If there are no frames, use the default frame rate which is 60 FPS.
val fps = if (framePerSecond > 0) framePerSecond else frames.size.toFloat()

if (fps > 0) {
frameTime = 1f / fps
}
}


Expand All @@ -46,25 +51,17 @@ open class AnimatedSprite(frames: Array<TextureRegion?>) : ExtendedSprite() {
*/
var frames = frames
set(value) {
stop()
textureRegion = value.firstOrNull()
field = value
if (!field.contentEquals(value)) {
stop()
field = value
textureRegion = value.firstOrNull()
}
}

/**
* The current state of the animation.
*
* Negative values will set the frame count as the frame rate.
* The duration of each frame in seconds.
*/
var fps = -1f

/**
* Whether the animation is playing.
*
* Setting this value to false will pause the animation and vice-versa.
* To stop the animation, use the [stop] method.
*/
var isPlaying = true
var frameTime = DEFAULT_FRAME_TIME

/**
* Whether the animation should loop.
Expand All @@ -76,43 +73,61 @@ open class AnimatedSprite(frames: Array<TextureRegion?>) : ExtendedSprite() {
*/
var elapsedSec = 0f

/**
* Whether the animation is playing.
*/
var isPlaying = true
private set

/**
* The current frame index.
*/
var frameIndex = 0
private set
private set(value) {
if (field != value) {
field = value
textureRegion = frames[value]
}
}


/**
* The duration of the animation in seconds.
*/
val duration
get() = frames.size * frameTime


init {
@Suppress("LeakingThis")
textureRegion = frames.firstOrNull()
if (frames.isNotEmpty()) {
@Suppress("LeakingThis")
textureRegion = frames[0]
}
}


override fun onManagedUpdate(pSecondsElapsed: Float) {
override fun onManagedUpdate(deltaTimeSec: Float) {

val frameCount = frames.size
if (frames.isNotEmpty()) {

if (frameCount > 0 && isPlaying) {
if (isPlaying) {
elapsedSec += deltaTimeSec

elapsedSec += pSecondsElapsed
if (elapsedSec >= duration) {

val framePerSec = if (fps < 0) frameCount.toFloat() else fps
val frameTime = (elapsedSec * framePerSec).toInt()

if (isLoop) {
frameIndex = frameTime % frameCount
} else if (frameTime >= frameCount) {
frameIndex = frameCount - 1
stop()
if (isLoop) {
elapsedSec %= duration
} else {
elapsedSec = duration
isPlaying = false
}
}
}

textureRegion = frames[frameIndex]
} else if (isPlaying) {
isPlaying = false
frameIndex = min(frames.size - 1, (elapsedSec / frameTime).toInt())
}

super.onManagedUpdate(pSecondsElapsed)
super.onManagedUpdate(deltaTimeSec)
}


Expand All @@ -132,16 +147,15 @@ open class AnimatedSprite(frames: Array<TextureRegion?>) : ExtendedSprite() {


override fun reset() {
super.reset()
elapsedSec = 0f
frameIndex = 0
stop()
isPlaying = true
super.reset()
}


companion object {

const val DEFAULT_FPS = 60f
const val DEFAULT_FRAME_TIME = 1f / 60f

}

Expand Down
2 changes: 1 addition & 1 deletion src/com/reco1l/framework/Bitmaps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import kotlin.random.*
* Converts the bitmap to a safe for work version where the content is black and the bounds are red.
*/
@JvmOverloads
fun Bitmap?.paintBitmap(boundSize: Int = 1, boundColor: Int = Random.nextColor(), fillColor: Int = 0x33000000, preserveShape: Boolean = keepTexturesShapeInNoTexturesMode): Bitmap? {
fun Bitmap?.paintBitmap(boundSize: Int = if (keepTexturesShapeInNoTexturesMode) 1 else 3, boundColor: Int = Random.nextColor(), fillColor: Int = 0x33000000, preserveShape: Boolean = keepTexturesShapeInNoTexturesMode): Bitmap? {

if (this == null) {
return null
Expand Down
10 changes: 2 additions & 8 deletions src/com/reco1l/framework/net/FileRequest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,11 @@ class FileRequest(val file: File, url: HttpUrl): WebRequest(url) {
}


/**
* Cancels the current download.
*
* If [execute] wasn't called at this point or the download has finished, this will not have any
* effect.
*/
fun cancel() {
override fun cancel() {
isDownloading = false
super.cancel()
}


override fun execute(): FileRequest {
try {
super.execute()
Expand Down
24 changes: 22 additions & 2 deletions src/com/reco1l/framework/net/WebRequest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ open class WebRequest(private var url: HttpUrl) : AutoCloseable {
lateinit var responseBody: ResponseBody
protected set

/**
* The call object used to execute the request.
* It will be initialized upon [execute] call.
*/
lateinit var call: Call
protected set


/**
* The client to be used for this request.
Expand Down Expand Up @@ -104,6 +111,20 @@ open class WebRequest(private var url: HttpUrl) : AutoCloseable {
responseBody.close()
}

if (::call.isInitialized) {
call.cancel()
}
}


/**
* Cancels the current request.
* This will have no effect if [execute] wasn't called or the request has already finished.
*/
open fun cancel() {
if (::call.isInitialized) {
call.cancel()
}
}


Expand All @@ -115,9 +136,8 @@ open class WebRequest(private var url: HttpUrl) : AutoCloseable {
@Throws(Exception::class)
open fun execute(): WebRequest {

val call = client.newCall(request)

try {
call = client.newCall(request)

if (BuildConfig.DEBUG) {
Log.i("WebRequest", "Request to: " + request.url)
Expand Down
16 changes: 2 additions & 14 deletions src/com/reco1l/osu/beatmaplisting/BeatmapDownloader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import com.reco1l.osu.multiplayer.Multiplayer
import com.reco1l.osu.multiplayer.RoomScene
import com.reco1l.osu.ui.DownloadFragment
import com.reco1l.toolkt.kotlin.async
import com.reco1l.toolkt.kotlin.decodeAsURL
import com.reco1l.toolkt.kotlin.replaceAlphanumeric
import net.lingala.zip4j.ZipFile
import org.apache.commons.io.FilenameUtils
import ru.nsu.ccfit.zuev.osu.Config
import ru.nsu.ccfit.zuev.osu.GlobalManager
import ru.nsu.ccfit.zuev.osu.ToastLogger
Expand Down Expand Up @@ -41,18 +38,9 @@ object BeatmapDownloader : IDownloaderObserver {
}
isDownloading = true

val name = suggestedFilename.decodeAsURL()
val filename = name.replaceAlphanumeric(with = "_")
currentFilename = suggestedFilename

if (!filename.endsWith(".osz")) {
ToastLogger.showText("Failed to start download. Invalid file extension", true)
return
}

currentFilename = FilenameUtils.removeExtension(filename)

val directory = context.getExternalFilesDir(DIRECTORY_DOWNLOADS)
val file = directory?.resolve("$filename.osz")!!
val file = context.getExternalFilesDir(DIRECTORY_DOWNLOADS)!!.resolve("$suggestedFilename.osz")

val downloader = FileRequest(file, url)
downloader.buildRequest { header("User-Agent", "Chrome/Android") }
Expand Down
4 changes: 2 additions & 2 deletions src/com/reco1l/osu/beatmaplisting/BeatmapListing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ class BeatmapSetDetails(val beatmapSet: BeatmapSetModel, val holder: BeatmapSetV

downloadButton.setOnClickListener {
val url = BeatmapListing.mirror.downloadEndpoint(beatmapSet.id)
BeatmapDownloader.download(url, "${beatmapSet.id} ${beatmapSet.artist} - ${beatmapSet.title}.osz")
BeatmapDownloader.download(url, "${beatmapSet.id} ${beatmapSet.artist} - ${beatmapSet.title}")
}

cover.setImageDrawable(holder.cover.drawable)
Expand Down Expand Up @@ -598,7 +598,7 @@ class BeatmapSetViewHolder(itemView: View, private val mediaScope: CoroutineScop

downloadButton.setOnClickListener {
val url = BeatmapListing.mirror.downloadEndpoint(beatmapSet.id)
BeatmapDownloader.download(url, "${beatmapSet.id} ${beatmapSet.artist} - ${beatmapSet.title}.osz")
BeatmapDownloader.download(url, "${beatmapSet.id} ${beatmapSet.artist} - ${beatmapSet.title}")
}


Expand Down
Loading

0 comments on commit eb7da1a

Please sign in to comment.