Skip to content

Commit

Permalink
improve: code readability; remove: unused variables
Browse files Browse the repository at this point in the history
This commit improves the code readability and also removes unused variables.
  • Loading branch information
ThePedroo committed Apr 20, 2024
1 parent e260fca commit 41881b3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 20 deletions.
14 changes: 8 additions & 6 deletions platforms/android/achievements.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,15 @@ ${achievementsSwitch}
}

export function _AchievementWrapperGive(achievements) {
const achievementCode = achievements.map((achievement) => {
if (visualNovel.optimizations.hashAchievementIds)
return `giveAchievement(${helper.getAchievementId(achievement.id)})`
else
return `giveAchievement(${helper.getAchievementId(achievement.id)}, "${helper.getAchievementId(achievement.id, true)}")`
})

return helper.codePrepare(`
${achievements.map((achievement) => {
if (visualNovel.optimizations.hashAchievementIds)
return `giveAchievement(${helper.getAchievementId(achievement.id)})`
else
return `giveAchievement(${helper.getAchievementId(achievement.id)}, "${helper.getAchievementId(achievement.id, true)}")`
}).join('\n')}\n\n`
${achievementCode.join('\n')}\n\n`
)
}

Expand Down
8 changes: 3 additions & 5 deletions platforms/android/coder.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import fs from 'fs'
import helper from '../main/helper.js'

import { _AchievementGive } from './achievements.js'
import { _ItemsParsingFunction, _ItemsRestore, _ItemsSaver } from './items.js'
import { _ItemsParsingFunction, _ItemsRestore } from './items.js'
import { _AddMenu } from './menu.js'
import { _ProcessScenes } from './scene.js'

Expand Down Expand Up @@ -131,8 +131,6 @@ function finalize() {
_ProcessScenes()

const SceneKeys = Object.keys(visualNovel.scenes)
const SubSceneKeys = Object.keys(visualNovel.subScenes)


if (visualNovel.achievements.length != 0)
helper.writeFunction('Android', _AchievementGive())
Expand Down Expand Up @@ -340,8 +338,8 @@ ${AndroidVisualNovel.savesWhen.join('\n')}
helper.lastMessage(finished)
})

let i = 0,
xmlLength = AndroidVisualNovel.customXML.length - 1
let i = 0, xmlLength = AndroidVisualNovel.customXML.length - 1

while (AndroidVisualNovel.customXML.length > 0) {
const customXML = AndroidVisualNovel.customXML.shift()

Expand Down
2 changes: 1 addition & 1 deletion platforms/android/items.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function _ItemsRestore() {
}

export function _ItemsSaver() {
return helper.codePrepare(` ",\\"items\\":" + itemsToJson() + `, 0, 0, false)
return helper.codePrepare(' ",\\"items\\":" + itemsToJson() + ', 0, 0, false)
}

export default {
Expand Down
20 changes: 13 additions & 7 deletions platforms/android/scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ export function _ProcessScene(scene, next, past, sceneIndex) {
}

if (character.animations.length - 1 == i) {
sceneCode += helper.codePrepare(`.start()\n`, 0, 2 + spaceAmount, false)
sceneCode += helper.codePrepare('.start()\n', 0, 2 + spaceAmount, false)
} else {
sceneCode += helper.codePrepare(`
.setListener(object : Animator.AnimatorListener {
Expand Down Expand Up @@ -659,6 +659,17 @@ ${position.join('\n')}
textViewAuthor.layoutParams = layoutParamsAuthor\n\n`, 4, 0, false
)

/*
Will execute if:
- There are no scenes OR
- The old scene has no speech OR
- The current scene has subScenes OR
- The current scene has a speech author OR
- The VN has scenes AND the current scene has a speech author AND the old scene has no speech author
*/

if (
visualNovel.scenes.length == 0 ||
!oldScene?.speech ||
Expand Down Expand Up @@ -1075,9 +1086,8 @@ ${finishScene.join('\n\n')}${itemRemover.length != 0 ? itemRemover.join('\n\n')
scene = _AddResource(scene, { type: 'sdp', dp: '150', spaces: 4 })

let requireItems = [ '', '' ]
let i = 0

while (true) {
for (let i = 0; i < 2; i++) {
if (scene.subScenes[i].item?.require) {
requireItems[i] = helper.codePrepare(`
if (!items.contains(${helper.getItemId(scene.subScenes[0].item.require)})) {
Expand All @@ -1095,10 +1105,6 @@ ${finishScene.join('\n\n')}${itemRemover.length != 0 ? itemRemover.join('\n\n')
}\n\n`, 6, 0, false)
}
}

if (i == 1) break

i++
}

const subFunctionParams = _GetSceneParams(visualNovel.subScenes[scene.subScenes[0].scene], scene)
Expand Down
2 changes: 1 addition & 1 deletion platforms/main/achievements.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function init(options) {

function give(page, achievementId) {
if (!visualNovel.achievements.find((achievement) => achievement.id == achievementId))
helper.logFatal(`The achievement '${achievementId}' doesn't exist.`)
helper.logFatal(`The achievement '${achievementId}' doesn't exist.`)

if (page.achievements.find((achievement) => achievement.id == achievementId))
helper.logFatal(`The achievement '${achievementId}' was already given.`)
Expand Down

0 comments on commit 41881b3

Please sign in to comment.