<commit_before>////////////////////////////////////////////////////////////
//
// DAGON - An Adventure Game Engine
// Copyright (c) 2011 Senscape s.r.l.
// All rights reserved.
//
// NOTICE: Senscape permits you to use, modify, and
// distribute this file in accordance with the terms of the
// license agreement accompanying it.
//
////////////////////////////////////////////////////////////

#ifndef DG_SPOTPROXY_H
#define DG_SPOTPROXY_H

////////////////////////////////////////////////////////////
// NOTE: This header file should never be included directly.
// It's auto-included by DGProxy.h
////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////

#include "DGAudioManager.h"
#include "DGSpot.h"
#include "DGSystem.h"
#include "DGTexture.h"
#include "DGVideoManager.h"

////////////////////////////////////////////////////////////
// Interface
////////////////////////////////////////////////////////////

class DGSpotProxy : public DGObjectProxy {
public:
    static const char className[];
    static Luna<DGSpotProxy>::RegType methods[];
    
    // Constructor
    DGSpotProxy(lua_State *L) {
        int flags = DGSpotUser;
        
        if (lua_istable(L, 3)) {
            lua_pushnil(L);
            while (lua_next(L, 3) != 0) {
                const char* key = lua_tostring(L, -2);
                
                // We can only read the key as a string, so we have no choice but
                // do an ugly nesting of strcmps()
                if (strcmp(key, "autoplay") == 0) flags = flags | DGSpotAuto;
                
                lua_pop(L, 1);
            }
        }
        
        if (lua_istable(L, 2)) {
            std::vector<int> arrayOfCoords;
            
            lua_pushnil(L);  // First key
            while (lua_next(L, 2) != 0) {
                // Uses key at index -2 and value at index -1
                arrayOfCoords.push_back(lua_tonumber(L, -1));
                lua_pop(L, 1);
            }
            
            s = new DGSpot(arrayOfCoords, luaL_checknumber(L, 1), flags);
            s->setVolume(1.0f); // Default volume
        }
        else luaL_error(L, DGMsg250004);
        
        // Init the base class
        this->setObject(s);
    }
    
    // TODO: In the future we should return a pointer to an attached object
    int attach(lua_State *L) {
        DGAction action;
        DGAudio* audio;
        DGTexture* texture;
        DGVideo* video;
        
        // For the video attach, autoplay defaults to true
        bool autoplay = true, loop, sync;
        
        int type = (int)luaL_checknumber(L, 1);
        
        switch (type) {
            case AUDIO:
                if (DGCheckProxy(L, 2) == DGObjectAudio) {
                    // Just set the audio object
                    s->setAudio(DGProxyToAudio(L, 2));
                }
                else {
                    // If not, create and set (deleted by the Audio Manager)
                    audio = new DGAudio;<commit_msg>Fix in the spot proxy.<commit_after>////////////////////////////////////////////////////////////
//
// DAGON - An Adventure Game Engine
// Copyright (c) 2011 Senscape s.r.l.
// All rights reserved.
//
// NOTICE: Senscape permits you to use, modify, and
// distribute this file in accordance with the terms of the
// license agreement accompanying it.
//
////////////////////////////////////////////////////////////

#ifndef DG_SPOTPROXY_H
#define DG_SPOTPROXY_H

////////////////////////////////////////////////////////////
// NOTE: This header file should never be included directly.
// It's auto-included by DGProxy.h
////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////

#include "DGAudioManager.h"
#include "DGSpot.h"
#include "DGSystem.h"
#include "DGTexture.h"
#include "DGVideoManager.h"

////////////////////////////////////////////////////////////
// Interface
////////////////////////////////////////////////////////////

class DGSpotProxy : public DGObjectProxy {
public:
    static const char className[];
    static Luna<DGSpotProxy>::RegType methods[];
    
    // Constructor
    DGSpotProxy(lua_State *L) {
        int flags = DGSpotUser;
        
        if (lua_istable(L, 3)) {
            lua_pushnil(L);
            while (lua_next(L, 3) != 0) {
                const char* key = lua_tostring(L, -2);
                
                // We can only read the key as a string, so we have no choice but
                // do an ugly nesting of strcmps()
                if (strcmp(key, "autoplay") == 0) flags = flags | DGSpotAuto;
                
                lua_pop(L, 1);
            }
        }
        
        if (lua_istable(L, 2)) {
            std::vector<int> arrayOfCoords;
            
            lua_pushnil(L);  // First key
            while (lua_next(L, 2) != 0) {
                // Uses key at index -2 and value at index -1
                arrayOfCoords.push_back(lua_tonumber(L, -1));
                lua_pop(L, 1);
            }
            
            s = new DGSpot(arrayOfCoords, luaL_checknumber(L, 1), flags);
            s->setVolume(1.0f); // Default volume
        }
        else luaL_error(L, DGMsg250004);
        
        // Init the base class
        this->setObject(s);
    }
    
    // TODO: In the future we should return a pointer to an attached object
    int attach(lua_State *L) {
        DGAction action;
        DGAudio* audio;
        DGTexture* texture;
        DGVideo* video;
        
        // For the video attach, autoplay defaults to true
        bool autoplay = true, loop = false, sync = false;
        
        int type = (int)luaL_checknumber(L, 1);
        
        switch (type) {
            case AUDIO:
                if (DGCheckProxy(L, 2) == DGObjectAudio) {
                    // Just set the audio object
                    s->setAudio(DGProxyToAudio(L, 2));
                }
                else {
                    // If not, create and set (deleted by the Audio Manager)
                    audio = new DGAudio;
{'fraction_non_alphanumeric': 0.2384137601528906, 'fraction_numerical': 0.00923713967192228, 'mean_word_length': 1.0685111989459815, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '307585', 'n_tokens_mistral': 1741, 'n_tokens_neox': 1609, 'n_words': 483}