about summary refs log tree commit diff stats
path: root/data/maps/daedalus/rooms/F Keyholder.txtpb
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2025-09-22 10:43:10 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2025-09-22 10:43:10 -0400
commitbc3f90b6bdfdb651570a7b3f0e80fea19db14974 (patch)
treed3f0c0d62f633aa6d5c0ace3533cd4976a670d84 /data/maps/daedalus/rooms/F Keyholder.txtpb
parentb53018acc54a7b8812a0b9830562879071d05fa6 (diff)
downloadlingo2-archipelago-bc3f90b6bdfdb651570a7b3f0e80fea19db14974.tar.gz
lingo2-archipelago-bc3f90b6bdfdb651570a7b3f0e80fea19db14974.tar.bz2
lingo2-archipelago-bc3f90b6bdfdb651570a7b3f0e80fea19db14974.zip
[Data] Fixed some stuff for worldport shuffle
Diffstat (limited to 'data/maps/daedalus/rooms/F Keyholder.txtpb')
0 files changed, 0 insertions, 0 deletions
> 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
#include "object.h"
#include <dirent.h>
#include <libxml/parser.h>
#include <memory>
#include "world.h"

static std::map<std::string, MapObject> allObjects;
static bool objsInit = false;

const std::map<std::string, MapObject>& MapObject::getAllObjects()
{
  if (!objsInit)
  {
    try
    {
      xmlDocPtr doc = xmlParseFile("res/entities.xml");
      if (doc == nullptr)
      {
        throw MapObjectLoadException("can't open file");
      }
  
      xmlNodePtr top = xmlDocGetRootElement(doc);
      if (top == nullptr)
      {
        throw MapObjectLoadException("missing root element");
      }
  
      if (xmlStrcmp(top->name, (const xmlChar*) "entities"))
      {
        throw MapObjectLoadException("root element is not entities");
      }

      for (xmlNodePtr node = top->xmlChildrenNode; node != NULL; node = node->next)
      {
        if (!xmlStrcmp(node->name, (const xmlChar*) "entity"))
        {
          xmlChar* idKey = xmlGetProp(node, (xmlChar*) "id");
          if (idKey == 0) throw MapObjectLoadException("entity missing id");
          std::string theID = (char*) idKey;
          xmlFree(idKey);
      
          allObjects.emplace(theID, theID);
          MapObject& mapObject = allObjects.at(theID);
      
          xmlChar* nameKey = xmlGetProp(node, (xmlChar*) "name");
          if (nameKey == 0) throw MapObjectLoadException("entity missing name");
          mapObject.name = (char*) nameKey;
          xmlFree(nameKey);
      
          xmlChar* spriteKey = xmlGetProp(node, (xmlChar*) "sprite");
          if (spriteKey == 0) throw MapObjectLoadException("entity missing sprite");
          mapObject.sprite = wxImage((char*) spriteKey);
          xmlFree(spriteKey);
      
          xmlChar* widthKey = xmlGetProp(node, (xmlChar*) "width");
          if (widthKey == 0) throw MapObjectLoadException("entity missing width");
          mapObject.width = atoi((char*) widthKey);
          xmlFree(widthKey);
      
          xmlChar* heightKey = xmlGetProp(node, (xmlChar*) "height");
          if (heightKey == 0) throw MapObjectLoadException("entity missing height");
          mapObject.height = atoi((char*) heightKey);
          xmlFree(heightKey);
      
          for (xmlNodePtr entityNode = node->xmlChildrenNode; entityNode != NULL; entityNode = entityNode->next)
          {
            if (!xmlStrcmp(entityNode->name, (const xmlChar*) "input"))
            {
              xmlChar* key = xmlGetProp(entityNode, (xmlChar*) "id");
              if (key == 0) throw MapObjectLoadException("input missing id");
              std::string inputID = (char*) key;
              xmlFree(key);
          
              Input& input = mapObject.inputs[inputID];
          
              key = xmlGetProp(entityNode, (xmlChar*) "name");
              if (key == 0) throw MapObjectLoadException("input missing name");
              input.name = (char*) key;
              xmlFree(key);
          
              key = xmlGetProp(entityNode, (xmlChar*) "type");
              if (key == 0) throw MapObjectLoadException("input missing type");
              std::string inputType = (char*) key;
              xmlFree(key);
          
              if (inputType == "choice")
              {
                input.type = Input::Type::Choice;
                
                for (xmlNodePtr choiceNode = entityNode->xmlChildrenNode; choiceNode != NULL; choiceNode = choiceNode->next)
                {
                  if (!xmlStrcmp(choiceNode->name, (xmlChar*) "value"))
                  {
                    key = xmlGetProp(choiceNode, (xmlChar*) "id");
                    if (key == 0) throw MapObjectLoadException("input value missing id");
                    int valueId = atoi((char*) key);
                    xmlFree(key);
                    
                    key = xmlNodeGetContent(choiceNode);
                    if (key == 0) throw MapObjectLoadException("input value missing content");
                    std::string choiceText = (char*) key;
                    xmlFree(key);
                    
                    input.choices[valueId] = choiceText;
                  }
                }
              } else if (inputType == "slider")
              {
                input.type = Input::Type::Slider;
            
                key = xmlGetProp(entityNode, (xmlChar*) "minvalue");
                if (key == 0) throw MapObjectLoadException("integer input missing minvalue");
                input.minvalue = atoi((char*) key);
                xmlFree(key);
            
                key = xmlGetProp(entityNode, (xmlChar*) "maxvalue");
                if (key == 0) throw MapObjectLoadException("integer input missing maxvalue");
                input.maxvalue = atoi((char*) key);
                xmlFree(key);
              }
            }
          }
        }
      }
    } catch (std::exception& ex)
    {
      wxMessageBox(ex.what(), "Error loading objects", wxOK | wxCENTRE | wxICON_ERROR);
      exit(3);
    }
    
    objsInit = true;
  }
  
  return allObjects;
}

MapObject::MapObject(std::string id) : id(id)
{
  
}

std::string MapObject::getID() const
{
  return id;
}

std::string MapObject::getName() const
{
  return name;
}

wxBitmap MapObject::getSprite() const
{
  return sprite;
}

int MapObject::getWidth() const
{
  return width;
}

int MapObject::getHeight() const
{
  return height;
}

const std::map<std::string, MapObject::Input>& MapObject::getInputs() const
{
  return inputs;
}

const MapObject::Input& MapObject::getInput(std::string id) const
{
  return inputs.at(id);
}

bool MapObject::operator==(const MapObject& other) const
{
  return id == other.id;
}

bool MapObject::operator!=(const MapObject& other) const
{
  return id != other.id;
}

MapObjectEntry::MapObjectEntry(const MapObject& object, int posx, int posy) : object(object)
{
  position = std::make_pair(posx, posy);
}

const MapObject& MapObjectEntry::getObject() const
{
  return object;
}

std::pair<int, int> MapObjectEntry::getPosition() const
{
  return position;
}

MapObjectEntry::Item& MapObjectEntry::getItem(std::string str)
{
  return items[str];
}

const std::map<std::string, MapObjectEntry::Item>& MapObjectEntry::getItems() const
{
  return items;
}

void MapObjectEntry::addItem(std::string id, Item& item)
{
  items[id] = item;
}

void MapObjectEntry::setPosition(int x, int y)
{
  position = std::make_pair(x, y);
}

bool MapObjectEntry::operator==(const MapObjectEntry& other) const
{
  return (object == other.object) && (position == other.position);
}

bool MapObjectEntry::operator!=(const MapObjectEntry& other) const
{
  return (object != other.object) && (position != other.position);
}

VariableChoiceValidator::VariableChoiceValidator(World& world, MapObjectEntry::Item& item) : world(world), item(item)
{
  
}

wxObject* VariableChoiceValidator::Clone() const
{
  return new VariableChoiceValidator(world, item);
}

bool VariableChoiceValidator::TransferFromWindow()
{
  wxChoice* choice = (wxChoice*) GetWindow();
  int sel = choice->GetSelection();
  int val = (intptr_t) choice->GetClientData(sel);
  item.intvalue = val;
  world.setDirty(true);
  
  return true;
}

bool VariableChoiceValidator::TransferToWindow()
{
  wxChoice* choice = (wxChoice*) GetWindow();
  for (size_t i=0; i<choice->GetCount(); i++)
  {
    if ((intptr_t) choice->GetClientData(i) == item.intvalue)
    {
      choice->SetSelection(i);
      return true;
    }
  }
  
  return false;
}

bool VariableChoiceValidator::Validate(wxWindow*)
{
  return true;
}

SliderItemValidator::SliderItemValidator(World& world, MapObjectEntry::Item& item) : world(world), item(item)
{
  
}

wxObject* SliderItemValidator::Clone() const
{
  return new SliderItemValidator(world, item);
}

bool SliderItemValidator::TransferFromWindow()
{
  wxSlider* slider = (wxSlider*) GetWindow();
  item.intvalue = slider->GetValue();
  world.setDirty(true);
  
  return true;
}

bool SliderItemValidator::TransferToWindow()
{
  wxSlider* slider = (wxSlider*) GetWindow();
  slider->SetValue(item.intvalue);
  
  return true;
}

bool SliderItemValidator::Validate(wxWindow*)
{
  return true;
}