Skip to content

Commit

Permalink
libcore|ScriptedInfo: Observing newly parsed block records
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Aug 16, 2014
1 parent a4f87b9 commit 23b51b9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
2 changes: 2 additions & 0 deletions doomsday/libcore/include/de/scriptsys/scriptedinfo.h
Expand Up @@ -125,6 +125,8 @@ class DENG2_PUBLIC ScriptedInfo
public:
typedef QSet<String> Paths;

DENG2_DEFINE_AUDIENCE2(NamedBlock, void parsedNamedBlock(String const &name, Record &block))

public:
/**
* Creates a new ScriptedInfo parser.
Expand Down
27 changes: 21 additions & 6 deletions doomsday/libcore/src/scriptsys/scriptedinfo.cpp
Expand Up @@ -230,13 +230,24 @@ DENG2_PIMPL(ScriptedInfo)
}
else if(!block.name().isEmpty())
{
// Create the block record if it doesn't exist.
String varName = variableName(block);
if(!ns.has(varName))
{
ns.addRecord(varName);
}
Record &blockRecord = ns[varName];

// Block type placed into a special variable (only with named blocks, though).
ns.add(variableName(block).concatenateMember(VAR_BLOCK_TYPE)) =
new TextValue(block.blockType());
blockRecord.addText(VAR_BLOCK_TYPE, block.blockType());

// Also store source location in a special variable.
ns.add(variableName(block).concatenateMember(VAR_SOURCE)) =
new TextValue(block.sourceLocation());
blockRecord.addText(VAR_SOURCE, block.sourceLocation());

DENG2_FOR_PUBLIC_AUDIENCE2(NamedBlock, i)
{
i->parsedNamedBlock(varName, blockRecord);
}
}

foreach(Info::Element const *sub, block.contentsInOrder())
Expand Down Expand Up @@ -380,8 +391,12 @@ DENG2_PIMPL(ScriptedInfo)
findBlocks(blockType, paths, *i.value(), prefix.concatenateMember(i.key()));
}
}

DENG2_PIMPL_AUDIENCE(NamedBlock)
};

DENG2_AUDIENCE_METHOD(ScriptedInfo, NamedBlock)

ScriptedInfo::ScriptedInfo(Record *globalNamespace)
: d(new Instance(this, globalNamespace))
{}
Expand Down Expand Up @@ -432,9 +447,9 @@ ScriptedInfo::Paths ScriptedInfo::allBlocksOfType(String const &blockType) const

String ScriptedInfo::absolutePathInContext(Record const &context, String const &relativePath) // static
{
if(context.has("__source__"))
if(context.has(VAR_SOURCE))
{
String src = context["__source__"].value<TextValue>();
String src = context[VAR_SOURCE].value<TextValue>();
int pos = src.lastIndexOf(':');
if(pos < 0) return src / relativePath;
src.truncate(pos);
Expand Down

0 comments on commit 23b51b9

Please sign in to comment.