procon_bypass_man 0.1.4 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.circleci/config.yml +40 -13
- data/.github/workflows/ruby.yml +33 -0
- data/.rubocop.yml +24 -0
- data/CHANGELOG.md +19 -1
- data/Gemfile +1 -0
- data/Gemfile.lock +25 -3
- data/README.md +12 -9
- data/Rakefile +10 -1
- data/docs/setup_raspi.md +12 -7
- data/docs/setup_raspi.mitamae.rb +48 -0
- data/docs/setup_raspi_by_mitamae.md +14 -0
- data/examples/practical/app.rb +2 -2
- data/lib/procon_bypass_man/configuration/layer.rb +30 -6
- data/lib/procon_bypass_man/configuration/loader.rb +17 -16
- data/lib/procon_bypass_man/configuration/validator.rb +70 -5
- data/lib/procon_bypass_man/configuration.rb +10 -7
- data/lib/procon_bypass_man/device_connector.rb +336 -0
- data/lib/procon_bypass_man/procon/button_collection.rb +3 -2
- data/lib/procon_bypass_man/procon/pressed_button_helper.rb +1 -1
- data/lib/procon_bypass_man/procon.rb +9 -7
- data/lib/procon_bypass_man/runner.rb +16 -39
- data/lib/procon_bypass_man/timer.rb +14 -0
- data/lib/procon_bypass_man/uptime.rb +13 -0
- data/lib/procon_bypass_man/version.rb +1 -1
- data/lib/procon_bypass_man.rb +19 -4
- data/procon_bypass_man.gemspec +1 -1
- data/project_template/README.md +17 -0
- data/project_template/app.rb +18 -0
- data/project_template/setting.yml +35 -0
- data/project_template/systemd_units/pbm.service +13 -0
- metadata +16 -8
- data/examples/pbm.service +0 -27
- data/examples/simple.rb +0 -13
- data/lib/procon_bypass_man/device_registry.rb +0 -42
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f5d2c0b9137168508351ca8a1492470cd1f03c31d7eb920010a32f08f92122e
|
4
|
+
data.tar.gz: c7f42dd711cb3d8932a8fd6d99ee0735084618411e6cd723eeee8860ca96cd8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71a45ddf739c64355197e1a0610d2441eb6445eb6d77eef8fd9cf711265d0a9fc23dfcf2d75075115bf1e546141fec7eab0e20c6469feff6b7dea238d4916951
|
7
|
+
data.tar.gz: 1bb4bc56c9310d94d682454b33c3d28ebc0a45753ee292c98cdee47bc94b3400c50ddbbb9c1f08b17ade330829760b4dbc1eef85ea22faf1aa8f9271e1b53e0f
|
data/.circleci/config.yml
CHANGED
@@ -2,19 +2,46 @@ version: 2.1
|
|
2
2
|
orbs:
|
3
3
|
ruby: circleci/ruby@0.1.2
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
executors:
|
6
|
+
ruby:
|
7
|
+
parameters:
|
8
|
+
tag:
|
9
|
+
type: string
|
10
|
+
default: "latest"
|
7
11
|
docker:
|
8
|
-
- image:
|
9
|
-
|
12
|
+
- image: ruby:<< parameters.tag >>
|
13
|
+
environment:
|
14
|
+
BUNDLE_PATH: vendor/bundle
|
15
|
+
BUNDLE_JOBS: 4
|
16
|
+
working_directory: ~/app
|
17
|
+
|
18
|
+
jobs:
|
19
|
+
rspec:
|
20
|
+
parameters:
|
21
|
+
version:
|
22
|
+
type: string
|
23
|
+
executor:
|
24
|
+
name: ruby
|
25
|
+
tag: << parameters.version >>
|
10
26
|
steps:
|
11
27
|
- checkout
|
12
|
-
- run:
|
13
|
-
|
14
|
-
|
15
|
-
- run:
|
16
|
-
|
17
|
-
|
18
|
-
- run:
|
19
|
-
|
20
|
-
|
28
|
+
- run: ruby --version
|
29
|
+
- run: bundle --version
|
30
|
+
- run: gem --version
|
31
|
+
- run: gem install bundler
|
32
|
+
- run: bundle install --jobs 4
|
33
|
+
- run: bundle exec rubocop
|
34
|
+
- run: bundle exec rspec
|
35
|
+
|
36
|
+
build_jobs: &build_jobs
|
37
|
+
- rspec:
|
38
|
+
matrix:
|
39
|
+
parameters:
|
40
|
+
version:
|
41
|
+
- "2.5"
|
42
|
+
- "2.7"
|
43
|
+
- "3.0"
|
44
|
+
workflows:
|
45
|
+
version: 2
|
46
|
+
build:
|
47
|
+
jobs: *build_jobs
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
[push]
|
12
|
+
|
13
|
+
jobs:
|
14
|
+
test:
|
15
|
+
|
16
|
+
runs-on: ubuntu-latest
|
17
|
+
strategy:
|
18
|
+
matrix:
|
19
|
+
ruby-version: ['2.5', '2.7', '3.0']
|
20
|
+
|
21
|
+
steps:
|
22
|
+
- uses: actions/checkout@v2
|
23
|
+
- name: Set up Ruby
|
24
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
25
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
26
|
+
# uses: ruby/setup-ruby@v1
|
27
|
+
uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
|
28
|
+
with:
|
29
|
+
ruby-version: ${{ matrix.ruby-version }}
|
30
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
31
|
+
- name: Run tests
|
32
|
+
run: bundle exec rubocop
|
33
|
+
run: bundle exec rake
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
AllCops:
|
2
|
+
NewCops: enable
|
3
|
+
SuggestExtensions: false
|
4
|
+
Include:
|
5
|
+
- 'lib/**/*.rb'
|
6
|
+
- 'spec/**/*.rb'
|
7
|
+
Style:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Metrics:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Layout:
|
14
|
+
Enabled: false
|
15
|
+
|
16
|
+
Naming:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Lint/ConstantDefinitionInBlock:
|
20
|
+
Enabled: false
|
21
|
+
Lint/UselessAssignment:
|
22
|
+
Enabled: false
|
23
|
+
Lint/EmptyBlock:
|
24
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,22 @@
|
|
1
|
-
## [0.1.
|
1
|
+
## [0.1.8] - 2021-09-19
|
2
|
+
- 使える場合、GC.auto_compactを有効にする
|
3
|
+
|
4
|
+
## [0.1.7] - 2021-09-11
|
5
|
+
- Support pbmenv
|
6
|
+
|
7
|
+
## [0.1.6] - 2021-08-19
|
8
|
+
- 設定ファイルを読み込むと内容のmd5を `pbm_root_dir/.setting_yaml_digest` へ出力するようにしました
|
9
|
+
|
10
|
+
## [0.1.5] - 2021-07-29
|
11
|
+
- siwtch, proコンが電源OFF時にCPU使いまくるのを修正した
|
12
|
+
- 連打中に無視するボタンを複数登録できるようにした
|
13
|
+
- キーのリマップ先に複数ボタンを登録できるようにした
|
14
|
+
- 1つのボタンへ連打とリマップをできないようにしました
|
15
|
+
- NG ex)
|
16
|
+
- flip :zr, if_pressed: [:y]
|
17
|
+
- remap :zr, to: [:x]
|
18
|
+
|
19
|
+
## [0.1.4] - 2021-07-11
|
2
20
|
- ProconBypassMan.rootの定義を、gem rootからproject rootへ変更した
|
3
21
|
- 連打の頻度を変更できるようにした
|
4
22
|
- シグナルで設定ファイルを読み直すとpid_pathが消滅する不具合を修正した
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,18 +1,25 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
procon_bypass_man (0.1.
|
4
|
+
procon_bypass_man (0.1.8)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
+
ast (2.4.2)
|
9
10
|
coderay (1.1.3)
|
10
11
|
diff-lcs (1.4.4)
|
11
12
|
method_source (1.0.0)
|
13
|
+
parallel (1.20.1)
|
14
|
+
parser (3.0.2.0)
|
15
|
+
ast (~> 2.4.1)
|
12
16
|
pry (0.14.1)
|
13
17
|
coderay (~> 1.1)
|
14
18
|
method_source (~> 1.0)
|
15
|
-
|
19
|
+
rainbow (3.0.0)
|
20
|
+
rake (13.0.6)
|
21
|
+
regexp_parser (2.1.1)
|
22
|
+
rexml (3.2.5)
|
16
23
|
rspec (3.10.0)
|
17
24
|
rspec-core (~> 3.10.0)
|
18
25
|
rspec-expectations (~> 3.10.0)
|
@@ -26,19 +33,34 @@ GEM
|
|
26
33
|
diff-lcs (>= 1.2.0, < 2.0)
|
27
34
|
rspec-support (~> 3.10.0)
|
28
35
|
rspec-support (3.10.2)
|
36
|
+
rubocop (1.20.0)
|
37
|
+
parallel (~> 1.10)
|
38
|
+
parser (>= 3.0.0.0)
|
39
|
+
rainbow (>= 2.2.2, < 4.0)
|
40
|
+
regexp_parser (>= 1.8, < 3.0)
|
41
|
+
rexml
|
42
|
+
rubocop-ast (>= 1.9.1, < 2.0)
|
43
|
+
ruby-progressbar (~> 1.7)
|
44
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
45
|
+
rubocop-ast (1.11.0)
|
46
|
+
parser (>= 3.0.1.1)
|
47
|
+
ruby-progressbar (1.11.0)
|
29
48
|
timecop (0.9.4)
|
49
|
+
unicode-display_width (2.0.0)
|
30
50
|
|
31
51
|
PLATFORMS
|
32
52
|
arm-linux
|
33
53
|
arm64-darwin-20
|
34
54
|
armv7l-linux
|
55
|
+
x86_64-linux
|
35
56
|
|
36
57
|
DEPENDENCIES
|
37
58
|
procon_bypass_man!
|
38
59
|
pry
|
39
60
|
rake (~> 13.0)
|
40
61
|
rspec
|
62
|
+
rubocop
|
41
63
|
timecop
|
42
64
|
|
43
65
|
BUNDLED WITH
|
44
|
-
2.2.
|
66
|
+
2.2.15
|
data/README.md
CHANGED
@@ -17,20 +17,20 @@ Switch <-- (PBM): ZR連打
|
|
17
17
|
* Switch本体とドック
|
18
18
|
* Raspberry Pi4 Model B/4GB(Raspberry Pi OS (32-bit))
|
19
19
|
* 他のシリーズは未確認です
|
20
|
+
* zeroは非対応
|
20
21
|
* データ通信が可能なUSBケーブル
|
21
22
|
|
22
23
|
## 使うソフトウェア
|
23
|
-
*
|
24
|
-
* ruby-3.0.x
|
24
|
+
* ruby-3.0.x
|
25
25
|
|
26
26
|
## Usage
|
27
27
|
* USBガジェットモードで起動するRaspberry Pi4を用意する
|
28
|
-
* https://github.com/
|
28
|
+
* https://github.com/splaplapla/procon_bypass_man/blob/master/docs/setup_raspi.md
|
29
29
|
* Raspberry Pi4で https://github.com/jiikko/procon_bypass_man_sample をclone して実行ファイルを動かす
|
30
|
-
* 実行ファイルと設定ファイルについては https://github.com/
|
30
|
+
* 実行ファイルと設定ファイルについては https://github.com/splaplapla/procon_bypass_man/wiki に詳細を書いていますが、まず動かすためにはcloneしたほうが早いです
|
31
31
|
|
32
32
|
## Plugins
|
33
|
-
* https://github.com/
|
33
|
+
* https://github.com/splaplapla/procon_bypass_man-splatoon2
|
34
34
|
|
35
35
|
## FAQ
|
36
36
|
* どうやって動かすの?
|
@@ -38,7 +38,7 @@ Switch <-- (PBM): ZR連打
|
|
38
38
|
* どうやって使うの?
|
39
39
|
* ケーブルでそれらを接続した状態で、Raspberry Pi4にsshして本プログラムを起動することで使用します
|
40
40
|
* ラズベリーパイ4のセットアップ方法は?
|
41
|
-
* https://github.com/
|
41
|
+
* https://github.com/splaplapla/procon_bypass_man/tree/master/docs/setup_raspi.md
|
42
42
|
* モード, マクロの違いは?
|
43
43
|
* modeはProconの入力をそのまま再現するため機能。レイヤーを切り替えるまで繰り返し続ける
|
44
44
|
* マクロは特定のキーを順番に入れていく機能。キーの入力が終わったらマクロは終了する
|
@@ -52,17 +52,16 @@ Switch <-- (PBM): ZR連打
|
|
52
52
|
* 操作するdeviceファイルの所有者がrootだから
|
53
53
|
|
54
54
|
## TODO
|
55
|
-
* 設定ファイルをwebから反映できる
|
56
|
-
* ラズパイのプロビジョニングを楽にしたい
|
57
55
|
* レコーディング機能(プロコンの入力をマクロとして登録ができる)
|
58
56
|
* マクロにdelayを入れれるようにする
|
57
|
+
* 設定ファイル マクロの引数に、ボタンを取れるようにする
|
59
58
|
|
60
59
|
## 開発系
|
61
60
|
```ruby
|
62
61
|
ProconBypassMan.tap do |pbm|
|
62
|
+
pbm.root = File.expand_path(__dir__)
|
63
63
|
pbm.logger = Logger.new("#{ProconBypassMan.root}/app.log", 5, 1024 * 1024 * 10)
|
64
64
|
pbm.logger.level = :debug
|
65
|
-
pbm.root = File.expand_path(__dir__)
|
66
65
|
end
|
67
66
|
```
|
68
67
|
|
@@ -71,6 +70,10 @@ end
|
|
71
70
|
sudo kill -USR2 `cat ./pbm_pid`
|
72
71
|
```
|
73
72
|
|
73
|
+
### リリース手順
|
74
|
+
* project_template/app.rb, lib/procon_bypass_man/version.rb のバージョンをあげる
|
75
|
+
* be rake release
|
76
|
+
|
74
77
|
## License
|
75
78
|
|
76
79
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
data/docs/setup_raspi.md
CHANGED
@@ -13,7 +13,7 @@
|
|
13
13
|
* /etc/dphys-swapfile を CONF_SWAPSIZE=1024 にする
|
14
14
|
* sudo /etc/init.d/dphys-swapfile restart && swapon -s
|
15
15
|
* tailscale をインストールする(optional)
|
16
|
-
* sudo apt-get install vim rbenv
|
16
|
+
* sudo apt-get install vim rbenv git -y
|
17
17
|
* rbenvでrubyを入れる
|
18
18
|
* git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
|
19
19
|
* rbenv install 3.0.1
|
@@ -22,20 +22,25 @@
|
|
22
22
|
* sshkeyを作成する
|
23
23
|
* github に鍵を登録する
|
24
24
|
* ~/.ssh/authorized_keys に鍵を登録する
|
25
|
-
* sudo pip3 install fluent-logger pytz
|
26
25
|
* ガジェットモードで起動する
|
27
26
|
* /boot/config.txtに、dtoverlay=dwc2を追記
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
* echo "dwc2" | sudo tee -a /etc/modules
|
28
|
+
* echo "libcomposite" | sudo tee -a /etc/modules
|
29
|
+
* sudo cat /etc/modules
|
31
30
|
* cd ~ && wget https://gist.githubusercontent.com/jiikko/3f9fb3194c0cc7685e31fbfcb5b5f9ff/raw/23ddee29d94350be80b79d290ac3c8ce8400bd88/add_procon_gadget.sh
|
32
31
|
* chmod 755 ~/add_procon_gadget.sh
|
33
32
|
* sudo reboot
|
34
33
|
* sudo sh ~/add_procon_gadget.sh の実行に成功させる
|
35
34
|
* /etc/rc.local に sh /home/pi/add_procon_gadget.sh って書く
|
36
|
-
* cd ~ && mkdir -p src && cd ~/src && git clone https://github.com/jiikko/procon_bypass_man_sample && cd
|
35
|
+
* cd ~ && mkdir -p src && cd ~/src && git clone https://github.com/jiikko/procon_bypass_man_sample && cd procon_bypass_man_sample
|
37
36
|
|
38
|
-
おわり. 起動する時は都度sudo ruby app.rb を実行する
|
37
|
+
おわり. 起動する時は都度 sudo ruby app.rb を実行する
|
39
38
|
|
40
39
|
## 参考
|
41
40
|
* https://mtosak-tech.hatenablog.jp/entry/2020/08/22/114622
|
41
|
+
|
42
|
+
# TIPS
|
43
|
+
* SDカードにイメージを焼くときは、ImagerのAdvanced Optionsを使うとセットアップが楽になる
|
44
|
+
* raspios_liteにした方が起動が早くなりそう
|
45
|
+
* https://qiita.com/Liesegang/items/dcdc669f80d1bf721c21
|
46
|
+
* http://ftp.jaist.ac.jp/pub/raspberrypi/raspios_lite_armhf
|
@@ -0,0 +1,48 @@
|
|
1
|
+
run_command "apt-get update"
|
2
|
+
|
3
|
+
package 'ruby' do
|
4
|
+
action :install
|
5
|
+
end
|
6
|
+
|
7
|
+
package 'vim' do
|
8
|
+
action :install
|
9
|
+
end
|
10
|
+
|
11
|
+
package 'git' do
|
12
|
+
action :install
|
13
|
+
end
|
14
|
+
|
15
|
+
gem_package 'bundler' do
|
16
|
+
action :install
|
17
|
+
end
|
18
|
+
|
19
|
+
# OTG
|
20
|
+
execute "append dtoverlay=dwc2 to /boot/config.txt" do
|
21
|
+
not_if "grep dtoverlay=dwc2 /boot/config.txt"
|
22
|
+
command "echo 'dtoverlay=dwc2' >> /boot/config.txt"
|
23
|
+
end
|
24
|
+
|
25
|
+
execute "append dwc2 to /etc/modules" do
|
26
|
+
not_if "grep dwc2 /etc/modules"
|
27
|
+
command "echo dwc2 >> /etc/modules"
|
28
|
+
end
|
29
|
+
|
30
|
+
execute "append libcomposite to /etc/modules" do
|
31
|
+
not_if "grep libcomposite /etc/modules"
|
32
|
+
command "echo libcomposite >> /etc/modules"
|
33
|
+
end
|
34
|
+
|
35
|
+
# PBM
|
36
|
+
execute "Initialize PBM" do
|
37
|
+
command <<~SHELL
|
38
|
+
sudo mkdir -p /usr/share/pbm/shared
|
39
|
+
wget https://gist.githubusercontent.com/jiikko/3f9fb3194c0cc7685e31fbfcb5b5f9ff/raw/23ddee29d94350be80b79d290ac3c8ce8400bd88/add_procon_gadget.sh -O /usr/share/pbm/shared/add_procon_gadget.sh
|
40
|
+
chmod +x /usr/share/pbm/shared/add_procon_gadget.sh
|
41
|
+
SHELL
|
42
|
+
end
|
43
|
+
|
44
|
+
run_command 'sudo systemctl disable triggerhappy.socket'
|
45
|
+
run_command 'sudo systemctl disable triggerhappy.service'
|
46
|
+
run_command 'sudo systemctl disable bluetooth'
|
47
|
+
run_command 'sudo systemctl disable apt-daily-upgrade.timer'
|
48
|
+
run_command 'sudo systemctl disable apt-daily.timer'
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# Raspberry Pi4のセットアップ手順 With mitamae
|
2
|
+
* SDカードにRaspberry Pi OS lite (32-bit)を焼く
|
3
|
+
* sshをできる状態で焼いておく
|
4
|
+
* SDカードをRaspberry Pi4本体に挿して起動する
|
5
|
+
* sshする
|
6
|
+
* curl -L https://github.com/itamae-kitchen/mitamae/releases/latest/download/mitamae-armhf-linux.tar.gz | tar xvz
|
7
|
+
* wget https://raw.githubusercontent.com/splaplapla/procon_bypass_man/master/docs/setup_raspi.mitamae.rb -O setup_raspi.mitamae.rb
|
8
|
+
* sudo ./mitamae-armhf-linux local setup_raspi.mitamae.rb -l debug
|
9
|
+
* sudo reboot
|
10
|
+
* sudo sh /usr/share/pbm/shared/add_procon_gadget.sh の実行に成功させる
|
11
|
+
* /etc/rc.local に sh /usr/share/pbm/shared/add_procon_gadget.sh って書く
|
12
|
+
* PCとRaspberry Pi4を接続し、プロコンとして認識していることを確認する
|
13
|
+
* sudo gem i pbmenv
|
14
|
+
* sudo pbmenv install latest
|
data/examples/practical/app.rb
CHANGED
@@ -8,8 +8,8 @@ require 'bundler/inline'
|
|
8
8
|
|
9
9
|
gemfile do
|
10
10
|
source 'https://rubygems.org'
|
11
|
-
gem 'procon_bypass_man', github: '
|
12
|
-
gem 'procon_bypass_man-splatoon2', github: '
|
11
|
+
gem 'procon_bypass_man', github: 'splaplapla/procon_bypass_man', branch: "edge"
|
12
|
+
gem 'procon_bypass_man-splatoon2', github: 'splaplapla/procon_bypass_man-splatoon2', branch: "0.1.0"
|
13
13
|
end
|
14
14
|
|
15
15
|
ProconBypassMan.tap do |pbm|
|
@@ -16,7 +16,7 @@ module ProconBypassMan
|
|
16
16
|
case if_pressed
|
17
17
|
when TrueClass
|
18
18
|
if_pressed = [button]
|
19
|
-
when Symbol
|
19
|
+
when Symbol, String
|
20
20
|
if_pressed = [if_pressed]
|
21
21
|
when Array, FalseClass
|
22
22
|
# sono mama
|
@@ -25,8 +25,16 @@ module ProconBypassMan
|
|
25
25
|
end
|
26
26
|
hash = { if_pressed: if_pressed }
|
27
27
|
if force_neutral
|
28
|
-
|
28
|
+
case force_neutral
|
29
|
+
when TrueClass, FalseClass
|
30
|
+
raise "ボタンを渡してください"
|
31
|
+
when Symbol, String
|
32
|
+
hash[:force_neutral] = [force_neutral]
|
33
|
+
when Array
|
34
|
+
hash[:force_neutral] = force_neutral
|
35
|
+
end
|
29
36
|
end
|
37
|
+
|
30
38
|
if flip_interval
|
31
39
|
if /\A(\d+)F\z/i =~ flip_interval
|
32
40
|
interval = ((frame = $1.to_i) / 60.0).floor(2)
|
@@ -35,17 +43,33 @@ module ProconBypassMan
|
|
35
43
|
end
|
36
44
|
hash[:flip_interval] = interval
|
37
45
|
end
|
38
|
-
self.flips[button]
|
46
|
+
if self.flips[button]
|
47
|
+
raise "#{button}への設定をすでに割り当て済みです"
|
48
|
+
else
|
49
|
+
self.flips[button] = hash
|
50
|
+
end
|
39
51
|
end
|
40
52
|
|
41
53
|
PRESET_MACROS = [:fast_return]
|
42
54
|
def macro(name, if_pressed: )
|
43
|
-
|
55
|
+
if name.respond_to?(:name)
|
56
|
+
macro_name = name.name.to_sym
|
57
|
+
else
|
58
|
+
macro_name = name
|
59
|
+
end
|
60
|
+
self.macros[macro_name] = { if_pressed: if_pressed }
|
44
61
|
end
|
45
62
|
|
46
63
|
def remap(button, to: )
|
47
|
-
|
48
|
-
|
64
|
+
case to
|
65
|
+
when TrueClass, FalseClass
|
66
|
+
raise "ボタンを渡してください"
|
67
|
+
when Symbol, String
|
68
|
+
self.remaps[button] = { to: [to] }
|
69
|
+
when Array
|
70
|
+
raise "ボタンを渡してください" if to.size.zero?
|
71
|
+
self.remaps[button] = { to: to }
|
72
|
+
end
|
49
73
|
end
|
50
74
|
|
51
75
|
# @return [Array]
|
@@ -1,24 +1,22 @@
|
|
1
1
|
module ProconBypassMan
|
2
2
|
class Configuration
|
3
3
|
module Loader
|
4
|
+
require 'digest/md5'
|
5
|
+
|
4
6
|
def self.load(setting_path: )
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
instance.errors[:base] << "yamlのシンタックスエラーです"
|
14
|
-
next(instance)
|
7
|
+
ProconBypassMan::Configuration.switch_new_context(:validation) do |validation_instance|
|
8
|
+
yaml = YAML.load_file(setting_path) or raise "読み込みに失敗しました"
|
9
|
+
validation_instance.instance_eval(yaml["setting"])
|
10
|
+
validator = Validator.new(validation_instance)
|
11
|
+
if validator.valid?
|
12
|
+
next
|
13
|
+
else
|
14
|
+
raise ProconBypassMan::CouldNotLoadConfigError, validator.errors
|
15
15
|
end
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
if !validation_instance.errors.empty?
|
21
|
-
raise ProconBypassMan::CouldNotLoadConfigError, validation_instance.errors
|
16
|
+
rescue SyntaxError
|
17
|
+
raise ProconBypassMan::CouldNotLoadConfigError, "Rubyのシンタックスエラーです"
|
18
|
+
rescue Psych::SyntaxError
|
19
|
+
raise ProconBypassMan::CouldNotLoadConfigError, "yamlのシンタックスエラーです"
|
22
20
|
end
|
23
21
|
|
24
22
|
yaml = YAML.load_file(setting_path)
|
@@ -33,6 +31,9 @@ module ProconBypassMan
|
|
33
31
|
ProconBypassMan.logger.warn "不明なバージョンです。failoverします"
|
34
32
|
ProconBypassMan::Configuration.instance.instance_eval(yaml["setting"])
|
35
33
|
end
|
34
|
+
|
35
|
+
File.write(ProconBypassMan.digest_path, Digest::MD5.hexdigest(yaml["setting"]))
|
36
|
+
|
36
37
|
ProconBypassMan::Configuration.instance
|
37
38
|
end
|
38
39
|
|
@@ -1,13 +1,19 @@
|
|
1
1
|
module ProconBypassMan
|
2
2
|
class Configuration
|
3
|
-
|
3
|
+
class Validator
|
4
|
+
def initialize(config)
|
5
|
+
@layers = config.layers
|
6
|
+
@prefix_keys = config.prefix_keys
|
7
|
+
end
|
8
|
+
|
4
9
|
# @return [Boolean]
|
5
10
|
def valid?
|
6
11
|
@errors = Hash.new {|h,k| h[k] = [] }
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
12
|
+
|
13
|
+
validate_require_prefix_keys
|
14
|
+
validate_config_of_button_lonely
|
15
|
+
validate_verify_button_existence
|
16
|
+
validate_flip_and_remap_are_hate_each_other
|
11
17
|
|
12
18
|
@errors.empty?
|
13
19
|
end
|
@@ -21,6 +27,65 @@ module ProconBypassMan
|
|
21
27
|
def errors
|
22
28
|
@errors ||= Hash.new {|h,k| h[k] = [] }
|
23
29
|
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def validate_config_of_button_lonely
|
34
|
+
@layers.each do |layer_key, value|
|
35
|
+
if ProconBypassMan::Procon::ModeRegistry::PRESETS.key?(value.mode)
|
36
|
+
next
|
37
|
+
else
|
38
|
+
if !value.flips.empty? || !value.macros.empty?
|
39
|
+
@errors[:layers] << "#{layer_key}でmodeを設定しているのでボタンの設定はできません。"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def validate_require_prefix_keys
|
46
|
+
if @prefix_keys.empty?
|
47
|
+
@errors[:prefix_keys] ||= []
|
48
|
+
@errors[:prefix_keys] << "prefix_keys_for_changing_layerに値が入っていません。"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def validate_verify_button_existence
|
53
|
+
@layers.each do |layer_key, value|
|
54
|
+
unverified_buttons = []
|
55
|
+
# teplevel target button
|
56
|
+
value.flips.keys.map(&:to_sym).each { |b| unverified_buttons << b }
|
57
|
+
value.remaps.keys.map(&:to_sym).each { |b| unverified_buttons << b }
|
58
|
+
# internal target button
|
59
|
+
value.flips.flat_map { |_flip_button, flip_option|
|
60
|
+
flip_option.flat_map { |flip_option_key, flip_option_target_button|
|
61
|
+
next if flip_option_key == :flip_interval
|
62
|
+
next if flip_option_target_button.is_a?(FalseClass) || flip_option_target_button.is_a?(TrueClass)
|
63
|
+
flip_option_target_button
|
64
|
+
}
|
65
|
+
}.compact.each { |b| unverified_buttons << b }
|
66
|
+
value.remaps.flat_map { |_button, option|
|
67
|
+
option.flat_map { |_flip_option_key, flip_option_target_button|
|
68
|
+
next if flip_option_target_button.is_a?(FalseClass) || flip_option_target_button.is_a?(TrueClass)
|
69
|
+
flip_option_target_button
|
70
|
+
}
|
71
|
+
}.compact.each { |b| unverified_buttons << b }
|
72
|
+
unless(nunsupport_buttons = (unverified_buttons - ProconBypassMan::Procon::ButtonCollection::BUTTONS)).length.zero?
|
73
|
+
@errors[:layers] << "#{layer_key}で存在しないボタン#{nunsupport_buttons.join(", ")}があります"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def validate_flip_and_remap_are_hate_each_other
|
79
|
+
@layers.each do |layer_key, value|
|
80
|
+
flip_buttons = []
|
81
|
+
remap_buttons = []
|
82
|
+
value.flips.keys.map(&:to_sym).each { |b| flip_buttons << b }
|
83
|
+
value.remaps.keys.map(&:to_sym).each { |b| remap_buttons << b }
|
84
|
+
if(duplicated_buttons = flip_buttons & remap_buttons).length > 0
|
85
|
+
@errors[:layers] << "レイヤー#{layer_key}で、連打とリマップの定義が重複しているボタン#{duplicated_buttons.join(", ")}があります"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
24
89
|
end
|
25
90
|
end
|
26
91
|
end
|
@@ -4,7 +4,6 @@ require "procon_bypass_man/configuration/layer"
|
|
4
4
|
|
5
5
|
module ProconBypassMan
|
6
6
|
class Configuration
|
7
|
-
include Validator
|
8
7
|
|
9
8
|
attr_accessor :layers,
|
10
9
|
:setting_path,
|
@@ -19,13 +18,12 @@ module ProconBypassMan
|
|
19
18
|
@@context[@@current_context_key] ||= new
|
20
19
|
end
|
21
20
|
|
22
|
-
def self.
|
23
|
-
@@context[key]
|
21
|
+
def self.switch_new_context(key)
|
22
|
+
@@context[key] = new
|
24
23
|
previous_key = @@current_context_key
|
25
24
|
if block_given?
|
26
25
|
@@current_context_key = key
|
27
26
|
value = yield(@@context[key])
|
28
|
-
@@context[key].reset!
|
29
27
|
@@current_context_key = previous_key
|
30
28
|
return value
|
31
29
|
else
|
@@ -39,11 +37,16 @@ module ProconBypassMan
|
|
39
37
|
|
40
38
|
MODES = [:manual]
|
41
39
|
def layer(direction, mode: :manual, &block)
|
42
|
-
|
43
|
-
|
40
|
+
if mode.respond_to?(:name)
|
41
|
+
mode_name = mode.name.to_sym
|
42
|
+
else
|
43
|
+
mode_name = mode
|
44
|
+
end
|
45
|
+
unless (MODES + ProconBypassMan::Procon::ModeRegistry.plugins.keys).include?(mode_name)
|
46
|
+
raise("#{mode_name} mode is unknown")
|
44
47
|
end
|
45
48
|
|
46
|
-
layer = Layer.new(mode:
|
49
|
+
layer = Layer.new(mode: mode_name)
|
47
50
|
layer.instance_eval(&block) if block_given?
|
48
51
|
self.layers[direction] = layer
|
49
52
|
self
|