#==============================================================================
# □ デバッグ用スクリプト(地形を元にリージョン塗りつぶし)
#==============================================================================
module Geo_To_Region
BACKUP_SAVE = false # バックアップの自動作成
CALL_BUTTON = :F5
end
#==============================================================================
# Game_Map拡張
#==============================================================================
class Game_Map
def geo_to_region(geo_num, region_id)
# 念のためリージョンIDのチェック
unless (0..63).include?(region_id)
p "リージョン番号が範囲外でした:#{region_id}"
return
end
# バックアップの作成
if Geo_To_Region::BACKUP_SAVE
i = 1
backup_filename = ""
loop do
backup_filename = sprintf("Data/Map%03d_backup%d.rvdata2", @map_id, i)
result = FileTest.exist?(backup_filename)
break unless result
i += 1
end
save_data(@map, backup_filename)
p "バックアップの作成:#{backup_filename}"
end
# リージョンの塗り潰し
for i in 0...width
for j in 0...height
if geo_num == autotile_type(i, j, 0)
@map.data[i,j,3] &= 0x00FF
@map.data[i,j,3] += region_id << 8
end
end
end
# データの保存、及び再セットアップ
map_filename = sprintf("Data/Map%03d.rvdata2", @map_id)
save_data(@map, map_filename)
p geo_num
p region_id
p "セーブ完了:#{map_filename}"
setup(@map_id)
end
end
#==============================================================================
# 実行確認用ウィンドウ
#==============================================================================
class Window_GeoToRegion < Window_Selectable
CONTENTS_MESSAGE = [
"プレイヤ位置を元にリージョン変更します",
"リージョン番号を指定してください",
"【↑:+1】【↓:-1】【→:+10】【←:-10】"
].freeze
attr_reader :region_id
#--------------------------------------------------------------------------
# ● オブジェクト初期化
#--------------------------------------------------------------------------
def initialize
super(0, 0, window_width, window_height)
@region_id = 0
update_placement
refresh
activate
end
#--------------------------------------------------------------------------
# ● 色調の更新
#--------------------------------------------------------------------------
def update_tone
self.tone.set(-255,64,0)
end
#--------------------------------------------------------------------------
# ● ウィンドウ位置の更新
#--------------------------------------------------------------------------
def update_placement
self.x = (Graphics.width - width) / 2
self.y = (Graphics.height - height) / 2
self.z = 1000
end
#--------------------------------------------------------------------------
# ● ウィンドウ幅の取得
#--------------------------------------------------------------------------
def window_width
return 400
end
#--------------------------------------------------------------------------
# ● ウィンドウ高さの取得
#--------------------------------------------------------------------------
def window_height
fitting_height(4)
end
#--------------------------------------------------------------------------
# ● アライメントの取得
#--------------------------------------------------------------------------
def alignment
return 1
end
#--------------------------------------------------------------------------
# ● リフレッシュ
#--------------------------------------------------------------------------
def refresh
contents.clear
rect = Rect.new(0,0,contents.width,line_height)
CONTENTS_MESSAGE.each do |mes|
draw_text(rect, mes, alignment)
rect.y += line_height
end
draw_text(rect,"リージョン番号:#{@region_id}", alignment)
end
#--------------------------------------------------------------------------
# ● カーソル移動可能判定
#--------------------------------------------------------------------------
def cursor_movable?
active && open?
end
#--------------------------------------------------------------------------
# ● カーソルを下に移動
#--------------------------------------------------------------------------
def cursor_down(wrap = false)
@region_id -= 1
@region_id += 64 if @region_id < 0
Sound.play_cursor
refresh
end
#--------------------------------------------------------------------------
# ● カーソルを上に移動
#--------------------------------------------------------------------------
def cursor_up(wrap = false)
@region_id += 1
@region_id %= 64
Sound.play_cursor
refresh
end
#--------------------------------------------------------------------------
# ● カーソルを右に移動
#--------------------------------------------------------------------------
def cursor_right(wrap = false)
@region_id += 10
@region_id %= 64
Sound.play_cursor
refresh
end
#--------------------------------------------------------------------------
# ● カーソルを左に移動
#--------------------------------------------------------------------------
def cursor_left(wrap = false)
@region_id -= 10
@region_id += 64 if @region_id < 0
Sound.play_cursor
refresh
end
end
class Scene_GeoToRegion < Scene_MenuBase
#--------------------------------------------------------------------------
# ● 開始処理
#--------------------------------------------------------------------------
def start
super
create_background
@geo_to_region_window = Window_GeoToRegion.new
@geo_to_region_window.set_handler(:ok, method(:on_ok))
@geo_to_region_window.set_handler(:cancel, method(:return_scene))
end
#--------------------------------------------------------------------------
# ● 終了処理
#--------------------------------------------------------------------------
def terminate
super
dispose_background
@geo_to_region_window.dispose
end
#--------------------------------------------------------------------------
# ● 決定時の処理
#--------------------------------------------------------------------------
def on_ok
geo_num = $game_map.autotile_type($game_player.x,$game_player.y,0)
region_id = @geo_to_region_window.region_id
$game_map.geo_to_region(geo_num, region_id)
return_scene
end
end
#==============================================================================
# Scene_Map拡張
#==============================================================================
class Scene_Map < Scene_Base
alias geo_to_region_update_scene update_scene
def update_scene
geo_to_region_update_scene
update_geo_to_region unless scene_changing?
end
def update_geo_to_region
if Input.trigger?(Geo_To_Region::CALL_BUTTON)
Sound.play_ok
SceneManager.call(Scene_GeoToRegion)
end
end
end