about summary refs log tree commit diff stats
path: root/data/maps/control_center/rooms/Shop Entrance.txtpb
blob: 154c55b3cf7938c60da03ff46d2d1b08a1b44adb (plain) (blame)
1
2
3
4
5
6
7
8
9
name: "Shop Entrance"
# The connection to The Shop isn't a worldport.
panels {
  name: "HOPS"
  path: "Panels/Hallway Left/entry_6"
  clue: "hops"
  answer: "shop"
  symbols: ANAGRAM
}
ff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#include "database.h"
#include <sqlite3.h>
#include <stdexcept>

database::database(std::string path)
{
  if (sqlite3_open_v2(
    path.c_str(),
    &ppdb_,
    SQLITE_OPEN_READONLY,
    NULL) != SQLITE_OK)
  {
    // We still have to free the resources allocated. In the event that
    // allocation failed, ppdb will be null and sqlite3_close_v2 will just
    // ignore it.
    std::string errmsg(sqlite3_errmsg(ppdb_));
    sqlite3_close_v2(ppdb_);

    throw std::logic_error(errmsg);
  }
}

database::database(database&& other) : database()
{
  swap(*this, other);
}

database& database::operator=(database&& other)
{
  swap(*this, other);

  return *this;
}

void swap(database& first, database& second)
{
  std::swap(first.ppdb_, second.ppdb_);
}

database::~database()
{
  sqlite3_close_v2(ppdb_);
}

achievement database::getRandomAchievement() const
{
  std::string queryString = "SELECT achievements.achievement_id, achievements.game_id, achievements.title, games.moon_image FROM achievements INNER JOIN games ON games.game_id = achievements.game_id ORDER BY RANDOM() LIMIT 1";

  sqlite3_stmt* ppstmt;
  if (sqlite3_prepare_v2(
    ppdb_,
    queryString.c_str(),
    queryString.length(),
    &ppstmt,
    NULL) != SQLITE_OK)
  {
    std::string errorMsg = sqlite3_errmsg(ppdb_);
    sqlite3_finalize(ppstmt);

    throw std::logic_error(errorMsg);
  }

  if (sqlite3_step(ppstmt) != SQLITE_ROW)
  {
    std::string errorMsg = sqlite3_errmsg(ppdb_);
    sqlite3_finalize(ppstmt);

    throw std::logic_error(errorMsg);
  }

  achievement result;

  result.achievementId = sqlite3_column_int(ppstmt, 0);
  result.gameId = sqlite3_column_int(ppstmt, 1);
  result.title = reinterpret_cast<const char*>(sqlite3_column_text(ppstmt, 2));
  result.moonImage = reinterpret_cast<const char*>(sqlite3_column_text(ppstmt, 3));

  sqlite3_finalize(ppstmt);

  return result;
}

std::string database::getRandomImageForGame(int gameId) const
{
  std::string queryString = "SELECT filename FROM images WHERE game_id = ? ORDER BY RANDOM() LIMIT 1";

  sqlite3_stmt* ppstmt;
  if (sqlite3_prepare_v2(
    ppdb_,
    queryString.c_str(),
    queryString.length(),
    &ppstmt,
    NULL) != SQLITE_OK)
  {
    std::string errorMsg = sqlite3_errmsg(ppdb_);
    sqlite3_finalize(ppstmt);

    throw std::logic_error(errorMsg);
  }

  if (sqlite3_bind_int(ppstmt, 1, gameId) != SQLITE_OK)
  {
    std::string errorMsg = sqlite3_errmsg(ppdb_);
    sqlite3_finalize(ppstmt);

    throw std::logic_error(errorMsg);
  }

  if (sqlite3_step(ppstmt) != SQLITE_ROW)
  {
    std::string errorMsg = sqlite3_errmsg(ppdb_);
    sqlite3_finalize(ppstmt);

    throw std::logic_error(errorMsg);
  }

  std::string result = reinterpret_cast<const char*>(sqlite3_column_text(ppstmt, 0));

  sqlite3_finalize(ppstmt);

  return result;
}