Skip to content

Commit

Permalink
libdoomsday|DED: Episode definitions may include Hub subrecords
Browse files Browse the repository at this point in the history
  • Loading branch information
danij-deng committed Aug 7, 2014
1 parent 3688fd5 commit a912a6e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
7 changes: 7 additions & 0 deletions doomsday/libdoomsday/include/doomsday/defs/episode.h
Expand Up @@ -44,6 +44,13 @@ class LIBDOOMSDAY_PUBLIC Episode : public de::RecordAccessor
operator bool() const;
int order() const;

de::Record &addHub();

int hubCount() const;
bool hasHub(int index) const;
de::Record &hub(int index);
de::Record const &hub(int index) const;

private:
de::Record *_def; ///< Modifiable access.
};
Expand Down
37 changes: 37 additions & 0 deletions doomsday/libdoomsday/src/defs/episode.cpp
Expand Up @@ -37,6 +37,7 @@ void Episode::resetToDefaults()
_def->addText("menuHelpInfo", ""); // None.
_def->addText("menuImage", ""); // URI. None.
_def->addText("menuShortcut", ""); // Key name. None.
_def->addArray("hub", new ArrayValue);
}

Episode &Episode::operator = (Record *d)
Expand All @@ -57,4 +58,40 @@ Episode::operator bool() const
return accessedRecordPtr() != 0;
}

Record &Episode::addHub()
{
DENG2_ASSERT(_def);

Record *def = new Record;

def->addText ("id", 0);
def->addArray("map", new ArrayValue);

(*_def)["hub"].value<ArrayValue>()
.add(new RecordValue(def, RecordValue::OwnsRecord));

return *def;
}

int Episode::hubCount() const
{
return int(geta("hub").size());
}

bool Episode::hasHub(int index) const
{
return index >= 0 && index < hubCount();
}

Record &Episode::hub(int index)
{
DENG2_ASSERT(_def);
return *_def->geta("hub")[index].as<RecordValue>().record();
}

Record const &Episode::hub(int index) const
{
return *geta("hub")[index].as<RecordValue>().record();
}

} // namespace defn

0 comments on commit a912a6e

Please sign in to comment.