Skip to content

Commit 555b0d7

Browse files
authored
Add support for oversized weapons (#11)
Add support for oversized weapons
1 parent cab8d79 commit 555b0d7

File tree

5 files changed

+122
-78
lines changed

5 files changed

+122
-78
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ func _ready():
4343
player.play(LPCAnimatedSprite2D.LPCAnimation.WALK_UP)
4444
```
4545

46+
## Support for Oversized Weapons
47+
Just select the appropriate Sprite Type
48+
49+
If using component sprites rather than a a pre-built spritesheet, pay attention to the order in which they are configured as it will influence visibility.
50+
4651
## Version number
4752

4853
I choose this type of version to match the Godot version plus the release version number of the plugin:

addons/LPCAnimatedSprite/LPCAnimatedSprite2D.gd

Lines changed: 25 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -3,64 +3,9 @@ extends Node2D
33

44
class_name LPCAnimatedSprite2D
55

6-
const Framerate:float = 10.0
7-
var AnimationData:Array[LPCAnimationData] = [
8-
LPCAnimationData.new(7,"CAST_UP",0,false),
9-
LPCAnimationData.new(7,"CAST_LEFT",1,false),
10-
LPCAnimationData.new(7,"CAST_DOWN",2,false),
11-
LPCAnimationData.new(7,"CAST_RIGHT",3,false),
12-
LPCAnimationData.new(8,"THRUST_UP",4,false),
13-
LPCAnimationData.new(8,"THRUST_LEFT",5,false),
14-
LPCAnimationData.new(8,"THRUST_DOWN",6,false),
15-
LPCAnimationData.new(8,"THRUST_RIGHT",7,false),
16-
LPCAnimationData.new(8,"WALK_UP",8,true),
17-
LPCAnimationData.new(8,"WALK_LEFT",9,true),
18-
LPCAnimationData.new(8,"WALK_DOWN",10,true),
19-
LPCAnimationData.new(8,"WALK_RIGHT",11,true),
20-
LPCAnimationData.new(6,"SLASH_UP",12,false),
21-
LPCAnimationData.new(6,"SLASH_LEFT",13,false),
22-
LPCAnimationData.new(6,"SLASH_DOWN",14,false),
23-
LPCAnimationData.new(6,"SLASH_RIGHT",15,false),
24-
LPCAnimationData.new(13,"SHOOT_UP",16,false),
25-
LPCAnimationData.new(13,"SHOOT_LEFT",17,false),
26-
LPCAnimationData.new(13,"SHOOT_DOWN",18,false),
27-
LPCAnimationData.new(13,"SHOOT_RIGHT",19,false),
28-
LPCAnimationData.new(6,"HURT_DOWN",20,false),
29-
LPCAnimationData.new(1,"IDLE_UP",8,false),
30-
LPCAnimationData.new(1,"IDLE_LEFT",9,false),
31-
LPCAnimationData.new(1,"IDLE_DOWN",10,false),
32-
LPCAnimationData.new(1,"IDLE_RIGHT",11,false)
33-
]
34-
356
@export var SpriteSheets:Array[LPCSpriteSheet]
7+
@export var DefaultAnimation:LPCAnimation = LPCAnimation.IDLE_DOWN
368

37-
#yeah, unfortunatly repeating above string list
38-
@export_enum("CAST_UP",
39-
"CAST_LEFT",
40-
"CAST_DOWN",
41-
"CAST_RIGHT",
42-
"THRUST_UP",
43-
"THRUST_LEFT",
44-
"THRUST_DOWN",
45-
"THRUST_RIGHT",
46-
"WALK_UP",
47-
"WALK_LEFT",
48-
"WALK_DOWN",
49-
"WALK_RIGHT",
50-
"SLASH_UP",
51-
"SLASH_LEFT",
52-
"SLASH_DOWN",
53-
"SLASH_RIGHT",
54-
"SHOOT_UP",
55-
"SHOOT_LEFT",
56-
"SHOOT_DOWN",
57-
"SHOOT_RIGHT",
58-
"HURT_DOWN",
59-
"IDLE_UP",
60-
"IDLE_LEFT",
61-
"IDLE_DOWN",
62-
"IDLE_RIGHT") var DefaultAnimation:int
63-
649
enum LPCAnimation {
6510
CAST_UP,
6611
CAST_LEFT,
@@ -86,17 +31,22 @@ enum LPCAnimation {
8631
IDLE_UP,
8732
IDLE_LEFT,
8833
IDLE_DOWN,
89-
IDLE_RIGHT
34+
IDLE_RIGHT,
35+
HURT_DOWN_LAST
9036
}
91-
37+
var AnimationNames:Array
9238
func _ready():
9339
if Engine.is_editor_hint() == false:
9440
LoadAnimations()
9541

9642
func play(animation: LPCAnimation):
97-
var sprites = get_children()
43+
var sprites = get_children() as Array[AnimatedSprite2D]
9844
for sprite in sprites:
99-
sprite.play(AnimationData[animation].Name)
45+
if sprite.sprite_frames.has_animation(AnimationNames[animation]):
46+
sprite.visible = true
47+
sprite.play(AnimationNames[animation])
48+
else:
49+
sprite.visible = false
10050

10151
func _notification(what):
10252
if what == NOTIFICATION_EDITOR_POST_SAVE:
@@ -106,38 +56,38 @@ func _enter_tree():
10656
if Engine.is_editor_hint():
10757
LoadAnimations()
10858

109-
11059
func LoadAnimations():
60+
AnimationNames = LPCAnimation.keys()
11161
var children = get_children();
11262
for child in children:
11363
remove_child(child)
11464

11565
for spriteSheet in SpriteSheets:
66+
if spriteSheet == null:
67+
push_warning("There are LPCSpriteSheets that are <empty> in the LPCAnimatedSprite2D panel")
68+
continue
11669
var animatedSprite = AnimatedSprite2D.new()
11770
animatedSprite.texture_filter = CanvasItem.TEXTURE_FILTER_NEAREST
118-
var spriteFrames = CreateSprites(spriteSheet.SpriteSheet)
71+
var spriteFrames = CreateSprites(spriteSheet)
11972
animatedSprite.frames = spriteFrames
12073
add_child(animatedSprite)
12174
if spriteSheet.Name == null || spriteSheet.Name == "":
12275
animatedSprite.name = "no_name"
12376
else:
12477
animatedSprite.name = spriteSheet.Name
12578
animatedSprite.owner = get_tree().edited_scene_root
126-
animatedSprite.play(AnimationData[DefaultAnimation].Name)
79+
play(DefaultAnimation)
12780

128-
func CreateSprites(spriteSheet:Texture):
81+
func CreateSprites(spriteSheet:LPCSpriteSheet):
12982
var spriteFrames = SpriteFrames.new()
13083
spriteFrames.remove_animation("default")
131-
for animationIndex in AnimationData.size():
132-
var data = AnimationData[animationIndex]
133-
var animationFrameCount = AnimationData[animationIndex].FrameCount
134-
var animationSpriteRow = AnimationData[animationIndex].Row
135-
var animationLoop = AnimationData[animationIndex].Loop
136-
AddAnimation(spriteSheet, spriteFrames, AnimationData[animationIndex])
84+
85+
for animationData in spriteSheet.AnimationData():
86+
AddAnimation(spriteSheet, spriteFrames, animationData)
13787
return spriteFrames
13888

139-
func AddAnimation(spriteSheet:Texture, spriteFrames:SpriteFrames, animationData:LPCAnimationData):
140-
if spriteSheet == null:
89+
func AddAnimation(spriteSheet:LPCSpriteSheet, spriteFrames:SpriteFrames, animationData:LPCAnimationData):
90+
if spriteSheet == null || spriteSheet.SpriteSheet == null:
14191
return
14292
if spriteFrames.has_animation(animationData.Name):
14393
spriteFrames.clear(animationData.Name)
@@ -147,8 +97,9 @@ func AddAnimation(spriteSheet:Texture, spriteFrames:SpriteFrames, animationData:
14797
if "WALK" in animationData.Name && col == 0:
14898
continue
14999
var atlasTexture = AtlasTexture.new()
150-
atlasTexture.atlas = spriteSheet
151-
atlasTexture.region = Rect2(64*col,64*animationData.Row,64,64)
100+
atlasTexture.atlas = spriteSheet.SpriteSheet
101+
var spriteSize:int = spriteSheet.Size()
102+
atlasTexture.region = Rect2(spriteSize*(col+animationData.Col), spriteSize*animationData.Row, spriteSize, spriteSize)
152103
spriteFrames.add_frame(animationData.Name, atlasTexture, 0.5)
153104
spriteFrames.set_animation_loop(animationData.Name, animationData.Loop)
154105
return spriteFrames

addons/LPCAnimatedSprite/LPCSpriteData.gd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ class_name LPCAnimationData
33
var FrameCount:int
44
var Name:String
55
var Row:int
6+
var Col:int
67
var Loop:bool
7-
func _init(frameCount:int, name:String, row:int, loop:bool):
8+
func _init(frameCount:int, name:String, row:int, col:int, loop:bool):
89
FrameCount = frameCount
910
Name = name
1011
Row = row
12+
Col = col
1113
Loop = loop
Lines changed: 88 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,94 @@
1+
@tool
12
extends Resource
23
class_name LPCSpriteSheet
34

45
@export var SpriteSheet:Texture
56
@export var Name:String = ""
67

7-
signal SpriteSheetChanged(texture:Texture)
8-
signal NameChanged
8+
@export var SpriteType: SpriteTypeEnum
9+
10+
enum SpriteTypeEnum {
11+
Normal,
12+
OversizeRod,
13+
OversizeThrust,
14+
OversizeSlash,
15+
OversizeWhip
16+
}
17+
18+
var NormalAnimationData:Array[LPCAnimationData] = [
19+
LPCAnimationData.new(7,"CAST_UP",0, 0,false),
20+
LPCAnimationData.new(7,"CAST_LEFT",1, 0,false),
21+
LPCAnimationData.new(7,"CAST_DOWN",2, 0,false),
22+
LPCAnimationData.new(7,"CAST_RIGHT",3, 0,false),
23+
LPCAnimationData.new(8,"THRUST_UP",4, 0,false),
24+
LPCAnimationData.new(8,"THRUST_LEFT",5, 0,false),
25+
LPCAnimationData.new(8,"THRUST_DOWN",6, 0,false),
26+
LPCAnimationData.new(8,"THRUST_RIGHT",7, 0,false),
27+
LPCAnimationData.new(8,"WALK_UP",8, 0,true),
28+
LPCAnimationData.new(8,"WALK_LEFT",9, 0,true),
29+
LPCAnimationData.new(8,"WALK_DOWN",10, 0,true),
30+
LPCAnimationData.new(8,"WALK_RIGHT",11, 0,true),
31+
LPCAnimationData.new(6,"SLASH_UP",12, 0,false),
32+
LPCAnimationData.new(6,"SLASH_LEFT",13, 0,false),
33+
LPCAnimationData.new(6,"SLASH_DOWN",14, 0,false),
34+
LPCAnimationData.new(6,"SLASH_RIGHT",15, 0,false),
35+
LPCAnimationData.new(6,"WHIP_UP",12, 0,false),
36+
LPCAnimationData.new(6,"WHIP_LEFT",13, 0,false),
37+
LPCAnimationData.new(6,"WHIP_DOWN",14, 0,false),
38+
LPCAnimationData.new(6,"WHIP_RIGHT",15, 0,false),
39+
LPCAnimationData.new(13,"SHOOT_UP",16, 0,false),
40+
LPCAnimationData.new(13,"SHOOT_LEFT",17, 0,false),
41+
LPCAnimationData.new(13,"SHOOT_DOWN",18, 0,false),
42+
LPCAnimationData.new(13,"SHOOT_RIGHT",19, 0,false),
43+
LPCAnimationData.new(6,"HURT_DOWN",20, 0,false),
44+
LPCAnimationData.new(1,"IDLE_UP",8, 0,false),
45+
LPCAnimationData.new(1,"IDLE_LEFT",9, 0,false),
46+
LPCAnimationData.new(1,"IDLE_DOWN",10, 0,false),
47+
LPCAnimationData.new(1,"IDLE_RIGHT",11, 0,false),
48+
LPCAnimationData.new(1,"HURT_DOWN_LAST",20, 5,false),
49+
]
50+
var SlashAnimationData:Array[LPCAnimationData] = [
51+
LPCAnimationData.new(6,"SLASH_UP",0, 0,false),
52+
LPCAnimationData.new(6,"SLASH_LEFT",1, 0,false),
53+
LPCAnimationData.new(6,"SLASH_DOWN",2, 0,false),
54+
LPCAnimationData.new(6,"SLASH_RIGHT",3, 0,false),
55+
]
56+
var ThrustAnimationData:Array[LPCAnimationData] = [
57+
LPCAnimationData.new(6,"THRUST_UP",0, 0,false),
58+
LPCAnimationData.new(6,"THRUST_LEFT",1, 0,false),
59+
LPCAnimationData.new(6,"THRUST_DOWN",2, 0,false),
60+
LPCAnimationData.new(6,"THRUST_RIGHT",3, 0,false),
61+
]
62+
var RodAnimationData:Array[LPCAnimationData] = [
63+
LPCAnimationData.new(6,"ROD_UP",0, 0,false),
64+
LPCAnimationData.new(6,"ROD_LEFT",1, 0,false),
65+
LPCAnimationData.new(6,"ROD_DOWN",2, 0,false),
66+
LPCAnimationData.new(6,"ROD_RIGHT",3, 0,false),
67+
]
68+
var WhipAnimationData:Array[LPCAnimationData] = [
69+
LPCAnimationData.new(8,"WHIP_UP",0, 0,false),
70+
LPCAnimationData.new(8,"WHIP_LEFT",1, 0,false),
71+
LPCAnimationData.new(8,"WHIP_DOWN",2, 0,false),
72+
LPCAnimationData.new(8,"WHIP_RIGHT",3, 0,false),
73+
]
74+
75+
func Size() -> int:
76+
match SpriteType:
77+
SpriteTypeEnum.Normal:
78+
return 64
79+
_:
80+
return 192
81+
func AnimationData() -> Array[LPCAnimationData]:
82+
match SpriteType:
83+
SpriteTypeEnum.Normal:
84+
return NormalAnimationData
85+
SpriteTypeEnum.OversizeRod:
86+
return RodAnimationData
87+
SpriteTypeEnum.OversizeThrust:
88+
return ThrustAnimationData
89+
SpriteTypeEnum.OversizeSlash:
90+
return SlashAnimationData
91+
SpriteTypeEnum.OversizeWhip:
92+
return WhipAnimationData
93+
_:
94+
return NormalAnimationData

addons/LPCAnimatedSprite/plugin.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="LPCAnimatedSprite"
44
description=""
55
author="Alexandro Trevisan"
6-
version="4.1.2.3"
6+
version="4.1.2.4"
77
script="LPCAnimatedSprite.gd"

0 commit comments

Comments
 (0)