-
Notifications
You must be signed in to change notification settings - Fork 12
/
Multiple Animations Display.rb
284 lines (253 loc) · 8.79 KB
/
Multiple Animations Display.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# =============================================================================
# TheoAllen - Multiple Animations Display
# Version : 1.1
# Contact : Discord: @Theo#3034 / Twitter: @theolized
# -----------------------------------------------------------------------------
# Requested by : LadyMinerva
# =============================================================================
($imported ||= {})[:Theo_MultiAnime] = true
# =============================================================================
# Change Logs:
# -----------------------------------------------------------------------------
# 2018.12.02 - Added feature to play multiple animations in map consecutively
# by using show animation in eventing.
# 2014.06.25 - Ported from TSBS addons. Now can be used independently
# - Got rid some unused codes
# 2014.06.23 - Multiple animation on animation guard
# 2014.05.13 - Fixed wrong animation flash target
# 2014.05.02 - Finished script
# =============================================================================
=begin
-------------------------------------------------------------------
Introduction :
By default, the animation only can hold up to 16 pictures. It's sometimes
prevent you to do some crazy animations. By adding this script, now you can
merge two different animations, mix them in a single animation call. However,
you still can not see them in editor at once. So, use your imagination =D
-------------------------------------------------------------------
How to use :
Put this script below material but above main.
There're two ways to setting up animation. The first way is to deal with
the configuration below. The second one is to add notetag in animation name
since there's no notebox in animation database.
The notetag is
<link: id,id,id>
id is an animation id that will be linked / merged to current animation. You
may add it as many as you want.
-------------------------------------------------------------------
Terms of use :
Credit me, TheoAllen. You are free to edit this script by your own. As long
as you don't claim it yours. For commercial purpose, don't forget to give me
a free copy of the game.
=end
# =============================================================================
# Configuration
# =============================================================================
module Theo
module MultiAnime
# ------------------------------------------------------------------------
# In script configuration. Record the animation links here. You make put
# multiple animation link by put them in array / inside [].
#
# Format :
# anim_id => link,
# anim_id => [link1, link2, link3],
#
# Anim_id is animation in database as a base which hold animation links
# to call other animation. Don't forget to add comma!
# ------------------------------------------------------------------------
AnimeList = {
89 => 92,
# Add more here
} # <-- dont touch
# ------------------------------------------------------------------------
# ------------------------------------------------------------------------
# Regular expression to read the notetag in animation name in database.
# Do not touch if you don't understand Ruby REGEXP
Regex = /<link\s*:\s*(.+)>/i
# ------------------------------------------------------------------------
end
end
#==============================================================================
# End Configuration
#==============================================================================
class RPG::Animation
def anime_links
return @anime_links if @anime_links
@anime_links = []
if name[Theo::MultiAnime::Regex]
$1.split(/,/).each do |anim_id|
@anime_links.push(anim_id.to_i)
end
end
return @anime_links
end
end
#==============================================================================
# Sprite multiple animation
#------------------------------------------------------------------------------
class Sprite_MultiAnime < Sprite_Base
def initialize(viewport, ref_sprite, anime, flip = false)
super(viewport)
@ref_sprite = ref_sprite
update_reference_sprite
start_animation(anime, flip)
end
def update
update_reference_sprite
super
dispose if !animation?
end
def update_reference_sprite
src_rect.set(@ref_sprite.src_rect)
self.ox = @ref_sprite.ox
self.oy = @ref_sprite.oy
self.x = @ref_sprite.x
self.y = @ref_sprite.y
self.z = @ref_sprite.z
end
# Overwrite animation process timing
def animation_process_timing(timing)
timing.se.play unless @ani_duplicated
case timing.flash_scope
when 1
@ref_sprite.flash(timing.flash_color, timing.flash_duration * @ani_rate)
when 2
if viewport && !@ani_duplicated
viewport.flash(timing.flash_color, timing.flash_duration * @ani_rate)
end
when 3
@ref_sprite.flash(nil, timing.flash_duration * @ani_rate)
end
end
end
#==============================================================================
# Sprite Battler
#------------------------------------------------------------------------------
class Sprite_Battler
attr_reader :multianimes
alias theo_multianim_init initialize
def initialize(viewport, battler = nil)
@multianimes = []
theo_multianim_init(viewport, battler)
end
alias theo_multianime_start_anim start_animation
def start_animation(anime, flip = false)
if @animation
spr_anim = Sprite_MultiAnime.new(viewport, self, anime, flip)
multianimes.push(spr_anim)
else
theo_multianime_start_anim(anime, flip)
multianime = @animation.anime_links
check_multi = Theo::MultiAnime::AnimeList[@animation.id]
if check_multi.is_a?(Array)
multianime += check_multi
elsif check_multi
multianime += [check_multi]
end
multianime.each do |ma|
start_animation($data_animations[ma], flip)
end
end
end
alias theo_multianim_update update
def update
theo_multianim_update
multianimes.delete_if do |anime|
anime.update
anime.disposed?
end
end
alias theo_multianim_dispose dispose
def dispose
theo_multianim_dispose
multianimes.each do |anime|
anime.dispose
end
end
def animation?
@animation || !multianimes.empty?
end
alias theo_multianime_update_anim update_animation
def update_animation
return unless @animation
theo_multianime_update_anim
end
end
#==============================================================================
# Sprite Character
#------------------------------------------------------------------------------
class Sprite_Character
attr_reader :multianimes
alias theo_multianim_init initialize
def initialize(viewport, char = nil)
@multianimes = []
theo_multianim_init(viewport, char)
end
alias theo_multianime_start_anim start_animation
def start_animation(anime, flip = false)
if @animation
spr_anim = Sprite_MultiAnime.new(viewport, self, anime, flip)
multianimes.push(spr_anim)
else
theo_multianime_start_anim(anime, flip)
multianime = @animation.anime_links
check_multi = Theo::MultiAnime::AnimeList[@animation.id]
if check_multi.is_a?(Array)
multianime += check_multi
elsif check_multi
multianime += [check_multi]
end
multianime.each do |ma|
start_animation($data_animations[ma], flip)
end
end
end
alias theo_multianim_update update
def update
theo_multianim_update
multianimes.delete_if do |anime|
anime.update
anime.disposed?
end
end
alias theo_multianim_dispose dispose
def dispose
theo_multianim_dispose
multianimes.each do |anime|
anime.dispose
end
end
def animation?
@animation || !multianimes.empty?
end
alias theo_multianime_update_anim update_animation
def update_animation
return unless @animation
theo_multianime_update_anim
end
end
#==============================================================================
# Game Character
#------------------------------------------------------------------------------
class Game_Character
# Overwrite animation_id=
def animation_id=(id)
@animation_id = id
return if id == 0
play_animation
end
def play_animation
spr = SceneManager.scene.instance_variable_get("@spriteset")
return unless spr
spr.find_char(self).start_animation($data_animations[@animation_id])
end
end
#==============================================================================
# Spriteset Map
#------------------------------------------------------------------------------
class Spriteset_Map
def find_char(char)
return @character_sprites.find {|spr| spr.character == char}
end
end