📖 src-game-controller-key-config
「 👇 レバーは -1 ~ 10、 ボタンは -1 ~ 128 まであるそうだぜ」
# ディレクター(Director)
extends Node2D
var re_button = RegEx.new()
var re_lever = RegEx.new()
# 起動直後に レバーが入った状態で始まることがあるから、1秒ぐらい無視するためのカウンター
var counter_of_wait = 0.0
# WaitForPrompt, Prompt, WaitForInput, Input, InputOk の5つ。 Wait を入れないと反応過敏になってしまう
var turn_state = &"WaitForPrompt"
var current_step = 1
# 操作したボタン (変数を増やしたくないのでレバーは+1000して入れる)
var button_number = -1
var button_presentation_name = &""
# Called when the node enters the scene tree for the first time.
func _ready():
# この文字列がどう変化するのか、さっぱり分からん
re_button.compile("Joypad Button (\\d)")
re_lever.compile("Joypad Motion on Axis (\\d)")
$"TelopCoordinator/TextBlock".text = """\
* * *
"""
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if not (turn_state in [&"WaitForPrompt", &"Prompt", &"WaitForInput", &"InputOk"]):
return
var is_ok = false
if self.current_step == 1:
if turn_state == &"WaitForPrompt":
if self.counter_of_wait < 1.0:
self.counter_of_wait += delta
return
turn_state = &"Prompt"
elif turn_state == &"Prompt":
$"GuiArtist/KeyConfig_CanvasLayer/決定ボタン".text = "(1)決定ボタン、メッセージ送りボタン を押してください"
turn_state = &"WaitForInput"
elif turn_state == &"WaitForInput":
if self.counter_of_wait < 1.0:
self.counter_of_wait += delta
return
turn_state = &"Input"
is_ok = true
elif self.current_step == 2:
if turn_state == &"InputOk":
$"GuiArtist/KeyConfig_CanvasLayer/決定ボタン".text = "(1)決定ボタン、メッセージ送りボタン: " + self.button_presentation_name
turn_state = &"WaitForPrompt"
elif turn_state == &"WaitForPrompt":
if self.counter_of_wait < 1.0:
self.counter_of_wait += delta
return
turn_state = &"Prompt"
elif turn_state == &"Prompt":
$"GuiArtist/KeyConfig_CanvasLayer/キャンセルボタン".text = "(2)キャンセルボタン、メニューボタン を押してください"
turn_state = &"WaitForInput"
elif turn_state == &"WaitForInput":
if self.counter_of_wait < 1.0:
self.counter_of_wait += delta
return
turn_state = &"Input"
is_ok = true
elif self.current_step == 3:
if turn_state == &"InputOk":
$"GuiArtist/KeyConfig_CanvasLayer/キャンセルボタン".text = "(2)キャンセルボタン、メニューボタン: " + self.button_presentation_name
turn_state = &"WaitForPrompt"
elif turn_state == &"WaitForPrompt":
if self.counter_of_wait < 1.0:
self.counter_of_wait += delta
return
turn_state = &"Prompt"
elif turn_state == &"Prompt":
$"GuiArtist/KeyConfig_CanvasLayer/メッセージ早送りボタン".text = "(3)メッセージ早送りボタン を押してください"
turn_state = &"WaitForInput"
elif turn_state == &"WaitForInput":
if self.counter_of_wait < 1.0:
self.counter_of_wait += delta
return
turn_state = &"Input"
is_ok = true
elif self.current_step == 4:
if turn_state == &"InputOk":
$"GuiArtist/KeyConfig_CanvasLayer/メッセージ早送りボタン".text = "(3)メッセージ早送りボタン: " + self.button_presentation_name
turn_state = &"WaitForPrompt"
elif turn_state == &"WaitForPrompt":
if self.counter_of_wait < 1.0:
self.counter_of_wait += delta
return
turn_state = &"Prompt"
elif turn_state == &"Prompt":
$"TelopCoordinator/TextBlock".text = "完了"
turn_state = &"WaitForInput"
elif turn_state == &"WaitForInput":
if self.counter_of_wait < 1.0:
self.counter_of_wait += delta
return
turn_state = &"Input"
is_ok = true
else:
pass
if is_ok:
self.counter_of_wait = 0.0
self.button_number = -1
self.button_presentation_name = &""
func _unhandled_input(event):
# 起動直後に、押してもないレバーが 押したことになっていることがある
var event_as_text = event.as_text()
print("入力: " + event_as_text)
if turn_state != &"Input":
return
var is_ok = false
var acception = "受付: "
# 📖 [enum JoyButton:](https://docs.godotengine.org/en/stable/classes/class_%40globalscope.html#enum-globalscope-joybutton)
# レバーは -1 ~ 10、 ボタンは -1 ~ 128 まであるそうだ
if not is_ok:
var matched = re_button.search(event_as_text)
if matched:
self.button_number = int(matched.get_string(1))
button_presentation_name = "ボタン" + str(self.button_number)
is_ok = true
if not is_ok:
var matched = re_lever.search(event_as_text)
if matched:
var number = int(matched.get_string(1))
button_presentation_name = "レバー" + str(number)
self.button_number = number + 1000
is_ok = true
if is_ok:
print(acception)
self.current_step += 1
turn_state = &"InputOk"
print("入力完了")
📺 動画
📺 動画
「 👆 あっ! キーコンフィグの内容を きふわらべRPGへ コピーできね!」
「 Godot のツリーは 仮想的なもので、実体は無いしな」
「 わたしたちは Godot の Scene の仕組みを もっと勉強した方がいいんじゃないの?」
「 👇 Godot 独自の機能を勉強したって 何になるか知らんけど……」
「 ツリーは *.tscn
ファイル1つに保存できるんじゃないか?
それで憶測だが *.tscn
は サブ・ツリーとしてインポートできるんじゃないか?」
「 サブツリーとして インポートするってのは ディレクトリーのマウントかだぜ?」
「 key_config.tscn
が既に サブツリー のファイルになってんじゃないの?」
「 じゃあ key_config.tscn
は きふわらべRPGから インポートできるのかだぜ?
やってみるか……」
Cannot open file 'res://main_font.tres'.
Failed loading resource: res://main_font.tres. Make sure resources have been imported by opening the project in the editor at least once.
Attempt to open script 'res://scripts/key_config_artist.gd' resulted in error 'File not found'.
Failed loading resource: res://scripts/key_config_artist.gd. Make sure resources have been imported by opening the project in the editor at least once.
scene/resources/resource_format_text.cpp:283 - res://sub_trees/key_config.tscn:86 - Parse Error:
Failed loading resource: res://sub_trees/key_config.tscn. Make sure resources have been imported by opening the project in the editor at least once.
「 リソース・ファイルのインポートも全部やってくれるのかと思ったら、
ファイルが足らんとエラーだぜ」
「 *.tscn
ファイルは インデックスの機能しかないのでは?
これがドキュメントの言う、 素材と レシピに分かれていて、 レシピ しかないという意味では?」
「 そんなもん 全部丸ごと やってほしいのに……、
フォルダーを整理するか……」
「 じゃあ studio_grayscale_keyconfig.tscn
とか、 studio_grayscale_kifuwaraberpg
とかかな。
そこまで 厳密にやるべきかどうか、少し考えてみるか……」
「 アンダースコア2つを区切りに利用して
studio__grayscale__key_config.tscn
と、 studio__grayscale__kifuwarabe_rpg.tscn
とか どうだぜ?」
「 studio_grayscale_presents_key_config.tscn
と、 studio_grayscale_presents_kifuwarabe_rpg.tscn
にしたら どうだぜ?」
「 ファイルパスが長くなるの ゴミ箱に入らなかったりして データが破損するんだよな」
「 🐔grayscale_🐤key_config.tscn
と、 🐔grayscale_🐤kifuwarabe_rpg.tscn
でどう?」
「 サークルと作品の関係性は、 にわとりとひよこの関係性とは 異なると思うぜ」
「 🏠grayscale_🎬key_config.tscn
と、 🏠grayscale_🎬kifuwarabe_rpg.tscn
でどう?」
「 サークルと作品の関係性は、ハウスとカチンコの関係性とは 異なると思うぜ」
「 シーンの意味はあってるのに。じゃあ ディレクター・チェアの絵文字は無いのかだぜ?」
「 絵文字の品揃えが偏ってて あんまりないのよ。
🪑grayscale_🎬key_config.tscn
と、 🪑grayscale_🎬kifuwarabe_rpg.tscn
でどう?」
「 👆 キッズ感出てくるが 椅子がポリティカル・コネクトネスに引っかかるとは思えないし、
これで進めよう」
「 そういう趣旨だろ。
サブツリーが見えると 散らばって 管理できなくなるしな」
# ディレクター取得
func get_director():
return $"../../Director"
「 ぶら下げたサブツリーから、外側のサブツリーへパスを合わせる方法も分からん」
「 👆 Director
が名前被りするんで、嫌なんで DirectorForKeyConfig
にリネームしたら……」
「 👆 ハードコーディングしてるパスも 書き直せよ、ということらしい」
「 情報技術を扱う わたしたちが なんでそんな手間 受け入れなくちゃいけないのかしらね?」
📺 動画
.
Crieitは誰でも投稿できるサービスです。 是非記事の投稿をお願いします。どんな軽い内容でも投稿できます。
また、「こんな記事が読みたいけど見つからない!」という方は是非記事投稿リクエストボードへ!
こじんまりと作業ログやメモ、進捗を書き残しておきたい方はボード機能をご利用ください。
ボードとは?
コメント