Skip to content

Instantly share code, notes, and snippets.

@rutan
Created July 11, 2015 06:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rutan/7bb415241e2751bdd38f to your computer and use it in GitHub Desktop.
Save rutan/7bb415241e2751bdd38f to your computer and use it in GitHub Desktop.
# encoding: utf-8
#===============================================================================
# ■ Input.repeat?速度調整スクリプト for RGSS3
#-------------------------------------------------------------------------------
# Ru/むっくRu
#-------------------------------------------------------------------------------
# RGSS組み込み機能のInput.repeatのキー入力間隔を調整します。
# アイテム入力欄などでのカーソル移動速度を早くできます。
#-------------------------------------------------------------------------------
# 【更新履歴】
# 2014/12/29 旧版から移植
#===============================================================================
# ------------------------------------------------------------------------------
# ■ 設定項目
# ------------------------------------------------------------------------------
module Torigoya
module InputRepeatExConfig
#---------------------------------------------------------------------------
# ● キー入力しっぱなし1回目のウェイト時間(フレーム数)
#---------------------------------------------------------------------------
# 「タン、タタタタ……」の「タン」の後のウェイト時間です。
# ここを短くするとカーソルの移動開始までの時間が短くなります。
# ツクールのデフォルトでは大体20くらいが設定されています。
#---------------------------------------------------------------------------
FIRST_WAIT = 12
#---------------------------------------------------------------------------
# ● キー入力しっぱなし2回目以降のウェイト時間(フレーム数)
#---------------------------------------------------------------------------
# 「タン、タタタタ……」の「タ」間のウェイト時間です。
# ここを短くするとカーソルの移動速度が早くなります。
# ツクールのデフォルトでは大体5くらいが設定されています。
#---------------------------------------------------------------------------
REPEAT_WAIT = 3
end
end
# ------------------------------------------------------------------------------
# ↑設定ここまで
# ------------------------------------------------------------------------------
module Torigoya
# 入力管理機構
class InputManager
KEYS = [:DOWN, :LEFT, :RIGHT, :UP, :A, :B, :C, :X, :Y, :Z, :L, :R,
:SHIFT, :CTRL, :ALT, :F5, :F6, :F7, :F8, :F9]
# 初期化
def initialize
@press_counts = Hash[KEYS.map { |n| [n, 0] }]
end
# 初回のウェイト時間(フレーム)
def first_wait
InputRepeatExConfig::FIRST_WAIT.to_i
end
# 2回目以降のウェイト時間(フレーム)
def repeat_wait
InputRepeatExConfig::REPEAT_WAIT.to_i
end
# 更新処理
def update
KEYS.each do |key|
if ::Input.press?(key)
@press_counts[key] += 1
else
@press_counts[key] = 0
end
end
end
# リピート入力の取得
# @param [Symbol] key キー名
# @param [Integer] first_wait 1回目のウェイトフレーム時間(省略可)
# @param [Integer] repeat_wait 2回目以降のウェイトフレーム時間(省略可)
# @return [Boolean]
def repeat?(key, first_wait = nil, repeat_wait = nil)
first_wait ||= self.first_wait
repeat_wait ||= self.repeat_wait
count = @press_counts[key].to_i
case
when count == 1
true
when (count > first_wait && (count - first_wait) % repeat_wait == 0)
true
else
false
end
end
end
end
class << Input
# [エイリアス] キー入力の更新
alias torigoya_input_repeat_ex_update update
def update
torigoya_input_repeat_ex_update
self.torigoya_input_manager.update
end
# [再定義] 繰り返し入力
def repeat?(key)
self.torigoya_input_manager.repeat?(key)
end
# 繰り返し入力+
def repeat_ex?(key, first_wait, repeat_wait)
self.torigoya_input_manager.repeat?(key, first_wait, repeat_wait)
end
# 入力管理機構の取得
def torigoya_input_manager
@torigoya_input_manager ||= Torigoya::InputManager.new
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment