nskins / goby

Command-line role-playing game framework
MIT License
122 stars 56 forks source link

Move to saved map #107

Closed nskins closed 7 years ago

nskins commented 7 years ago

A circular reference arises if we try to place one Event each on two Maps for moving to and from one another.

Since saved maps are accessible by the name of the Map (via Player.saved_maps), one possible solution is to create a new function where the name is specified rather than the Map object (see #Player.move_to). The function would be pretty similar to #move_to. Alternatively, we could extend move_to to accept either a Map or String and to act accordingly. It might prevent duplicate code, although the documentation would be more confusing. The code might be stinky, too.

nskins commented 7 years ago

Actually, this can be solved by referring to the first map via Player.saved_maps. For instance, the first map might contain the line:

player.move_to(Couple.new(0,0), Island.new)

Knowing that :the Player has saved the first map (say, with name "City"), the second map would have this line:

player.move_to(Couple.new(0,0), player.saved_maps["City"])

Since the circular reference problem is resolved, I'll just close this for now.