Class: Sunniesnow::Chart

Inherits:
Object
  • Object
show all
Defined in:
lib/sscharter/chart.rb

Overview

A class to represent a chart. Basically a wrapper around the metadata and events (Event) of a chart. The main method is #to_json, which converts the chart to a JSON string that is actually recognizable by Sunniesnow.

Constant Summary collapse

SCHEMA =

The schema URL for the output JSON. This will be set as the ‘$schema` property in the generated JSON.

'https://sunniesnow.github.io/schema/chart-1.0.json'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(live_reload_port: 31108, production: false) ⇒ Chart

Returns a new instance of Chart.

Parameters:

  • live_reload_port (Integer) (defaults to: 31108)

    The port to use for live reload. It is useless if production is true.

  • production (Boolean) (defaults to: false)

    Whether the chart is in production or not. If true, the generated JSON (see #to_json) will not contain necessary information for sscharter integration in Sunniesnow (such as the live reload feature and reverse search feature).



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/sscharter/chart.rb', line 40

def initialize live_reload_port: 31108, production: false
  @title = ''
  @artist = ''
  @charter = ''
  @difficulty_name = ''
  @difficulty_color = '#000000'
  @difficulty = ''
  @difficulty_sup = ''
  @events = []
  @live_reload_port = live_reload_port
  @production = production
end

Instance Attribute Details

#artistObject

Returns the value of attribute artist.



24
25
26
# File 'lib/sscharter/chart.rb', line 24

def artist
  @artist
end

#charterObject

Returns the value of attribute charter.



25
26
27
# File 'lib/sscharter/chart.rb', line 25

def charter
  @charter
end

#difficultyObject

Returns the value of attribute difficulty.



28
29
30
# File 'lib/sscharter/chart.rb', line 28

def difficulty
  @difficulty
end

#difficulty_colorObject

Returns the value of attribute difficulty_color.



27
28
29
# File 'lib/sscharter/chart.rb', line 27

def difficulty_color
  @difficulty_color
end

#difficulty_nameObject

Returns the value of attribute difficulty_name.



26
27
28
# File 'lib/sscharter/chart.rb', line 26

def difficulty_name
  @difficulty_name
end

#difficulty_supObject

Returns the value of attribute difficulty_sup.



29
30
31
# File 'lib/sscharter/chart.rb', line 29

def difficulty_sup
  @difficulty_sup
end

#eventsObject (readonly)

An array of Sunniesnow::Event.



32
33
34
# File 'lib/sscharter/chart.rb', line 32

def events
  @events
end

#titleObject

The title of the music. This is one of the metadata of the chart which will be reflected in the generated JSON. Also, see chart file specifications for more info.



22
23
24
# File 'lib/sscharter/chart.rb', line 22

def title
  @title
end

Instance Method Details

#to_json(*args) ⇒ Object

Convert to JSON. A Sunniesnow chart is always a JSON file in the level file. This method is used to generate that JSON file.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/sscharter/chart.rb', line 57

def to_json *args
  hash = {
    '$schema': SCHEMA,
    title: @title,
    artist: @artist,
    charter: @charter,
    difficultyName: @difficulty_name,
    difficultyColor: @difficulty_color,
    difficulty: @difficulty,
    difficultySup: @difficulty_sup,
    events: @events
  }
  hash[:sscharter] = {
    version: Sunniesnow::Charter::VERSION,
    port: @live_reload_port
  } unless @production
  hash.to_json *args
end