neri 0.1.7 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/neri/dxruby.rb CHANGED
@@ -4,38 +4,28 @@ require "dxruby" unless defined? DXRuby
4
4
 
5
5
  module Neri
6
6
  module DXRubyImage
7
- def load(path, x=nil, y=nil, width=nil, height=nil)
8
- if Neri.exist_in_datafile?(path)
9
- image = load_from_file_in_memory(Neri.file_read(path))
10
- image = image.slice(x, y, width, height) if x && y && width && height
11
- return image
12
- else
13
- return super
14
- end
7
+ def load(path, x = nil, y = nil, width = nil, height = nil)
8
+ return super unless Neri.exist_in_datafile?(path)
9
+
10
+ image = load_from_file_in_memory(Neri.file_read(path))
11
+ image = image.slice(x, y, width, height) if x && y && width && height
12
+ image
15
13
  end
16
-
17
- def load_tiles(path, xcount, ycount, share_switch=true)
18
- if Neri.exist_in_datafile?(path) && !share_switch
19
- image = load_from_file_in_memory(Neri.file_read(path))
20
- return image.slice_tiles(xcount, ycount)
21
- else
22
- return super
23
- end
14
+
15
+ def load_tiles(path, xcount, ycount, share_switch = true)
16
+ return super unless Neri.exist_in_datafile?(path) && !share_switch
17
+
18
+ image = load_from_file_in_memory(Neri.file_read(path))
19
+ image.slice_tiles(xcount, ycount)
24
20
  end
25
21
  end
26
-
22
+
27
23
  module DXRubySound
28
24
  def new(path)
29
- if Neri.exist_in_datafile?(path)
30
- case File.extname(path)
31
- when ".mid"
32
- return load_from_memory(Neri.file_read(path), DXRuby::TYPE_MIDI)
33
- else
34
- return load_from_memory(Neri.file_read(path), DXRuby::TYPE_WAV)
35
- end
36
- else
37
- return super
38
- end
25
+ return super unless Neri.exist_in_datafile?(path)
26
+
27
+ load_from_memory(Neri.file_read(path),
28
+ File.extname(path) == ".mid" ? DXRuby::TYPE_MIDI : DXRuby::TYPE_WAV)
39
29
  end
40
30
  end
41
31
  end
@@ -46,7 +36,7 @@ module DXRuby
46
36
  prepend Neri::DXRubyImage
47
37
  end
48
38
  end
49
-
39
+
50
40
  class Sound
51
41
  class << self
52
42
  prepend Neri::DXRubySound
@@ -5,7 +5,7 @@ require "dxruby_tiled" unless defined? DXRuby::Tiled
5
5
  module DXRuby
6
6
  module Tiled
7
7
  module_function
8
-
8
+
9
9
  def read_file(file, encoding = Encoding::UTF_8)
10
10
  Neri.file_read(file, encoding)
11
11
  end
data/lib/neri/runtime.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require "neri/version"
2
2
 
3
- alias :_neri_orig_require :require
4
- alias :_neri_orig_load :load
3
+ alias _neri_orig_require require
4
+ alias _neri_orig_load load
5
5
 
6
6
  def require(feature)
7
7
  Neri.require(feature)
@@ -16,12 +16,14 @@ module Neri
16
16
  @datafile = nil
17
17
  @system_dir = nil
18
18
  @files = {}
19
+ @fullpath_files = nil
20
+ @current_directory = nil
19
21
  @xor = nil
20
-
22
+
21
23
  class << self
22
24
  def datafile=(datafile)
23
- @datafile = datafile
24
- @system_dir = File.dirname(File.expand_path(datafile)) + File::SEPARATOR
25
+ @datafile = datafile.encode(Encoding::UTF_8)
26
+ @system_dir = File.dirname(File.expand_path(@datafile)) + File::SEPARATOR
25
27
  files_length = File.binread(@datafile, BLOCK_LENGTH).to_i
26
28
  files_str = read(files_length, BLOCK_LENGTH)
27
29
  pos = files_length + BLOCK_LENGTH
@@ -31,115 +33,116 @@ module Neri
31
33
  filename, length, offset = line.split("\t")
32
34
  @files[filename] = [length.to_i, offset.to_i + pos]
33
35
  end
36
+ @current_directory = nil
34
37
  end
35
-
38
+
36
39
  def key=(key)
37
- @xor = key.scan(/../).map{|a| a.to_i(16)}.pack("c*")
40
+ @xor = key.scan(/../).map { |a| a.to_i(16) }.pack("c*")
38
41
  end
39
-
42
+
40
43
  def require(feature)
44
+ feature = feature.encode(Encoding::UTF_8)
41
45
  filepath = nil
42
- load_path.each do |path|
46
+ (feature.start_with?(/[a-z]:/i, "\\", "/", ".") ? [""] : load_path).each do |path|
43
47
  ["", ".rb"].each do |ext|
44
- next unless exist_in_datafile?(path + feature + ext)
45
- filepath = adjust_path(path + feature + ext)
48
+ tmp_path = path + feature + ext
49
+ filepath ||= tmp_path if exist_in_datafile?(tmp_path)
46
50
  end
47
51
  end
48
-
49
- if filepath
50
- return false if $LOADED_FEATURES.index(filepath)
51
- code = load_code(filepath)
52
- eval(code, nil, filepath)
53
- $LOADED_FEATURES.push(filepath)
54
- return true
55
- else
56
- return _neri_orig_require(feature)
57
- end
52
+
53
+ return _neri_orig_require(feature) unless filepath
54
+ return false if $LOADED_FEATURES.index(filepath)
55
+
56
+ code = load_code(filepath)
57
+ eval(code, TOPLEVEL_BINDING, filepath)
58
+ $LOADED_FEATURES.push(filepath)
59
+ true
58
60
  end
59
-
61
+
60
62
  def load(file, priv = false)
63
+ file = file.encode(Encoding::UTF_8)
61
64
  filepath = nil
62
- (load_path + [""]).each do |path|
63
- filepath = path + file if exist_in_datafile?(path + file)
65
+ paths = file.start_with?(/[a-z]:/i, "\\", "/", ".") ? [""] : load_path + [""]
66
+ paths.each do |path|
67
+ filepath ||= path + file if exist_in_datafile?(path + file)
64
68
  end
65
-
66
- if filepath
67
- code = load_code(filepath)
68
- if priv
69
- eval(code, nil, filepath)
70
- else
71
- Module.new.module_eval(code, filepath)
72
- end
69
+
70
+ return _neri_orig_load(file, priv) unless filepath
71
+
72
+ code = load_code(filepath)
73
+ if priv
74
+ Module.new.module_eval(code, filepath)
73
75
  else
74
- _neri_orig_load(filepath || file, priv)
76
+ eval(code, TOPLEVEL_BINDING, filepath)
75
77
  end
78
+ true
76
79
  end
77
-
80
+
78
81
  def file_exist?(filename)
79
- return exist_in_datafile?(filename) || File.exist?(filename)
82
+ exist_in_datafile?(filename) || File.exist?(filename)
80
83
  end
81
-
84
+
82
85
  def file_read(filename, encoding = Encoding::BINARY)
86
+ filename = filename.encode(Encoding::UTF_8)
83
87
  str = nil
84
88
  if exist_in_datafile?(filename)
85
- length, offset = @files[adjust_path(filename.encode(Encoding::UTF_8))]
89
+ length, offset = fullpath_files[File.expand_path(filename)]
86
90
  str = read(length, offset)
87
91
  else
88
92
  str = File.binread(filename)
89
93
  end
90
94
  str.force_encoding(encoding)
91
- return str
92
95
  end
93
-
94
- def files()
95
- return @files.keys
96
+
97
+ def files
98
+ @files.keys
96
99
  end
97
-
100
+
98
101
  def exist_in_datafile?(filename)
99
- return @files.has_key?(adjust_path(filename.encode(Encoding::UTF_8)))
102
+ fullpath_files.key?(File.expand_path(filename.encode(Encoding::UTF_8)))
100
103
  end
101
-
104
+
102
105
  private
103
-
104
- def xor(str)
105
- str.force_encoding(Encoding::BINARY)
106
- while str.bytesize % BLOCK_LENGTH != 0
107
- str << rand(256).chr
108
- end
109
- if defined?(Xorcist)
110
- return Xorcist.xor!(str, @xor * (str.bytesize / BLOCK_LENGTH))
111
- else
112
- s = []
113
- str.unpack("Q*").zip((@xor * (str.bytesize / BLOCK_LENGTH)).unpack("Q*")){|a, b| s.push(a ^ b)}
114
- return s.pack("Q*")
106
+
107
+ def fullpath_files
108
+ if @current_directory != Dir.pwd
109
+ @current_directory = Dir.pwd
110
+ @fullpath_files = @files.transform_keys { |k| File.expand_path(k) }
115
111
  end
112
+ @fullpath_files
116
113
  end
117
-
118
- def adjust_path(path)
119
- return path.sub(/^\.\//, "")
114
+
115
+ def xor(str)
116
+ str.force_encoding(Encoding::BINARY)
117
+ str << rand(256).chr while str.bytesize % BLOCK_LENGTH != 0
118
+ xor_str = @xor * (str.bytesize / BLOCK_LENGTH)
119
+ return Xorcist.xor!(str, xor_str) if defined?(Xorcist)
120
+
121
+ s = []
122
+ str.unpack("Q*").zip((xor_str).unpack("Q*")) { |a, b| s.push(a ^ b) }
123
+ s.pack("Q*")
120
124
  end
121
-
125
+
122
126
  def read(length, offset)
123
- if @xor
124
- tmp_length = length
125
- tmp_length += BLOCK_LENGTH - length % BLOCK_LENGTH unless length % BLOCK_LENGTH == 0
126
- return xor(File.binread(@datafile, tmp_length, offset))[0, length]
127
- else
128
- return File.binread(@datafile, length, offset)
129
- end
127
+ return File.binread(@datafile, length, offset) unless @xor
128
+
129
+ tmp_length = length
130
+ tmp_length += BLOCK_LENGTH - length % BLOCK_LENGTH unless length % BLOCK_LENGTH == 0
131
+ xor(File.binread(@datafile, tmp_length, offset))[0, length]
130
132
  end
131
-
132
- def load_path()
133
- return $LOAD_PATH unless @system_dir
134
- return $LOAD_PATH.map{|path| path.sub(@system_dir, "*neri*#{File::SEPARATOR}") + File::SEPARATOR }
133
+
134
+ def load_path
135
+ paths = $LOAD_PATH.map { |path| path.encode(Encoding::UTF_8) }
136
+ return paths unless @system_dir
137
+
138
+ paths.map { |path| path.sub(@system_dir, "*neri*#{File::SEPARATOR}") + File::SEPARATOR }
135
139
  end
136
-
140
+
137
141
  def load_code(file)
138
142
  code = file_read(file)
139
143
  encoding = "UTF-8"
140
- encoding = $1 if code.lines[0..2].join("\n").match(/coding:\s*(\S+)/)
144
+ encoding = Regexp.last_match(1) if code.lines[0..2].join("\n").match(/coding:\s*(\S+)/)
141
145
  code.force_encoding(encoding)
142
- return code
143
146
  end
144
147
  end
145
148
  end
data/lib/neri/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Neri
2
- VERSION = "0.1.7"
2
+ VERSION = -"0.9.3"
3
3
  end
data/neri.gemspec CHANGED
@@ -1,36 +1,35 @@
1
- # coding: utf-8
2
- lib = File.expand_path("../lib", __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "neri/version"
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/neri/version"
5
4
 
6
5
  Gem::Specification.new do |spec|
7
6
  spec.name = "neri"
8
7
  spec.version = Neri::VERSION
9
8
  spec.authors = ["nodai2hITC"]
10
9
  spec.email = ["nodai2h.itc@gmail.com"]
11
-
12
- spec.summary = %q{One-Click Ruby Application Builder}
13
- spec.description = %q{Neri builds Windows batfile or exefile from Ruby script.}
10
+
11
+ spec.summary = "One-Click Ruby Application Builder"
12
+ spec.description = "Neri builds Windows batfile or exefile from Ruby script."
14
13
  spec.homepage = "https://github.com/nodai2hITC/neri"
15
14
  spec.license = "MIT"
16
-
17
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
- # to allow pushing to a single host or delete this section to allow pushing to any host.
19
- if spec.respond_to?(:metadata)
20
- # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
21
- else
22
- raise "RubyGems 2.0 or newer is required to protect against " \
23
- "public gem pushes."
24
- end
25
-
26
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
- f.match(%r{^(test|spec|features)/})
15
+ spec.required_ruby_version = ">= 2.5.0"
16
+
17
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'https://mygemserver.com'"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = spec.homepage
21
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject do |f|
27
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
28
+ end
28
29
  end
29
30
  spec.bindir = "exe"
30
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
31
32
  spec.require_paths = ["lib"]
32
-
33
- spec.add_development_dependency "bundler", "~> 1.15"
34
- spec.add_development_dependency "rake", "~> 10.0"
35
- spec.add_development_dependency "pry"
33
+
34
+ spec.add_dependency "win32api"
36
35
  end
metadata CHANGED
@@ -1,51 +1,23 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neri
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - nodai2hITC
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-04 00:00:00.000000000 Z
11
+ date: 2021-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.15'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.15'
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '10.0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '10.0'
41
- - !ruby/object:Gem::Dependency
42
- name: pry
14
+ name: win32api
43
15
  requirement: !ruby/object:Gem::Requirement
44
16
  requirements:
45
17
  - - ">="
46
18
  - !ruby/object:Gem::Version
47
19
  version: '0'
48
- type: :development
20
+ type: :runtime
49
21
  prerelease: false
50
22
  version_requirements: !ruby/object:Gem::Requirement
51
23
  requirements:
@@ -60,7 +32,6 @@ executables:
60
32
  extensions: []
61
33
  extra_rdoc_files: []
62
34
  files:
63
- - ".gitignore"
64
35
  - Gemfile
65
36
  - LICENSE.txt
66
37
  - README.ja.md
@@ -81,8 +52,10 @@ files:
81
52
  homepage: https://github.com/nodai2hITC/neri
82
53
  licenses:
83
54
  - MIT
84
- metadata: {}
85
- post_install_message:
55
+ metadata:
56
+ homepage_uri: https://github.com/nodai2hITC/neri
57
+ source_code_uri: https://github.com/nodai2hITC/neri
58
+ post_install_message:
86
59
  rdoc_options: []
87
60
  require_paths:
88
61
  - lib
@@ -90,16 +63,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
90
63
  requirements:
91
64
  - - ">="
92
65
  - !ruby/object:Gem::Version
93
- version: '0'
66
+ version: 2.5.0
94
67
  required_rubygems_version: !ruby/object:Gem::Requirement
95
68
  requirements:
96
69
  - - ">="
97
70
  - !ruby/object:Gem::Version
98
71
  version: '0'
99
72
  requirements: []
100
- rubyforge_project:
101
- rubygems_version: 2.6.12
102
- signing_key:
73
+ rubygems_version: 3.2.30
74
+ signing_key:
103
75
  specification_version: 4
104
76
  summary: One-Click Ruby Application Builder
105
77
  test_files: []
data/.gitignore DELETED
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/