A 2D tile-based sandbox game.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Mod.cc 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "Mod.h"
  2. #include <stdio.h>
  3. namespace Swan {
  4. void Mod::init(const std::string &name) {
  5. name_ = name;
  6. inited_ = true;
  7. fprintf(stderr, "Mod initing: %s\n", name_.c_str());
  8. }
  9. void Mod::registerTile(const std::string &name, Tile *tile) {
  10. tile->name_ = name_ + "::" + name;
  11. fprintf(stderr, "Adding tile: %s\n", tile->name_.c_str());
  12. std::string asset_path = path_ + "/" + tile->path_;
  13. if (!tile->image_.loadFromFile(asset_path)) {
  14. fprintf(stderr, "Tile %s: Failed to load image %s\n", tile->name_.c_str(), asset_path.c_str());
  15. tile->image_ = Tile::INVALID_IMAGE;
  16. }
  17. tiles_.push_back(std::shared_ptr<Tile>(tile));
  18. }
  19. void Mod::registerWorldGen(const std::string &name, WorldGen::Factory *gen) {
  20. gen->name_ = name_ + "::" + name;
  21. worldgens_.push_back(std::shared_ptr<WorldGen::Factory>(gen));
  22. }
  23. void Mod::registerEntity(const std::string &name, Entity::Factory *ent) {
  24. ent->name_ = name_ + "::" + name;
  25. entities_.push_back(std::shared_ptr<Entity::Factory>(ent));
  26. }
  27. void Mod::registerAsset(const std::string &name, Asset *asset) {
  28. asset->name_ = name_ + "::" + name;
  29. if (!asset->load(path_)) {
  30. fprintf(stderr, "Asset %s: Failed to load image '%s'", name.c_str(), (path_ + "/" + asset->path_).c_str());
  31. abort();
  32. }
  33. assets_.push_back(std::shared_ptr<Asset>(asset));
  34. }
  35. }