#------------------------------------------------------------------------------#
# How to use #
#------------------------------------------------------------------------------#
# *AutoLight #
# MODE 0/2 #
# To use autolights, put a light- and/or shadow-map picture in the #
# folder ../Graphics/Pictures/ #
# Name to picture correct! Start with the, by you set, light- and/or #
# shadow-map name, followed by the corresponding map-ID. #
# Put the AutoLight mode to 0 or 2 to show light- and/or shadow-maps. #
# #
# MODE 1/2 #
# To use the spot, put your spotpicture in the folder ../Graphics/Pictures/ #
# and set the name correct! #
# Put the AutoLight mode to 1 or 2 to show the spot. #
# #
# #
# *EventLight #
# To make a event cast a light, give it a comment with the following code: #
# cast(*picture, *color, *opacity, *blend_type, *zoom) #
# All the parameters are optional. Default they are set to: #
# picture: Default, set in the module #
# color: White #
# opacity: 255 #
# blend_type: 1 #
# zoom: 100 #
# For the color you can choose: #
# - white #
# - red #
# - green #
# - blue #
# - yellow #
# - orange #
# - purple #
# - random (one of above, but not the same as it is at the moment (if set)) #
# #
#------------------------------------------------------------------------------#
#--------------------------#
# Customization AutoLights #
#--------------------------#
module AL
def check_existence(file)
format_list = [".png", ".jpeg", ".jpg"]
format_list.each do |format|
return true if FileTest.exist?("Graphics/Pictures/#{file}#{format}")
end
return false
end
def create_lights
@viewport = Viewport.new(0, 0, 544, 416)
case Mode
when 0
draw_light
draw_shadow
when 1
draw_spot
when 2
draw_light
draw_shadow
draw_spot
end
update
end
def dispose
case Mode
when 0
dispose_light
dispose_shadow
when 1
dispose_spot
when 2
dispose_light
dispose_shadow
dispose_spot
end
@viewport.dispose
end
def dispose_light
return if !(@light_exist and [email protected]?)
@light.dispose
end
def dispose_shadow
return if !(@shadow_exist and [email protected]?)
@shadow.dispose
end
def dispose_spot
return if !(@spot_exist and [email protected]?)
@spot.dispose
end
end
#--------------------------#
# Script eventlight engine #
#--------------------------#
class EventLight
attr_reader :event_lights
def initialize
create_autolights
end
def create_autolights
@event_lights = {}
$game_map.events.values.each do |event|
next if event.list == nil
event.list.each do |list|
if (list.code == 108 or list.code == 408) and
list.parameters[0].include?("cast")
data = eval(list.parameters[0])
el = Event_LightHolder.new(event, data)
settings(el, data)
@event_lights[event.id] = el
update
end
end
end
end
def cast(pic = EL::Default,
color = "white",
opacity = 255,
blend_type = 1,
zoom = 100,
range = 0)
return [pic, color, opacity, blend_type, zoom, range]
end
#---------------#
# Read event_id #
#---------------#
class Game_Interpreter
attr_reader :event_id
end
#---------------------#
# Change Functions AL #
#---------------------#
module AL
def self.mode(val)
@val = val
return if !fixnum?(@val)
eval("AL::Mode = #{@val}")
$AutoLight.dispose
$AutoLight = AutoLight.new
end
def self.light(parm, val)
@val = val
case parm.capitalize
when "Name"; @val.to_s!
when "Visible"; return if !boolean?(@val)
else; return if !fixnum?(@val)
end
eval("AL::Light::#{parm.capitalize} = #{@val}")
$AutoLight.dispose
$AutoLight = AutoLight.new
end
def self.shadow(parm, val)
@val = val
case parm.capitalize
when "Name"; @val.to_s!
when "Visible"; return if !boolean?(@val)
else; return if !fixnum?(@val)
end
eval("AL::Shadow::#{parm.capitalize} = #{@val}")
$AutoLight.dispose
$AutoLight = AutoLight.new
end
def self.spot(parm, val)
@val = val
case parm.capitalize
when "Name"; @val.to_s!
when "Visible"; return if !boolean?(@val)
else; return if !fixnum?(@val)
end
eval("AL::Spot::#{parm.capitalize} = #{@val}")
$AutoLight.dispose
$AutoLight = AutoLight.new
end
def self.flicker(parm, val)
@val = val
return if !fixnum?(@val)
eval("AL::Spot::Flicker::#{parm.capitalize} = #{@val}")
$AutoLight.dispose
$AutoLight = AutoLight.new
end
end
#---------------------#
# Change Functions EL #
#---------------------#
module EL
def self.bitmap(val, index = nil)
@val = val
index = $game_map.interpreter.event_id if index == nil
$EventLight.event_lights[index].el.bitmap = Cache.picture(@val)
end
def self.color(val, index = nil)
@val = val
index = $game_map.interpreter.event_id if index == nil
old_value = $EventLight.event_lights[index].el.tone
$EventLight.event_lights[index].el.tone = pick_color(@val, old_value)
end
def self.opacity(val, index = nil)
@val = val
return if !fixnum?(@val)
index = $game_map.interpreter.event_id if index == nil
$EventLight.event_lights[index].el.opacity = @val
end
def self.blend(val, index = nil)
@val = val
return if !fixnum?(@val)
index = $game_map.interpreter.event_id if index == nil
$EventLight.event_lights[index].el.blend_type = @val
end
def self.visible(val, index = nil)
@val = val
return if !boolean?(@val)
index = $game_map.interpreter.event_id if index == nil
$EventLight.event_lights[index].el.visible = @val
end
def self.zoom(val, index = nil)
@val = val
return if !fixnum?(@val)
index = $game_map.interpreter.event_id if index == nil
$EventLight.event_lights[index].el.zoom_x = @val / 100.0
$EventLight.event_lights[index].el.zoom_y = @val / 100.0
end
def self.range(val, index = nil)
@val = val
return if !fixnum?(@val)
index = $game_map.interpreter.event_id if index == nil
$EventLight.event_lights[index].range = @val
end
# String/Fixnum -> Boolean
def boolean?(val)
return false if !(val.is_a? FalseClass or
val.is_a? TrueClass or
val.is_a? String or
val.is_a? Fixnum)
@val = eval(val) if val.is_a? String
if val.is_a? Fixnum or @val.is_a? Fixnum
val = @val if @val.is_a? Fixnum
if val == -1 or val == 1; @val = true
elsif val == 0; @val = false
else; return false
end
end
return true
end
# String -> Fixnum
def fixnum?(val)
return false if !(val.is_a? Fixnum or val.is_a? String)
@val = val.to_i if val.is_a? String
return true
end