Skip to content

Commit

Permalink
qtscript: New function addLabel(object, label)
Browse files Browse the repository at this point in the history
  • Loading branch information
perim committed Nov 17, 2012
1 parent d9b0863 commit 5de3539
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/qtscriptfuncs.cpp
Expand Up @@ -546,6 +546,22 @@ static QScriptValue js_enumLabels(QScriptContext *, QScriptEngine *engine)
return result;
}

//-- \subsection{addLabel(object, label)}
//-- Add a label to a game object. If the game object already has a label, it is overwritten.
static QScriptValue js_addLabel(QScriptContext *context, QScriptEngine *engine)
{
struct labeltype value;
QScriptValue structVal = context->argument(0);
value.id = structVal.property("id").toInt32();
value.player = structVal.property("player").toInt32();
value.type = OBJ_DROID;
BASE_OBJECT *psObj = IdToPointer(value.id, value.player);
SCRIPT_ASSERT(context, psObj, "Object id %d not found belonging to player %d", value.id, value.player);
QString key = context->argument(1).toString();
labels.insert(key, value);
return QScriptValue();
}

//-- \subsection{label(key)}
//-- Fetch something denoted by a label. A label refers to an area, a position or a \emph{game object} on
//-- the map defined using the map editor and stored together with the map. The only argument
Expand Down Expand Up @@ -2817,6 +2833,7 @@ bool registerFunctions(QScriptEngine *engine)
// Register functions to the script engine here
engine->globalObject().setProperty("_", engine->newFunction(js_translate));
engine->globalObject().setProperty("label", engine->newFunction(js_label));
engine->globalObject().setProperty("addLabel", engine->newFunction(js_addLabel));
engine->globalObject().setProperty("enumLabels", engine->newFunction(js_enumLabels));
engine->globalObject().setProperty("enumGateways", engine->newFunction(js_enumGateways));
engine->globalObject().setProperty("enumTemplates", engine->newFunction(js_enumTemplates));
Expand Down

0 comments on commit 5de3539

Please sign in to comment.