Example #1
0
Savegame::Savegame(const ReaderMapping& reader) :
  filename(),
  status(),
  needed_time(),
  saved_pingus()
{
  reader.read_string("filename", filename);
  reader.read_enum("status", status, string_to_status);
  reader.read_int("time", needed_time);
  reader.read_int("saved-pingus", saved_pingus);
}
Example #2
0
void
PingusWorldmap::parse_properties(const ReaderMapping& reader)
{
  reader.read_string("music",  impl->music);
  reader.read_string("author", impl->author);
  reader.read_string("name",   impl->name);
  reader.read_string("short-name", impl->short_name);
  reader.read_string("email",  impl->email);
  reader.read_int("width",     impl->width);
  reader.read_int("height",    impl->height);

  reader.read_string("default-node", impl->default_node);
  reader.read_string("final-node",   impl->final_node);
}
Example #3
0
IceBlock::IceBlock(const ReaderMapping& reader) :
  pos(),
  width(),
  thickness(1.0),
  is_finished(false),
  last_contact(0),
  block_sur("worldobjs/iceblock"),
  block_sur_cmap("worldobjs/iceblock_cmap")
{
  reader.read_vector("position", pos);
  if (!reader.read_int("repeat", width))
  {
    log_warn("old 'width' tag used");
    reader.read_int("width", width);
  }
}
Example #4
0
SpriteDescriptionPtr
SpriteDescription::from_file(const Pathname& path)
{
  ReaderObject reader_object = FileReader::parse(path);
  ReaderMapping reader = reader_object.get_mapping();

  SpriteDescriptionPtr desc(new SpriteDescription);

  reader.read_int("speed", desc->speed);
  reader.read_bool("loop", desc->loop);
  reader.read_vector2i("offset", desc->offset);

  reader.read_enum("origin", desc->origin, string2origin);

  if (!reader.read_path("image", desc->filename))
  {
    log_error("'image' missing for %1%", reader_object.get_name());
  }

  desc->filename = Pathname(desc->filename.get_raw_path(), Pathname::DATA_PATH); // FIXME: Hack
  reader.read_size("array", desc->array);
  reader.read_vector2i("position",   desc->frame_pos);
  reader.read_size("size",  desc->frame_size);

  return desc;
}
Example #5
0
ServerEvent::ServerEvent(const ReaderObject& reader_object) :
    type(PINGU_ACTION_EVENT),
    time_stamp(0),
    pingu_id(0),
    pos(),
    pingu_action(ActionName::WALKER)
{
    ReaderMapping reader = reader_object.get_mapping();
    if (reader_object.get_name() == "armageddon")
    {
        type = ARMAGEDDON_EVENT;
        reader.read_int("time", time_stamp);
    }
    else if (reader_object.get_name() == "end")
    {
        type = END_EVENT;
        reader.read_int("time", time_stamp);
    }
    else if (reader_object.get_name() == "finish")
    {
        type = FINISH_EVENT;
        reader.read_int("time", time_stamp);
    }
    else if (reader_object.get_name() == "pingu-action")
    {
        std::string raw_x;
        std::string raw_y;

        type = PINGU_ACTION_EVENT;
        reader.read_int ("time",   time_stamp);
        int pingu_id_tmp;
        reader.read_int ("id", pingu_id_tmp);
        pingu_id = static_cast<unsigned int>(pingu_id_tmp);

        if (reader.read_string("raw-x", raw_x))
            pos.x = Math::string2float(raw_x);

        if (reader.read_string("raw-y", raw_y))
            pos.y = Math::string2float(raw_y);

        reader.read_enum("action", pingu_action, &ActionName::from_string);
    }
    else
    {
        raise_exception(std::runtime_error, "ServerEvent: Parse error: Unknown event: " << reader_object.get_name());
    }
}
Example #6
0
ConveyorBelt::ConveyorBelt(const ReaderMapping& reader) :
  left_sur  (Sprite ("worldobjs/conveyorbelt_left")),
  right_sur (Sprite ("worldobjs/conveyorbelt_right")),
  middle_sur(Sprite ("worldobjs/conveyorbelt_middle")),
  pos(),
  width(),
  speed(),
  counter()
{
  reader.read_vector("position", pos);
  if (!reader.read_int   ("repeat",    width))
  {
    log_warn("old 'width' tag used");
    reader.read_int   ("width",    width);
  }
  reader.read_float ("speed",    speed);
}
StarfieldBackground::StarfieldBackground(const ReaderMapping& reader) :
  small_stars_count(100),
  middle_stars_count(50),
  large_stars_count(25),
  stars()
{
  reader.read_int("small-stars",  small_stars_count);
  reader.read_int("middle-stars", middle_stars_count);
  reader.read_int("large-stars",  large_stars_count);

  for (int i=0; i < small_stars_count; ++i)
    stars.push_back(new StarfieldBackgroundStars(StarfieldBackgroundStars::SMALL_STAR));

  for (int i=0; i < middle_stars_count; ++i)
    stars.push_back(new StarfieldBackgroundStars(StarfieldBackgroundStars::MIDDLE_STAR));

  for (int i=0; i < large_stars_count; ++i)
    stars.push_back(new StarfieldBackgroundStars(StarfieldBackgroundStars::LARGE_STAR));
}
Example #8
0
Exit::Exit(const ReaderMapping& reader) :
  desc(),
  pos(),
  owner_id(),
  sprite(),
  flag(),
  smallmap_symbol("core/misc/smallmap_exit")
{
  reader.read_vector("position", pos);
  reader.read_desc  ("surface",  desc);
  reader.read_int   ("owner-id", owner_id);

  // Set default owner ID to 0
  if (owner_id < 0 || owner_id > 3) owner_id = 0;

  flag = Sprite("core/misc/flag" + StringUtil::to_string(owner_id));

  sprite = Sprite(desc);
}
Example #9
0
void
PingusLevel::load(const std::string& resname,
                  const Pathname& pathname)
{
  impl->checksum = System::checksum(pathname);

  impl->resname = resname;
  ReaderObject reader_object = FileReader::parse(pathname);

  if (reader_object.get_name() != "pingus-level")
  {
    raise_exception(std::runtime_error, "Error: " << pathname.str() << ": not a 'pingus-level' file");
  }
  else
  {
    ReaderMapping reader = reader_object.get_mapping();

    int version;
    if (reader.read_int("version", version))
      log_info("Levelfile Version: %1%", version);
    else
      log_info("Unknown Levelfile Version: %1%", version);

    ReaderMapping head;
    if (!reader.read_mapping("head", head))
    {
      raise_exception(std::runtime_error, "Error: (head) section not found in '" << pathname.str() << "'");
    }
    else
    {
      log_info("Reading head");
      head.read_string("levelname",        impl->levelname);
      head.read_string("description",      impl->description);
      head.read_size  ("levelsize",        impl->size);
      head.read_string("music",            impl->music);
      head.read_int   ("time",             impl->time);
      head.read_int   ("number-of-pingus", impl->number_of_pingus);
      head.read_int   ("number-to-save",   impl->number_to_save);
      head.read_colorf("ambient-light",    impl->ambient_light);
      head.read_string("author",           impl->author);

      log_info("Size: %1%x%2%", impl->size.width, impl->size.height);

      ReaderMapping actions;
      if (head.read_mapping("actions", actions))
      {
        std::vector<std::string> lst = actions.get_keys();
        for(std::vector<std::string>::iterator i = lst.begin(); i != lst.end(); ++i)
        {
          int count = 0;
          log_info("Actions: %1%", i->c_str());
          if (actions.read_int(i->c_str(), count))
            impl->actions[*i] = count;
        }
      }
      else
      {
        raise_exception(std::runtime_error,
                        "Error: (pingus-level head actions) not found in '" << pathname.str() << "'");
      }
    }

    ReaderCollection collection;
    if (reader.read_collection("objects", collection))
    {
      std::vector<ReaderObject> object_lst = collection.get_objects();
      for(auto i = object_lst.begin(); i != object_lst.end(); ++i)
      {
        impl->objects.push_back(*i);
      }
    }
  }
}