Пример #1
0
PingusLevel
PLFResMgr::load_plf_from_filename(const Pathname& pathname)
{
  // FIXME: Ugly resname guessing is ugly
  std::string res_name = System::basename(pathname.get_sys_path());

  // This should give us the tutorial/, wip/, etc. part of the res_name
  std::string dirname  = System::basename(System::dirname(pathname.get_sys_path()));

  return load_plf_raw(dirname + "/" + res_name.substr(0, res_name.length()-7),
                      pathname);
}
Пример #2
0
void
Options::save(const Pathname& filename) const
{
  std::ostringstream out;
  SExprFileWriter writer(out);

  writer.begin_section("pingus-config");

  if (framebuffer_type.is_set())
    writer.write_enum("renderer", framebuffer_type.get(), framebuffer_type_to_string);

  if (master_volume.is_set())
    writer.write_int("master-volume", master_volume.get());

  if (sound_volume.is_set())
    writer.write_int("sound-volume", sound_volume.get());

  if (music_volume.is_set())
    writer.write_int("music-volume", music_volume.get());

  if (geometry.is_set())
    writer.write_size("geometry", geometry.get());

  if (fullscreen_resolution.is_set())
    writer.write_size("fullscreen-resolution", fullscreen_resolution.get());

  if (fullscreen.is_set())
    writer.write_bool("fullscreen", fullscreen.get());

  if (resizable.is_set())
    writer.write_bool("resizable", resizable.get());

  if (mouse_grab.is_set())
    writer.write_bool("mouse-grab", mouse_grab.get());

  if (print_fps.is_set())
    writer.write_bool("print-fps", print_fps.get());

  if (controller.is_set())
    writer.write_string("controller", controller.get());

  if (language.is_set())
    writer.write_string("language", language.get());
  
  if (software_cursor.is_set())
    writer.write_bool("software-cursor", software_cursor.get());

  if (auto_scrolling.is_set())
    writer.write_bool("auto-scrolling", auto_scrolling.get());

  if (drag_drop_scrolling.is_set())
    writer.write_bool("drag-drop-scrolling", drag_drop_scrolling.get());
  
  writer.end_section(); // pingus-config

  out << std::endl;

  System::write_file(filename.get_sys_path(), out.str());
}
Пример #3
0
Surface::Surface(const Pathname& pathname)
{
  SDL_Surface* surface = IMG_Load(pathname.get_sys_path().c_str());
  if (surface)
    {
      impl = boost::shared_ptr<SurfaceImpl>(new SurfaceImpl(surface, true));
    }
}
Пример #4
0
// Save the current level
void
EditorScreen::save(const Pathname& file)
{
  std::string filename = file.get_sys_path();

  if (System::get_file_extension(filename) == "prefab")
  {
    level_pathname = file;
    log_info("Save to: %1%", file.str());
    plf->save_prefab(filename);
  }
  else
  {
    level_pathname = file;
    log_info("Save to: %1%", file.str());
    plf->save_level(filename);
  }
}
Пример #5
0
void
ResourceManager::add_resources_from_directory(const Pathname& path)
{
  assert(path.get_type() == Pathname::DATA_PATH);

  std::vector<std::string> files = System::opendir_recursive(path.get_sys_path());
  for(auto it = files.begin(); it != files.end(); ++it)
  {
    if (StringUtil::has_suffix(*it, ".sprite") ||
        StringUtil::has_suffix(*it, ".png") ||
        StringUtil::has_suffix(*it, ".jpg"))
    {
      // FIXME: ugly hack to remove "data/images/" prefix, need better
      // way to cut stuff away
      m_resources.push_back(System::cut_file_extension(it->substr(12)));
    }
  }

  std::sort(m_resources.begin(), m_resources.end());
}
Пример #6
0
std::vector<ReaderObject>
Reader::parse_many(const Pathname& pathname)
{
  return {};
#if 0
  std::shared_ptr<lisp::Lisp> sexpr = lisp::Parser::parse(pathname.get_sys_path());
  if (sexpr)
  {
    std::vector<Reader> sections;
    for(size_t i = 0; i < sexpr->get_list_size(); ++i)
    {
      sections.push_back(Reader(std::make_shared<SExprReaderImpl>(sexpr->get_list_elem(i))));
    }

    return sections;
  }
  else
  {
    return std::vector<Reader>();
  }
#endif
}
Пример #7
0
// Load a new level
void
EditorScreen::load(const Pathname& file)
{
  try
  {
    std::string filename = file.get_sys_path();

    if (System::get_file_extension(filename) == "prefab")
    {
      level_pathname = file;
      set_level(EditorLevel::from_prefab_file(level_pathname));
    }
    else
    {
      level_pathname = file;
      set_level(EditorLevel::from_level_file(level_pathname));
    }
  }
  catch(const std::exception& err)
  {
    // FIXME: show a MessageBox
    log_error("%1%", err.what());
  }
}
Пример #8
0
std::string
System::checksum(const Pathname& pathname)
{
  return checksum(pathname.get_sys_path());
}
Пример #9
0
Credits::Credits(const Pathname& filename) :
  scene_context(),
  fast_scrolling(false),
  background("core/menu/wood"),
  blackboard("core/menu/blackboard"),
  pingu("core/misc/creditpingu"),
  font(),
  font_small(),
  is_init(),
  end_offset(),
  offset(),
  credits()
{
  scene_context = util::make_unique<SceneContext>();
  fast_scrolling = false;
  gui_manager->add(util::make_unique<CreditsOkButton>(this));

  font       = Fonts::chalk_normal;
  font_small = Fonts::chalk_large;

  // The credits vector holds the strings to display. The first
  // character of each string is a special character, which indicates
  // the size of the font or other special stuff. "-" means large
  // font, "_" is a small font and "n" means a newline.

  { // read credit information from filename
    std::ifstream in(filename.get_sys_path());
    if (!in)
    {
      log_error("couldn't open %1%", filename);

      std::ostringstream out;
      out << "couldn't open " << filename;
      credits.push_back(out.str());
    }
    else
    {
      std::string line;
      while(std::getline(in, line))
      {
        credits.push_back(line);
      }
    }
  }

  end_offset = -static_cast<float>(Display::get_height())/2 - 50; // screen height + grace time
  for (std::vector<std::string>::iterator i = credits.begin(); i != credits.end(); ++i)
  {
    switch ((*i)[0])
    {
      case '-':
        end_offset += static_cast<float>(font.get_height() + 5);
        break;
      case '_':
        end_offset += static_cast<float>(font_small.get_height() + 5);
        break;
      case 'n':
        end_offset += 50;
        break;
      default:
        log_error("Credits: Syntax error: Unknown format: '%1%'", (*i)[0]);
        break;
    }
  }
  end_offset = -end_offset;
}
Пример #10
0
ReaderObject
Reader::parse(const Pathname& pathname)
{
  return parse(pathname.get_sys_path());
}