Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Sprite Yeet PR (ie safely remove sprites) #24

Merged
merged 7 commits into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/main/kotlin/rhmodding/bread/editor/BCCADEditor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,17 @@ class BCCADEditor(app: Bread, mainPane: MainPane, dataFile: File, data: BCCAD, i

override fun removeSprite(sprite: ISprite) {
if (sprite is Sprite) {
val index = data.sprites.indexOf(sprite).toUShort()

for (anim in data.animations) {
for (step in anim.steps) {
if (step.spriteIndex == index) {
step.spriteIndex = 0.toUShort()
} else if (step.spriteIndex > index) {
step.spriteIndex = (step.spriteIndex - 1.toUShort()).toUShort()
}
}
}
data.sprites -= sprite
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/kotlin/rhmodding/bread/editor/BRCADEditor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,17 @@ class BRCADEditor(app: Bread, mainPane: MainPane, dataFile: File, data: BRCAD, i

override fun removeSprite(sprite: ISprite) {
if (sprite is Sprite) {
val index = data.sprites.indexOf(sprite).toUShort()

for (anim in data.animations) {
for (step in anim.steps) {
if (step.spriteIndex == index) {
step.spriteIndex = 0.toUShort()
} else if (step.spriteIndex > index) {
step.spriteIndex = (step.spriteIndex - 1.toUShort()).toUShort()
}
}
}
data.sprites -= sprite
}
}
Expand Down
57 changes: 49 additions & 8 deletions src/main/kotlin/rhmodding/bread/editor/SpritesTab.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import javafx.scene.layout.*
import javafx.scene.paint.Color
import javafx.stage.Modality
import javafx.stage.Stage
import rhmodding.bread.model.bccad.Animation as BCCADAnimation
import rhmodding.bread.model.IDataModel
import rhmodding.bread.model.ISprite
import rhmodding.bread.model.ISpritePart
Expand Down Expand Up @@ -122,15 +123,55 @@ open class SpritesTab<F : IDataModel>(editor: Editor<F>) : EditorSubTab<F>(edito
children += Button("Remove").apply {
setOnAction {
if (data.sprites.size > 1) {
val alert = Alert(Alert.AlertType.CONFIRMATION)
editor.app.addBaseStyleToDialog(alert.dialogPane)
alert.title = "Remove this sprite?"
alert.headerText = "Remove this sprite?"
alert.contentText = "Are you sure you want to remove this sprite?\nYou won't be able to undo this action."
if (alert.showAndWait().get() == ButtonType.OK) {
editor.removeSprite(currentSprite)
updateSpriteSpinners(false)
// Check every step because at this point we don't know if the sprite is used in any anims
var cancel = false
var isbreak = false
val index = data.sprites.indexOf(currentSprite).toUShort()
for (anim in data.animations) {
for (step in anim.steps) {
if (step.spriteIndex == index) {
val alert = Alert(Alert.AlertType.CONFIRMATION).apply {
editor.app.addBaseStyleToDialog(dialogPane)
if (anim is BCCADAnimation)
title = "Sprite used in animation " + anim.name
else
title = "Sprite used in animation " + data.animations.indexOf(anim).toString()
headerText = "Sprite is currently used in an animation"
contentText = "Are you absolutely sure you want to remove this sprite?\nThe animation step(s) will be set to sprite 0 if you do."
}
if (alert.showAndWait().get() == ButtonType.OK) {
isbreak = true
break
}
else {
cancel = true
break
}
}
}
if (isbreak || cancel) break
}

if (!cancel) {
if (!isbreak) {
// This way, the number of alert boxes is reduced to 1 always
val alert = Alert(Alert.AlertType.CONFIRMATION).apply {
editor.app.addBaseStyleToDialog(dialogPane)
title = "Remove this sprite?"
headerText = "Remove this sprite?"
contentText = "Are you sure you want to remove this sprite?\nYou won't be able to undo this action."
}
if (alert.showAndWait().get() == ButtonType.OK) {
editor.removeSprite(currentSprite)
updateSpriteSpinners(false)
}
} else {
editor.removeSprite(currentSprite)
updateSpriteSpinners(false)
}

}

}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/rhmodding/bread/util/Credits.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ object Credits {
Credit("meuol", "https://www.youtube.com/channel/UCNAUWWq3RKyGDHzBuKgEcPg"),
Credit("MF5K", "https://www.youtube.com/user/MrMariofan2020"),
Credit("kimbjo", "https://github.com/oddMLan"),
Credit("CebolaBros64", "https://github.com/CebolaBros64")
Credit("CebolaBros64", "https://github.com/CebolaBros64"),
Credit("patataofcourse", "https://github.com/patataofcourse")
)
}

Expand Down