#ifndef TRIGGER_H
#define TRIGGER_H
#include "cutscene.h"
#include "pixelGameEngine.h"
#include "flags.h"
#include "SeasonI.h"

using namespace olc;

namespace TriggerName{
    //When adding new triggers to the list, you will have to add a new line to trigger.cpp to get it to appear in the editor.
    enum Trigger{
        NONE,
        START_CUTSCENE_1,
        GOTO_MAP,
    };
}

extern void DisplayMessageBox(std::string targetT);
extern SeasonI*GAME;
extern std::map<CutsceneName::Cutscene,Cutscene*> CUTSCENES;
extern Map*CURRENT_MAP;
extern vi2d HIGHLIGHTED_TILE;

class Trigger{
    vi2d pos;
    vi2d size;
    TriggerName::Trigger id;
    vi2d extraCoords;
    Map*mapChoice;
    public:
    Trigger(vi2d pos,vi2d size,TriggerName::Trigger id,vi2d extraCoords={0,0},Map*mapChoice=nullptr)
    :pos(pos),size(size),id(id),extraCoords(extraCoords),mapChoice(mapChoice){}
    bool IsInside(vd2d point) {
        return point.x>pos.x&&point.x<pos.x+size.x&&point.y>pos.y&&point.y<pos.y+size.y;
    }
    void Interact() {
        switch (id) {
            case TriggerName::START_CUTSCENE_1:{
                if (!GAME->GetGameFlag(Flag::TEST_FLAG1)) {
                    DisplayMessageBox("You have triggered this scene.");
                    GAME->SetGameFlag(Flag::TEST_FLAG1,true);
                }
            }break;
            case TriggerName::GOTO_MAP:{
                MapTransitionCutscene*scene=(MapTransitionCutscene*)CUTSCENES[CutsceneName::TRANSFER_MAP_CUTSCENE];
                std::vector<CutsceneAction*>actions=scene->GetActions();
                LoadMap*mapLoadAction=(LoadMap*)actions[1];
                mapLoadAction->SetTargetMap(mapChoice);
                MovePlayerObjects*playerMoveAction=(MovePlayerObjects*)actions[2];
                playerMoveAction->SetTargetPos(extraCoords);
                GAME->StartCutscene(scene);
            }break; 
        }
    }
    vi2d GetPos() {
        return pos;
    }
    vi2d GetSize() {
        return size;
    }
    int GetPosX() {
        return pos.x;
    }
    int GetPosY() {
        return pos.y;
    }
    int GetSizeX() {
        return size.x;
    }
    int GetSizeY() {
        return size.y;
    }
    int GetID() {
        return id;
    }
    Map*GetMapPtr(){
        return mapChoice;
    }
    vd2d GetAdditionalCoordData(){
        return extraCoords;
    }
    void SetExtraCoords(vd2d coords) {
        extraCoords=coords;
    }
    void SetMap(Map*map) {
        mapChoice=map;
    }
};
#endif