Skip to content

Commit

Permalink
qtscript: Add new function changePlayerColour()
Browse files Browse the repository at this point in the history
Also added initial script for automated testing.
  • Loading branch information
perim committed Dec 29, 2016
1 parent 8ffa53f commit 2e3d23d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/qtscriptfuncs.cpp
Expand Up @@ -65,6 +65,7 @@
#include "atmos.h"
#include "warcam.h"
#include "projectile.h"
#include "component.h"

#define FAKE_REF_LASSAT 999
#define ALL_PLAYERS -1
Expand Down Expand Up @@ -4215,6 +4216,17 @@ static QScriptValue js_replaceTexture(QScriptContext *context, QScriptEngine *)
return QScriptValue();
}

//-- \subsection{changePlayerColour(player, colour)}
//-- Change a player's colour slot. The current player colour can be read from the playerData array. There are as many
//-- colour slots as the maximum number of players. (3.2.3+ only)
static QScriptValue js_changePlayerColour(QScriptContext *context, QScriptEngine *)
{
int player = context->argument(0).toInt32();
int colour = context->argument(1).toInt32();
setPlayerColour(player, colour);
return QScriptValue();
}

// ----------------------------------------------------------------------------------------
// Register functions with scripting system

Expand Down Expand Up @@ -4940,6 +4952,7 @@ bool registerFunctions(QScriptEngine *engine, QString scriptName)
engine->globalObject().setProperty("removeSpotter", engine->newFunction(js_removeSpotter));
engine->globalObject().setProperty("syncRequest", engine->newFunction(js_syncRequest));
engine->globalObject().setProperty("replaceTexture", engine->newFunction(js_replaceTexture));
engine->globalObject().setProperty("changePlayerColour", engine->newFunction(js_changePlayerColour));

// horrible hacks follow -- do not rely on these being present!
engine->globalObject().setProperty("hackNetOff", engine->newFunction(js_hackNetOff));
Expand Down
38 changes: 38 additions & 0 deletions tests/test.sh
@@ -0,0 +1,38 @@
#!/bin/bash

rm -rf tmp
mkdir -p tmp

trap ctrl_c INT

function ctrl_c() {
echo " * Caught ctrl+c - aborting!"
exit 1
}

function run
{
echo
echo " -- $2 --"
echo
gdb -q --ex run --ex quit --args src/warzone2100 --window --configdir=tmp --resolution=1024x768 --shadows --sound --texturecompression $1
}

function cam
{
echo
echo " ==== $2 ===="
run "--game=$1 --saveandquit=savegames/campaign/$1.gam" "Initial run"
run "--loadcampaign=$1 --saveandquit=savegames/campaign/$1-loadsave.gam" "Loadsave run"
}

echo
echo "Running Warzone2100 automated tests"
echo -n "Time is: "
date -R

cam CAM_1A "Alpha campaign"
cam CAM_2A "Beta campaign"
cam CAM_3A "Gamma campaign"
cam TUTORIAL3 "Tutorial"
cam FASTPLAY "Fastplay"

0 comments on commit 2e3d23d

Please sign in to comment.