#==============================================================================
# ** Mapping Layers
#------------------------------------------------------------------------------
# SephirothSpawn
# Version 2.1
# 2007-07-25
# SDK : Version 2.0+, Parts I & II
#------------------------------------------------------------------------------
# * Version History :
#
# Version 1 ---------------------------------------------------- ()
# Version 2 ---------------------------------------------------- (2007-04-03)
# - Update : Rescripted entire system.
# Version 2.1 ------------------------------------------------- (2007-07-25)
# - Update : Updated code. Added script calls.
#------------------------------------------------------------------------------
# * Requirements :
#
# Method & Class Library 2.1+ (When Using Keyboard Buttons)
#------------------------------------------------------------------------------
# * Description :
#
# This script was designed as a debugging tool or just for fun. It allows
# you to turn off "map layers" with the press of a button or script call.
# You may customize any Input or Keyboard button, and assign it to any of
# the following layer types :
#
# 'viewport1' 'viewport2' 'viewport3'
# 'layer1' 'layer2' 'layer3'
# 'fog' 'panorama' 'weather'
# 'tilemap' 'sprites' 'pictures' 'timer'
#------------------------------------------------------------------------------
# * Instructions :
#
# Place The Script Below the SDK and Above Main.
#------------------------------------------------------------------------------
# * Customization :
#
# Customizing Input keys that toggle layers or objects
# - Input_Toggles[<object>] = <Input::Constant>
#
# Customizing Keyboard keys that toggle layers or objects
# - Keyboard_Toggles[<object>] = <Keyboard::Constant>
#
# See Description for layer or object list. See * Toggle Buttons for further
# instructions.
#------------------------------------------------------------------------------
# * Syntax :
#
# Setting /Reading Spriteset and Tilemap to Mapping Layers Module
# - Mapping_Layers.spriteset = spriteset object
# - Mapping_Layers.tilemap = tilemap object
#
# Toggling Layers
# - Mapping_Layers.toggle_spriteset_object(<object>)
# - Mapping_Layers.toggle_tilemap_object(<object>)
#
# 'layer1', 'layer2' and 'layer3' require the toggle tilemap method.
# All other objects use toggle spriteset object method.
#==============================================================================
#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
SDK.log('Mapping Layers', 'SephirothSpawn', 2.1, '2007-07-25')
SDK.check_requirements(2.0, [2])
#------------------------------------------------------------------------------
# * Begin SDK Enable Test
#------------------------------------------------------------------------------
if SDK.enabled?('Mapping Layers')
#==============================================================================
# ** Mapping_Layers
#==============================================================================
module Mapping_Layers
#--------------------------------------------------------------------------
# * Toggle Buttons
#
# Input Toggles (Uses Default Input Module)
# - Input_Toggles = { 'layername' => Input::Constant, ... }
#
# Keyboard Toggles (Uses Keyboard Module)
# - Keyboard_Toggles = 'layername' => Keyboard::Constant, ... }
#
# * Input Button List
#
# DOWN, LEFT, RIGHT, UP, SHIFT, CTRL, ALT,
# A, B, C, X, Y, Z, L, R, F5, F6, F7, F8, F9
#
# * Keyboard Button List
#
# (See Keyboard Module Constant List)
#
# * Layer Names List
#
# 'viewport1' 'viewport2' 'viewport3'
# 'layer1' 'layer2' 'layer3'
# 'fog' 'panorama' 'weather'
# 'tilemap' 'sprites' 'pictures' 'timer'
#--------------------------------------------------------------------------
Input_Toggles = {}
Input_Toggles['layer1'] = Input::F5
Input_Toggles['layer2'] = Input::F6
Input_Toggles['layer3'] = Input::F7
Keyboard_Toggles = {}
#--------------------------------------------------------------------------
# * Read Spriteset
#--------------------------------------------------------------------------
def self.spriteset
return @spriteset
end
#--------------------------------------------------------------------------
# * Write Spriteset
#--------------------------------------------------------------------------
def self.spriteset=(spriteset)
@spriteset = spriteset
end
#--------------------------------------------------------------------------
# * Read Tilemap
#--------------------------------------------------------------------------
def self.tilemap
return @tilemap
end
#--------------------------------------------------------------------------
# * Write Tilemap
#--------------------------------------------------------------------------
def self.tilemap=(tilemap)
@tilemap = tilemap
end
#--------------------------------------------------------------------------
# * Toggle Spriteset Object
#--------------------------------------------------------------------------
def self.toggle_spriteset_object(key, ss = @spriteset)
# Return if Nil Spriteset
return if ss.nil?
# Keys List
ks = %w(viewport1 viewport2 viewport3 fog panorama weather tilemap timer)
# Instance Variables
instances = [ss.viewport1, ss.viewport2, ss.viewport3, ss.fog,
ss.panorama, ss.weather, ss.tilemap, ss.timer_sprite]
# If Key is 'Sprites'
if key.downcase == 'sprites'
# Update all Sprites in List
ss.character_sprites.each { |s| s.visible = !s.visible }
# If Key is 'Sprites'
elsif key.downcase == 'pictures'
# Update all Sprites in List
ss.picture_sprites.each { |s| s.visible = !s.visible }
elsif ks.include?(key.downcase)
# Gets Index
index = ks.index(key)
# Change Visibleness
instances[index].visible = !instances[index].visible
end
end
#--------------------------------------------------------------------------
# * Toggle Tilemap Object
#--------------------------------------------------------------------------
def self.toggle_tilemap_object(key, tm = @tilemap)
# Return if Nil Tilemap
return if tm.nil?
# Gets Layer Keys
keys = %w(layer1 layer2 layer3)
# Return if not layer
return unless keys.include?(key.downcase)
# Create Map Data If Nil Map Data
@map_data = {} if @map_data.nil?
# Gets Z layer
z = keys.index(layer)
# If Layer Already Created
if @map_data.has_key?(z) && @map_data[z] != nil
# Pass Through Tilemap X
for x in 0...tm.map_data.xsize
# Pass Through Tilemap Y
for y in 0...tm.map_data.ysize
# Restore Map Data
tm.map_data[x, y, z] = @map_data[z][x, y]
end
end
# Clear Map Layer Data
@map_data[z] = nil
# If Layer Not Created
else
# Create Layer Data
@map_data[z] = Table.new(tm.map_data.xsize,
tm.map_data.ysize)
# Pass Through Tilemap X
for x in 0...tm.map_data.xsize
# Pass Through Tilemap Y
for y in 0...tm.map_data.ysize
# Store Map Data
@map_data[z][x, y] = tm.map_data[x, y, z]
# Clear Map Data
tm.map_data[x, y, z] = 0
end
end
end
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def self.ss_update(ss = @spriteset)
# Keys List
ks = %w(viewport1 viewport2 viewport3 fog panorama weather tilemap timer)
# Instance Variables
instances = [ss.viewport1, ss.viewport2, ss.viewport3, ss.fog,
ss.panorama, ss.weather, ss.tilemap, ss.timer_sprite]
# Pass Through Input Buttons
Input_Toggles.each do |key, button|
# If Button Pressed
if Input.trigger?(button)
# If Key is 'Sprites'
if key == 'sprites'
# Update all Sprites in List
ss.character_sprites.each { |s| s.visible = !s.visible }
# If Key is 'Sprites'
elsif key == 'pictures'
# Update all Sprites in List
ss.picture_sprites.each { |s| s.visible = !s.visible }
elsif ks.include?(key)
# Gets Index
index = ks.index(key)
# Change Visibleness
instances[index].visible = !instances[index].visible
end
end
end
# If Keyboard Module Enabled
if SDK.enabled?('Method & Class Library', 2.1)
# Pass Through Keyboard Buttons
Keyboard_Toggles.each do |key, button|
# If Button Pressed
if Keyboard.trigger?(button)
# If Key is 'Sprites'
if key == 'sprites'
# Update all Sprites in List
ss.character_sprites.each { |s| s.visible = !s.visible }
# If Key is 'Sprites'
elsif key == 'pictures'
# Update all Sprites in List
ss.picture_sprites.each { |s| s.visible = !s.visible }
elsif ks.include?(key)
# Gets Index
index = ks.index(key)
# Change Visibleness
instances[index].visible = !instances[index].visible
end
end
end
end
end
#--------------------------------------------------------------------------
# * Frame Update : Tilemap Layers
#--------------------------------------------------------------------------
def self.tml_update(tilemap = @spriteset.tilemap)
# Gets Layer Keys
keys = %w(layer1 layer2 layer3)
# Pass Through Each Layer
keys.each do |layer|
# Turn Off Switch Layer
switch_layer = false
# If Input Key Defined
if Input_Toggles.has_key?(layer)
# If Key Pressed
if Input.trigger?(Input_Toggles[layer])
# Turn On Switch Layer
switch_layer = true
end
end
# If Keyboard Module Enabled
if SDK.enabled?('Method & Class Library', 2.1)
# If Keyboard Key Defined
if Keyboard_Toggles.has_key?(layer)
# If Key Pressed
if Keyboard.trigger?(Keyboard_Toggles[layer])
# Turn On Switch Layer
switch_layer = true
end
end
end
# If Switch Layer
if switch_layer
# Create Map Data If Nil Map Data
@map_data = {} if @map_data.nil?
# Gets Z layer
z = keys.index(layer)
# If Layer Already Created
if @map_data.has_key?(z) && @map_data[z] != nil
# Pass Through Tilemap X
for x in 0...tilemap.map_data.xsize
# Pass Through Tilemap Y
for y in 0...tilemap.map_data.ysize
# Restore Map Data
tilemap.map_data[x, y, z] = @map_data[z][x, y]
end
end
# Clear Map Layer Data
@map_data[z] = nil
# If Layer Not Created
else
# Create Layer Data
@map_data[z] = Table.new(tilemap.map_data.xsize,
tilemap.map_data.ysize)
# Pass Through Tilemap X
for x in 0...tilemap.map_data.xsize
# Pass Through Tilemap Y
for y in 0...tilemap.map_data.ysize
# Store Map Data
@map_data[z][x, y] = tilemap.map_data[x, y, z]
# Clear Map Data
tilemap.map_data[x, y, z] = 0
end
end
end
end
end
end
#--------------------------------------------------------------------------
# * Clear Map Data
#--------------------------------------------------------------------------
def self.clear_map_data
@map_data = {}
end
end
#==============================================================================
# ** Spriteset_Map
#==============================================================================
class Spriteset_Map
#--------------------------------------------------------------------------
# * Public Instance Variables
#--------------------------------------------------------------------------
attr_reader :viewport1, :viewport2, :viewport3, :fog, :panorama, :weather
attr_reader :tilemap, :character_sprites, :picture_sprites, :timer_sprite
#--------------------------------------------------------------------------
# * Alias Listings
#--------------------------------------------------------------------------
alias_method :seph_mappinglayers_ssmap_init_tm, :init_tilemap
alias_method :seph_mappinglayers_ssmap_update, :update
#--------------------------------------------------------------------------
# * Object Initialization : Tilemap
#--------------------------------------------------------------------------
def init_tilemap
# Original Initialization
seph_mappinglayers_ssmap_init_tm
# Clear Mapping Layers Map Data
Mapping_Layers.clear_map_data
# Set Spriteset
Mapping_Layers.spriteset = self
# Set Tilemap
Mapping_Layers.tilemap = @tilemap
end
#--------------------------------------------------------------------------
# * Frame Update
#--------------------------------------------------------------------------
def update
# Update Mapping Layers Module
Mapping_Layers.ss_update
# Update Tilemap Layers
Mapping_Layers.tml_update
# Original Update
seph_mappinglayers_ssmap_update
end
end
#--------------------------------------------------------------------------
# * End SDK Enable Test
#--------------------------------------------------------------------------
end