about summary refs log tree commit diff stats
path: root/src/global.cpp
blob: 1eb3f8d0da185eaa8897da0a3af2c0f2c2d76324 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "global.h"

#include <whereami.h>

#include <filesystem>
#include <string>
#include <string_view>

#include "ap_state.h"
#include "game_data.h"

const std::filesystem::path& GetExecutableDirectory() {
  static const std::filesystem::path* executable_directory = []() {
    int length = wai_getExecutablePath(NULL, 0, NULL);
    std::string buf(length, 0);
    wai_getExecutablePath(buf.data(), length, NULL);

    std::filesystem::path exec_path(buf);
    return new std::filesystem::path(exec_path.parent_path());
  }();

  return *executable_directory;
}

std::string GetAbsolutePath(std::string_view path) {
  return (GetExecutableDirectory() / path).string();
}

bool IsLocationWinCondition(const Location& location) {
  switch (AP_GetVictoryCondition()) {
    case kTHE_END:
      return location.ap_location_name ==
             "Orange Tower Seventh Floor - THE END";
    case kTHE_MASTER:
      return location.ap_location_name ==
             "Orange Tower Seventh Floor - THE MASTER";
    case kLEVEL_2:
      return location.ap_location_name == "Second Room - LEVEL 2";
    case kPILGRIMAGE:
      return location.ap_location_name == "Pilgrim Antechamber - PILGRIM";
  }
}