glqgamemaster/Gentle-Love-Quest — pull request #21 by gegerlan (2012-01-03 00:45:48+00:00)
Title: Rewritten achievements

Achievements is now a singleton containing all achievements and their state.

Achievements
SAVE_FILE = "Data/Achievements.rvdata"
Where the completed achievements are stored
self.instance
returns instantiated Achievements
:[index]
returns achievement at index
:get(index)
returns achievement at index
:size
returns number of achievements
:load_data
loads saved achievement definition and completions into memory
:save
stores the completed achievements
:clear
removes all achievements

Since the class is a singleton, you'll need to call :instance to make sure that the same Achievements are being worked on.

Example
@achievements_i1 = Achievements.instance
@achievements_i2 = Achievements.instance # points to @achievements_i1
@achievements_n = Achievements.new
@achievements_i1.get(1).completed?
=> false
@achievements_i2.get(1).completed?
=> false
@achievements_n.get(1).completed?
=> false
@achievements_i1.get(1).completed = true
=> true
@achievements_i2.get(1).completed?
=> true # true since pointing to the value of @achievements_i1
@achievements_n.get(1).completed?
=> false # separate object

This can be a blessing or a curse, depending on who is coding. Just be aware of it.

Achievements in turn are stored as Achievement objects
:title
returns the title of the achievement
:description
returns the description of the achievement
:completed
returns or sets completed status (TRUE/FALSE)
:completed?
returns true if achievement is completed

Scene and Window classes that uses Achievements has been updated to use the new definitions.

Improvements could be...
* removal of false in the achievement definitions (the value is not used).
* to have a separate textile with the achievement definitions (e.g. an ini file).
* automatic tracking of variables and switches to see if the requirement for the achievement is met (to the extent it can be tracked through these means).
* some better singleton solution, to avoid issues related to people not calling Achievements.instance when they intend to.