Permalink
Fetching contributors…
Cannot retrieve contributors at this time
9245 lines (7944 sloc) 274 KB
/**
* miniSphere JavaScript game engine
* Copyright (c) 2015-2018, Fat Cerberus
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of miniSphere nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
**/
// WARNING: the Sphere v1 API contains a lot of redundancy and as a result its implementation here
// duplicates code often. it would be nice to prune some of this mess back, but Sphere v1
// is deprecated so I have more important things to do. maybe someday...
#include "minisphere.h"
#include "vanilla.h"
#include "animation.h"
#include "api.h"
#include "audio.h"
#include "byte_array.h"
#include "debugger.h"
#include "dispatch.h"
#include "font.h"
#include "galileo.h"
#include "image.h"
#include "input.h"
#include "jsal.h"
#include "kev_file.h"
#include "legacy.h"
#include "logger.h"
#include "map_engine.h"
#include "script.h"
#include "spriteset.h"
#include "windowstyle.h"
#define API_VERSION 2.0
#define API_VERSION_STRING "v2.0"
static bool js_Abort (int num_args, bool is_ctor, intptr_t magic);
static bool js_AddTrigger (int num_args, bool is_ctor, intptr_t magic);
static bool js_AddZone (int num_args, bool is_ctor, intptr_t magic);
static bool js_ApplyColorMask (int num_args, bool is_ctor, intptr_t magic);
static bool js_AreKeysLeft (int num_args, bool is_ctor, intptr_t magic);
static bool js_AreZonesAt (int num_args, bool is_ctor, intptr_t magic);
static bool js_AttachCamera (int num_args, bool is_ctor, intptr_t magic);
static bool js_AttachInput (int num_args, bool is_ctor, intptr_t magic);
static bool js_AttachPlayerInput (int num_args, bool is_ctor, intptr_t magic);
static bool js_BezierCurve (int num_args, bool is_ctor, intptr_t magic);
static bool js_BindJoystickButton (int num_args, bool is_ctor, intptr_t magic);
static bool js_BindKey (int num_args, bool is_ctor, intptr_t magic);
static bool js_BlendColors (int num_args, bool is_ctor, intptr_t magic);
static bool js_CallDefaultMapScript (int num_args, bool is_ctor, intptr_t magic);
static bool js_CallDefaultPersonScript (int num_args, bool is_ctor, intptr_t magic);
static bool js_CallMapScript (int num_args, bool is_ctor, intptr_t magic);
static bool js_CallPersonScript (int num_args, bool is_ctor, intptr_t magic);
static bool js_ChangeMap (int num_args, bool is_ctor, intptr_t magic);
static bool js_ClearPersonCommands (int num_args, bool is_ctor, intptr_t magic);
static bool js_CreatePerson (int num_args, bool is_ctor, intptr_t magic);
static bool js_CreateByteArray (int num_args, bool is_ctor, intptr_t magic);
static bool js_CreateByteArrayFromString (int num_args, bool is_ctor, intptr_t magic);
static bool js_CreateColor (int num_args, bool is_ctor, intptr_t magic);
static bool js_CreateColorMatrix (int num_args, bool is_ctor, intptr_t magic);
static bool js_CreateDirectory (int num_args, bool is_ctor, intptr_t magic);
static bool js_CreateSpriteset (int num_args, bool is_ctor, intptr_t magic);
static bool js_CreateStringFromByteArray (int num_args, bool is_ctor, intptr_t magic);
static bool js_CreateStringFromCode (int num_args, bool is_ctor, intptr_t magic);
static bool js_CreateSurface (int num_args, bool is_ctor, intptr_t magic);
static bool js_DeflateByteArray (int num_args, bool is_ctor, intptr_t magic);
static bool js_DestroyPerson (int num_args, bool is_ctor, intptr_t magic);
static bool js_DetachCamera (int num_args, bool is_ctor, intptr_t magic);
static bool js_DetachInput (int num_args, bool is_ctor, intptr_t magic);
static bool js_DetachPlayerInput (int num_args, bool is_ctor, intptr_t magic);
static bool js_DoEvents (int num_args, bool is_ctor, intptr_t magic);
static bool js_DoesFileExist (int num_args, bool is_ctor, intptr_t magic);
static bool js_DoesPersonExist (int num_args, bool is_ctor, intptr_t magic);
static bool js_Delay (int num_args, bool is_ctor, intptr_t magic);
static bool js_EvaluateScript (int num_args, bool is_ctor, intptr_t magic);
static bool js_EvaluateSystemScript (int num_args, bool is_ctor, intptr_t magic);
static bool js_ExecuteGame (int num_args, bool is_ctor, intptr_t magic);
static bool js_ExecuteTrigger (int num_args, bool is_ctor, intptr_t magic);
static bool js_ExecuteZoneScript (int num_args, bool is_ctor, intptr_t magic);
static bool js_ExecuteZones (int num_args, bool is_ctor, intptr_t magic);
static bool js_Exit (int num_args, bool is_ctor, intptr_t magic);
static bool js_ExitMapEngine (int num_args, bool is_ctor, intptr_t magic);
static bool js_FilledCircle (int num_args, bool is_ctor, intptr_t magic);
static bool js_FilledComplex (int num_args, bool is_ctor, intptr_t magic);
static bool js_FilledEllipse (int num_args, bool is_ctor, intptr_t magic);
static bool js_FlipScreen (int num_args, bool is_ctor, intptr_t magic);
static bool js_FollowPerson (int num_args, bool is_ctor, intptr_t magic);
static bool js_GarbageCollect (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetActingPerson (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetCameraPerson (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetCameraX (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetCameraY (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetClippingRectangle (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetCurrentMap (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetCurrentPerson (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetCurrentTrigger (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetCurrentZone (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetDirectoryList (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetFileList (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetFrameRate (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetGameList (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetInputPerson (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetJoystickAxis (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetKey (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetKeyString (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetLayerAngle (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetLayerHeight (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetLayerMask (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetLayerName (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetLayerWidth (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetLocalAddress (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetLocalName (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetMapEngine (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetMapEngineFrameRate (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetMouseWheelEvent (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetMouseX (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetMouseY (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetNextAnimatedTile (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetNumJoysticks (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetNumJoystickAxes (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetNumJoystickButtons (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetNumLayers (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetNumMouseWheelEvents (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetNumTiles (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetNumTriggers (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetNumZones (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetObstructingPerson (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetObstructingTile (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetPersonAngle (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetPersonBase (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetPersonData (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetPersonDirection (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetPersonFollowDistance (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetPersonFollowers (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetPersonFrame (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetPersonFrameNext (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetPersonFrameRevert (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetPersonIgnoreList (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetPersonLayer (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetPersonLeader (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetPersonList (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetPersonMask (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetPersonOffsetX (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetPersonOffsetY (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetPersonSpeedX (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetPersonSpeedY (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetPersonSpriteset (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetPersonValue (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetPersonX (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetPersonY (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetPersonXFloat (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetPersonYFloat (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetPlayerKey (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetScreenHeight (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetScreenWidth (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetSystemArrow (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetSystemDownArrow (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetSystemFont (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetSystemUpArrow (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetSystemWindowStyle (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetTalkActivationButton (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetTalkActivationKey (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetTalkDistance (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetTile (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetTileDelay (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetTileHeight (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetTileImage (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetTileName (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetTileSurface (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetTileWidth (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetTime (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetToggleState (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetTriggerLayer (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetTriggerX (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetTriggerY (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetVersion (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetVersionString (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetZoneHeight (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetZoneLayer (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetZoneSteps (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetZoneWidth (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetZoneX (int num_args, bool is_ctor, intptr_t magic);
static bool js_GetZoneY (int num_args, bool is_ctor, intptr_t magic);
static bool js_GrabImage (int num_args, bool is_ctor, intptr_t magic);
static bool js_GrabSurface (int num_args, bool is_ctor, intptr_t magic);
static bool js_GradientCircle (int num_args, bool is_ctor, intptr_t magic);
static bool js_GradientComplex (int num_args, bool is_ctor, intptr_t magic);
static bool js_GradientEllipse (int num_args, bool is_ctor, intptr_t magic);
static bool js_GradientLine (int num_args, bool is_ctor, intptr_t magic);
static bool js_GradientRectangle (int num_args, bool is_ctor, intptr_t magic);
static bool js_GradientTriangle (int num_args, bool is_ctor, intptr_t magic);
static bool js_HashByteArray (int num_args, bool is_ctor, intptr_t magic);
static bool js_HashFromFile (int num_args, bool is_ctor, intptr_t magic);
static bool js_IgnorePersonObstructions (int num_args, bool is_ctor, intptr_t magic);
static bool js_IgnoreTileObstructions (int num_args, bool is_ctor, intptr_t magic);
static bool js_InflateByteArray (int num_args, bool is_ctor, intptr_t magic);
static bool js_IsAnyKeyPressed (int num_args, bool is_ctor, intptr_t magic);
static bool js_IsCameraAttached (int num_args, bool is_ctor, intptr_t magic);
static bool js_IsCommandQueueEmpty (int num_args, bool is_ctor, intptr_t magic);
static bool js_IsIgnoringPersonObstructions (int num_args, bool is_ctor, intptr_t magic);
static bool js_IsIgnoringTileObstructions (int num_args, bool is_ctor, intptr_t magic);
static bool js_IsInputAttached (int num_args, bool is_ctor, intptr_t magic);
static bool js_IsJoystickButtonPressed (int num_args, bool is_ctor, intptr_t magic);
static bool js_IsKeyPressed (int num_args, bool is_ctor, intptr_t magic);
static bool js_IsLayerReflective (int num_args, bool is_ctor, intptr_t magic);
static bool js_IsLayerVisible (int num_args, bool is_ctor, intptr_t magic);
static bool js_IsMapEngineRunning (int num_args, bool is_ctor, intptr_t magic);
static bool js_IsMouseButtonPressed (int num_args, bool is_ctor, intptr_t magic);
static bool js_IsPersonObstructed (int num_args, bool is_ctor, intptr_t magic);
static bool js_IsPersonVisible (int num_args, bool is_ctor, intptr_t magic);
static bool js_IsTriggerAt (int num_args, bool is_ctor, intptr_t magic);
static bool js_Line (int num_args, bool is_ctor, intptr_t magic);
static bool js_LineIntersects (int num_args, bool is_ctor, intptr_t magic);
static bool js_LineSeries (int num_args, bool is_ctor, intptr_t magic);
static bool js_ListenOnPort (int num_args, bool is_ctor, intptr_t magic);
static bool js_LoadAnimation (int num_args, bool is_ctor, intptr_t magic);
static bool js_LoadFont (int num_args, bool is_ctor, intptr_t magic);
static bool js_LoadImage (int num_args, bool is_ctor, intptr_t magic);
static bool js_LoadSound (int num_args, bool is_ctor, intptr_t magic);
static bool js_LoadSoundEffect (int num_args, bool is_ctor, intptr_t magic);
static bool js_LoadSpriteset (int num_args, bool is_ctor, intptr_t magic);
static bool js_LoadSurface (int num_args, bool is_ctor, intptr_t magic);
static bool js_LoadWindowStyle (int num_args, bool is_ctor, intptr_t magic);
static bool js_MapEngine (int num_args, bool is_ctor, intptr_t magic);
static bool js_MapToScreenX (int num_args, bool is_ctor, intptr_t magic);
static bool js_MapToScreenY (int num_args, bool is_ctor, intptr_t magic);
static bool js_OpenAddress (int num_args, bool is_ctor, intptr_t magic);
static bool js_OpenFile (int num_args, bool is_ctor, intptr_t magic);
static bool js_OpenLog (int num_args, bool is_ctor, intptr_t magic);
static bool js_OpenRawFile (int num_args, bool is_ctor, intptr_t magic);
static bool js_OutlinedCircle (int num_args, bool is_ctor, intptr_t magic);
static bool js_OutlinedComplex (int num_args, bool is_ctor, intptr_t magic);
static bool js_OutlinedEllipse (int num_args, bool is_ctor, intptr_t magic);
static bool js_OutlinedRectangle (int num_args, bool is_ctor, intptr_t magic);
static bool js_OutlinedRoundRectangle (int num_args, bool is_ctor, intptr_t magic);
static bool js_Point (int num_args, bool is_ctor, intptr_t magic);
static bool js_PointSeries (int num_args, bool is_ctor, intptr_t magic);
static bool js_Polygon (int num_args, bool is_ctor, intptr_t magic);
static bool js_Print (int num_args, bool is_ctor, intptr_t magic);
static bool js_QueuePersonCommand (int num_args, bool is_ctor, intptr_t magic);
static bool js_QueuePersonScript (int num_args, bool is_ctor, intptr_t magic);
static bool js_Rectangle (int num_args, bool is_ctor, intptr_t magic);
static bool js_RemoveDirectory (int num_args, bool is_ctor, intptr_t magic);
static bool js_RemoveFile (int num_args, bool is_ctor, intptr_t magic);
static bool js_RemoveTrigger (int num_args, bool is_ctor, intptr_t magic);
static bool js_RemoveZone (int num_args, bool is_ctor, intptr_t magic);
static bool js_Rename (int num_args, bool is_ctor, intptr_t magic);
static bool js_RenderMap (int num_args, bool is_ctor, intptr_t magic);
static bool js_ReplaceTilesOnLayer (int num_args, bool is_ctor, intptr_t magic);
static bool js_RequireScript (int num_args, bool is_ctor, intptr_t magic);
static bool js_RequireSystemScript (int num_args, bool is_ctor, intptr_t magic);
static bool js_RestartGame (int num_args, bool is_ctor, intptr_t magic);
static bool js_RoundRectangle (int num_args, bool is_ctor, intptr_t magic);
static bool js_ScreenToMapX (int num_args, bool is_ctor, intptr_t magic);
static bool js_ScreenToMapY (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetCameraX (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetCameraY (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetClippingRectangle (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetColorMask (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetDefaultMapScript (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetDefaultPersonScript (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetDelayScript (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetFrameRate (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetLayerAngle (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetLayerHeight (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetLayerMask (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetLayerReflective (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetLayerRenderer (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetLayerScaleFactorX (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetLayerScaleFactorY (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetLayerSize (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetLayerVisible (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetLayerWidth (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetMapEngineFrameRate (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetMousePosition (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetNextAnimatedTile (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetPersonAngle (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetPersonData (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetPersonDirection (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetPersonFollowDistance (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetPersonFrame (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetPersonFrameNext (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetPersonFrameRevert (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetPersonIgnoreList (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetPersonLayer (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetPersonMask (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetPersonOffsetX (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetPersonOffsetY (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetPersonScaleAbsolute (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetPersonScaleFactor (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetPersonScript (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetPersonSpeed (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetPersonSpeedXY (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetPersonSpriteset (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetPersonValue (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetPersonVisible (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetPersonX (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetPersonXYFloat (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetPersonY (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetRenderScript (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetTalkActivationButton (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetTalkActivationKey (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetTalkDistance (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetTile (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetTileDelay (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetTileImage (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetTileName (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetTileSurface (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetTriggerLayer (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetTriggerScript (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetTriggerXY (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetUpdateScript (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetZoneDimensions (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetZoneLayer (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetZoneScript (int num_args, bool is_ctor, intptr_t magic);
static bool js_SetZoneSteps (int num_args, bool is_ctor, intptr_t magic);
static bool js_Triangle (int num_args, bool is_ctor, intptr_t magic);
static bool js_UnbindJoystickButton (int num_args, bool is_ctor, intptr_t magic);
static bool js_UnbindKey (int num_args, bool is_ctor, intptr_t magic);
static bool js_UpdateMapEngine (int num_args, bool is_ctor, intptr_t magic);
static bool js_Animation_get_height (int num_args, bool is_ctor, intptr_t magic);
static bool js_Animation_get_width (int num_args, bool is_ctor, intptr_t magic);
static bool js_Animation_drawFrame (int num_args, bool is_ctor, intptr_t magic);
static bool js_Animation_drawZoomedFrame (int num_args, bool is_ctor, intptr_t magic);
static bool js_Animation_getDelay (int num_args, bool is_ctor, intptr_t magic);
static bool js_Animation_getNumFrames (int num_args, bool is_ctor, intptr_t magic);
static bool js_Animation_readNextFrame (int num_args, bool is_ctor, intptr_t magic);
static bool js_ByteArray_get_length (int num_args, bool is_ctor, intptr_t magic);
static bool js_ByteArray_concat (int num_args, bool is_ctor, intptr_t magic);
static bool js_ByteArray_slice (int num_args, bool is_ctor, intptr_t magic);
static bool js_ByteArray_toString (int num_args, bool is_ctor, intptr_t magic);
static bool js_Color_get_alpha (int num_args, bool is_ctor, intptr_t magic);
static bool js_Color_get_blue (int num_args, bool is_ctor, intptr_t magic);
static bool js_Color_get_green (int num_args, bool is_ctor, intptr_t magic);
static bool js_Color_get_red (int num_args, bool is_ctor, intptr_t magic);
static bool js_Color_set_alpha (int num_args, bool is_ctor, intptr_t magic);
static bool js_Color_set_blue (int num_args, bool is_ctor, intptr_t magic);
static bool js_Color_set_green (int num_args, bool is_ctor, intptr_t magic);
static bool js_Color_set_red (int num_args, bool is_ctor, intptr_t magic);
static bool js_Color_toString (int num_args, bool is_ctor, intptr_t magic);
static bool js_ColorMatrix_toString (int num_args, bool is_ctor, intptr_t magic);
static bool js_File_close (int num_args, bool is_ctor, intptr_t magic);
static bool js_File_flush (int num_args, bool is_ctor, intptr_t magic);
static bool js_File_getKey (int num_args, bool is_ctor, intptr_t magic);
static bool js_File_getNumKeys (int num_args, bool is_ctor, intptr_t magic);
static bool js_File_read (int num_args, bool is_ctor, intptr_t magic);
static bool js_File_toString (int num_args, bool is_ctor, intptr_t magic);
static bool js_File_write (int num_args, bool is_ctor, intptr_t magic);
static bool js_Font_clone (int num_args, bool is_ctor, intptr_t magic);
static bool js_Font_drawText (int num_args, bool is_ctor, intptr_t magic);
static bool js_Font_drawTextBox (int num_args, bool is_ctor, intptr_t magic);
static bool js_Font_drawZoomedText (int num_args, bool is_ctor, intptr_t magic);
static bool js_Font_getCharacterImage (int num_args, bool is_ctor, intptr_t magic);
static bool js_Font_getColorMask (int num_args, bool is_ctor, intptr_t magic);
static bool js_Font_getHeight (int num_args, bool is_ctor, intptr_t magic);
static bool js_Font_getStringHeight (int num_args, bool is_ctor, intptr_t magic);
static bool js_Font_getStringWidth (int num_args, bool is_ctor, intptr_t magic);
static bool js_Font_setCharacterImage (int num_args, bool is_ctor, intptr_t magic);
static bool js_Font_setColorMask (int num_args, bool is_ctor, intptr_t magic);
static bool js_Font_toString (int num_args, bool is_ctor, intptr_t magic);
static bool js_Font_wordWrapString (int num_args, bool is_ctor, intptr_t magic);
static bool js_Image_get_height (int num_args, bool is_ctor, intptr_t magic);
static bool js_Image_get_width (int num_args, bool is_ctor, intptr_t magic);
static bool js_Image_blit (int num_args, bool is_ctor, intptr_t magic);
static bool js_Image_blitMask (int num_args, bool is_ctor, intptr_t magic);
static bool js_Image_createSurface (int num_args, bool is_ctor, intptr_t magic);
static bool js_Image_rotateBlit (int num_args, bool is_ctor, intptr_t magic);
static bool js_Image_rotateBlitMask (int num_args, bool is_ctor, intptr_t magic);
static bool js_Image_toString (int num_args, bool is_ctor, intptr_t magic);
static bool js_Image_transformBlit (int num_args, bool is_ctor, intptr_t magic);
static bool js_Image_transformBlitMask (int num_args, bool is_ctor, intptr_t magic);
static bool js_Image_zoomBlit (int num_args, bool is_ctor, intptr_t magic);
static bool js_Image_zoomBlitMask (int num_args, bool is_ctor, intptr_t magic);
static bool js_Logger_beginBlock (int num_args, bool is_ctor, intptr_t magic);
static bool js_Logger_endBlock (int num_args, bool is_ctor, intptr_t magic);
static bool js_Logger_toString (int num_args, bool is_ctor, intptr_t magic);
static bool js_Logger_write (int num_args, bool is_ctor, intptr_t magic);
static bool js_RawFile_close (int num_args, bool is_ctor, intptr_t magic);
static bool js_RawFile_getPosition (int num_args, bool is_ctor, intptr_t magic);
static bool js_RawFile_getSize (int num_args, bool is_ctor, intptr_t magic);
static bool js_RawFile_read (int num_args, bool is_ctor, intptr_t magic);
static bool js_RawFile_setPosition (int num_args, bool is_ctor, intptr_t magic);
static bool js_RawFile_toString (int num_args, bool is_ctor, intptr_t magic);
static bool js_RawFile_write (int num_args, bool is_ctor, intptr_t magic);
static bool js_Socket_close (int num_args, bool is_ctor, intptr_t magic);
static bool js_Socket_getPendingReadSize (int num_args, bool is_ctor, intptr_t magic);
static bool js_Socket_isConnected (int num_args, bool is_ctor, intptr_t magic);
static bool js_Socket_read (int num_args, bool is_ctor, intptr_t magic);
static bool js_Socket_toString (int num_args, bool is_ctor, intptr_t magic);
static bool js_Socket_write (int num_args, bool is_ctor, intptr_t magic);
static bool js_Sound_getLength (int num_args, bool is_ctor, intptr_t magic);
static bool js_Sound_getPan (int num_args, bool is_ctor, intptr_t magic);
static bool js_Sound_getPitch (int num_args, bool is_ctor, intptr_t magic);
static bool js_Sound_getPosition (int num_args, bool is_ctor, intptr_t magic);
static bool js_Sound_getRepeat (int num_args, bool is_ctor, intptr_t magic);
static bool js_Sound_getVolume (int num_args, bool is_ctor, intptr_t magic);
static bool js_Sound_isPlaying (int num_args, bool is_ctor, intptr_t magic);
static bool js_Sound_isSeekable (int num_args, bool is_ctor, intptr_t magic);
static bool js_Sound_pause (int num_args, bool is_ctor, intptr_t magic);
static bool js_Sound_play (int num_args, bool is_ctor, intptr_t magic);
static bool js_Sound_reset (int num_args, bool is_ctor, intptr_t magic);
static bool js_Sound_setPan (int num_args, bool is_ctor, intptr_t magic);
static bool js_Sound_setPitch (int num_args, bool is_ctor, intptr_t magic);
static bool js_Sound_setPosition (int num_args, bool is_ctor, intptr_t magic);
static bool js_Sound_setRepeat (int num_args, bool is_ctor, intptr_t magic);
static bool js_Sound_setVolume (int num_args, bool is_ctor, intptr_t magic);
static bool js_Sound_stop (int num_args, bool is_ctor, intptr_t magic);
static bool js_Sound_toString (int num_args, bool is_ctor, intptr_t magic);
static bool js_SoundEffect_getPan (int num_args, bool is_ctor, intptr_t magic);
static bool js_SoundEffect_getPitch (int num_args, bool is_ctor, intptr_t magic);
static bool js_SoundEffect_getVolume (int num_args, bool is_ctor, intptr_t magic);
static bool js_SoundEffect_setPan (int num_args, bool is_ctor, intptr_t magic);
static bool js_SoundEffect_setPitch (int num_args, bool is_ctor, intptr_t magic);
static bool js_SoundEffect_setVolume (int num_args, bool is_ctor, intptr_t magic);
static bool js_SoundEffect_play (int num_args, bool is_ctor, intptr_t magic);
static bool js_SoundEffect_stop (int num_args, bool is_ctor, intptr_t magic);
static bool js_SoundEffect_toString (int num_args, bool is_ctor, intptr_t magic);
static bool js_Spriteset_get_filename (int num_args, bool is_ctor, intptr_t magic);
static bool js_Spriteset_clone (int num_args, bool is_ctor, intptr_t magic);
static bool js_Spriteset_save (int num_args, bool is_ctor, intptr_t magic);
static bool js_Spriteset_toString (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_get_height (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_get_width (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_applyColorFX (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_applyColorFX4 (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_applyLookup (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_bezierCurve (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_blit (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_blitMaskSurface (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_blitSurface (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_clone (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_cloneSection (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_createImage (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_drawText (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_filledCircle (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_filledEllipse (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_flipHorizontally (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_flipVertically (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_getPixel (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_gradientCircle (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_gradientEllipse (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_gradientLine (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_gradientRectangle (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_line (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_lineSeries (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_outlinedCircle (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_outlinedEllipse (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_outlinedRectangle (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_pointSeries (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_rotate (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_rotateBlitMaskSurface (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_rotateBlitSurface (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_rectangle (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_replaceColor (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_rescale (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_save (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_setAlpha (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_setBlendMode (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_setPixel (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_toString (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_transformBlitMaskSurface (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_transformBlitSurface (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_zoomBlitMaskSurface (int num_args, bool is_ctor, intptr_t magic);
static bool js_Surface_zoomBlitSurface (int num_args, bool is_ctor, intptr_t magic);
static bool js_WindowStyle_drawWindow (int num_args, bool is_ctor, intptr_t magic);
static bool js_WindowStyle_getColorMask (int num_args, bool is_ctor, intptr_t magic);
static bool js_WindowStyle_setColorMask (int num_args, bool is_ctor, intptr_t magic);
static bool js_WindowStyle_toString (int num_args, bool is_ctor, intptr_t magic);
static void js_Animation_finalize (void* host_ptr);
static void js_ByteArray_finalize (void* host_ptr);
static void js_Color_finalize (void* host_ptr);
static void js_File_finalize (void* host_ptr);
static void js_Font_finalize (void* host_ptr);
static void js_Image_finalize (void* host_ptr);
static void js_Logger_finalize (void* host_ptr);
static void js_RawFile_finalize (void* host_ptr);
static void js_Socket_finalize (void* host_ptr);
static void js_Sound_finalize (void* host_ptr);
static void js_SoundEffect_finalize (void* host_ptr);
static void js_Spriteset_finalize (void* host_ptr);
static void js_Surface_finalize (void* host_ptr);
static void js_WindowStyle_finalize (void* host_ptr);
enum line_series_type
{
LINE_MULTIPLE,
LINE_STRIP,
LINE_LOOP,
};
enum sound_effect_mode
{
SE_SINGLE,
SE_MULTIPLE,
};
static font_t* s_default_font;
static int s_frame_rate = 0;
static mixer_t* s_sound_mixer;
void
vanilla_init(void)
{
console_log(1, "initializing Sphere v1 API (%s)", API_VERSION_STRING);
// note: `font_clone` is used purposely here to prevent the color mask from getting
// clobbered by internal text rendering (e.g. the FPS counter).
s_default_font = font_clone(game_default_font(g_game));
s_sound_mixer = mixer_new(44100, 16, 2);
// set up a dictionary to track RequireScript() calls
jsal_push_hidden_stash();
jsal_push_new_bare_object();
jsal_put_prop_string(-2, "RequireScript");
jsal_pop(1);
// stashed person data (used by Get/SetPersonData() APIs)
jsal_push_hidden_stash();
jsal_push_new_object();
jsal_put_prop_string(-2, "personData");
jsal_pop(1);
// register the absolutely ginormous (and deprecated!) Sphere v1 API.
api_define_function(NULL, "Abort", js_Abort, 0);
api_define_function(NULL, "AddTrigger", js_AddTrigger, 0);
api_define_function(NULL, "AddZone", js_AddZone, 0);
api_define_function(NULL, "ApplyColorMask", js_ApplyColorMask, 0);
api_define_function(NULL, "AreKeysLeft", js_AreKeysLeft, 0);
api_define_function(NULL, "AreZonesAt", js_AreZonesAt, 0);
api_define_function(NULL, "AttachCamera", js_AttachCamera, 0);
api_define_function(NULL, "AttachInput", js_AttachInput, 0);
api_define_function(NULL, "AttachPlayerInput", js_AttachPlayerInput, 0);
api_define_function(NULL, "BezierCurve", js_BezierCurve, 0);
api_define_function(NULL, "BindJoystickButton", js_BindJoystickButton, 0);
api_define_function(NULL, "BindKey", js_BindKey, 0);
api_define_function(NULL, "BlendColors", js_BlendColors, 0);
api_define_function(NULL, "BlendColorsWeighted", js_BlendColors, 0);
api_define_function(NULL, "CallDefaultMapScript", js_CallDefaultMapScript, 0);
api_define_function(NULL, "CallDefaultPersonScript", js_CallDefaultPersonScript, 0);
api_define_function(NULL, "CallMapScript", js_CallMapScript, 0);
api_define_function(NULL, "CallPersonScript", js_CallPersonScript, 0);
api_define_function(NULL, "ChangeMap", js_ChangeMap, 0);
api_define_function(NULL, "ClearPersonCommands", js_ClearPersonCommands, 0);
api_define_function(NULL, "CreateByteArray", js_CreateByteArray, 0);
api_define_function(NULL, "CreateByteArrayFromString", js_CreateByteArrayFromString, 0);
api_define_function(NULL, "CreateColor", js_CreateColor, 0);
api_define_function(NULL, "CreateColorMatrix", js_CreateColorMatrix, 0);
api_define_function(NULL, "CreateDirectory", js_CreateDirectory, 0);
api_define_function(NULL, "CreatePerson", js_CreatePerson, 0);
api_define_function(NULL, "CreateSpriteset", js_CreateSpriteset, 0);
api_define_function(NULL, "CreateStringFromByteArray", js_CreateStringFromByteArray, 0);
api_define_function(NULL, "CreateStringFromCode", js_CreateStringFromCode, 0);
api_define_function(NULL, "CreateSurface", js_CreateSurface, 0);
api_define_function(NULL, "DeflateByteArray", js_DeflateByteArray, 0);
api_define_function(NULL, "Delay", js_Delay, 0);
api_define_function(NULL, "DestroyPerson", js_DestroyPerson, 0);
api_define_function(NULL, "DetachCamera", js_DetachCamera, 0);
api_define_function(NULL, "DetachInput", js_DetachInput, 0);
api_define_function(NULL, "DetachPlayerInput", js_DetachPlayerInput, 0);
api_define_function(NULL, "DoEvents", js_DoEvents, 0);
api_define_function(NULL, "DoesFileExist", js_DoesFileExist, 0);
api_define_function(NULL, "DoesPersonExist", js_DoesPersonExist, 0);
api_define_function(NULL, "EvaluateScript", js_EvaluateScript, 0);
api_define_function(NULL, "EvaluateSystemScript", js_EvaluateSystemScript, 0);
api_define_function(NULL, "Exit", js_Exit, 0);
api_define_function(NULL, "ExitMapEngine", js_ExitMapEngine, 0);
api_define_function(NULL, "ExecuteGame", js_ExecuteGame, 0);
api_define_function(NULL, "ExecuteTrigger", js_ExecuteTrigger, 0);
api_define_function(NULL, "ExecuteZoneScript", js_ExecuteZoneScript, 0);
api_define_function(NULL, "ExecuteZones", js_ExecuteZones, 0);
api_define_function(NULL, "FilledCircle", js_FilledCircle, 0);
api_define_function(NULL, "FilledComplex", js_FilledComplex, 0);
api_define_function(NULL, "FilledEllipse", js_FilledEllipse, 0);
api_define_function(NULL, "FlipScreen", js_FlipScreen, 0);
api_define_function(NULL, "FollowPerson", js_FollowPerson, 0);
api_define_function(NULL, "GarbageCollect", js_GarbageCollect, 0);
api_define_function(NULL, "GetActingPerson", js_GetActingPerson, 0);
api_define_function(NULL, "GetCameraPerson", js_GetCameraPerson, 0);
api_define_function(NULL, "GetCameraX", js_GetCameraX, 0);
api_define_function(NULL, "GetCameraY", js_GetCameraY, 0);
api_define_function(NULL, "GetClippingRectangle", js_GetClippingRectangle, 0);
api_define_function(NULL, "GetCurrentMap", js_GetCurrentMap, 0);
api_define_function(NULL, "GetCurrentPerson", js_GetCurrentPerson, 0);
api_define_function(NULL, "GetCurrentTrigger", js_GetCurrentTrigger, 0);
api_define_function(NULL, "GetCurrentZone", js_GetCurrentZone, 0);
api_define_function(NULL, "GetDirectoryList", js_GetDirectoryList, 0);
api_define_function(NULL, "GetFileList", js_GetFileList, 0);
api_define_function(NULL, "GetFrameRate", js_GetFrameRate, 0);
api_define_function(NULL, "GetGameList", js_GetGameList, 0);
api_define_function(NULL, "GetInputPerson", js_GetInputPerson, 0);
api_define_function(NULL, "GetJoystickAxis", js_GetJoystickAxis, 0);
api_define_function(NULL, "GetLocalAddress", js_GetLocalAddress, 0);
api_define_function(NULL, "GetLocalName", js_GetLocalName, 0);
api_define_function(NULL, "GetKey", js_GetKey, 0);
api_define_function(NULL, "GetKeyString", js_GetKeyString, 0);
api_define_function(NULL, "GetLayerAngle", js_GetLayerAngle, 0);
api_define_function(NULL, "GetLayerHeight", js_GetLayerHeight, 0);
api_define_function(NULL, "GetLayerMask", js_GetLayerMask, 0);
api_define_function(NULL, "GetLayerName", js_GetLayerName, 0);
api_define_function(NULL, "GetLayerWidth", js_GetLayerWidth, 0);
api_define_function(NULL, "GetMapEngine", js_GetMapEngine, 0);
api_define_function(NULL, "GetMapEngineFrameRate", js_GetMapEngineFrameRate, 0);
api_define_function(NULL, "GetMouseWheelEvent", js_GetMouseWheelEvent, 0);
api_define_function(NULL, "GetMouseX", js_GetMouseX, 0);
api_define_function(NULL, "GetMouseY", js_GetMouseY, 0);
api_define_function(NULL, "GetNumJoysticks", js_GetNumJoysticks, 0);
api_define_function(NULL, "GetNumJoystickAxes", js_GetNumJoystickAxes, 0);
api_define_function(NULL, "GetNumJoystickButtons", js_GetNumJoystickButtons, 0);
api_define_function(NULL, "GetNumMouseWheelEvents", js_GetNumMouseWheelEvents, 0);
api_define_function(NULL, "GetNextAnimatedTile", js_GetNextAnimatedTile, 0);
api_define_function(NULL, "GetNumLayers", js_GetNumLayers, 0);
api_define_function(NULL, "GetNumTiles", js_GetNumTiles, 0);
api_define_function(NULL, "GetNumTriggers", js_GetNumTriggers, 0);
api_define_function(NULL, "GetNumZones", js_GetNumZones, 0);
api_define_function(NULL, "GetObstructingPerson", js_GetObstructingPerson, 0);
api_define_function(NULL, "GetObstructingTile", js_GetObstructingTile, 0);
api_define_function(NULL, "GetPersonAngle", js_GetPersonAngle, 0);
api_define_function(NULL, "GetPersonBase", js_GetPersonBase, 0);
api_define_function(NULL, "GetPersonData", js_GetPersonData, 0);
api_define_function(NULL, "GetPersonDirection", js_GetPersonDirection, 0);
api_define_function(NULL, "GetPersonFollowDistance", js_GetPersonFollowDistance, 0);
api_define_function(NULL, "GetPersonFollowers", js_GetPersonFollowers, 0);
api_define_function(NULL, "GetPersonFrame", js_GetPersonFrame, 0);
api_define_function(NULL, "GetPersonFrameNext", js_GetPersonFrameNext, 0);
api_define_function(NULL, "GetPersonFrameRevert", js_GetPersonFrameRevert, 0);
api_define_function(NULL, "GetPersonIgnoreList", js_GetPersonIgnoreList, 0);
api_define_function(NULL, "GetPersonLayer", js_GetPersonLayer, 0);
api_define_function(NULL, "GetPersonLeader", js_GetPersonLeader, 0);
api_define_function(NULL, "GetPersonList", js_GetPersonList, 0);
api_define_function(NULL, "GetPersonMask", js_GetPersonMask, 0);
api_define_function(NULL, "GetPersonOffsetX", js_GetPersonOffsetX, 0);
api_define_function(NULL, "GetPersonOffsetY", js_GetPersonOffsetY, 0);
api_define_function(NULL, "GetPersonSpeedX", js_GetPersonSpeedX, 0);
api_define_function(NULL, "GetPersonSpeedY", js_GetPersonSpeedY, 0);
api_define_function(NULL, "GetPersonSpriteset", js_GetPersonSpriteset, 0);
api_define_function(NULL, "GetPersonValue", js_GetPersonValue, 0);
api_define_function(NULL, "GetPersonX", js_GetPersonX, 0);
api_define_function(NULL, "GetPersonXFloat", js_GetPersonXFloat, 0);
api_define_function(NULL, "GetPersonY", js_GetPersonY, 0);
api_define_function(NULL, "GetPersonYFloat", js_GetPersonYFloat, 0);
api_define_function(NULL, "GetPlayerKey", js_GetPlayerKey, 0);
api_define_function(NULL, "GetScreenHeight", js_GetScreenHeight, 0);
api_define_function(NULL, "GetScreenWidth", js_GetScreenWidth, 0);
api_define_function(NULL, "GetSystemArrow", js_GetSystemArrow, 0);
api_define_function(NULL, "GetSystemDownArrow", js_GetSystemDownArrow, 0);
api_define_function(NULL, "GetSystemFont", js_GetSystemFont, 0);
api_define_function(NULL, "GetSystemUpArrow", js_GetSystemUpArrow, 0);
api_define_function(NULL, "GetSystemWindowStyle", js_GetSystemWindowStyle, 0);
api_define_function(NULL, "GetTalkActivationButton", js_GetTalkActivationButton, 0);
api_define_function(NULL, "GetTalkActivationKey", js_GetTalkActivationKey, 0);
api_define_function(NULL, "GetTalkDistance", js_GetTalkDistance, 0);
api_define_function(NULL, "GetTile", js_GetTile, 0);
api_define_function(NULL, "GetTileDelay", js_GetTileDelay, 0);
api_define_function(NULL, "GetTileImage", js_GetTileImage, 0);
api_define_function(NULL, "GetTileHeight", js_GetTileHeight, 0);
api_define_function(NULL, "GetTileName", js_GetTileName, 0);
api_define_function(NULL, "GetTileSurface", js_GetTileSurface, 0);
api_define_function(NULL, "GetTileWidth", js_GetTileWidth, 0);
api_define_function(NULL, "GetTime", js_GetTime, 0);
api_define_function(NULL, "GetToggleState", js_GetToggleState, 0);
api_define_function(NULL, "GetTriggerLayer", js_GetTriggerLayer, 0);
api_define_function(NULL, "GetTriggerX", js_GetTriggerX, 0);
api_define_function(NULL, "GetTriggerY", js_GetTriggerY, 0);
api_define_function(NULL, "GetVersion", js_GetVersion, 0);
api_define_function(NULL, "GetVersionString", js_GetVersionString, 0);
api_define_function(NULL, "GetZoneHeight", js_GetZoneHeight, 0);
api_define_function(NULL, "GetZoneLayer", js_GetZoneLayer, 0);
api_define_function(NULL, "GetZoneSteps", js_GetZoneSteps, 0);
api_define_function(NULL, "GetZoneWidth", js_GetZoneWidth, 0);
api_define_function(NULL, "GetZoneX", js_GetZoneX, 0);
api_define_function(NULL, "GetZoneY", js_GetZoneY, 0);
api_define_function(NULL, "GrabImage", js_GrabImage, 0);
api_define_function(NULL, "GrabSurface", js_GrabSurface, 0);
api_define_function(NULL, "GradientCircle", js_GradientCircle, 0);
api_define_function(NULL, "GradientComplex", js_GradientComplex, 0);
api_define_function(NULL, "GradientEllipse", js_GradientEllipse, 0);
api_define_function(NULL, "GradientLine", js_GradientLine, 0);
api_define_function(NULL, "GradientRectangle", js_GradientRectangle, 0);
api_define_function(NULL, "GradientTriangle", js_GradientTriangle, 0);
api_define_function(NULL, "HashByteArray", js_HashByteArray, 0);
api_define_function(NULL, "HashFromFile", js_HashFromFile, 0);
api_define_function(NULL, "IgnorePersonObstructions", js_IgnorePersonObstructions, 0);
api_define_function(NULL, "IgnoreTileObstructions", js_IgnoreTileObstructions, 0);
api_define_function(NULL, "InflateByteArray", js_InflateByteArray, 0);
api_define_function(NULL, "IsAnyKeyPressed", js_IsAnyKeyPressed, 0);
api_define_function(NULL, "IsCameraAttached", js_IsCameraAttached, 0);
api_define_function(NULL, "IsCommandQueueEmpty", js_IsCommandQueueEmpty, 0);
api_define_function(NULL, "IsIgnoringPersonObstructions", js_IsIgnoringPersonObstructions, 0);
api_define_function(NULL, "IsIgnoringTileObstructions", js_IsIgnoringTileObstructions, 0);
api_define_function(NULL, "IsInputAttached", js_IsInputAttached, 0);
api_define_function(NULL, "IsJoystickButtonPressed", js_IsJoystickButtonPressed, 0);
api_define_function(NULL, "IsKeyPressed", js_IsKeyPressed, 0);
api_define_function(NULL, "IsLayerReflective", js_IsLayerReflective, 0);
api_define_function(NULL, "IsLayerVisible", js_IsLayerVisible, 0);
api_define_function(NULL, "IsMapEngineRunning", js_IsMapEngineRunning, 0);
api_define_function(NULL, "IsMouseButtonPressed", js_IsMouseButtonPressed, 0);
api_define_function(NULL, "IsPersonObstructed", js_IsPersonObstructed, 0);
api_define_function(NULL, "IsPersonVisible", js_IsPersonVisible, 0);
api_define_function(NULL, "IsTriggerAt", js_IsTriggerAt, 0);
api_define_function(NULL, "Line", js_Line, 0);
api_define_function(NULL, "LineIntersects", js_LineIntersects, 0);
api_define_function(NULL, "LineSeries", js_LineSeries, 0);
api_define_function(NULL, "ListenOnPort", js_ListenOnPort, 0);
api_define_function(NULL, "LoadAnimation", js_LoadAnimation, 0);
api_define_function(NULL, "LoadFont", js_LoadFont, 0);
api_define_function(NULL, "LoadImage", js_LoadImage, 0);
api_define_function(NULL, "LoadSound", js_LoadSound, 0);
api_define_function(NULL, "LoadSoundEffect", js_LoadSoundEffect, 0);
api_define_function(NULL, "LoadSpriteset", js_LoadSpriteset, 0);
api_define_function(NULL, "LoadSurface", js_LoadSurface, 0);
api_define_function(NULL, "LoadWindowStyle", js_LoadWindowStyle, 0);
api_define_function(NULL, "MapEngine", js_MapEngine, 0);
api_define_function(NULL, "MapToScreenX", js_MapToScreenX, 0);
api_define_function(NULL, "MapToScreenY", js_MapToScreenY, 0);
api_define_function(NULL, "OpenAddress", js_OpenAddress, 0);
api_define_function(NULL, "OpenFile", js_OpenFile, 0);
api_define_function(NULL, "OpenLog", js_OpenLog, 0);
api_define_function(NULL, "OpenRawFile", js_OpenRawFile, 0);
api_define_function(NULL, "OutlinedCircle", js_OutlinedCircle, 0);
api_define_function(NULL, "OutlinedComplex", js_OutlinedComplex, 0);
api_define_function(NULL, "OutlinedEllipse", js_OutlinedEllipse, 0);
api_define_function(NULL, "OutlinedRectangle", js_OutlinedRectangle, 0);
api_define_function(NULL, "OutlinedRoundRectangle", js_OutlinedRoundRectangle, 0);
api_define_function(NULL, "Point", js_Point, 0);
api_define_function(NULL, "PointSeries", js_PointSeries, 0);
api_define_function(NULL, "Polygon", js_Polygon, 0);
api_define_function(NULL, "Print", js_Print, 0);
api_define_function(NULL, "QueuePersonCommand", js_QueuePersonCommand, 0);
api_define_function(NULL, "QueuePersonScript", js_QueuePersonScript, 0);
api_define_function(NULL, "Rectangle", js_Rectangle, 0);
api_define_function(NULL, "RemoveDirectory", js_RemoveDirectory, 0);
api_define_function(NULL, "RemoveFile", js_RemoveFile, 0);
api_define_function(NULL, "RemoveTrigger", js_RemoveTrigger, 0);
api_define_function(NULL, "RemoveZone", js_RemoveZone, 0);
api_define_function(NULL, "RenderMap", js_RenderMap, 0);
api_define_function(NULL, "Rename", js_Rename, 0);
api_define_function(NULL, "ReplaceTilesOnLayer", js_ReplaceTilesOnLayer, 0);
api_define_function(NULL, "RequireScript", js_RequireScript, 0);
api_define_function(NULL, "RequireSystemScript", js_RequireSystemScript, 0);
api_define_function(NULL, "RestartGame", js_RestartGame, 0);
api_define_function(NULL, "RoundRectangle", js_RoundRectangle, 0);
api_define_function(NULL, "ScreenToMapX", js_ScreenToMapX, 0);
api_define_function(NULL, "ScreenToMapY", js_ScreenToMapY, 0);
api_define_function(NULL, "SetCameraX", js_SetCameraX, 0);
api_define_function(NULL, "SetCameraY", js_SetCameraY, 0);
api_define_function(NULL, "SetClippingRectangle", js_SetClippingRectangle, 0);
api_define_function(NULL, "SetColorMask", js_SetColorMask, 0);
api_define_function(NULL, "SetDefaultMapScript", js_SetDefaultMapScript, 0);
api_define_function(NULL, "SetDefaultPersonScript", js_SetDefaultPersonScript, 0);
api_define_function(NULL, "SetDelayScript", js_SetDelayScript, 0);
api_define_function(NULL, "SetFrameRate", js_SetFrameRate, 0);
api_define_function(NULL, "SetLayerAngle", js_SetLayerAngle, 0);
api_define_function(NULL, "SetLayerHeight", js_SetLayerHeight, 0);
api_define_function(NULL, "SetLayerMask", js_SetLayerMask, 0);
api_define_function(NULL, "SetLayerReflective", js_SetLayerReflective, 0);
api_define_function(NULL, "SetLayerRenderer", js_SetLayerRenderer, 0);
api_define_function(NULL, "SetLayerScaleFactorX", js_SetLayerScaleFactorX, 0);
api_define_function(NULL, "SetLayerScaleFactorY", js_SetLayerScaleFactorY, 0);
api_define_function(NULL, "SetLayerSize", js_SetLayerSize, 0);
api_define_function(NULL, "SetLayerVisible", js_SetLayerVisible, 0);
api_define_function(NULL, "SetLayerWidth", js_SetLayerWidth, 0);
api_define_function(NULL, "SetMapEngineFrameRate", js_SetMapEngineFrameRate, 0);
api_define_function(NULL, "SetMousePosition", js_SetMousePosition, 0);
api_define_function(NULL, "SetNextAnimatedTile", js_SetNextAnimatedTile, 0);
api_define_function(NULL, "SetPersonAngle", js_SetPersonAngle, 0);
api_define_function(NULL, "SetPersonData", js_SetPersonData, 0);
api_define_function(NULL, "SetPersonDirection", js_SetPersonDirection, 0);
api_define_function(NULL, "SetPersonFollowDistance", js_SetPersonFollowDistance, 0);
api_define_function(NULL, "SetPersonFrame", js_SetPersonFrame, 0);
api_define_function(NULL, "SetPersonFrameNext", js_SetPersonFrameNext, 0);
api_define_function(NULL, "SetPersonFrameRevert", js_SetPersonFrameRevert, 0);
api_define_function(NULL, "SetPersonIgnoreList", js_SetPersonIgnoreList, 0);
api_define_function(NULL, "SetPersonLayer", js_SetPersonLayer, 0);
api_define_function(NULL, "SetPersonMask", js_SetPersonMask, 0);
api_define_function(NULL, "SetPersonOffsetX", js_SetPersonOffsetX, 0);
api_define_function(NULL, "SetPersonOffsetY", js_SetPersonOffsetY, 0);
api_define_function(NULL, "SetPersonScaleAbsolute", js_SetPersonScaleAbsolute, 0);
api_define_function(NULL, "SetPersonScaleFactor", js_SetPersonScaleFactor, 0);
api_define_function(NULL, "SetPersonScript", js_SetPersonScript, 0);
api_define_function(NULL, "SetPersonSpeed", js_SetPersonSpeed, 0);
api_define_function(NULL, "SetPersonSpeedXY", js_SetPersonSpeedXY, 0);
api_define_function(NULL, "SetPersonSpriteset", js_SetPersonSpriteset, 0);
api_define_function(NULL, "SetPersonValue", js_SetPersonValue, 0);
api_define_function(NULL, "SetPersonVisible", js_SetPersonVisible, 0);
api_define_function(NULL, "SetPersonX", js_SetPersonX, 0);
api_define_function(NULL, "SetPersonXYFloat", js_SetPersonXYFloat, 0);
api_define_function(NULL, "SetPersonY", js_SetPersonY, 0);
api_define_function(NULL, "SetRenderScript", js_SetRenderScript, 0);
api_define_function(NULL, "SetTalkActivationButton", js_SetTalkActivationButton, 0);
api_define_function(NULL, "SetTalkActivationKey", js_SetTalkActivationKey, 0);
api_define_function(NULL, "SetTalkDistance", js_SetTalkDistance, 0);
api_define_function(NULL, "SetTile", js_SetTile, 0);
api_define_function(NULL, "SetTileDelay", js_SetTileDelay, 0);
api_define_function(NULL, "SetTileImage", js_SetTileImage, 0);
api_define_function(NULL, "SetTileName", js_SetTileName, 0);
api_define_function(NULL, "SetTileSurface", js_SetTileSurface, 0);
api_define_function(NULL, "SetTriggerLayer", js_SetTriggerLayer, 0);
api_define_function(NULL, "SetTriggerScript", js_SetTriggerScript, 0);
api_define_function(NULL, "SetTriggerXY", js_SetTriggerXY, 0);
api_define_function(NULL, "SetUpdateScript", js_SetUpdateScript, 0);
api_define_function(NULL, "SetZoneDimensions", js_SetZoneDimensions, 0);
api_define_function(NULL, "SetZoneLayer", js_SetZoneLayer, 0);
api_define_function(NULL, "SetZoneScript", js_SetZoneScript, 0);
api_define_function(NULL, "SetZoneSteps", js_SetZoneSteps, 0);
api_define_function(NULL, "Triangle", js_Triangle, 0);
api_define_function(NULL, "UnbindJoystickButton", js_UnbindJoystickButton, 0);
api_define_function(NULL, "UnbindKey", js_UnbindKey, 0);
api_define_function(NULL, "UpdateMapEngine", js_UpdateMapEngine, 0);
api_define_class("v1Animation", SV1_ANIMATION, NULL, js_Animation_finalize, 0);
api_define_property("v1Animation", "width", false, js_Animation_get_width, NULL);
api_define_property("v1Animation", "height", false, js_Animation_get_height, NULL);
api_define_method("v1Animation", "getDelay", js_Animation_getDelay, 0);
api_define_method("v1Animation", "getNumFrames", js_Animation_getNumFrames, 0);
api_define_method("v1Animation", "drawFrame", js_Animation_drawFrame, 0);
api_define_method("v1Animation", "drawZoomedFrame", js_Animation_drawZoomedFrame, 0);
api_define_method("v1Animation", "readNextFrame", js_Animation_readNextFrame, 0);
api_define_class("v1ByteArray", SV1_BYTE_ARRAY, NULL, js_ByteArray_finalize, 0);
api_define_property("v1ByteArray", "length", false, js_ByteArray_get_length, NULL);
api_define_method("v1ByteArray", "concat", js_ByteArray_concat, 0);
api_define_method("v1ByteArray", "slice", js_ByteArray_slice, 0);
api_define_method("v1ByteArray", "toString", js_ByteArray_toString, 0);
api_define_class("v1Color", SV1_COLOR, NULL, NULL, 0);
api_define_property("v1Color", "alpha", true, js_Color_get_alpha, js_Color_set_alpha);
api_define_property("v1Color", "blue", true, js_Color_get_blue, js_Color_set_blue);
api_define_property("v1Color", "green", true, js_Color_get_green, js_Color_set_green);
api_define_property("v1Color", "red", true, js_Color_get_red, js_Color_set_red);
api_define_method("v1Color", "toString", js_Color_toString, 0);
api_define_class("v1ColorMatrix", SV1_COLOR_MATRIX, NULL, NULL, 0);
api_define_method("v1ColorMatrix", "toString", js_ColorMatrix_toString, 0);
api_define_class("v1File", SV1_FILE, NULL, js_File_finalize, 0);
api_define_method("v1File", "close", js_File_close, 0);
api_define_method("v1File", "flush", js_File_flush, 0);
api_define_method("v1File", "getKey", js_File_getKey, 0);
api_define_method("v1File", "getNumKeys", js_File_getNumKeys, 0);
api_define_method("v1File", "read", js_File_read, 0);
api_define_method("v1File", "toString", js_File_toString, 0);
api_define_method("v1File", "write", js_File_write, 0);
api_define_class("v1Font", SV1_FONT, NULL, js_Font_finalize, 0);
api_define_method("v1Font", "clone", js_Font_clone, 0);
api_define_method("v1Font", "drawText", js_Font_drawText, 0);
api_define_method("v1Font", "drawTextBox", js_Font_drawTextBox, 0);
api_define_method("v1Font", "drawZoomedText", js_Font_drawZoomedText, 0);
api_define_method("v1Font", "getCharacterImage", js_Font_getCharacterImage, 0);
api_define_method("v1Font", "getColorMask", js_Font_getColorMask, 0);
api_define_method("v1Font", "getHeight", js_Font_getHeight, 0);
api_define_method("v1Font", "getStringHeight", js_Font_getStringHeight, 0);
api_define_method("v1Font", "getStringWidth", js_Font_getStringWidth, 0);
api_define_method("v1Font", "setCharacterImage", js_Font_setCharacterImage, 0);
api_define_method("v1Font", "setColorMask", js_Font_setColorMask, 0);
api_define_method("v1Font", "toString", js_Font_toString, 0);
api_define_method("v1Font", "wordWrapString", js_Font_wordWrapString, 0);
api_define_class("v1Image", SV1_IMAGE, NULL, js_Image_finalize, 0);
api_define_property("v1Image", "height", false, js_Image_get_height, NULL);
api_define_property("v1Image", "width", false, js_Image_get_width, NULL);
api_define_method("v1Image", "blit", js_Image_blit, 0);
api_define_method("v1Image", "blitMask", js_Image_blitMask, 0);
api_define_method("v1Image", "createSurface", js_Image_createSurface, 0);
api_define_method("v1Image", "rotateBlit", js_Image_rotateBlit, 0);
api_define_method("v1Image", "rotateBlitMask", js_Image_rotateBlitMask, 0);
api_define_method("v1Image", "toString", js_Image_toString, 0);
api_define_method("v1Image", "transformBlit", js_Image_transformBlit, 0);
api_define_method("v1Image", "transformBlitMask", js_Image_transformBlitMask, 0);
api_define_method("v1Image", "zoomBlit", js_Image_zoomBlit, 0);
api_define_method("v1Image", "zoomBlitMask", js_Image_zoomBlitMask, 0);
api_define_class("v1Logger", SV1_LOGGER, NULL, js_Logger_finalize, 0);
api_define_method("v1Logger", "toString", js_Logger_toString, 0);
api_define_method("v1Logger", "beginBlock", js_Logger_beginBlock, 0);
api_define_method("v1Logger", "endBlock", js_Logger_endBlock, 0);
api_define_method("v1Logger", "write", js_Logger_write, 0);
api_define_class("v1RawFile", SV1_RAW_FILE, NULL, js_RawFile_finalize, 0);
api_define_method("v1RawFile", "close", js_RawFile_close, 0);
api_define_method("v1RawFile", "getPosition", js_RawFile_getPosition, 0);
api_define_method("v1RawFile", "getSize", js_RawFile_getSize, 0);
api_define_method("v1RawFile", "read", js_RawFile_read, 0);
api_define_method("v1RawFile", "setPosition", js_RawFile_setPosition, 0);
api_define_method("v1RawFile", "toString", js_RawFile_toString, 0);
api_define_method("v1RawFile", "write", js_RawFile_write, 0);
api_define_class("v1Socket", SV1_SOCKET, NULL, js_Socket_finalize, 0);
api_define_method("v1Socket", "close", js_Socket_close, 0);
api_define_method("v1Socket", "getPendingReadSize", js_Socket_getPendingReadSize, 0);
api_define_method("v1Socket", "isConnected", js_Socket_isConnected, 0);
api_define_method("v1Socket", "read", js_Socket_read, 0);
api_define_method("v1Socket", "toString", js_Socket_toString, 0);
api_define_method("v1Socket", "write", js_Socket_write, 0);
api_define_class("v1Sound", SV1_SOUND, NULL, js_Sound_finalize, 0);
api_define_method("v1Sound", "getLength", js_Sound_getLength, 0);
api_define_method("v1Sound", "getPan", js_Sound_getPan, 0);
api_define_method("v1Sound", "getPitch", js_Sound_getPitch, 0);
api_define_method("v1Sound", "getPosition", js_Sound_getPosition, 0);
api_define_method("v1Sound", "getRepeat", js_Sound_getRepeat, 0);
api_define_method("v1Sound", "getVolume", js_Sound_getVolume, 0);
api_define_method("v1Sound", "isPlaying", js_Sound_isPlaying, 0);
api_define_method("v1Sound", "isSeekable", js_Sound_isSeekable, 0);
api_define_method("v1Sound", "pause", js_Sound_pause, 0);
api_define_method("v1Sound", "play", js_Sound_play, 0);
api_define_method("v1Sound", "reset", js_Sound_reset, 0);
api_define_method("v1Sound", "setPan", js_Sound_setPan, 0);
api_define_method("v1Sound", "setPitch", js_Sound_setPitch, 0);
api_define_method("v1Sound", "setPosition", js_Sound_setPosition, 0);
api_define_method("v1Sound", "setRepeat", js_Sound_setRepeat, 0);
api_define_method("v1Sound", "setVolume", js_Sound_setVolume, 0);
api_define_method("v1Sound", "stop", js_Sound_stop, 0);
api_define_method("v1Sound", "toString", js_Sound_toString, 0);
api_define_class("v1SoundEffect", SV1_SOUND_EFFECT, NULL, js_SoundEffect_finalize, 0);
api_define_method("v1SoundEffect", "getPan", js_SoundEffect_getPan, 0);
api_define_method("v1SoundEffect", "getPitch", js_SoundEffect_getPitch, 0);
api_define_method("v1SoundEffect", "getVolume", js_SoundEffect_getVolume, 0);
api_define_method("v1SoundEffect", "setPan", js_SoundEffect_setPan, 0);
api_define_method("v1SoundEffect", "setPitch", js_SoundEffect_setPitch, 0);
api_define_method("v1SoundEffect", "setVolume", js_SoundEffect_setVolume, 0);
api_define_method("v1SoundEffect", "play", js_SoundEffect_play, 0);
api_define_method("v1SoundEffect", "stop", js_SoundEffect_stop, 0);
api_define_method("v1SoundEffect", "toString", js_SoundEffect_toString, 0);
api_define_class("v1Spriteset", SV1_SPRITESET, NULL, js_Spriteset_finalize, 0);
api_define_property("v1Spriteset", "filename", false, js_Spriteset_get_filename, NULL);
api_define_method("v1Spriteset", "clone", js_Spriteset_clone, 0);
api_define_method("v1Spriteset", "save", js_Spriteset_save, 0);
api_define_method("v1Spriteset", "toString", js_Spriteset_toString, 0);
api_define_class("v1Surface", SV1_SURFACE, NULL, js_Surface_finalize, 0);
api_define_property("v1Surface", "height", false, js_Surface_get_height, NULL);
api_define_property("v1Surface", "width", false, js_Surface_get_width, NULL);
api_define_method("v1Surface", "applyColorFX", js_Surface_applyColorFX, 0);
api_define_method("v1Surface", "applyColorFX4", js_Surface_applyColorFX4, 0);
api_define_method("v1Surface", "applyLookup", js_Surface_applyLookup, 0);
api_define_method("v1Surface", "bezierCurve", js_Surface_bezierCurve, 0);
api_define_method("v1Surface", "blit", js_Surface_blit, 0);
api_define_method("v1Surface", "blitMaskSurface", js_Surface_blitMaskSurface, 0);
api_define_method("v1Surface", "blitSurface", js_Surface_blitSurface, 0);
api_define_method("v1Surface", "clone", js_Surface_clone, 0);
api_define_method("v1Surface", "cloneSection", js_Surface_cloneSection, 0);
api_define_method("v1Surface", "createImage", js_Surface_createImage, 0);
api_define_method("v1Surface", "drawText", js_Surface_drawText, 0);
api_define_method("v1Surface", "filledCircle", js_Surface_filledCircle, 0);
api_define_method("v1Surface", "filledEllipse", js_Surface_filledEllipse, 0);
api_define_method("v1Surface", "flipHorizontally", js_Surface_flipHorizontally, 0);
api_define_method("v1Surface", "flipVertically", js_Surface_flipVertically, 0);
api_define_method("v1Surface", "getPixel", js_Surface_getPixel, 0);
api_define_method("v1Surface", "gradientCircle", js_Surface_gradientCircle, 0);
api_define_method("v1Surface", "gradientEllipse", js_Surface_gradientEllipse, 0);
api_define_method("v1Surface", "gradientLine", js_Surface_gradientLine, 0);
api_define_method("v1Surface", "gradientRectangle", js_Surface_gradientRectangle, 0);
api_define_method("v1Surface", "line", js_Surface_line, 0);
api_define_method("v1Surface", "lineSeries", js_Surface_lineSeries, 0);
api_define_method("v1Surface", "outlinedCircle", js_Surface_outlinedCircle, 0);
api_define_method("v1Surface", "outlinedEllipse", js_Surface_outlinedEllipse, 0);
api_define_method("v1Surface", "outlinedRectangle", js_Surface_outlinedRectangle, 0);
api_define_method("v1Surface", "pointSeries", js_Surface_pointSeries, 0);
api_define_method("v1Surface", "rotate", js_Surface_rotate, 0);
api_define_method("v1Surface", "rotateBlitMaskSurface", js_Surface_rotateBlitMaskSurface, 0);
api_define_method("v1Surface", "rotateBlitSurface", js_Surface_rotateBlitSurface, 0);
api_define_method("v1Surface", "rectangle", js_Surface_rectangle, 0);
api_define_method("v1Surface", "replaceColor", js_Surface_replaceColor, 0);
api_define_method("v1Surface", "rescale", js_Surface_rescale, 0);
api_define_method("v1Surface", "save", js_Surface_save, 0);
api_define_method("v1Surface", "setAlpha", js_Surface_setAlpha, 0);
api_define_method("v1Surface", "setBlendMode", js_Surface_setBlendMode, 0);
api_define_method("v1Surface", "setPixel", js_Surface_setPixel, 0);
api_define_method("v1Surface", "toString", js_Surface_toString, 0);
api_define_method("v1Surface", "transformBlitMaskSurface", js_Surface_transformBlitMaskSurface, 0);
api_define_method("v1Surface", "transformBlitSurface", js_Surface_transformBlitSurface, 0);
api_define_method("v1Surface", "zoomBlitMaskSurface", js_Surface_zoomBlitMaskSurface, 0);
api_define_method("v1Surface", "zoomBlitSurface", js_Surface_zoomBlitSurface, 0);
api_define_class("v1WindowStyle", SV1_WINDOW_STYLE, NULL, js_WindowStyle_finalize, 0);
api_define_method("v1WindowStyle", "drawWindow", js_WindowStyle_drawWindow, 0);
api_define_method("v1WindowStyle", "getColorMask", js_WindowStyle_getColorMask, 0);
api_define_method("v1WindowStyle", "setColorMask", js_WindowStyle_setColorMask, 0);
api_define_method("v1WindowStyle", "toString", js_WindowStyle_toString, 0);
// blend modes for Surfaces
api_define_const(NULL, "BLEND", BLEND_NORMAL);
api_define_const(NULL, "REPLACE", BLEND_REPLACE);
api_define_const(NULL, "RGB_ONLY", BLEND_COPY_RGB);
api_define_const(NULL, "ALPHA_ONLY", BLEND_COPY_ALPHA);
api_define_const(NULL, "ADD", BLEND_ADD);
api_define_const(NULL, "SUBTRACT", BLEND_SUBTRACT);
api_define_const(NULL, "MULTIPLY", BLEND_MULTIPLY);
api_define_const(NULL, "AVERAGE", BLEND_AVERAGE);
api_define_const(NULL, "INVERT", BLEND_INVERT);
// person movement commands
api_define_const(NULL, "COMMAND_WAIT", COMMAND_WAIT);
api_define_const(NULL, "COMMAND_ANIMATE", COMMAND_ANIMATE);
api_define_const(NULL, "COMMAND_FACE_NORTH", COMMAND_FACE_NORTH);
api_define_const(NULL, "COMMAND_FACE_NORTHEAST", COMMAND_FACE_NORTHEAST);
api_define_const(NULL, "COMMAND_FACE_EAST", COMMAND_FACE_EAST);
api_define_const(NULL, "COMMAND_FACE_SOUTHEAST", COMMAND_FACE_SOUTHEAST);
api_define_const(NULL, "COMMAND_FACE_SOUTH", COMMAND_FACE_SOUTH);
api_define_const(NULL, "COMMAND_FACE_SOUTHWEST", COMMAND_FACE_SOUTHWEST);
api_define_const(NULL, "COMMAND_FACE_WEST", COMMAND_FACE_WEST);
api_define_const(NULL, "COMMAND_FACE_NORTHWEST", COMMAND_FACE_NORTHWEST);
api_define_const(NULL, "COMMAND_MOVE_NORTH", COMMAND_MOVE_NORTH);
api_define_const(NULL, "COMMAND_MOVE_NORTHEAST", COMMAND_MOVE_NORTHEAST);
api_define_const(NULL, "COMMAND_MOVE_EAST", COMMAND_MOVE_EAST);
api_define_const(NULL, "COMMAND_MOVE_SOUTHEAST", COMMAND_MOVE_SOUTHEAST);
api_define_const(NULL, "COMMAND_MOVE_SOUTH", COMMAND_MOVE_SOUTH);
api_define_const(NULL, "COMMAND_MOVE_SOUTHWEST", COMMAND_MOVE_SOUTHWEST);
api_define_const(NULL, "COMMAND_MOVE_WEST", COMMAND_MOVE_WEST);
api_define_const(NULL, "COMMAND_MOVE_NORTHWEST", COMMAND_MOVE_NORTHWEST);
// joystick axes
api_define_const(NULL, "JOYSTICK_AXIS_X", 0);
api_define_const(NULL, "JOYSTICK_AXIS_Y", 1);
api_define_const(NULL, "JOYSTICK_AXIS_Z", 2);
api_define_const(NULL, "JOYSTICK_AXIS_R", 3);
api_define_const(NULL, "JOYSTICK_AXIS_U", 4);
api_define_const(NULL, "JOYSTICK_AXIS_V", 5);
// LineSeries() modes
api_define_const(NULL, "LINE_MULTIPLE", LINE_MULTIPLE);
api_define_const(NULL, "LINE_STRIP", LINE_STRIP);
api_define_const(NULL, "LINE_LOOP", LINE_LOOP);
// keyboard keys
api_define_const(NULL, "KEY_NONE", 0);
api_define_const(NULL, "KEY_SHIFT", ALLEGRO_KEY_LSHIFT);
api_define_const(NULL, "KEY_CTRL", ALLEGRO_KEY_LCTRL);
api_define_const(NULL, "KEY_ALT", ALLEGRO_KEY_ALT);
api_define_const(NULL, "KEY_UP", ALLEGRO_KEY_UP);
api_define_const(NULL, "KEY_DOWN", ALLEGRO_KEY_DOWN);
api_define_const(NULL, "KEY_LEFT", ALLEGRO_KEY_LEFT);
api_define_const(NULL, "KEY_RIGHT", ALLEGRO_KEY_RIGHT);
api_define_const(NULL, "KEY_APOSTROPHE", ALLEGRO_KEY_QUOTE);
api_define_const(NULL, "KEY_BACKSLASH", ALLEGRO_KEY_BACKSLASH);
api_define_const(NULL, "KEY_BACKSPACE", ALLEGRO_KEY_BACKSPACE);
api_define_const(NULL, "KEY_CLOSEBRACE", ALLEGRO_KEY_CLOSEBRACE);
api_define_const(NULL, "KEY_CAPSLOCK", ALLEGRO_KEY_CAPSLOCK);
api_define_const(NULL, "KEY_COMMA", ALLEGRO_KEY_COMMA);
api_define_const(NULL, "KEY_DELETE", ALLEGRO_KEY_DELETE);
api_define_const(NULL, "KEY_END", ALLEGRO_KEY_END);
api_define_const(NULL, "KEY_ENTER", ALLEGRO_KEY_ENTER);
api_define_const(NULL, "KEY_EQUALS", ALLEGRO_KEY_EQUALS);
api_define_const(NULL, "KEY_ESCAPE", ALLEGRO_KEY_ESCAPE);
api_define_const(NULL, "KEY_HOME", ALLEGRO_KEY_HOME);
api_define_const(NULL, "KEY_INSERT", ALLEGRO_KEY_INSERT);
api_define_const(NULL, "KEY_MINUS", ALLEGRO_KEY_MINUS);
api_define_const(NULL, "KEY_NUMLOCK", ALLEGRO_KEY_NUMLOCK);
api_define_const(NULL, "KEY_OPENBRACE", ALLEGRO_KEY_OPENBRACE);
api_define_const(NULL, "KEY_PAGEDOWN", ALLEGRO_KEY_PGDN);
api_define_const(NULL, "KEY_PAGEUP", ALLEGRO_KEY_PGUP);
api_define_const(NULL, "KEY_PERIOD", ALLEGRO_KEY_FULLSTOP);
api_define_const(NULL, "KEY_SCROLLOCK", ALLEGRO_KEY_SCROLLLOCK);
api_define_const(NULL, "KEY_SCROLLLOCK", ALLEGRO_KEY_SCROLLLOCK);
api_define_const(NULL, "KEY_SEMICOLON", ALLEGRO_KEY_SEMICOLON);
api_define_const(NULL, "KEY_SPACE", ALLEGRO_KEY_SPACE);
api_define_const(NULL, "KEY_SLASH", ALLEGRO_KEY_SLASH);
api_define_const(NULL, "KEY_TAB", ALLEGRO_KEY_TAB);
api_define_const(NULL, "KEY_TILDE", ALLEGRO_KEY_TILDE);
api_define_const(NULL, "KEY_F1", ALLEGRO_KEY_F1);
api_define_const(NULL, "KEY_F2", ALLEGRO_KEY_F2);
api_define_const(NULL, "KEY_F3", ALLEGRO_KEY_F3);
api_define_const(NULL, "KEY_F4", ALLEGRO_KEY_F4);
api_define_const(NULL, "KEY_F5", ALLEGRO_KEY_F5);
api_define_const(NULL, "KEY_F6", ALLEGRO_KEY_F6);
api_define_const(NULL, "KEY_F7", ALLEGRO_KEY_F7);
api_define_const(NULL, "KEY_F8", ALLEGRO_KEY_F8);
api_define_const(NULL, "KEY_F9", ALLEGRO_KEY_F9);
api_define_const(NULL, "KEY_F10", ALLEGRO_KEY_F10);
api_define_const(NULL, "KEY_F11", ALLEGRO_KEY_F11);
api_define_const(NULL, "KEY_F12", ALLEGRO_KEY_F12);
api_define_const(NULL, "KEY_A", ALLEGRO_KEY_A);
api_define_const(NULL, "KEY_B", ALLEGRO_KEY_B);
api_define_const(NULL, "KEY_C", ALLEGRO_KEY_C);
api_define_const(NULL, "KEY_D", ALLEGRO_KEY_D);
api_define_const(NULL, "KEY_E", ALLEGRO_KEY_E);
api_define_const(NULL, "KEY_F", ALLEGRO_KEY_F);
api_define_const(NULL, "KEY_G", ALLEGRO_KEY_G);
api_define_const(NULL, "KEY_H", ALLEGRO_KEY_H);
api_define_const(NULL, "KEY_I", ALLEGRO_KEY_I);
api_define_const(NULL, "KEY_J", ALLEGRO_KEY_J);
api_define_const(NULL, "KEY_K", ALLEGRO_KEY_K);
api_define_const(NULL, "KEY_L", ALLEGRO_KEY_L);
api_define_const(NULL, "KEY_M", ALLEGRO_KEY_M);
api_define_const(NULL, "KEY_N", ALLEGRO_KEY_N);
api_define_const(NULL, "KEY_O", ALLEGRO_KEY_O);
api_define_const(NULL, "KEY_P", ALLEGRO_KEY_P);
api_define_const(NULL, "KEY_Q", ALLEGRO_KEY_Q);
api_define_const(NULL, "KEY_R", ALLEGRO_KEY_R);
api_define_const(NULL, "KEY_S", ALLEGRO_KEY_S);
api_define_const(NULL, "KEY_T", ALLEGRO_KEY_T);
api_define_const(NULL, "KEY_U", ALLEGRO_KEY_U);
api_define_const(NULL, "KEY_V", ALLEGRO_KEY_V);
api_define_const(NULL, "KEY_W", ALLEGRO_KEY_W);
api_define_const(NULL, "KEY_X", ALLEGRO_KEY_X);
api_define_const(NULL, "KEY_Y", ALLEGRO_KEY_Y);
api_define_const(NULL, "KEY_Z", ALLEGRO_KEY_Z);
api_define_const(NULL, "KEY_1", ALLEGRO_KEY_1);
api_define_const(NULL, "KEY_2", ALLEGRO_KEY_2);
api_define_const(NULL, "KEY_3", ALLEGRO_KEY_3);
api_define_const(NULL, "KEY_4", ALLEGRO_KEY_4);
api_define_const(NULL, "KEY_5", ALLEGRO_KEY_5);
api_define_const(NULL, "KEY_6", ALLEGRO_KEY_6);
api_define_const(NULL, "KEY_7", ALLEGRO_KEY_7);
api_define_const(NULL, "KEY_8", ALLEGRO_KEY_8);
api_define_const(NULL, "KEY_9", ALLEGRO_KEY_9);
api_define_const(NULL, "KEY_0", ALLEGRO_KEY_0);
api_define_const(NULL, "KEY_NUM_1", ALLEGRO_KEY_PAD_1);
api_define_const(NULL, "KEY_NUM_2", ALLEGRO_KEY_PAD_2);
api_define_const(NULL, "KEY_NUM_3", ALLEGRO_KEY_PAD_3);
api_define_const(NULL, "KEY_NUM_4", ALLEGRO_KEY_PAD_4);
api_define_const(NULL, "KEY_NUM_5", ALLEGRO_KEY_PAD_5);
api_define_const(NULL, "KEY_NUM_6", ALLEGRO_KEY_PAD_6);
api_define_const(NULL, "KEY_NUM_7", ALLEGRO_KEY_PAD_7);
api_define_const(NULL, "KEY_NUM_8", ALLEGRO_KEY_PAD_8);
api_define_const(NULL, "KEY_NUM_9", ALLEGRO_KEY_PAD_9);
api_define_const(NULL, "KEY_NUM_0", ALLEGRO_KEY_PAD_0);
api_define_const(NULL, "MOUSE_LEFT", MOUSE_BUTTON_LEFT);
api_define_const(NULL, "MOUSE_MIDDLE", MOUSE_BUTTON_MIDDLE);
api_define_const(NULL, "MOUSE_RIGHT", MOUSE_BUTTON_RIGHT);
api_define_const(NULL, "MOUSE_WHEEL_UP", MOUSE_KEY_WHEEL_UP);
api_define_const(NULL, "MOUSE_WHEEL_DOWN", MOUSE_KEY_WHEEL_DOWN);
api_define_const(NULL, "PLAYER_1", PLAYER_1);
api_define_const(NULL, "PLAYER_2", PLAYER_2);
api_define_const(NULL, "PLAYER_3", PLAYER_3);
api_define_const(NULL, "PLAYER_4", PLAYER_4);
api_define_const(NULL, "PLAYER_KEY_MENU", PLAYER_KEY_MENU);
api_define_const(NULL, "PLAYER_KEY_UP", PLAYER_KEY_UP);
api_define_const(NULL, "PLAYER_KEY_DOWN", PLAYER_KEY_DOWN);
api_define_const(NULL, "PLAYER_KEY_LEFT", PLAYER_KEY_LEFT);
api_define_const(NULL, "PLAYER_KEY_RIGHT", PLAYER_KEY_RIGHT);
api_define_const(NULL, "PLAYER_KEY_A", PLAYER_KEY_A);
api_define_const(NULL, "PLAYER_KEY_B", PLAYER_KEY_B);
api_define_const(NULL, "PLAYER_KEY_X", PLAYER_KEY_X);
api_define_const(NULL, "PLAYER_KEY_Y", PLAYER_KEY_Y);
// map script types
api_define_const(NULL, "SCRIPT_ON_ENTER_MAP", MAP_SCRIPT_ON_ENTER);
api_define_const(NULL, "SCRIPT_ON_LEAVE_MAP", MAP_SCRIPT_ON_LEAVE);
api_define_const(NULL, "SCRIPT_ON_LEAVE_MAP_NORTH", MAP_SCRIPT_ON_LEAVE_NORTH);
api_define_const(NULL, "SCRIPT_ON_LEAVE_MAP_EAST", MAP_SCRIPT_ON_LEAVE_EAST);
api_define_const(NULL, "SCRIPT_ON_LEAVE_MAP_SOUTH", MAP_SCRIPT_ON_LEAVE_SOUTH);
api_define_const(NULL, "SCRIPT_ON_LEAVE_MAP_WEST", MAP_SCRIPT_ON_LEAVE_WEST);
// person script types
api_define_const(NULL, "SCRIPT_ON_CREATE", PERSON_SCRIPT_ON_CREATE);
api_define_const(NULL, "SCRIPT_ON_DESTROY", PERSON_SCRIPT_ON_DESTROY);
api_define_const(NULL, "SCRIPT_ON_ACTIVATE_TOUCH", PERSON_SCRIPT_ON_TOUCH);
api_define_const(NULL, "SCRIPT_ON_ACTIVATE_TALK", PERSON_SCRIPT_ON_TALK);
api_define_const(NULL, "SCRIPT_COMMAND_GENERATOR", PERSON_SCRIPT_GENERATOR);
api_define_const(NULL, "SE_SINGLE", 0);
api_define_const(NULL, "SE_MULTIPLE", 1);
}
void
jsal_push_sphere_bytearray(bytearray_t* array)
{
jsal_push_class_obj(SV1_BYTE_ARRAY, bytearray_ref(array), false);
jsal_make_buffer(-1, JS_UINT8ARRAY, bytearray_buffer(array), bytearray_len(array));
}
void
jsal_push_sphere_color(color_t color)
{
color_t* color_ptr;
jsal_push_class_fatobj(SV1_COLOR, false, sizeof(color_t), (void**)&color_ptr);
*color_ptr = color;
}
void
jsal_push_sphere_font(font_t* font)
{
jsal_push_class_obj(SV1_FONT, font_ref(font), false);
}
void
jsal_push_sphere_spriteset(spriteset_t* spriteset)
{
rect_t base;
image_t* image;
const char* pose_name;
int i, j;
jsal_push_class_obj(SV1_SPRITESET, spriteset_ref(spriteset), false);
// Spriteset:base
base = spriteset_get_base(spriteset);
jsal_push_new_object();
jsal_push_int(base.x1); jsal_put_prop_string(-2, "x1");
jsal_push_int(base.y1); jsal_put_prop_string(-2, "y1");
jsal_push_int(base.x2); jsal_put_prop_string(-2, "x2");
jsal_push_int(base.y2); jsal_put_prop_string(-2, "y2");
jsal_put_prop_string(-2, "base");
// Spriteset:images
jsal_push_new_array();
for (i = 0; i < spriteset_num_images(spriteset); ++i) {
image = spriteset_image(spriteset, i);
jsal_push_class_obj(SV1_IMAGE, image_ref(image), false);
jsal_put_prop_index(-2, i);
}
jsal_put_prop_string(-2, "images");
// Spriteset:directions
jsal_push_new_array();
for (i = 0; i < spriteset_num_poses(spriteset); ++i) {
pose_name = spriteset_pose_name(spriteset, i);
jsal_push_new_object();
jsal_push_string(pose_name);
jsal_put_prop_string(-2, "name");
jsal_push_new_array();
for (j = 0; j < spriteset_num_frames(spriteset, pose_name); ++j) {
jsal_push_new_object();
jsal_push_int(spriteset_frame_image_index(spriteset, pose_name, j));
jsal_put_prop_string(-2, "index");
jsal_push_int(spriteset_frame_delay(spriteset, pose_name, j));
jsal_put_prop_string(-2, "delay");
jsal_put_prop_index(-2, j);
}
jsal_put_prop_string(-2, "frames");
jsal_put_prop_index(-2, i);
}
jsal_put_prop_string(-2, "directions");
}
static int
jsal_require_map_layer(int at_index)
{
long strtol_out;
int layer_index;
const char* name;
char* p_end;
if (!map_engine_running())
jsal_error(JS_RANGE_ERROR, "Map engine not running");
if (jsal_is_number(at_index)) {
layer_index = jsal_get_int(at_index);
goto have_index;
}
else if (jsal_is_string(at_index)) {
// don't anyone ever say I'm not dedicated to compatibility! there are a few
// poorly written Sphere 1.5 games that pass layer IDs as strings. usually this
// would fail because miniSphere supports named layers, but here I go out of my
// way to support it anyway.
name = jsal_get_string(at_index);
strtol_out = strtol(name, &p_end, 0);
if ((layer_index = map_layer_by_name(name)) >= 0) {
goto have_index;
}
else if (name[0] != '\0' && *p_end == '\0') {
layer_index = (int)strtol_out;
goto have_index;
}
else {
jsal_error(JS_RANGE_ERROR, "Layer name does not exist '%s'", name);
}
}
else {
jsal_dup(at_index);
jsal_push_new_error(JS_TYPE_ERROR, "'%s' is not a map layer", jsal_to_string(-1));
jsal_remove(-2);
jsal_throw();
}
have_index:
if (layer_index < 0 || layer_index >= map_num_layers())
jsal_error(JS_RANGE_ERROR, "Layer index out of range '%d'", layer_index);
return layer_index;
}
color_t
jsal_require_sphere_color(int index)
{
color_t* color_ptr;
color_ptr = jsal_require_class_obj(index, SV1_COLOR);
return *color_ptr;
}
color_fx_t
jsal_require_sphere_color_fx(int index)
{
color_fx_t matrix;
jsal_require_class_obj(index, SV1_COLOR_MATRIX);
jsal_get_prop_string(index, "rn"); matrix.rn = jsal_get_int(-1); jsal_pop(1);
jsal_get_prop_string(index, "rr"); matrix.rr = jsal_get_int(-1); jsal_pop(1);
jsal_get_prop_string(index, "rg"); matrix.rg = jsal_get_int(-1); jsal_pop(1);
jsal_get_prop_string(index, "rb"); matrix.rb = jsal_get_int(-1); jsal_pop(1);
jsal_get_prop_string(index, "gn"); matrix.gn = jsal_get_int(-1); jsal_pop(1);
jsal_get_prop_string(index, "gr"); matrix.gr = jsal_get_int(-1); jsal_pop(1);
jsal_get_prop_string(index, "gg"); matrix.gg = jsal_get_int(-1); jsal_pop(1);
jsal_get_prop_string(index, "gb"); matrix.gb = jsal_get_int(-1); jsal_pop(1);
jsal_get_prop_string(index, "bn"); matrix.bn = jsal_get_int(-1); jsal_pop(1);
jsal_get_prop_string(index, "br"); matrix.br = jsal_get_int(-1); jsal_pop(1);
jsal_get_prop_string(index, "bg"); matrix.bg = jsal_get_int(-1); jsal_pop(1);
jsal_get_prop_string(index, "bb"); matrix.bb = jsal_get_int(-1); jsal_pop(1);
return matrix;
}
script_t*
jsal_require_sphere_script(int index, const char* name)
{
lstring_t* codestring;
script_t* script;
index = jsal_normalize_index(index);
if (jsal_is_function(index)) {
// caller passed function directly
script = script_new_function(index);
}
else if (jsal_is_string(index)) {
// caller passed code string, compile it
codestring = jsal_require_lstring_t(index);
script = script_new(codestring, "%s", name);
lstr_free(codestring);
}
else if (jsal_is_null(index) || jsal_is_undefined(index))
return NULL;
else
jsal_error(JS_TYPE_ERROR, "Expected a string, function, or null/undefined");
return script;
}
spriteset_t*
jsal_require_sphere_spriteset(int index)
{
// note: this creates a new spriteset from the JavaScript object passed in, which
// is rather inefficient, but consistent with Sphere 1.x behavior. I assume
// this was the easiest way to allow JS code to modify spritesets, as it
// avoids the need to trap property accesses.
rect_t base;
int delay;
image_t* image;
int image_index;
int num_frames;
int num_images;
int num_poses;
const char* pose_name;
spriteset_t* spriteset;
int i, j;
index = jsal_normalize_index(index);
jsal_require_class_obj(index, SV1_SPRITESET);
spriteset = spriteset_new();
jsal_get_prop_string(index, "base");
jsal_get_prop_string(-1, "x1");
base.x1 = jsal_require_int(-1);
jsal_get_prop_string(-2, "y1");
base.y1 = jsal_require_int(-1);
jsal_get_prop_string(-3, "x2");
base.x2 = jsal_require_int(-1);
jsal_get_prop_string(-4, "y2");
base.y2 = jsal_require_int(-1);
spriteset_set_base(spriteset, base);
jsal_pop(5);
jsal_get_prop_string(index, "images");
num_images = jsal_get_length(-1);
for (i = 0; i < num_images; ++i) {
jsal_get_prop_index(-1, i);
image = jsal_require_class_obj(-1, SV1_IMAGE);
spriteset_add_image(spriteset, image);
jsal_pop(1);
}
jsal_pop(1);
jsal_get_prop_string(index, "directions");
num_poses = jsal_get_length(-1);
for (i = 0; i < num_poses; ++i) {
jsal_get_prop_index(-1, i);
jsal_get_prop_string(-1, "name");
pose_name = jsal_require_string(-1);
spriteset_add_pose(spriteset, pose_name);
jsal_get_prop_string(-2, "frames");
num_frames = jsal_get_length(-1);
for (j = 0; j < num_frames; ++j) {
jsal_get_prop_index(-1, j);
jsal_get_prop_string(-1, "index");
image_index = jsal_require_int(-1);
jsal_get_prop_string(-2, "delay");
delay = jsal_require_int(-1);
spriteset_add_frame(spriteset, pose_name, image_index, delay);
jsal_pop(3);
}
jsal_pop(3);
}
jsal_pop(1);
return spriteset;
}
static void
jsal_push_sphere_windowstyle(windowstyle_t* winstyle)
{
jsal_push_class_obj(SV1_WINDOW_STYLE, winstyle_ref(winstyle), false);
}
static uint8_t*
jsal_require_rgba_lut(int index)
{
uint8_t* lut;
int length;
int i;
index = jsal_normalize_index(index);
jsal_require_object_coercible(index);
lut = malloc(sizeof(uint8_t) * 256);
length = fmin(jsal_get_length(index), 256);
for (i = length; i < 256; ++i) lut[i] = i;
for (i = 0; i < length; ++i) {
jsal_get_prop_index(index, i);
lut[i] = fmin(fmax(jsal_to_int(-1), 0), 255);
jsal_pop(1);
}
return lut;
}
static bool
js_Abort(int num_args, bool is_ctor, intptr_t magic)
{
const char* message;
char* text;
message = num_args >= 1
? jsal_to_string(0)
: "Some type of eaty pig just ate your game\n\n\n...and you*munch*";
text = strnewf("abort requested...\n\n%s\n", message);
sphere_abort(text);
return false;
}
static bool
js_AddTrigger(int num_args, bool is_ctor, intptr_t magic)
{
rect_t bounds;
int layer;
script_t* script;
int x;
int y;
x = jsal_to_int(0);
y = jsal_to_int(1);
layer = jsal_require_map_layer(2);
script = jsal_require_sphere_script(3, "%/triggerScript.js");
if (!map_engine_running())
jsal_error(JS_RANGE_ERROR, "Map engine not running");
bounds = map_bounds();
if (x < bounds.x1 || y < bounds.y1 || x >= bounds.x2 || y >= bounds.y2)
jsal_error(JS_RANGE_ERROR, "X/Y out of bounds (%d,%d)", x, y);
if (!map_add_trigger(x, y, layer, script))
jsal_error(JS_ERROR, "Couldn't allocate new trigger");
jsal_push_number(map_num_triggers() - 1);
return true;
}
static bool
js_AddZone(int num_args, bool is_ctor, intptr_t magic)
{
rect_t bounds;
int height;
int layer;
script_t* script;
int width;
int x;
int y;
x = jsal_to_int(0);
y = jsal_to_int(1);
width = jsal_to_int(2);
height = jsal_to_int(3);
layer = jsal_require_map_layer(4);
script = jsal_require_sphere_script(5, "%/zoneScript.js");
if (!map_engine_running())
jsal_error(JS_RANGE_ERROR, "Map engine not running");
bounds = map_bounds();
if (width <= 0 || height <= 0)
jsal_error(JS_RANGE_ERROR, "Invalid zone width/height [%d,%d]", width, height);
if (x < bounds.x1 || y < bounds.y1 || x + width > bounds.x2 || y + height > bounds.y2)
jsal_error(JS_RANGE_ERROR, "X/Y out of bounds (%d,%d)", x, y);
if (!map_add_zone(mk_rect(x, y, width, height), layer, script, 8))
jsal_error(JS_ERROR, "Couldn't allocate new zone");
jsal_push_number(map_num_zones() - 1);
script_unref(script);
return true;
}
static bool
js_ApplyColorMask(int num_args, bool is_ctor, intptr_t magic)
{
color_t color;
size2_t resolution;
color = jsal_require_sphere_color(0);
if (screen_skipping_frame(g_screen))
return false;
resolution = screen_size(g_screen);
galileo_reset();
al_draw_filled_rectangle(0, 0, resolution.width, resolution.height,
nativecolor(color));
return false;
}
static bool
js_AreKeysLeft(int num_args, bool is_ctor, intptr_t magic)
{
update_input();
jsal_push_boolean(kb_queue_len() > 0);
return true;
}
static bool
js_AreZonesAt(int num_args, bool is_ctor, intptr_t magic)
{
int layer;
int x;
int y;
x = jsal_to_int(0);
y = jsal_to_int(1);
layer = jsal_require_map_layer(2);
jsal_push_boolean(map_zone_at(x, y, layer, 0) >= 0);
return true;
}
static bool
js_AttachCamera(int num_args, bool is_ctor, intptr_t magic)
{
const char* name;
person_t* person;
name = jsal_to_string(0);
if (!(person = map_person_by_name(name)))
jsal_error(JS_REF_ERROR, "No such person '%s'", name);
map_engine_set_subject(person);
return false;
}
static bool
js_AttachInput(int num_args, bool is_ctor, intptr_t magic)
{
const char* name;
person_t* person;
name = jsal_require_string(0);
if (!(person = map_person_by_name(name)))
jsal_error(JS_REF_ERROR, "No such person '%s'", name);
map_engine_set_player(PLAYER_1, person);
return false;
}
static bool
js_AttachPlayerInput(int num_args, bool is_ctor, intptr_t magic)
{
const char* name;
person_t* person;
player_id_t player;
name = jsal_require_string(0);
player = jsal_to_int(1);
if (player < 0 || player >= PLAYER_MAX)
jsal_error(JS_RANGE_ERROR, "Invalid player constant");
if (!(person = map_person_by_name(name)))
jsal_error(JS_REF_ERROR, "No such person '%s'", name);
map_engine_set_player(player, person);
return false;
}
static bool
js_BezierCurve(int num_args, bool is_ctor, intptr_t magic)
{
color_t color;
float cp[8];
int num_points;
ALLEGRO_VERTEX* points;
bool quadratic = true;
double step_size;
float x1, x2, x3, x4;
float y1, y2, y3, y4;
int i;
color = jsal_require_sphere_color(0);
step_size = jsal_to_number(1);
x1 = trunc(jsal_to_number(2));
y1 = trunc(jsal_to_number(3));
x2 = trunc(jsal_to_number(4));
y2 = trunc(jsal_to_number(5));
x3 = trunc(jsal_to_number(6));
y3 = trunc(jsal_to_number(7));
if (num_args >= 10) {
quadratic = false;
x4 = trunc(jsal_to_number(8));
y4 = trunc(jsal_to_number(9));
}
if (screen_skipping_frame(g_screen))
return false;
cp[0] = x1; cp[1] = y1;
cp[2] = x2; cp[3] = y2;
cp[4] = x3; cp[5] = y3;
cp[6] = x4; cp[7] = y4;
if (quadratic) {
// convert quadratic Bezier curve to cubic
cp[6] = x3; cp[7] = y3;
cp[2] = x1 + (2.0 / 3.0) * (x2 - x1);
cp[3] = y1 + (2.0 / 3.0) * (y2 - y1);
cp[4] = x3 + (2.0 / 3.0) * (x2 - x3);
cp[5] = y3 + (2.0 / 3.0) * (y2 - y3);
}
step_size = step_size < 0.001 ? 0.001
: step_size > 1.0 ? 1.0
: step_size;
num_points = 1.0 / step_size;
points = alloca(num_points * sizeof(ALLEGRO_VERTEX));
memset(points, 0, num_points * sizeof(ALLEGRO_VERTEX));
al_calculate_spline(&points[0].x, sizeof(ALLEGRO_VERTEX), cp, 0.0, num_points);
for (i = 0; i < num_points; ++i)
points[i].color = nativecolor(color);
galileo_reset();
al_draw_prim(points, NULL, NULL, 0, num_points, ALLEGRO_PRIM_POINT_LIST);
return false;
}
static bool
js_BindJoystickButton(int num_args, bool is_ctor, intptr_t magic)
{
int joy_index = jsal_to_int(0);
int button = jsal_to_int(1);
script_t* on_down_script = jsal_require_sphere_script(2, "[button-down script]");
script_t* on_up_script = jsal_require_sphere_script(3, "[button-up script]");
if (joy_index < 0 || joy_index >= MAX_JOYSTICKS)
jsal_error(JS_RANGE_ERROR, "Joystick index '%d' out of range", joy_index);
if (button < 0 || button >= MAX_JOY_BUTTONS)
jsal_error(JS_RANGE_ERROR, "Button index '%d' out of range", button);
joy_bind_button(joy_index, button, on_down_script, on_up_script);
return false;
}
static bool
js_BindKey(int num_args, bool is_ctor, intptr_t magic)
{
int keycode = jsal_to_int(0);
script_t* on_down_script = jsal_require_sphere_script(1, "[key-down script]");
script_t* on_up_script = jsal_require_sphere_script(2, "[key-up script]");
if (keycode < 0 || keycode >= ALLEGRO_KEY_MAX)
jsal_error(JS_RANGE_ERROR, "Invalid key constant");
kb_bind_key(keycode, on_down_script, on_up_script);
return false;
}
static bool
js_BlendColors(int num_args, bool is_ctor, intptr_t magic)
{
color_t color1;
color_t color2;
float w1 = 1.0;
float w2 = 1.0;
color1 = jsal_require_sphere_color(0);
color2 = jsal_require_sphere_color(1);
if (num_args > 2) {
w1 = jsal_to_number(2);
w2 = jsal_to_number(3);
}
if (w1 < 0.0 || w2 < 0.0)
jsal_error(JS_RANGE_ERROR, "Invalid weight(s) '%g'/'%g'", w1, w2);
jsal_push_sphere_color(color_mix(color1, color2, w1, w2));
return true;
}
static bool
js_CallDefaultMapScript(int num_args, bool is_ctor, intptr_t magic)
{
int map_op;
map_op = jsal_to_int(0);
if (!map_engine_running())
jsal_error(JS_RANGE_ERROR, "Map engine not running");
if (map_op < 0 || map_op >= MAP_SCRIPT_MAX)
jsal_error(JS_RANGE_ERROR, "Invalid script type constant");
map_call_default(map_op);
return false;
}
static bool
js_CallDefaultPersonScript(int num_args, bool is_ctor, intptr_t magic)
{
person_t* actor = NULL;
const char* name;
person_t* person;
int type;
name = jsal_require_string(0);
type = jsal_require_int(1);
if (!(person = map_person_by_name(name)))
jsal_error(JS_REF_ERROR, "No such person '%s'", name);
if (type < 0 || type >= PERSON_SCRIPT_MAX)
jsal_error(JS_ERROR, "Invalid script type constant");
if (type == PERSON_SCRIPT_ON_TALK || type == PERSON_SCRIPT_ON_TOUCH)
actor = person;
person_call_default(person, type, actor);
return false;
}
static bool
js_CallMapScript(int num_args, bool is_ctor, intptr_t magic)
{
int type;
type = jsal_to_int(0);
if (!map_engine_running())
jsal_error(JS_RANGE_ERROR, "Map engine not running");
if (type < 0 || type >= MAP_SCRIPT_MAX)
jsal_error(JS_RANGE_ERROR, "Invalid script type constant");
map_activate(type, false);
return false;
}
static bool
js_CallPersonScript(int num_args, bool is_ctor, intptr_t magic)
{
const char* name;
person_t* person;
int type;
name = jsal_require_string(0);
type = jsal_require_int(1);
if (!(person = map_person_by_name(name)))
jsal_error(JS_REF_ERROR, "No such person '%s'", name);
if (type < 0 || type >= PERSON_SCRIPT_MAX)
jsal_error(JS_ERROR, "Invalid script type constant");
if (type == PERSON_SCRIPT_ON_TALK || type == PERSON_SCRIPT_ON_TOUCH)
person_activate(person, type, person, false);
else
person_activate(person, type, NULL, false);
return false;
}
static bool
js_ChangeMap(int num_args, bool is_ctor, intptr_t magic)
{
const char* filename;
filename = jsal_require_pathname(0, "maps", true, false);
if (!map_engine_running())
jsal_error(JS_RANGE_ERROR, "Map engine not running");
if (!map_engine_change_map(filename))
jsal_error(JS_ERROR, "Couldn't load map file '%s'", filename);
return false;
}
static bool
js_ClearPersonCommands(int num_args, bool is_ctor, intptr_t magic)
{
const char* name;
person_t* person;
name = jsal_require_string(0);
if (!(person = map_person_by_name(name)))
jsal_error(JS_REF_ERROR, "No such person '%s'", name);
person_clear_queue(person);
return false;
}
static bool
js_CreateByteArray(int num_args, bool is_ctor, intptr_t magic)
{
bytearray_t* array;
int size;
size = jsal_to_int(0);
if (size < 0)
jsal_error(JS_RANGE_ERROR, "Invalid byte array size");
if (!(array = bytearray_new(size)))
jsal_error(JS_ERROR, "Couldn't allocate byte array");
jsal_push_sphere_bytearray(array);
bytearray_unref(array);
return true;
}
static bool
js_CreateByteArrayFromString(int num_args, bool is_ctor, intptr_t magic)
{
bytearray_t* array;
lstring_t* string;
string = jsal_require_lstring_t(0);
if (!(array = bytearray_from_lstring(string)))
jsal_error(JS_ERROR, "Couldn't allocate byte array");
lstr_free(string);
jsal_push_sphere_bytearray(array);
bytearray_unref(array);
return true;
}
static bool
js_CreateColor(int num_args, bool is_ctor, intptr_t magic)
{
int red;
int green;
int blue;
int alpha = 255;
red = jsal_to_int(0);
green = jsal_to_int(1);
blue = jsal_to_int(2);
if (num_args >= 4)
alpha = jsal_to_int(3);
// clamp components to 8-bit [0-255]
red = red < 0 ? 0 : red > 255 ? 255 : red;
green = green < 0 ? 0 : green > 255 ? 255 : green;
blue = blue < 0 ? 0 : blue > 255 ? 255 : blue;
alpha = alpha < 0 ? 0 : alpha > 255 ? 255 : alpha;
// construct a Color object
jsal_push_sphere_color(mk_color(red, green, blue, alpha));
return true;
}
static bool
js_CreateColorMatrix(int num_args, bool is_ctor, intptr_t magic)
{
int rn = jsal_to_int(0);
int rr = jsal_to_int(1);
int rg = jsal_to_int(2);
int rb = jsal_to_int(3);
int gn = jsal_to_int(4);
int gr = jsal_to_int(5);
int gg = jsal_to_int(6);
int gb = jsal_to_int(7);
int bn = jsal_to_int(8);
int br = jsal_to_int(9);
int bg = jsal_to_int(10);
int bb = jsal_to_int(11);
// construct a ColorMatrix object
jsal_push_class_obj(SV1_COLOR_MATRIX, NULL, false);
jsal_push_int(rn); jsal_put_prop_string(-2, "rn");
jsal_push_int(rr); jsal_put_prop_string(-2, "rr");
jsal_push_int(rg); jsal_put_prop_string(-2, "rg");
jsal_push_int(rb); jsal_put_prop_string(-2, "rb");
jsal_push_int(gn); jsal_put_prop_string(-2, "gn");
jsal_push_int(gr); jsal_put_prop_string(-2, "gr");
jsal_push_int(gg); jsal_put_prop_string(-2, "gg");
jsal_push_int(gb); jsal_put_prop_string(-2, "gb");
jsal_push_int(bn); jsal_put_prop_string(-2, "bn");
jsal_push_int(br); jsal_put_prop_string(-2, "br");
jsal_push_int(bg); jsal_put_prop_string(-2, "bg");
jsal_push_int(bb); jsal_put_prop_string(-2, "bb");
return true;
}
static bool
js_CreateDirectory(int num_args, bool is_ctor, intptr_t magic)
{
const char* name;
name = jsal_require_pathname(0, "save", true, true);
if (!game_mkdir(g_game, name))
jsal_error(JS_ERROR, "Couldn't create directory '%s'", name);
return false;
}
static bool
js_CreatePerson(int num_args, bool is_ctor, intptr_t magic)
{
bool destroy_with_map;
const char* filename;
const char* name;
person_t* person;
spriteset_t* spriteset;
name = jsal_require_string(0);
destroy_with_map = jsal_to_boolean(2);
if (jsal_is_class_obj(1, SV1_SPRITESET)) {
// ref the spriteset so we can safely free it later. this avoids
// having to check the argument type again.
spriteset = jsal_require_sphere_spriteset(1);
}
else {
filename = jsal_require_pathname(1, "spritesets", true, false);
if (!(spriteset = spriteset_load(filename)))
jsal_error(JS_ERROR, "Couldn't load spriteset file '%s'", filename);
}
// create the person and its JS-side data object
person = person_new(name, spriteset, !destroy_with_map, NULL);
spriteset_unref(spriteset);
jsal_push_hidden_stash();
jsal_get_prop_string(-1, "personData");
jsal_push_new_object(); jsal_put_prop_string(-2, name);
jsal_pop(2);
return false;
}
static bool
js_CreateSpriteset(int num_args, bool is_ctor, intptr_t magic)
{
int height;
image_t* image;
int num_frames;
int num_images;
int num_poses;
char pose_name[32];
spriteset_t* spriteset;
int width;
int i, j;
width = jsal_to_int(0);
height = jsal_to_int(1);
num_images = jsal_to_int(2);
num_poses = jsal_to_int(3);
num_frames = jsal_to_int(4);
spriteset = spriteset_new();
spriteset_set_base(spriteset, mk_rect(0, 0, width, height));
image = image_new(width, height, NULL);
for (i = 0; i < num_images; ++i) {
// use the same image in all slots to save memory. this works because
// images are read-only, so it doesn't matter that they all share the same
// pixel data.
spriteset_add_image(spriteset, image);
}
image_unref(image);
for (i = 0; i < num_poses; ++i) {
sprintf(pose_name, "unnamed %d", i + 1);
spriteset_add_pose(spriteset, pose_name);
for (j = 0; j < num_frames; ++j)
spriteset_add_frame(spriteset, pose_name, 0, 8);
}
jsal_push_sphere_spriteset(spriteset);
spriteset_unref(spriteset);
return true;
}
static bool
js_CreateStringFromByteArray(int num_args, bool is_ctor, intptr_t magic)
{
bytearray_t* array;
uint8_t* buffer;
size_t size;
array = jsal_require_class_obj(0, SV1_BYTE_ARRAY);
buffer = bytearray_buffer(array);
size = bytearray_len(array);
jsal_push_lstring((char*)buffer, size);
return true;
}
static bool
js_CreateStringFromCode(int num_args, bool is_ctor, intptr_t magic)
{
int code;
code = jsal_to_int(0);
if (code < 0 || code > 255)
jsal_error(JS_RANGE_ERROR, "Invalid ASCII character code '%d'", code);
jsal_push_sprintf("%c", code);
return true;
}
static bool
js_CreateSurface(int num_args, bool is_ctor, intptr_t magic)
{
color_t fill_color;
int height;
image_t* image;
int width;
width = jsal_to_int(0);
height = jsal_to_int(1);
fill_color = num_args >= 3 ? jsal_require_sphere_color(2) : mk_color(0, 0, 0, 0);
if (!(image = image_new(width, height, NULL)))
jsal_error(JS_ERROR, "Couldn't create GPU texture");
image_fill(image, fill_color);
jsal_push_class_obj(SV1_SURFACE, image, false);
return true;
}
static bool
js_DeflateByteArray(int num_args, bool is_ctor, intptr_t magic)
{
bytearray_t* input_array;
int level = 6;
bytearray_t* new_array;
input_array = jsal_require_class_obj(0, SV1_BYTE_ARRAY);
if (num_args >= 2)
level = jsal_to_int(1);
if (level < 0 || level > 9)
jsal_error(JS_RANGE_ERROR, "Invalid compression level '%d'", level);
if (!(new_array = bytearray_deflate(input_array, level)))
jsal_error(JS_ERROR, "Couldn't deflate byte array");
jsal_push_sphere_bytearray(new_array);
return true;
}
static bool
js_Delay(int num_args, bool is_ctor, intptr_t magic)
{
double timeout;
timeout = jsal_to_number(0);
if (timeout < 0.0)
jsal_error(JS_RANGE_ERROR, "Invalid delay timeout '%g'", timeout);
sphere_sleep(floor(timeout) / 1000.0);
return false;
}
static bool
js_DestroyPerson(int num_args, bool is_ctor, intptr_t magic)
{
const char* name;
person_t* person;
name = jsal_require_string(0);
if (!(person = map_person_by_name(name)))
jsal_error(JS_REF_ERROR, "No such person '%s'", name);
person_free(person);
return false;
}
static bool
js_DetachCamera(int num_args, bool is_ctor, intptr_t magic)
{
map_engine_set_subject(NULL);
return false;
}
static bool
js_DetachInput(int num_args, bool is_ctor, intptr_t magic)
{
map_engine_set_player(PLAYER_1, NULL);
return false;
}
static bool
js_DetachPlayerInput(int num_args, bool is_ctor, intptr_t magic)
{
const char* name;
person_t* person;
int player;
int i;
if (num_args < 1) {
jsal_error(JS_ERROR, "Missing first argument");
}
else if (jsal_is_string(0)) {
name = jsal_get_string(0);
if (!(person = map_person_by_name(name)))
jsal_error(JS_REF_ERROR, "No such person '%s'", name);
player = -1;
for (i = PLAYER_1; i < PLAYER_MAX; ++i) {
if (person == map_engine_get_player(i)) {
player = i;
break;
}
}
if (player == -1)
return false;
}
else if (jsal_is_number(0)) {
player = jsal_get_int(0);
}
else {
jsal_error(JS_ERROR, "First argument is not a number or string");
}
if (player < 0 || player >= PLAYER_MAX)
jsal_error(JS_RANGE_ERROR, "Invalid player constant");
map_engine_set_player(player, NULL);
return false;
}
static bool
js_DoEvents(int num_args, bool is_ctor, intptr_t magic)
{
sphere_heartbeat(true, 1);
dispatch_run(JOB_ON_TICK);
jsal_push_boolean_true();
return true;
}
static bool
js_DoesFileExist(int num_args, bool is_ctor, intptr_t magic)
{
const char* filename;
filename = jsal_require_pathname(0, NULL, true, false);
jsal_push_boolean(game_file_exists(g_game, filename));
return true;
}
static bool
js_DoesPersonExist(int num_args, bool is_ctor, intptr_t magic)
{
const char* name;
name = jsal_require_string(0);
jsal_push_boolean(map_person_by_name(name) != NULL);
return true;
}
static bool
js_EvaluateScript(int num_args, bool is_ctor, intptr_t magic)
{
const char* filename;
filename = jsal_require_pathname(0, "scripts", true, false);
if (!game_file_exists(g_game, filename))
jsal_error(JS_ERROR, "file '%s' not found", filename);
if (!script_eval(filename))
jsal_throw();
return true;
}
static bool
js_EvaluateSystemScript(int num_args, bool is_ctor, intptr_t magic)
{
char path[SPHERE_PATH_MAX];
const char* pathname;
pathname = jsal_require_string(0);
sprintf(path, "@/scripts/lib/%s", pathname);
if (!game_file_exists(g_game, path))
sprintf(path, "#/scripts/%s", pathname);
if (!game_file_exists(g_game, path))
jsal_error(JS_ERROR, "System script '%s' not found", pathname);
if (!script_eval(path))
jsal_throw();
return true;
}
static bool
js_ExecuteGame(int num_args, bool is_ctor, intptr_t magic)
{
path_t* base_path;
path_t* path;
const char* pathname;
pathname = jsal_require_string(0);
// if the passed-in path is relative, resolve it relative to <engine>/games.
// this is done for compatibility with Sphere 1.x.
path = path_new(pathname);
base_path = path_rebase(path_new("games/"), assets_path());
path_rebase(path, base_path);
path_free(base_path);
sphere_change_game(path_cstr(path));
path_free(path);
return false;
}
static bool
js_ExecuteTrigger(int num_args, bool is_ctor, intptr_t magic)
{
int index;
int layer;
int x;
int y;
x = jsal_to_int(0);
y = jsal_to_int(1);
layer = jsal_require_map_layer(2);
if (!map_engine_running())
jsal_error(JS_RANGE_ERROR, "Map engine not running");
if ((index = map_trigger_at(x, y, layer)) >= 0)
trigger_activate(index);
return false;
}
static bool
js_ExecuteZoneScript(int num_args, bool is_ctor, intptr_t magic)
{
int zone_index;
zone_index = jsal_to_int(0);
if (!map_engine_running())
jsal_error(JS_RANGE_ERROR, "Map engine not running");
if (zone_index < 0 || zone_index >= map_num_zones())
jsal_error(JS_RANGE_ERROR, "Invalid zone index '%d'", zone_index);
zone_activate(zone_index);
return false;
}
static bool
js_ExecuteZones(int num_args, bool is_ctor, intptr_t magic)
{
int index;
int layer;
int x;
int y;
int i;
x = jsal_to_int(0);
y = jsal_to_int(1);
layer = jsal_require_map_layer(2);
if (!map_engine_running())
jsal_error(JS_RANGE_ERROR, "Map engine not running");
i = 0;
while ((index = map_zone_at(x, y, layer, i++)) >= 0)
zone_activate(index);
return false;
}
static bool
js_Exit(int num_args, bool is_ctor, intptr_t magic)
{
sphere_exit(true);
return false;
}
static bool
js_ExitMapEngine(int num_args, bool is_ctor, intptr_t magic)
{
if (!map_engine_running())
jsal_error(JS_RANGE_ERROR, "Map engine not running");
map_engine_exit();
return false;
}
static bool
js_FilledCircle(int num_args, bool is_ctor, intptr_t magic)
{
color_t color;
int num_points;
double phi;
float radius;
ALLEGRO_VERTEX* vertices;
float x;
float y;
int i;
x = trunc(jsal_to_number(0));
y = trunc(jsal_to_number(1));
radius = trunc(jsal_to_number(2));
color = jsal_require_sphere_color(3);
if (screen_skipping_frame(g_screen))
return false;
num_points = fmin(radius, 126);
vertices = alloca((num_points + 2) * sizeof(ALLEGRO_VERTEX));
vertices[0].x = x;
vertices[0].y = y;
vertices[0].z = 0.0f;
vertices[0].color = nativecolor(color);
for (i = 0; i < num_points; ++i) {
phi = 2 * M_PI * i / num_points;
vertices[i + 1].x = x + cosf(phi) * radius;
vertices[i + 1].y = y - sinf(phi) * radius;
vertices[i + 1].z = 0.0f;
vertices[i + 1].color = nativecolor(color);
}
vertices[i + 1].x = x + cosf(0.0f) * radius;
vertices[i + 1].y = y - sinf(0.0f) * radius;
vertices[i + 1].z = 0.0f;
vertices[i + 1].color = nativecolor(color);
galileo_reset();
al_draw_prim(vertices, NULL, NULL, 0, num_points + 2, ALLEGRO_PRIM_TRIANGLE_FAN);
return false;
}
static bool
js_FilledComplex(int num_args, bool is_ctor, intptr_t magic)
{
jsal_error(JS_ERROR, "Not implemented");
return false;
}
static bool
js_FilledEllipse(int num_args, bool is_ctor, intptr_t magic)
{
color_t color;
int num_points;
double phi;
float radius_x;
float radius_y;
ALLEGRO_VERTEX* vertices;
float x;
float y;
int i;
x = trunc(jsal_to_number(0));
y = trunc(jsal_to_number(1));
radius_x = trunc(jsal_to_number(2));
radius_y = trunc(jsal_to_number(3));
color = jsal_require_sphere_color(4);
if (screen_skipping_frame(g_screen))
return false;
num_points = ceil(fmin(10 * sqrt((radius_x + radius_y) / 2), 126));
vertices = alloca((num_points + 2) * sizeof(ALLEGRO_VERTEX));
vertices[0].x = x;
vertices[0].y = y;
vertices[0].z = 0.0f;
vertices[0].color = nativecolor(color);
for (i = 0; i < num_points; ++i) {
phi = 2 * M_PI * i / num_points;
vertices[i + 1].x = x + cosf(phi) * radius_x;
vertices[i + 1].y = y - sinf(phi) * radius_y;
vertices[i + 1].z = 0.0f;
vertices[i + 1].color = nativecolor(color);
}
vertices[i + 1].x = x + cosf(0.0f) * radius_x;
vertices[i + 1].y = y - sinf(0.0f) * radius_y;
vertices[i + 1].z = 0.0f;
vertices[i + 1].color = nativecolor(color);
galileo_reset();
al_draw_prim(vertices, NULL, NULL, 0, num_points + 2, ALLEGRO_PRIM_TRIANGLE_FAN);
return false;
}
static bool
js_FlipScreen(int num_args, bool is_ctor, intptr_t magic)
{
sphere_tick(1, true, s_frame_rate);
return false;
}
static bool
js_FollowPerson(int num_args, bool is_ctor, intptr_t magic)
{
int distance = 0;
person_t* leader = NULL;
const char* leader_name = "";
const char* name;
person_t* person;
name = jsal_require_string(0);
if (!jsal_is_null(1))
leader_name = jsal_require_string(1);
if (leader_name[0] != '\0')
distance = jsal_require_int(2);
if (!(person = map_person_by_name(name)))
jsal_error(JS_REF_ERROR, "No such person '%s'", name);
if (!(leader_name[0] == '\0' || (leader = map_person_by_name(leader_name))))
jsal_error(JS_REF_ERROR, "No such person '%s'", leader_name);
if (distance <= 0 && leader_name[0] != '\0')
jsal_error(JS_RANGE_ERROR, "Invalid distance '%d'", distance);
if (!person_set_leader(person, leader, distance))
jsal_error(JS_ERROR, "Illegal cycle in FollowPerson train");
return false;
}
static bool
js_GarbageCollect(int num_args, bool is_ctor, intptr_t magic)
{
jsal_gc();
return false;
}
static bool
js_GetActingPerson(int num_args, bool is_ctor, intptr_t magic)
{
const person_t* person;
if (!map_engine_running())
jsal_error(JS_RANGE_ERROR, "Map engine not running");
person = map_engine_acting_person();
if (person == NULL)
jsal_error(JS_ERROR, "No current person activation or actor unknown");
jsal_push_string(person_name(person));
return true;
}
static bool
js_GetCameraPerson(int num_args, bool is_ctor, intptr_t magic)
{
person_t* subject;
subject = map_engine_get_subject();
if (subject == NULL)
jsal_error(JS_ERROR, "Camera is not attached");
jsal_push_string(person_name(subject));
return true;
}
static bool
js_GetCameraX(int num_args, bool is_ctor, intptr_t magic)
{
point2_t position;
if (!map_engine_running())
jsal_error(JS_RANGE_ERROR, "Map engine not running");
position = map_get_camera_xy();
jsal_push_int(position.x);
return true;
}
static bool
js_GetCameraY(int num_args, bool is_ctor, intptr_t magic)
{
point2_t position;
if (!map_engine_running())
jsal_error(JS_RANGE_ERROR, "Map engine not running");
position = map_get_camera_xy();
jsal_push_int(position.y);
return true;
}
static bool
js_GetClippingRectangle(int num_args, bool is_ctor, intptr_t magic)
{
rect_t clip;
clip = image_get_scissor(screen_backbuffer(g_screen));
jsal_push_new_object();
jsal_push_int(clip.x1);
jsal_put_prop_string(-2, "x");
jsal_push_int(clip.y1);
jsal_put_prop_string(-2, "y");
jsal_push_int(clip.x2 - clip.x1);
jsal_put_prop_string(-2, "width");
jsal_push_int(clip.y2 - clip.y1);
jsal_put_prop_string(-2, "height");
return true;
}
static bool
js_GetCurrentMap(int num_args, bool is_ctor, intptr_t magic)
{
path_t* path;
if (!map_engine_running())
jsal_error(JS_RANGE_ERROR, "Map engine not running");
// GetCurrentMap() in Sphere 1.x returns the map path relative to the
// 'maps' directory.
path = game_relative_path(g_game, map_pathname(), "@/maps");
jsal_push_string(path_cstr(path));
path_free(path);
return true;
}
static bool
js_GetCurrentPerson(int num_args, bool is_ctor, intptr_t magic)
{
const person_t* person;
if (!map_engine_running())
jsal_error(JS_RANGE_ERROR, "Map engine not running");
person = map_engine_active_person();
if (person == NULL)
jsal_error(JS_ERROR, "No current person activation");
jsal_push_string(person_name(person));
return true;
}
static bool
js_GetCurrentTrigger(int num_args, bool is_ctor, intptr_t magic)
{
int trigger;
if (!map_engine_running())
jsal_error(JS_RANGE_ERROR, "Map engine not running");
trigger = map_engine_active_trigger();
if (trigger == -1)
jsal_error(JS_ERROR, "No current trigger activation");
jsal_push_int(trigger);
return true;
}
static bool
js_GetCurrentZone(int num_args, bool is_ctor, intptr_t magic)
{
int zone;
if (!map_engine_running())
jsal_error(JS_RANGE_ERROR, "Map engine not running");
zone = map_engine_active_zone();
if (zone == -1)
jsal_error(JS_ERROR, "No current zone activation");
jsal_push_int(zone);
return true;
}
static bool
js_GetDirectoryList(int num_args, bool is_ctor, intptr_t magic)
{
directory_t* dir;
const char* dir_name = "@/";
const path_t* entry;
int index = 0;
if (num_args >= 1)
dir_name = jsal_require_pathname(0, NULL, true, false);
jsal_push_new_array();
if (!(dir = directory_open(g_game, dir_name)))
return true;
while ((entry = directory_next(dir))) {
if (path_is_file(entry))
continue;
jsal_push_string(path_hop(entry, path_num_hops(entry) - 1));
jsal_put_prop_index(-2, index++);
}
directory_close(dir);
return true;
}
static bool
js_GetFileList(int num_args, bool is_ctor, intptr_t magic)
{
directory_t* dir;
const char* dir_name = "@/save";
const path_t* entry;
int index = 0;
if (num_args >= 1)
dir_name = jsal_require_pathname(0, NULL, true, false);
jsal_push_new_array();
if (!(dir = directory_open(g_game, dir_name)))
return true;
while ((entry = directory_next(dir))) {
if (!path_is_file(entry))
continue;
jsal_push_string(path_filename(entry));
jsal_put_prop_index(-2, index++);
}
directory_close(dir);
return true;
}
static bool
js_GetFrameRate(int num_args, bool is_ctor, intptr_t magic)
{
jsal_push_int(s_frame_rate);
return true;
}
static bool
js_GetGameList(int num_args, bool is_ctor, intptr_t magic)
{
ALLEGRO_FS_ENTRY* file_info;
ALLEGRO_FS_ENTRY* fse;
game_t* game;
path_t* path = NULL;
path_t* paths[2];
int i, j = 0;
// build search paths
paths[0] = path_rebase(path_new("games/"), engine_path());
paths[1] = path_rebase(path_new("miniSphere/Games/"), home_path());
// search for supported games
jsal_push_new_array();
for (i = sizeof paths / sizeof(path_t*) - 1; i >= 0; --i) {
fse = al_create_fs_entry(path_cstr(paths[i]));
if (al_get_fs_entry_mode(fse) & ALLEGRO_FILEMODE_ISDIR && al_open_directory(fse)) {
while ((file_info = al_read_directory(fse))) {
path = path_new(al_get_fs_entry_name(file_info));
if ((game = game_open(path_cstr(path)))) {
jsal_push_ref_weak(game_manifest(game));
jsal_push_string(path_cstr(path));
jsal_put_prop_string(-2, "directory");
jsal_put_prop_index(-2, j++);
game_unref(game);
}
path_free(path);
}
}
al_destroy_fs_entry(fse);
path_free(paths[i]);
}
return true;
}
static bool
js_GetInputPerson(int num_args, bool is_ctor, intptr_t magic)
{
person_t* person;
int player = PLAYER_1;
if (num_args >= 1)
player = jsal_to_int(0);
if (player < 0 || player >= PLAYER_MAX)
jsal_error(JS_RANGE_ERROR, "Invalid player constant");
person = map_engine_get_player(player);
if (person == NULL)
jsal_error(JS_ERROR, "Input is not attached for Player %d", player + 1);
jsal_push_string(person_name(person));
return true;
}
static bool
js_GetJoystickAxis(int num_args, bool is_ctor, intptr_t magic)
{
int joy_index = jsal_to_int(0);
int axis_index = jsal_to_int(1);
jsal_push_number(joy_position(joy_index, axis_index));
return true;
}
static bool
js_GetKey(int num_args, bool is_ctor, intptr_t magic)
{
while (kb_queue_len() == 0)
sphere_sleep(0.05);
jsal_push_int(kb_get_key());
return true;
}
static bool
js_GetKeyString(int num_args, bool is_ctor, intptr_t magic)
{
int keycode;
bool shift = false;
keycode = jsal_to_int(0);
if (num_args >= 2)
shift = jsal_to_boolean(1);
switch (keycode) {
case ALLEGRO_KEY_A: jsal_push_string(shift ? "A" : "a"); break;
case ALLEGRO_KEY_B: jsal_push_string(shift ? "B" : "b"); break;
case ALLEGRO_KEY_C: jsal_push_string(shift ? "C" : "c"); break;
case ALLEGRO_KEY_D: jsal_push_string(shift ? "D" : "d"); break;
case ALLEGRO_KEY_E: jsal_push_string(shift ? "E" : "e"); break;
case ALLEGRO_KEY_F: jsal_push_string(shift ? "F" : "f"); break;
case ALLEGRO_KEY_G: jsal_push_string(shift ? "G" : "g"); break;
case ALLEGRO_KEY_H: jsal_push_string(shift ? "H" : "h"); break;
case ALLEGRO_KEY_I: jsal_push_string(shift ? "I" : "i"); break;
case ALLEGRO_KEY_J: jsal_push_string(shift ? "J" : "j"); break;
case ALLEGRO_KEY_K: jsal_push_string(shift ? "K" : "k"); break;
case ALLEGRO_KEY_L: jsal_push_string(shift ? "L" : "l"); break;
case ALLEGRO_KEY_M: jsal_push_string(shift ? "M" : "m"); break;
case ALLEGRO_KEY_N: jsal_push_string(shift ? "N" : "n"); break;
case ALLEGRO_KEY_O: jsal_push_string(shift ? "O" : "o"); break;
case ALLEGRO_KEY_P: jsal_push_string(shift ? "P" : "p"); break;
case ALLEGRO_KEY_Q: jsal_push_string(shift ? "Q" : "q"); break;
case ALLEGRO_KEY_R: jsal_push_string(shift ? "R" : "r"); break;
case ALLEGRO_KEY_S: jsal_push_string(shift ? "S" : "s"); break;
case ALLEGRO_KEY_T: jsal_push_string(shift ? "T" : "t"); break;
case ALLEGRO_KEY_U: jsal_push_string(shift ? "U" : "u"); break;
case ALLEGRO_KEY_V: jsal_push_string(shift ? "V" : "v"); break;
case ALLEGRO_KEY_W: jsal_push_string(shift ? "W" : "w"); break;
case ALLEGRO_KEY_X: jsal_push_string(shift ? "X" : "x"); break;
case ALLEGRO_KEY_Y: jsal_push_string(shift ? "Y" : "y"); break;
case ALLEGRO_KEY_Z: jsal_push_string(shift ? "Z" : "z"); break;
case ALLEGRO_KEY_1: jsal_push_string(shift ? "!" : "1"); break;
case ALLEGRO_KEY_2: jsal_push_string(shift ? "@" : "2"); break;
case ALLEGRO_KEY_3: jsal_push_string(shift ? "#" : "3"); break;
case ALLEGRO_KEY_4: jsal_push_string(shift ? "$" : "4"); break;
case ALLEGRO_KEY_5: jsal_push_string(shift ? "%" : "5"); break;
case ALLEGRO_KEY_6: jsal_push_string(shift ? "^" : "6"); break;
case ALLEGRO_KEY_7: jsal_push_string(shift ? "&" : "7"); break;
case ALLEGRO_KEY_8: jsal_push_string(shift ? "*" : "8"); break;
case ALLEGRO_KEY_9: jsal_push_string(shift ? "(" : "9"); break;
case ALLEGRO_KEY_0: jsal_push_string(shift ? ")" : "0"); break;
case ALLEGRO_KEY_BACKSLASH: jsal_push_string(shift ? "|" : "\\"); break;
case ALLEGRO_KEY_FULLSTOP: jsal_push_string(shift ? ">" : "."); break;
case ALLEGRO_KEY_CLOSEBRACE: jsal_push_string(shift ? "}" : "]"); break;
case ALLEGRO_KEY_COMMA: jsal_push_string(shift ? "<" : ","); break;
case ALLEGRO_KEY_EQUALS: jsal_push_string(shift ? "+" : "="); break;
case ALLEGRO_KEY_MINUS: jsal_push_string(shift ? "_" : "-"); break;
case ALLEGRO_KEY_QUOTE: jsal_push_string(shift ? "\"" : "'"); break;
case ALLEGRO_KEY_OPENBRACE: jsal_push_string(shift ? "{" : "["); break;
case ALLEGRO_KEY_SEMICOLON: jsal_push_string(shift ? ":" : ";"); break;
case ALLEGRO_KEY_SLASH: jsal_push_string(shift ? "?" : "/"); break;
case ALLEGRO_KEY_SPACE: jsal_push_string(" "); break;
case ALLEGRO_KEY_TAB: jsal_push_string("\t"); break;
case ALLEGRO_KEY_TILDE: jsal_push_string(shift ? "~" : "`"); break;
default:
jsal_push_string("");
}
return true;
}
static bool
js_GetLayerAngle(int num_args, bool is_ctor, intptr_t magic)
{
jsal_error(JS_ERROR, "Not implemented");
return false;
}
static bool
js_GetLayerHeight(int num_args, bool is_ctor, intptr_t magic)
{
int layer;
layer = jsal_require_map_layer(0);
if (!map_engine_running())
jsal_error(JS_RANGE_ERROR, "Map engine not running");
jsal_push_int(layer_size(layer).height);
return true;
}
static bool
js_GetLayerMask(int num_args, bool is_ctor, intptr_t magic)
{
int layer = jsal_require_map_layer(0);
if (!map_engine_running())
jsal_error(JS_RANGE_ERROR, "Map engine not running");
jsal_push_sphere_color(layer_get_color_mask(layer));
return true;
}
static bool
js_GetLayerName(int num_args, bool is_ctor, intptr_t magic)
{
int layer = jsal_require_map_layer(0);
if (!map_engine_running())
jsal_error(JS_RANGE_ERROR, "Map engine not running");
jsal_push_string(layer_name(layer));
return true;
}
static bool
js_GetLayerWidth(int num_args, bool is_ctor, intptr_t magic)
{
int layer;
layer = jsal_require_map_layer(0);
if (!map_engine_running())
jsal_error(JS_RANGE_ERROR, "Map engine not running");
jsal_push_int(layer_size(layer).width);
return true;
}
static bool
js_GetLocalAddress(int num_args, bool is_ctor, intptr_t magic)
{
jsal_push_string("127.0.0.1");
return true;
}
static bool
js_GetLocalName(int num_args, bool is_ctor, intptr_t magic)
{
jsal_push_string("localhost");
return true;
}
static bool
js_GetMapEngine(int num_args, bool is_ctor, intptr_t magic)
{
jsal_error(JS_ERROR, "Not implemented");
return true;
}
static bool
js_GetMapEngineFrameRate(int num_args, bool is_ctor, intptr_t magic)
{
jsal_push_int(map_engine_get_framerate());
return true;
}
static bool
js_GetMouseWheelEvent(int num_args, bool is_ctor, intptr_t magic)
{
mouse_event_t event;
do {
while (mouse_queue_len() == 0)
sphere_sleep(0.05);
event = mouse_get_event();
} while (event.key != MOUSE_KEY_WHEEL_UP && event.key != MOUSE_KEY_WHEEL_DOWN);
jsal_push_int(event.key);
return true;
}
static bool
js_GetMouseX(int num_args, bool is_ctor, intptr_t magic)
{
int x;
int y;
screen_get_mouse_xy(g_screen, &x, &y);
jsal_push_int(x);
return true;
}
static bool
js_GetMouseY(int num_args, bool is_ctor, intptr_t magic)
{
int x;
int y;
screen_get_mouse_xy(g_screen, &x, &y);
jsal_push_int(y);
return true;
}
static bool
js_GetNextAnimatedTile(int num_args, bool is_ctor, intptr_t magic)
{
int tile_index;
tileset_t* tileset;
tile_index = jsal_to_int(0);
if (!map_engine_running())
jsal_error(JS_RANGE_ERROR, "Map engine not running");
tileset = map_tileset();
if (tile_index < 0 || tile_index >= tileset_len(tileset))
jsal_error(JS_RANGE_ERROR, "invalid tile index");
jsal_push_int(tileset_get_next(tileset, tile_index));
return true;
}
static bool
js_GetNumJoysticks(int num_args, bool is_ctor, intptr_t magic)
{
jsal_push_int(joy_num_devices());
return true;
}
static bool
js_GetNumJoystickAxes(int num_args, bool is_ctor, intptr_t magic)
{
int joy_index;
joy_index = jsal_to_int(0);
jsal_push_int(joy_num_axes(joy_index));
return true;
}
static bool
js_GetNumJoystickButtons(int num_args, bool is_ctor, intptr_t magic)
{
int joy_index;
joy_index = jsal_to_int(0);
jsal_push_int(joy_num_buttons(joy_index));
return true;
}
static bool
js_GetNumLayers(int num_args, bool is_ctor, intptr_t magic)
{
if (!map_engine_running())
jsal_error(JS_RANGE_ERROR, "Map engine not running");
jsal_push_int(map_num_layers());
return true;
}