sscharter 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: '078536b530d41a0c31d05aefb2554ad1baf4221776ce7980b1dc05a6aa3c3603'
4
+ data.tar.gz: '0598dab880aa3f14a92f0c1b76df6814000b9e3c2499b9b79f6a2b0e9a458f09'
5
+ SHA512:
6
+ metadata.gz: 51b40f93074b6076c0b432ba5936788812c2f383dc6cfd8809adc3961cb14454133487753210ad53ba154ba548306796272cbbb9cb474aca4c036304f99cfce0
7
+ data.tar.gz: 3af6cee975b795e582f143c1d3b769cd47819fdee1eeab6d44e3ce66e43abf263e12448ad16e088286db5d038049e6c9e893f85cf4af529de75274528eccb2ef
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at ulysseszhan@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in sscharter.gemspec
6
+ gemspec
7
+
8
+ group :develop do
9
+ gem "rake", "~> 13.0"
10
+ gem "minitest", "~> 5.0"
11
+ end
12
+
13
+ gem 'rubyzip', '~> 2.3'
14
+ gem 'launchy', '~> 2.5'
15
+ gem 'webrick', '~> 1.8'
16
+ gem 'filewatcher', '~> 2.0'
data/Gemfile.lock ADDED
@@ -0,0 +1,39 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sscharter (0.1.0)
5
+ filewatcher (~> 2.0)
6
+ launchy (~> 2.5)
7
+ rubyzip (~> 2.3)
8
+ webrick (~> 1.8)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ addressable (2.8.5)
14
+ public_suffix (>= 2.0.2, < 6.0)
15
+ filewatcher (2.1.0)
16
+ module_methods (~> 0.1.0)
17
+ launchy (2.5.2)
18
+ addressable (~> 2.8)
19
+ minitest (5.19.0)
20
+ module_methods (0.1.0)
21
+ public_suffix (5.0.3)
22
+ rake (13.0.6)
23
+ rubyzip (2.3.2)
24
+ webrick (1.8.1)
25
+
26
+ PLATFORMS
27
+ x86_64-linux
28
+
29
+ DEPENDENCIES
30
+ filewatcher (~> 2.0)
31
+ launchy (~> 2.5)
32
+ minitest (~> 5.0)
33
+ rake (~> 13.0)
34
+ rubyzip (~> 2.3)
35
+ sscharter!
36
+ webrick (~> 1.8)
37
+
38
+ BUNDLED WITH
39
+ 2.4.13
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 sunniesnow
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # Sscharter
2
+
3
+ A Ruby DSL for writing Sunniesnow charts.
4
+
5
+ ## Installation
6
+
7
+ [Install Ruby](https://www.ruby-lang.org/en/documentation/installation/).
8
+ Then, run
9
+
10
+ ```shell
11
+ gem install sscharter
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ See [the tutorial](https://github.com/sunniesnow/sscharter/blob/master/tutorial/tutorial.md).
17
+
18
+ ## Development
19
+
20
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
21
+
22
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
23
+
24
+ ## Contributing
25
+
26
+ Bug reports and pull requests are welcome on GitHub at https://github.com/sunniesnow/sscharter. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/sunniesnow/sscharter/blob/master/CODE_OF_CONDUCT.md).
27
+
28
+ ## Code of Conduct
29
+
30
+ Everyone interacting in the Sscharter project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/sscharter/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/test_*.rb"]
10
+ end
11
+
12
+ task default: :test
data/exe/sscharter ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'sscharter'
5
+ require 'sscharter/cli'
6
+
7
+ command = ARGV.shift&.to_sym
8
+ unless Sunniesnow::Charter::CLI::COMMANDS.include? command
9
+ $stderr.puts "Usage: #{File.basename $0} <#{Sunniesnow::Charter::CLI::COMMANDS.join '|'}>"
10
+ exit 1
11
+ end
12
+
13
+ exit Sunniesnow::Charter::CLI.send(command, *ARGV) || 0
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ class Sunniesnow::Chart
6
+
7
+ using Sunniesnow::Utils
8
+
9
+ attr_accessor :title, :artist, :charter
10
+ attr_accessor :difficulty_name, :difficulty_color, :difficulty
11
+ attr_reader :events
12
+
13
+ def initialize
14
+ @title = ''
15
+ @artist = ''
16
+ @charter = ''
17
+ @difficulty_name = ''
18
+ @difficulty_color = '#000000'
19
+ @difficulty = ''
20
+ @events = []
21
+ end
22
+
23
+ def to_json *args
24
+ {
25
+ title: @title,
26
+ artist: @artist,
27
+ charter: @charter,
28
+ difficultyName: @difficulty_name,
29
+ difficultyColor: @difficulty_color,
30
+ difficulty: @difficulty,
31
+ events: @events
32
+ }.to_json
33
+ end
34
+ end
35
+
36
+ class Sunniesnow::Event
37
+
38
+ attr_accessor :time, :type
39
+ attr_reader :properties
40
+
41
+ def initialize time, type, **properties
42
+ @time = time
43
+ @type = type
44
+ @properties = properties
45
+ end
46
+
47
+ def [] key
48
+ @properties[key]
49
+ end
50
+
51
+ def []= key, value
52
+ @properties[key] = value
53
+ end
54
+
55
+ def to_json *args
56
+ {time: @time, type: @type, properties: @properties}.to_json
57
+ end
58
+ end
@@ -0,0 +1,192 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fileutils'
4
+ require 'yaml'
5
+ require 'cgi'
6
+
7
+ require 'zip'
8
+ require 'launchy'
9
+ require 'webrick'
10
+ require 'filewatcher'
11
+ require 'rake'
12
+ require 'bundler'
13
+
14
+ require 'sscharter'
15
+
16
+ module Sunniesnow
17
+ class Charter
18
+ module CLI
19
+ end
20
+ end
21
+ end
22
+
23
+ class Filewatcher
24
+ # This is a hack. See:
25
+ # https://github.com/filewatcher/filewatcher/blob/v2.0.0/lib/filewatcher.rb#L42
26
+ # The `exit` call here will cause the WEBrick server to report a fatal error.
27
+ def exit
28
+ stop
29
+ end
30
+ end
31
+
32
+ module Sunniesnow::Charter::CLI
33
+ module_function
34
+
35
+ COMMANDS = %i[init build serve]
36
+
37
+ def config
38
+ config_filename = '.sscharter.yml'
39
+ config_filename = '.sscharter.yaml' unless File.exist? config_filename
40
+ unless File.exist? config_filename
41
+ puts 'No .sscharter.yml found'
42
+ return nil
43
+ end
44
+ YAML.load_file config_filename, symbolize_names: true
45
+ end
46
+
47
+ def init project_dir, *files
48
+ if File.directory? project_dir
49
+ puts "Directory #{project_dir} already exists"
50
+ return 1
51
+ end
52
+ files_dir = File.join project_dir, 'files'
53
+ FileUtils.mkdir_p files_dir
54
+ FileUtils.cp_r files, files_dir
55
+ FileUtils.cd project_dir do
56
+ File.write 'Gemfile', <<~GEMFILE
57
+ # frozen_string_literal: true
58
+ source 'https://rubygems.org'
59
+ gem 'sscharter', '~> #{Sunniesnow::Charter::VERSION}'
60
+ gem 'rake', '~> #{Rake::VERSION}'
61
+ gem 'bundler', '~> #{Bundler::VERSION}'
62
+ GEMFILE
63
+ File.write 'Rakefile', <<~RAKEFILE
64
+ # frozen_string_literal: true
65
+ task default: :build
66
+ task :build do
67
+ exec 'bundle exec sscharter build'
68
+ end
69
+ task :serve do
70
+ exec 'bundle exec sscharter serve'
71
+ end
72
+ RAKEFILE
73
+ File.write '.gitignore', <<~GITIGNORE
74
+ /.bundle/
75
+ /tmp/
76
+ /build/
77
+ GITIGNORE
78
+ File.write '.sscharter.yml', <<~SSCHARTER
79
+ ---
80
+ project_name: #{File.basename project_dir}
81
+ build_dir: build
82
+ files_dir: files
83
+ sources_dir: src
84
+ include:
85
+ - README.md
86
+ SSCHARTER
87
+ File.write 'README.md', <<~README
88
+ # #{File.basename project_dir}
89
+
90
+ <!-- TODO: Write a description for your project here -->
91
+
92
+ ## Building
93
+
94
+ [Install Ruby (>= 3.0.0)](https://www.ruby-lang.org/en/documentation/installation/),
95
+ and then run `rake`.
96
+ The built chart will be `build/#{File.basename project_dir}.ssc`.
97
+
98
+ ## Legal status
99
+
100
+ <!-- The artist should have explicitly stated publicly that they permit charting the music,
101
+ or have contacted you to give proper permission.
102
+ Whether or not, you should state clearly the legal status of the chart here. -->
103
+ README
104
+ FileUtils.mkdir_p 'src'
105
+ File.write 'src/master.rb', <<~CHART
106
+ # frozen_string_literal: true
107
+
108
+ Sunniesnow::Charter.open 'master' do
109
+
110
+ title 'The title of the music'
111
+ artist 'The artist of the music'
112
+ charter 'Your name'
113
+ difficulty_name 'Master'
114
+ difficulty_color '#8c68f3'
115
+ difficulty '12'
116
+
117
+ offset 0
118
+ bpm 120
119
+
120
+ tp_chain 0, 0, 1 do
121
+ t -50, 0, 'hello'
122
+ b 1 # proceed by 1 beat
123
+ t 50, 0, 'world'
124
+ end
125
+
126
+ end
127
+ CHART
128
+ end
129
+ puts "Project initialized at #{project_dir}"
130
+ end
131
+
132
+ def build
133
+ return 1 unless config = self.config
134
+ project_name = config[:project_name] || File.basename(Dir.pwd)
135
+ build_dir = config[:build_dir] || 'build'
136
+ files_dir = config[:files_dir] || 'files'
137
+ sources_dir = config[:sources_dir] || 'src'
138
+ include_files = config[:include] || []
139
+ ::Sunniesnow::Charter.charts.clear
140
+ Dir.glob File.join sources_dir, '*.rb' do |filename|
141
+ load filename
142
+ rescue Exception => e
143
+ puts "Error loading #{filename}:"
144
+ puts e.full_message
145
+ return 1
146
+ end
147
+ FileUtils.mkdir_p build_dir
148
+ build_filename = File.join build_dir, "#{project_name}.ssc"
149
+ FileUtils.rm build_filename if File.exist? build_filename
150
+ Zip::File.open build_filename, create: true do |zip_file|
151
+ Dir.glob File.join files_dir, '**', '*' do |filename|
152
+ zip_file.add filename["#{files_dir}/".length..], filename
153
+ end
154
+ include_files.each do |pattern|
155
+ Dir.glob pattern do |filename|
156
+ zip_file.add filename, filename
157
+ end
158
+ end
159
+ ::Sunniesnow::Charter.charts.each do |name, chart|
160
+ zip_file.get_output_stream "#{name}.json" do |file|
161
+ file.write chart.output_json
162
+ end
163
+ end
164
+ end
165
+ 0
166
+ end
167
+
168
+ def serve port = 8011
169
+ port = port.to_i
170
+ config = self.config
171
+ server = WEBrick::HTTPServer.new Port: port, DocumentRoot: config[:build_dir]
172
+ server.mount_proc "/#{config[:project_name]}.ssc" do |request, response|
173
+ response['Content-Type'] = 'application/zip'
174
+ response['Access-Control-Allow-Origin'] = '*'
175
+ response.body = File.read File.join config[:build_dir], "#{config[:project_name]}.ssc"
176
+ end
177
+ url = CGI.escape "http://localhost:#{port}/#{config[:project_name]}.ssc"
178
+ filewatcher = Filewatcher.new [config[:files_dir], config[:sources_dir], *config[:include]]
179
+ Launchy.open "https://sunniesnow.github.io/game/?level-file=online&level-file-online=#{url}"
180
+ filewatcher_thread = Thread.new do
181
+ puts 'Building...'
182
+ puts build == 0 ? 'Finished' : 'Failed'
183
+ filewatcher.watch do |changes|
184
+ puts 'Rebuilding...'
185
+ puts build == 0 ? 'Finished' : 'Failed'
186
+ end
187
+ server.shutdown
188
+ end
189
+ server.start
190
+ 0
191
+ end
192
+ end
@@ -0,0 +1,41 @@
1
+ module Sunniesnow::Utils
2
+
3
+ refine Array do
4
+ # If there no match, return the next index.
5
+ # Less than all: return 0. Greater than all: return array.length.
6
+ def bisect value = nil, right: false, &compare_function
7
+ if value && compare_function
8
+ raise ArgumentError, "Cannot specify both value and compare_function"
9
+ end
10
+ compare_function ||= ->e { e <=> value }
11
+ low = 0
12
+ high = length
13
+ while low < high
14
+ mid = (low + high) / 2
15
+ compare = compare_function.(self[mid])
16
+ if compare == 0
17
+ return mid
18
+ elsif compare < 0
19
+ low = mid + 1
20
+ else
21
+ high = mid
22
+ end
23
+ end
24
+ right ? high - 1 : low
25
+ end
26
+ end
27
+
28
+ refine String do
29
+ def snake_to_camel
30
+ result = self.split('_').map!(&:capitalize).join
31
+ result[0] = result[0].downcase
32
+ result
33
+ end
34
+ end
35
+
36
+ refine Symbol do
37
+ def snake_to_camel
38
+ to_s.snake_to_camel.to_sym
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sunniesnow
4
+ class Charter
5
+ VERSION = "0.1.0"
6
+ end
7
+ end