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).



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/sscharter/chart.rb', line 82

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

#artistString

The artist 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.

Returns:

  • (String)


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

def artist
  @artist
end

#charterString

The author of the chart. 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.

Returns:

  • (String)


39
40
41
# File 'lib/sscharter/chart.rb', line 39

def charter
  @charter
end

#difficultyString

The difficulty of the chart. 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.

Returns:

  • (String)


63
64
65
# File 'lib/sscharter/chart.rb', line 63

def difficulty
  @difficulty
end

#difficulty_colorString

The difficulty color of the chart. 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.

Returns:

  • (String)


55
56
57
# File 'lib/sscharter/chart.rb', line 55

def difficulty_color
  @difficulty_color
end

#difficulty_nameString

The difficulty name of the chart. 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.

Returns:

  • (String)


47
48
49
# File 'lib/sscharter/chart.rb', line 47

def difficulty_name
  @difficulty_name
end

#difficulty_supString

The difficulty superscript of the chart. 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.

Returns:

  • (String)


71
72
73
# File 'lib/sscharter/chart.rb', line 71

def difficulty_sup
  @difficulty_sup
end

#eventsArray<Sunniesnow::Event> (readonly)

Returns:



74
75
76
# File 'lib/sscharter/chart.rb', line 74

def events
  @events
end

#titleString

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.

Returns:

  • (String)


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

def title
  @title
end

Instance Method Details

#to_json(*args) ⇒ String

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

Returns:

  • (String)


99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/sscharter/chart.rb', line 99

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