Skip to content

Commit

Permalink
Fix coldboot/gameboot loading code, default replaces custom one right…
Browse files Browse the repository at this point in the history
… away as there is no null check there

Unload coldboot/gameboot images when their respective screen ended
  • Loading branch information
EmiyaSyahriel committed Dec 4, 2022
1 parent a96fde8 commit 33a9c16
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import id.psw.vshlauncher.livewallpaper.XMBWaveSurfaceView
import id.psw.vshlauncher.submodules.GamepadSubmodule
import id.psw.vshlauncher.typography.FontCollections
import java.io.File
import java.nio.file.Files.exists
import kotlin.system.exitProcess

class VshViewColdBootState(
Expand Down Expand Up @@ -62,10 +63,15 @@ fun XmbView.cbStart(){

fun XmbView.cbEnsureImageLoaded(){
if(state.coldBoot.image == null){
val i = context.vsh.getAllPathsFor(VshBaseDirs.VSH_RESOURCES_DIR, "COLDBOOT.PNG", createParentDir = false).find { it.exists() }

// Load custom coldboot if exists
val i = context.vsh.getAllPathsFor(VshBaseDirs.VSH_RESOURCES_DIR, "COLDBOOT.PNG", createParentDir = true).firstOrNull { it.exists() }
if(i != null) { state.coldBoot.image = BitmapFactory.decodeFile(i.absolutePath) }

state.coldBoot.image = getDrawable(R.drawable.coldboot_internal)?.toBitmap(1280, 720)
// Load default if no custom coldboot can be loaded
if(state.coldBoot.image == null) {
state.coldBoot.image = getDrawable(R.drawable.coldboot_internal)?.toBitmap(1280, 720)
}
}
}

Expand Down Expand Up @@ -141,7 +147,9 @@ fun XmbView.cbOnTouchScreen(a: PointF, b:PointF, act:Int){
}

fun XmbView.cbEnd(){
// NativeGL.setSpeed(state.coldBoot.waveSpeed)
// Unload coldboot image
state.coldBoot.image?.recycle()
state.coldBoot.image = null
}

fun XmbView.cbOnGamepad(k:GamepadSubmodule.Key, isPress:Boolean) : Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,15 @@ fun XmbView.gbStart(){

private fun XmbView.gbEnsureImageLoaded(){
if(state.gameBoot.image == null){
val i = context.vsh.getAllPathsFor(VshBaseDirs.VSH_RESOURCES_DIR, "GAMEBOOT.PNG", createParentDir = false).find { it.exists() }

// Load custom gameboot if exists
val i = context.vsh.getAllPathsFor(VshBaseDirs.VSH_RESOURCES_DIR, "GAMEBOOT.PNG", createParentDir = true).firstOrNull { it.exists() }
if(i != null) { state.gameBoot.image = BitmapFactory.decodeFile(i.absolutePath) }
state.gameBoot.image = getDrawable(R.drawable.gameboot_internal)?.toBitmap(1280, 720)

// Load default if no custom gameboot can be loaded
if(state.gameBoot.image == null){
state.gameBoot.image = getDrawable(R.drawable.gameboot_internal)?.toBitmap(1280, 720)
}
}

if(state.gameBoot.pParticleTexture == null){
Expand Down Expand Up @@ -184,6 +190,10 @@ fun XmbView.gbOnTouchScreen(a:PointF, b:PointF, act:Int){

fun XmbView.gbEnd(){
state.gameBoot.currentTime = 0.0f

// Unload gameboot image
state.gameBoot.image?.recycle()
state.gameBoot.image = null
}

fun XmbView.gbOnGamepad(k: GamepadSubmodule.Key, isPress:Boolean) : Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.graphics.*
import android.os.Build
import android.text.TextPaint
import android.util.AttributeSet
import android.util.Log
import android.view.*
import androidx.core.content.res.ResourcesCompat
import androidx.core.graphics.drawable.toBitmap
Expand All @@ -17,7 +16,6 @@ import id.psw.vshlauncher.activities.XMB
import id.psw.vshlauncher.submodules.GamepadSubmodule
import id.psw.vshlauncher.typography.FontCollections
import id.psw.vshlauncher.views.dialogviews.SubDialogUI
import id.psw.vshlauncher.views.dialogviews.TestDialogView
import java.util.*
import kotlin.ConcurrentModificationException
import kotlin.concurrent.thread
Expand Down

0 comments on commit 33a9c16

Please sign in to comment.