Skip to content

Instantly share code, notes, and snippets.

@ir-norn
Last active October 31, 2015 18:25
Show Gist options
  • Save ir-norn/e939b080202883ba7e53 to your computer and use it in GitHub Desktop.
Save ir-norn/e939b080202883ba7e53 to your computer and use it in GitHub Desktop.
dxruby _ key save replay

リプレイ保存、再生 

データ圧縮は

MessagePack 、LZMA

このあたりを試す

#coding:utf-8
require "yaml"
require "dxruby"
require "pp"
if $0 == __FILE__
Dir.chdir File.dirname $0
end
# module Create_VK_action_mxxxxxx
# def VK_update;end # Create_VK_action_ex
# def self.arg profile
# key_data = YAML.load open("./dat/keyconfig.yaml")
# [ :VK_Push? , :padPush? ,:keyPush? ,
# :VK_Down? , :padDown? ,:keyDown? ,
# ].each_slice(3) do | me , pad , key |
# define_method me do | vk |
# key_data[ profile ][ vk ].any? do | m |
# Input.method(m=~/P_/?pad:key)[
# DXRuby.constants.inject({}){|r,s|s=~/K_|P_/&&r[s]=DXRuby.const_get(s);r}[m] ]
# end
# end # mod
# end # each
# self
# end
# end
module Create_VK_action_m
def self.arg profile , save_file = "./dat/replay/__default_replay.yaml"
flame = 0 ; define_method :VK_update do flame+=1 end
keyhs = Hash.new ; keyhs.default_proc =->h,k{h[k]=[]}
[*:VK_0..:VK_15,:VK_LEFT,:VK_UP,:VK_RIGHT,:VK_DOWN]
.each do|vk| keyhs[vk] << nil end
save =-> profile , vk do
keyhs[vk] << flame
data = { :VK_log => keyhs }
open( save_file ,"w") do|nyan| YAML.dump(data , nyan) end
return true
end
key_data = YAML.load open("./dat/keyconfig.yaml")
[ :VK_Push? , :padPush? ,:keyPush? ,
:VK_Down? , :padDown? ,:keyDown? ,
].each_slice(3) do | me , pad , key |
define_method me do | vk |
key_data[ profile ][ vk ].any? do | m |
save.call(profile, vk) if Input.method(m=~/P_/?pad:key)[
DXRuby.constants.inject({}){|r,s|s=~/K_|P_/&&r[s]=DXRuby.const_get(s);r}[m] ]
end
end # mod
end # each
self
end
end
module Create_VK_action_replay
def self.arg profile , save_file
flame = 0 ; define_method :VK_update do flame+=1 end
key_save_data = YAML.load open(save_file)
[:VK_Push?,:VK_Down?].each do |me|
define_method me do |vk|
key_save_data[:VK_log][vk].include?(flame)
end
end
self
end
end
o = Object.new
o.extend Create_VK_action_m.arg(:profile0,"./dat/replay/replay1.yaml")
# o.extend Create_VK_action_replay.arg(:profile0,"./dat/replay/replay1.yaml")
g=[ [false]*10,[true]*4].flatten.cycle
Window.loop do
o.VK_update
if g.next
if o.VK_Down? :VK_3
p :t
end
end
p :vk0 if o.VK_Push? :VK_0
p :vk1 if o.VK_Down? :VK_1
exit if Input.keyPush? K_F9
end
---
default: profile0
profile0:
VK_0:
- K_Z
- K_RETURN
- P_BUTTON0
VK_1:
- K_X
- K_ESCAPE
- P_BUTTON1
VK_2:
- K_LSHIFT
- P_BUTTON2
VK_3:
- K_A
- P_BUTTON3
VK_4:
- K_S
- P_BUTTON4
VK_5:
- K_D
- P_BUTTON5
VK_6:
- K_F
- P_BUTTON6
VK_7:
- K_G
- P_BUTTON7
VK_8:
- K_H
- P_BUTTON8
VK_9:
- K_J
- P_BUTTON9
VK_10:
- K_K
- P_BUTTON10
VK_11:
- K_L
- P_BUTTON11
VK_12:
- K_C
- P_BUTTON12
VK_13:
- K_V
- P_BUTTON13
VK_14:
- K_B
- P_BUTTON14
VK_15:
- K_N
- P_BUTTON15
VK_LEFT:
- K_LEFT
- P_LEFT
VK_UP:
- K_UP
- P_UP
VK_RIGHT:
- K_RIGHT
- P_RIGHT
VK_DOWN:
- K_DOWN
- P_DOWN
profile1:
VK_0:
- K_C
VK_1:
- K_X
VK_2:
- K_LSHIFT
VK_3:
- K_LCONTROL
VK_4:
- K_Q
VK_5:
- K_S
VK_6:
- K_P
VK_7:
- K_G
VK_8:
- K_H
VK_9:
- K_B
VK_10:
- K_B
VK_11:
- K_B
VK_12:
- K_B
VK_13:
- K_B
VK_14:
- K_B
VK_15:
- K_B
VK_LEFT:
- K_LEFT
- P_LEFT
VK_UP:
- K_UP
- P_UP
VK_RIGHT:
- K_RIGHT
- P_RIGHT
VK_DOWN:
- K_DOWN
- P_DOWN
profile3:
VK_0:
- P_BUTTON0
VK_1:
- P_BUTTON1
VK_2:
- P_BUTTON2
VK_3:
- P_BUTTON3
VK_4:
- P_BUTTON4
VK_5:
- P_BUTTON5
VK_6:
- P_BUTTON6
VK_7:
- P_BUTTON7
VK_8:
- P_BUTTON8
VK_9:
- P_BUTTON9
VK_10:
- P_BUTTON10
VK_11:
- P_BUTTON11
VK_12:
- P_BUTTON12
VK_13:
- P_BUTTON13
VK_14:
- P_BUTTON14
VK_15:
- P_BUTTON15
VK_LEFT:
- P_LEFT
VK_UP:
- P_UP
VK_RIGHT:
- P_RIGHT
VK_DOWN:
- P_DOWN
---
:VK_log:
:VK_0:
-
- 30
- 53
- 70
- 80
- 89
- 127
- 139
- 151
- 162
- 172
- 187
- 199
:VK_1:
-
- 108
- 109
- 110
- 111
:VK_2:
-
:VK_3:
-
:VK_4:
-
:VK_5:
-
:VK_6:
-
:VK_7:
-
:VK_8:
-
:VK_9:
-
:VK_10:
-
:VK_11:
-
:VK_12:
-
:VK_13:
-
:VK_14:
-
:VK_15:
-
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment