Skip to content

Commit

Permalink
improve: multi-platform compability (part 2)
Browse files Browse the repository at this point in the history
This commit allows easier integration of more platforms.
  • Loading branch information
ThePedroo committed Oct 28, 2023
1 parent 482e39c commit 63aba21
Show file tree
Hide file tree
Showing 12 changed files with 329 additions and 162 deletions.
132 changes: 74 additions & 58 deletions android/app/src/main/java/com/perforvnm/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ class MainActivity : Activity() {
mediaPlayer = null
}

scene1()
scene1(true)
}

frameLayout.addView(buttonStart)
Expand Down Expand Up @@ -340,7 +340,7 @@ class MainActivity : Activity() {
mediaPlayer = null
}

scene1()
scene1(true)
}

frameLayout.addView(buttonStart)
Expand Down Expand Up @@ -559,7 +559,7 @@ class MainActivity : Activity() {
mediaPlayer = null
}

scene1()
scene1(true)
}

frameLayout.addView(buttonStart)
Expand Down Expand Up @@ -1025,7 +1025,7 @@ class MainActivity : Activity() {
mediaPlayer = null
}

scene1()
scene1(true)
}

frameLayout.addView(buttonStart)
Expand Down Expand Up @@ -1388,7 +1388,7 @@ class MainActivity : Activity() {
mediaPlayer = null
}

scene1()
scene1(true)
}

frameLayout.addView(buttonStart)
Expand Down Expand Up @@ -1563,7 +1563,7 @@ class MainActivity : Activity() {
setContentView(frameLayout)
}

private fun scene1() {
private fun scene1(animate: Boolean) {
val frameLayout = FrameLayout(this)
frameLayout.setBackgroundColor(0xFF000000.toInt())

Expand All @@ -1578,7 +1578,7 @@ class MainActivity : Activity() {

frameLayout.addView(imageView_scenario)

imageView_scenario.startAnimation(animationFadeIn)
if (animate) imageView_scenario.startAnimation(animationFadeIn)

val imageView_Pedro = ImageView(this)
imageView_Pedro.setImageResource(R.raw.pedro_staring)
Expand All @@ -1595,55 +1595,59 @@ class MainActivity : Activity() {

frameLayout.addView(imageView_Pedro)

imageView_Pedro.startAnimation(animationFadeIn)

animationFadeIn.setAnimationListener(object : Animation.AnimationListener {
override fun onAnimationStart(animation: Animation?) {}

override fun onAnimationEnd(animation: Animation?) {
imageView_Pedro.animate()
.translationY(-10f)
.setDuration(500)
.setInterpolator(OvershootInterpolator())
.setListener(object : Animator.AnimatorListener {
override fun onAnimationStart(animation: Animator) {}

override fun onAnimationEnd(animation: Animator) {
imageView_Pedro.animate()
.translationY(0f)
.setDuration(500)
.setInterpolator(OvershootInterpolator())
.setListener(object : Animator.AnimatorListener {
override fun onAnimationStart(animation: Animator) {}

override fun onAnimationEnd(animation: Animator) {
handler.postDelayed(object : Runnable {
override fun run() {
imageView_Pedro.animate()
.translationX(-10f)
.translationY(0f)
.setDuration(1000)
.setInterpolator(LinearInterpolator())
.start()
}
}, 1000)
}

override fun onAnimationCancel(animation: Animator) {}

override fun onAnimationRepeat(animation: Animator) {}
})
.start()
}
if (animate) {
imageView_Pedro.startAnimation(animationFadeIn)

animationFadeIn.setAnimationListener(object : Animation.AnimationListener {
override fun onAnimationStart(animation: Animation?) {}

override fun onAnimationEnd(animation: Animation?) {
imageView_Pedro.animate()
.translationY(-10f)
.setDuration(500)
.setInterpolator(OvershootInterpolator())
.setListener(object : Animator.AnimatorListener {
override fun onAnimationStart(animation: Animator) {}

override fun onAnimationEnd(animation: Animator) {
imageView_Pedro.animate()
.translationY(0f)
.setDuration(500)
.setInterpolator(OvershootInterpolator())
.setListener(object : Animator.AnimatorListener {
override fun onAnimationStart(animation: Animator) {}

override fun onAnimationEnd(animation: Animator) {
handler.postDelayed(object : Runnable {
override fun run() {
imageView_Pedro.animate()
.translationX(-10f)
.translationY(0f)
.setDuration(1000)
.setInterpolator(LinearInterpolator())
.start()
}
}, 1000)
}

override fun onAnimationCancel(animation: Animator) {}

override fun onAnimationRepeat(animation: Animator) {}
})
.start()
}

override fun onAnimationCancel(animation: Animator) {}
override fun onAnimationCancel(animation: Animator) {}

override fun onAnimationRepeat(animation: Animator) {}
})
override fun onAnimationRepeat(animation: Animator) {}
})
}

override fun onAnimationRepeat(animation: Animation?) {}
})
} else {
imageView_Pedro.translationX = -10f
}

mediaPlayer = MediaPlayer.create(this@MainActivity, R.raw.menu_music)

Expand Down Expand Up @@ -1789,6 +1793,9 @@ class MainActivity : Activity() {

findViewById<FrameLayout>(android.R.id.content).setOnClickListener(null)

scenes.set(scenesLength, 1722916383)
scenesLength++

scene2(true)
}

Expand Down Expand Up @@ -1821,15 +1828,20 @@ class MainActivity : Activity() {

findViewById<FrameLayout>(android.R.id.content).setOnClickListener(null)

scenes.set(scenesLength, 1722916384)
scenesLength++

scene3(true)
}

frameLayout.addView(buttonSubScenes2)

giveAchievement(1183596997)

items.set(itemsLength, 1789536792)
itemsLength++
if (!items.contains(1789536792)) {
items.set(itemsLength, 1789536792)
itemsLength++
}

setContentView(frameLayout)
}
Expand Down Expand Up @@ -2489,12 +2501,10 @@ class MainActivity : Activity() {

findViewById<FrameLayout>(android.R.id.content).setOnClickListener(null)

val scene = scenes.get(scenesLength - 1)

scenesLength--
scenes.set(scenesLength, 0)

switchScene(scene)
scene4(false)
}

frameLayout.addView(buttonBack)
Expand Down Expand Up @@ -2739,7 +2749,10 @@ class MainActivity : Activity() {

findViewById<FrameLayout>(android.R.id.content).setOnClickListener(null)

scene1()
scenesLength--
scenes.set(scenesLength, 0)

scene1(false)
}

frameLayout.addView(buttonBack)
Expand Down Expand Up @@ -2995,7 +3008,10 @@ class MainActivity : Activity() {

findViewById<FrameLayout>(android.R.id.content).setOnClickListener(null)

scene1()
scenesLength--
scenes.set(scenesLength, 0)

scene1(false)
}

frameLayout.addView(buttonBack)
Expand All @@ -3016,7 +3032,7 @@ class MainActivity : Activity() {

private fun switchScene(scene: Int) {
when (scene) {
1722916382 -> scene1()
1722916382 -> scene1(false)
1722916385 -> scene4(false)
1722916386 -> scene5()
969329308 -> no_items()
Expand Down
1 change: 0 additions & 1 deletion platforms/android/achievements.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* TODO: Achievements searchs from O(n) to O(1) through objects */
/* TODO: Option for scenes to require an achievement and if not, fallback to another scene */

import helper from '../main/helper.js'
Expand Down
55 changes: 32 additions & 23 deletions platforms/android/coder.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ import { _ProcessWNextScene, _ProcessWONextScene, _ProcessSceneSave, _FinalizeSc
import { _SetAchievementsMenu, _AchievementGive } from './achievements.js'
import { _ItemsParsingFunction, _ItemsRestore, _ItemsSaver } from './items.js'

global.AndroidVisualNovel = { menu: null, internalInfo: {}, code: '', scenes: [], subScenes: [], achievements: [], items: [], customXML: [] }
global.PerforVNM = {
codeGeneratorVersion: '1.23.0',
generatedCodeVersion: '1.21.0',
repository: 'https://github.com/PerformanC/PerforVNMaker'
}
global.AndroidVisualNovel = { menu: null, internalInfo: {}, code: '', scenes: {}, subScenes: {}, achievements: [], items: [], customXML: [] }

function init(options) {
helper.logOk('Starting VN, coding main code.', 'Android')
Expand Down Expand Up @@ -122,39 +117,48 @@ function finalize() {

let savesSwitchCode = ''

if (AndroidVisualNovel.scenes.length) {
const SceneKeys = Object.keys(visualNovel.scenes)
const SubSceneKeys = Object.keys(visualNovel.subScenes)

if (visualNovel.scenesLength) {
let scenesCode = ''

AndroidVisualNovel.scenes.forEach((scene, i) => {
SceneKeys.forEach((key, i) => {
const scene = visualNovel.scenes[key]
let code = AndroidVisualNovel.scenes[key]

savesSwitchCode += _ProcessSceneSave(scene)

if (scene.next) {
const tmp = _ProcessWNextScene(i, scene, switchesCode, 'scene')
scene.code = tmp.code
const tmp = _ProcessWNextScene(i, scene, code, switchesCode, 'scene')
code = tmp.code
switchesCode = tmp.switchesCode
} else {
const tmp = _ProcessWONextScene(i, scene, switchesCode, 'scene')
scene.code = tmp.code
const tmp = _ProcessWONextScene(i, SceneKeys, scene, code, switchesCode, 'scene')
code = tmp.code
switchesCode = tmp.switchesCode
}

scenesCode += '\n\n' + scene.code
scenesCode += '\n\n' + code
})

AndroidVisualNovel.subScenes.forEach((scene, i) => {
SubSceneKeys.forEach((key, i) => {
const scene = visualNovel.subScenes[key]
let code = AndroidVisualNovel.subScenes[key]

savesSwitchCode += _ProcessSceneSave(scene)

if (scene.next.scene) {
const tmp = _ProcessWNextScene(i, scene, switchesCode, 'subScene')
scene.code = tmp.code
const tmp = _ProcessWNextScene(i, scene, code, switchesCode, 'subScene')
code = tmp.code
switchesCode = tmp.switchesCode
} else {
const tmp = _ProcessWONextScene(i, scene, switchesCode, 'subScene')
scene.code = tmp.code
const tmp = _ProcessWONextScene(i, SceneKeys, scene, code, switchesCode, 'subScene')
code = tmp.code
switchesCode = tmp.switchesCode
}

scenesCode += '\n\n' + scene.code
scenesCode += '\n\n' + code
})

helper.replace('Android', '__PERFORVNM_SCENES__', `${scenesCode}__PERFORVNM_SCENES__`)
Expand Down Expand Up @@ -183,7 +187,7 @@ function finalize() {
helper.replace('Android', '__PERFORVNM_SCENES__', '')
helper.replace('Android', '__PERFORVNM_MENU__', '// No menu created.')
helper.replace('Android', '__PERFORVNM_CLASSES__', '')
helper.replace('Android', '__PERFORVNM_MULTI_PATH__', AndroidVisualNovel.scenes.length != 0 ? `scenes.set(0, ${helper.getSceneId(AndroidVisualNovel.scenes[0].name)})` : '// No scenes created.')
helper.replace('Android', '__PERFORVNM_MULTI_PATH__', visualNovel.scenes.length != 0 ? `scenes.set(0, ${helper.getSceneId(visualNovel.scenes[SceneKeys[0]].name)})` : '// No scenes created.')
if (!visualNovel.optimizations.preCalculateRounding) {
const defaultSaveSwitchCode = helper.codePrepare(`
when (characterData.getJSONObject("position").getString("sideType")) {
Expand Down Expand Up @@ -251,19 +255,24 @@ function finalize() {
releaseCode = '// No music to release.'
}

const scene = visualNovel.scenes[SceneKeys[0]]

const functionParams = []
if (scene.speech || scene.subScenes.length != 0) functionParams.push('true')

menuCode += helper.codePrepare(`
${AndroidVisualNovel.scenes.length != 0 ? `${AndroidVisualNovel.scenes[0].name}(${(AndroidVisualNovel.scenes[0].speech ? 'true' : '')})` : '// No scenes created.'}
${visualNovel.scenes.length != 0 ? `${scene.name}(${functionParams.join(', ')})` : '// No scenes created.'}
}`, 2
)

helper.replace('Android', /__PERFORVNM_MENU_START__/g, menuCode)
helper.replace('Android', /__PERFORVNM_RELEASE_MEDIA_PLAYER__/g, releaseCode)
}

helper.replace('Android', /__PERFORVNM_SCENES_LENGTH__/g, AndroidVisualNovel.scenes.length + AndroidVisualNovel.subScenes.length)
helper.replace('Android', /__PERFORVNM_SCENES_LENGTH__/g, visualNovel.scenes.length + visualNovel.subScenes.length)

let addHeaders = helper.codePrepare(`
private var scenes = MutableList<${visualNovel.optimizations.hashScenesNames ? 'Int' : 'String'}>(${AndroidVisualNovel.scenes.length + AndroidVisualNovel.subScenes.length}) { ${visualNovel.optimizations.hashScenesNames ? '0' : '""'} }
private var scenes = MutableList<${visualNovel.optimizations.hashScenesNames ? 'Int' : 'String'}>(${visualNovel.scenesLength + visualNovel.subScenesLength}) { ${visualNovel.optimizations.hashScenesNames ? '0' : '""'} }
private var scenesLength = 1\n`, 2
)

Expand Down
Loading

0 comments on commit 63aba21

Please sign in to comment.