コード例 #1
0
ファイル: Resources.cpp プロジェクト: bogy159/PUGame
/* 
======================================									
Load Resources
====================================== 
*/
bool Resources::LoadResources (char *pTilesetFile)
{
	if (!LoadEditorElements())							return false;
	if (!LoadTileset (pTilesetFile))					return false;

	return true;
}
コード例 #2
0
ファイル: pmd2_levels.cpp プロジェクト: PsyCommando/ppmdu
 void ExportATileset( const pmd2::level_info & lvlinf, const filetypes::LevelBgEntry & entry, const std::string & destdir )
 {
     Tileset tset( LoadTileset(m_mapbgdir, entry, lvlinf) );
     ExportTilesetToRaw(destdir, lvlinf.name, tset);
     //PrintAssembledTilesetPreviewToPNG(utils::TryAppendSlash(destdir) + "preview", tset );
     DumpCellsToPNG( destdir, tset );
 }
コード例 #3
0
ファイル: map_mode.cpp プロジェクト: Tresky/urban-spork
bool MapMode::LoadMap()
{
  std::string script_name = "data/maps/" + map_name + "-map.lua";

  if (!read_script)
    read_script = new rpg_script::ReadScript();

  if (read_script->IsOpen())
    read_script->CloseFile();

  if (!read_script->OpenFile(script_name))
  {
    PRINT_ERROR << "Failed to open tilemap script: " << script_name << endl;
    return false;
  }

  // cout << "---------- Tilemap Information ----------" << endl;
  // cout << "| File: " << _lua_filepath << endl;

  read_script->OpenTable("map_data");

  string script_path = read_script->ReadData<string>("script_path", "");

  int map_width = read_script->ReadData<int>("num_cols", -1);
  int map_height = read_script->ReadData<int>("num_rows", -1);
  if (map_width < 0 || map_height < 0)
  {
    PRINT_ERROR << "Invalid map dimensions in map script." << endl;
    return false;
  }

  // string name = read_script->ReadData<string>("name", "");
  // cout << "| Name: " << name << endl;
  // cout << "|" << endl;
  //
  // cout << "| Dimensions: " << map_width << " x " << map_height << endl;
  // cout << "|\n---------- Tileset Information ----------" << endl;

  if (!tile_supervisor)
    tile_supervisor = new private_map_mode::TileSupervisor();

  read_script->OpenTable("tilesets");
  int num_tilesets = read_script->ReadData<int>("count", -1);

  // cout << "| Tileset Count: " << num_tilesets << endl;

  if (num_tilesets < 0)
  {
    PRINT_ERROR << "No tilesets found in map script." << endl;
    return false;
  }

  for (int i = 0; i < num_tilesets; ++i)
  {
    string path = read_script->ReadData<string>(i, "");
    // cout << "| " << i << ". " << path << endl;
    if (path.empty() || !LoadTileset(path))
    {
      PRINT_ERROR << "Failed to load tileset" << endl;
      return false;
    }
  }
  read_script->CloseTable();

  // cout << "|\n----------- Layer Information -----------" << endl;

  // Load in the layer data
  read_script->OpenTable("layers");
  int num_layers = read_script->ReadData<int>("num_layers", -1);

  // cout << "| Layer Count: " << num_layers << endl;
  if (num_layers < 0)
  {
    PRINT_ERROR << "No layers found in map script." << endl;
    return false;
  }

  if (read_script->HasError())
  {
    read_script->PrintErrors();
    return false;
  }

  for (int l = 0; l < num_layers; ++l)
  {
    read_script->OpenTableIntegers(l);

    MapLayerType type;
    string str_type = read_script->ReadData<string>("type", "");

    if (str_type == "ground")
      type = MapLayerType::GROUND;
    else if (str_type == "wall")
      type = MapLayerType::WALL;
    else if (str_type == "sky")
      type = MapLayerType::SKY;
    else
    {
      PRINT_WARNING << "Unknown type for layer" << endl;
      continue;
    }

    // cout << "| " << l << ". " << str_type << endl;

    private_map_mode::MapLayer layer(type);
    for (int row = 0; row < map_height; ++row)
    {
      read_script->OpenTableIntegers(row + 1);
      // cout << "|\t";
      vector<int> temp;
      for (int col = 0; col < map_width; ++col)
      {
        int id = read_script->ReadData<int>(col + 1, -1);
        // cout << setw(3) << id << " ";
        temp.push_back(id);
      }
      // cout << endl;
      layer.tiles.push_back(temp);
      read_script->CloseTable();
    }

    tile_supervisor->layers.push_back(layer);

    read_script->CloseTable();
  }
  read_script->CloseTable();

  // cout << "|\n--------- Collision Information ---------" << endl;
  // Load object data
  if (!object_supervisor)
    object_supervisor = new private_map_mode::ObjectSupervisor();

  // cout << "| " << "Static Collision Matrix" << endl;

  read_script->OpenTable("collision");

  if (read_script->HasError())
  {
    read_script->PrintErrors();
    return false;
  }

  for (int i = 0; i < map_height; ++i)
  {
    read_script->OpenTableIntegers(i + 1);
    // cout << "|\t";
    vector<int> temp;
    for (int j = 0; j < map_width; ++j)
    {
      int value = read_script->ReadData<int>(j + 1, -1);
      // cout << setw(2) << value << " ";
      temp.push_back(value);
    }
    object_supervisor->collision_grid.push_back(temp);
    // cout << endl;
    read_script->CloseTable();
  }

  if (read_script->HasError())
  {
      read_script->PrintErrors();
      return false;
  }

  read_script->CloseTable();
  read_script->CloseFile();

  // cout << "-----------------------------------------" << endl;

  if (script_path.empty())
    return false;

  if (!read_script->OpenFile(script_path))
  {
    PRINT_ERROR << "Failed to open tilemap script: " << script_path << endl;
    return false;
  }

  IF_PRINT_DEBUG(MAP_MODE_DEBUG) << "Loading tilemap functionality script" << endl;

  read_script->CallFunction("Load");
  if (read_script->HasError())
  {
      read_script->PrintErrors();
      return false;
  }

  // read_script->CloseFile();

  return true;
}