/** * Get a text reference from the \a rcd_file, retrieve the corresponding text data, and put it in the \a txt destination. * @param rcd_file File to load from. * @param texts Texts already loaded from this file. * @param [out] txt Pointer to write the loaded text data reference to. * @return Loading was successful. */ bool LoadTextFromFile(RcdFileReader *rcd_file, const TextMap &texts, TextData **txt) { uint32 val = rcd_file->GetUInt32(); if (val == 0) { *txt = nullptr; return true; } const auto iter = texts.find(val); if (iter == texts.end()) return false; *txt = iter->second; return true; }
void PIC_IC::initPackage( MicroInfo * microInfo ) { // The code in this function is a stripped down version of that in PICComponent::initPackage if (!microInfo) return; MicroPackage * microPackage = microInfo->package(); if (!microPackage) return; //BEGIN Get pin IDs QStringList allPinIDs = microPackage->pinIDs(); QStringList ioPinIDs = microPackage->pinIDs( PicPin::type_bidir | PicPin::type_input | PicPin::type_open ); // Now, we make the unwanted pin ids blank, so a pin is not created for them const QStringList::iterator allPinIDsEnd = allPinIDs.end(); for ( QStringList::iterator it = allPinIDs.begin(); it != allPinIDsEnd; ++it ) { if ( !ioPinIDs.contains(*it) ) *it = ""; } //END Get pin IDs //BEGIN Remove old stuff // Remove old text TextMap textMapCopy = m_textMap; const TextMap::iterator textMapEnd = textMapCopy.end(); for ( TextMap::iterator it = textMapCopy.begin(); it != textMapEnd; ++it ) removeDisplayText(it.key()); // Remove old nodes NodeInfoMap nodeMapCopy = m_nodeMap; const NodeInfoMap::iterator nodeMapEnd = nodeMapCopy.end(); for ( NodeInfoMap::iterator it = nodeMapCopy.begin(); it != nodeMapEnd; ++it ) { if ( !ioPinIDs.contains(it.key()) ) removeNode( it.key() ); } //END Remove old stuff //BEGIN Create new stuff initDIPSymbol( allPinIDs, 80 ); initDIP(allPinIDs); //END Create new stuff addDisplayText( "picid", QRect(offsetX(), offsetY()-16, width(), 16), microInfo->id() ); }
/** * Load sprites from the disk. * @param filename Name of the RCD file to load. * @return Error message if load failed, else \c nullptr. * @todo Try to re-use already loaded blocks. * @todo Code will use last loaded surface as grass. */ const char *SpriteManager::Load(const char *filename) { RcdFileReader rcd_file(filename); if (!rcd_file.CheckFileHeader("RCDF", 2)) return "Bad header"; ImageMap sprites; // Sprites loaded from this file. TextMap texts; // Texts loaded from this file. TrackPiecesMap track_pieces; // Track pieces loaded from this file. /* Load blocks. */ for (uint blk_num = 1;; blk_num++) { if (!rcd_file.ReadBlockHeader()) return nullptr; // End reached. /* Skip meta blocks. */ if (strcmp(rcd_file.name, "INFO") == 0) { rcd_file.SkipBytes(rcd_file.size); continue; } if (strcmp(rcd_file.name, "8PXL") == 0 || strcmp(rcd_file.name, "32PX") == 0) { ImageData *imd = LoadImage(&rcd_file); if (imd == nullptr) { return "Image data loading failed"; } std::pair<uint, ImageData *> p(blk_num, imd); sprites.insert(p); continue; } if (strcmp(rcd_file.name, "SURF") == 0) { if (!this->LoadSURF(&rcd_file, sprites)) return "Surface block loading failed."; continue; } if (strcmp(rcd_file.name, "TSEL") == 0) { if (!this->LoadTSEL(&rcd_file, sprites)) return "Tile-selection block loading failed."; continue; } if (strcmp(rcd_file.name, "PATH") == 0) { if (!this->LoadPATH(&rcd_file, sprites)) return "Path-sprites block loading failed."; continue; } if (strcmp(rcd_file.name, "TCOR") == 0) { if (!this->LoadTCOR(&rcd_file, sprites)) return "Tile-corners block loading failed."; continue; } if (strcmp(rcd_file.name, "FUND") == 0) { if (!this->LoadFUND(&rcd_file, sprites)) return "Foundation block loading failed."; continue; } if (strcmp(rcd_file.name, "PLAT") == 0) { if (!this->LoadPLAT(&rcd_file, sprites)) return "Platform block loading failed."; continue; } if (strcmp(rcd_file.name, "SUPP") == 0) { if (!this->LoadSUPP(&rcd_file, sprites)) return "Support block loading failed."; continue; } if (strcmp(rcd_file.name, "BDIR") == 0) { if (!this->LoadBDIR(&rcd_file, sprites)) return "Build arrows block loading failed."; continue; } if (strcmp(rcd_file.name, "GCHK") == 0) { if (!_gui_sprites.LoadGCHK(&rcd_file, sprites)) return "Loading Checkable GUI sprites failed."; continue; } if (strcmp(rcd_file.name, "GBOR") == 0) { if (!_gui_sprites.LoadGBOR(&rcd_file, sprites)) return "Loading Border GUI sprites failed."; continue; } if (strcmp(rcd_file.name, "GSLI") == 0) { if (!_gui_sprites.LoadGSLI(&rcd_file, sprites)) return "Loading Slider bar GUI sprites failed."; continue; } if (strcmp(rcd_file.name, "GSCL") == 0) { if (!_gui_sprites.LoadGSCL(&rcd_file, sprites)) return "Loading Scrollbar GUI sprites failed."; continue; } if (strcmp(rcd_file.name, "GSLP") == 0) { if (!_gui_sprites.LoadGSLP(&rcd_file, sprites, texts)) return "Loading slope selection GUI sprites failed."; continue; } if (strcmp(rcd_file.name, "ANIM") == 0) { Animation *anim = new Animation; if (!anim->Load(&rcd_file)) { delete anim; return "Animation failed to load."; } if (anim->person_type == PERSON_INVALID || anim->anim_type == ANIM_INVALID) { delete anim; return "Unknown animation."; } this->AddBlock(anim); this->AddAnimation(anim); this->store.RemoveAnimations(anim->anim_type, (PersonType)anim->person_type); continue; } if (strcmp(rcd_file.name, "ANSP") == 0) { AnimationSprites *an_spr = new AnimationSprites; if (!an_spr->Load(&rcd_file, sprites)) { delete an_spr; return "Animation sprites failed to load."; } if (an_spr->person_type == PERSON_INVALID || an_spr->anim_type == ANIM_INVALID) { delete an_spr; return "Unknown animation."; } this->AddBlock(an_spr); this->store.AddAnimationSprites(an_spr); continue; } if (strcmp(rcd_file.name, "PRSG") == 0) { if (!LoadPRSG(&rcd_file)) return "Graphics Person type data failed to load."; continue; } if (strcmp(rcd_file.name, "TEXT") == 0) { TextData *txt = new TextData; if (!txt->Load(&rcd_file)) { delete txt; return "Text block failed to load."; } this->AddBlock(txt); std::pair<uint, TextData *> p(blk_num, txt); texts.insert(p); continue; } if (strcmp(rcd_file.name, "SHOP") == 0) { ShopType *shop_type = new ShopType; if (!shop_type->Load(&rcd_file, sprites, texts)) { delete shop_type; return "Shop type failed to load."; } _rides_manager.AddRideType(shop_type); continue; } if (strcmp(rcd_file.name, "TRCK") == 0) { auto tp = std::make_shared<TrackPiece>(); if (!tp->Load(&rcd_file, sprites)) { return "Track piece failed to load."; } track_pieces.insert({blk_num, tp}); continue; } if (strcmp(rcd_file.name, "RCST") == 0) { CoasterType *ct = new CoasterType; if (!ct->Load(&rcd_file, texts, track_pieces)) { delete ct; return "Coaster type failed to load."; } _rides_manager.AddRideType(ct); continue; } if (strcmp(rcd_file.name, "CSPL") == 0) { if (!LoadCoasterPlatform(&rcd_file, sprites)) return "Coaster platform failed to load."; continue; } if (strcmp(rcd_file.name, "CARS") == 0) { CarType *ct = GetNewCarType(); if (ct == nullptr) return "No room to store a car type."; if (!ct->Load(&rcd_file, sprites)) return "Car type failed to load."; continue; } /* Unknown block in the RCD file. Skip the block. */ fprintf(stderr, "Unknown RCD block '%s', version %i, ignoring it\n", rcd_file.name, rcd_file.version); rcd_file.SkipBytes(rcd_file.size); } }
void PICComponent::initPackage( MicroInfo * microInfo ) { MicroPackage * microPackage = microInfo ? microInfo->package() : 0l; if ( microPackage ) { m_bCreatedInitialPackage = true; //BEGIN Get pin IDs QStringList allPinIDs = microPackage->pinIDs(); QStringList ioPinIDs = microPackage->pinIDs( PicPin::type_bidir | PicPin::type_input | PicPin::type_open ); // Now, we make the unwanted pin ids blank, so a pin is not created for them const QStringList::iterator allPinIDsEnd = allPinIDs.end(); for ( QStringList::iterator it = allPinIDs.begin(); it != allPinIDsEnd; ++it ) { if ( !ioPinIDs.contains(*it) ) *it = ""; } //END Get pin IDs //BEGIN Remove old stuff // Remove old text TextMap textMapCopy = m_textMap; const TextMap::iterator textMapEnd = textMapCopy.end(); for ( TextMap::iterator it = textMapCopy.begin(); it != textMapEnd; ++it ) removeDisplayText(it.key()); // Remove the old pins deletePICComponentPins(); // Remove old nodes NodeInfoMap nodeMapCopy = m_nodeMap; const NodeInfoMap::iterator nodeMapEnd = nodeMapCopy.end(); for ( NodeInfoMap::iterator it = nodeMapCopy.begin(); it != nodeMapEnd; ++it ) { if ( !ioPinIDs.contains(it.key()) ) removeNode( it.key() ); } removeElements(); //END Remove old stuff //BEGIN Create new stuff initDIPSymbol( allPinIDs, 80 ); initDIP(allPinIDs); PicPinMap picPinMap = microPackage->pins( PicPin::type_bidir | PicPin::type_input | PicPin::type_open ); const PicPinMap::iterator picPinMapEnd = picPinMap.end(); for ( PicPinMap::iterator it = picPinMap.begin(); it != picPinMapEnd; ++it ) m_picComponentPinMap[it.key()] = new PICComponentPin( this, it.value() ); //END Create new stuff removeDisplayText( "no_file" ); addDisplayText( "picid", QRect(offsetX(), offsetY()-16, width(), 16), microInfo->id() ); } else { setSize( -48, -72, 96, 144 ); removeDisplayText( "picid" ); addDisplayText( "no_file", sizeRect(), i18n("(No\nprogram\nloaded)") ); } //BEGIN Update button positions int leftpos = (width()-88)/2+offsetX(); button("run")->setOriginalRect( QRect( leftpos, height()+4+offsetY(), 20, 20 ) ); button("pause")->setOriginalRect( QRect( leftpos+23, height()+4+offsetY(), 20, 20 ) ); button("reset")->setOriginalRect( QRect( leftpos+46, height()+4+offsetY(), 20, 20 ) ); button("reload")->setOriginalRect( QRect( leftpos+69, height()+4+offsetY(), 20, 20 ) ); updateAttachedPositioning(); //END Update button positions }