Skip to content

Commit

Permalink
option to add full frame hurtboxes
Browse files Browse the repository at this point in the history
  • Loading branch information
TwilCynder committed Mar 28, 2024
1 parent 55a27bc commit 87b4026
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 11 deletions.
17 changes: 17 additions & 0 deletions editor/javaEditor/src/UI/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,14 @@ public void actionPerformed(ActionEvent e) {
}
};

Action makeDefaultHurtboxesAction = new AbstractAction("Make default hurtboxes") {
@Override
public void actionPerformed(ActionEvent e) {
makeFullFrameHurtboxes();
}

};

Action changeSourceImageAction = new AbstractAction("Change animation source image") {
@Override
public void actionPerformed(ActionEvent e) {
Expand Down Expand Up @@ -1184,6 +1192,7 @@ private void initMenus(){
animationGamedataMenuItems.add(new JMenuItem(changeDescriptorAction));
animationGamedataMenuItems.add(new JMenuItem(renameSourceImageAction));
animationGamedataMenuItems.add(new JMenuItem(changeSourceImageAction));
animationGamedataMenuItems.add(new JMenuItem(makeDefaultHurtboxesAction));

championGamedataMenuItems.add(new JMenuItem(renameChampionDescriptorAction));

Expand Down Expand Up @@ -1390,6 +1399,14 @@ private boolean changeCurrentAnimSourceImage() throws WindowStateException{
return changeAnimSourceImage(anim);
}

private boolean makeFullFrameHurtboxes() {
EntityAnimation anim = getCurrentEntityAnimation();
anim.fullFramehurtboxes();
notifyDataModified();
updateVisualEditor();
return true;
}

private boolean renameChampionDescriptor(Champion champion){
return (new RenameChampionDescriptorForm(this, champion).showForm()) == JOptionPane.OK_OPTION;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ public void actionPerformed(ActionEvent e){
item = new JMenuItem("Move origin here");
item.addActionListener(createMoveOriginActionListener(this));
add(item);

item = new JMenuItem("Create default hurtboxes");
item.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
makeDefaultHurtboxes();
cancelSelection(displayer);
}
});
add(item);
}

@Override
Expand Down Expand Up @@ -204,6 +213,15 @@ private void createHurtbox(Rectangle rect){
notifyDataModified();
}

private void makeDefaultHurtboxes(){
EntityAnimationDisplayer editor = getEditor();
EntityAnimation anim = editor.getAnimation();

anim.fullFramehurtboxes();

notifyDataModified();
}

private void createHitbox(Rectangle rect){
EntityAnimationDisplayer editor = getEditor();
Frame frame = editor.getCurrentFrame();
Expand Down
1 change: 1 addition & 0 deletions editor/javaEditor/src/UI/forms/NewAnimationForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ protected boolean confirm(){

try {
currentRessourcePath.addAnimation(champion, animName, nbFrames, sourceImageFilename, descriptorFilename);
editor.notifyDataModified();
editor.updateAnimations();
currentData.printAnimations();
} catch (RessourceException ex){
Expand Down
15 changes: 15 additions & 0 deletions editor/javaEditor/src/gamedata/EntityAnimation.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import gamedata.EntityFrame.FrameMovementAxis;
import gamedata.exceptions.FrameOutOfBoundsException;
import gamedata.exceptions.GameDataException;
import gamedata.exceptions.WhatTheHellException;
import gamedata.parsers.AnimationParser;

import java.awt.Image;
Expand Down Expand Up @@ -227,6 +228,20 @@ public static void moveOriginY(Frame frame, EntityFrame entity_frame, int new_y)
shiftElements(entity_frame, diff);
}

public void fullFramehurtboxes(){
for (int i = 0; i < this.getNbFrames(); i++){
Frame frame; EntityFrame entity_frame;
try {
frame = this.getFrame(i);
entity_frame = this.getEntityFrame(i);
} catch (FrameOutOfBoundsException e){
throw new WhatTheHellException("Supposedly safe array iteration went out of bounds", e);
}

entity_frame.fullFrameHurtbox(frame);
}
}

@Override
public AnimationType getType(){
return AnimationType.ENTITY;
Expand Down
12 changes: 1 addition & 11 deletions editor/javaEditor/src/gamedata/parsers/AnimationParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -300,17 +300,7 @@ private static void parseAnimationDescriptor(Animation anim, String descriptor_f
fields = StringHelper.split(line, " ");
if (fields.length > 1 && fields[1].equals("all")){
EntityAnimation eanim = estate.getAnimation();
for (int i = 0; i < anim.getNbFrames(); i++){
Frame frame; EntityFrame entity_frame;
try {
frame = anim.getFrame(i);
entity_frame = eanim.getEntityFrame(i);
} catch (FrameOutOfBoundsException e){
throw new WhatTheHellException("Supposedly safe array iteration went out of bounds", e);
}

entity_frame.fullFrameHurtbox(frame);
}
eanim.fullFramehurtboxes();
} else {

if (fields.length < 2){
Expand Down

0 comments on commit 87b4026

Please sign in to comment.