diff --git a/C++ProjectTemplate b/C++ProjectTemplate index cc90544..d0b7dfd 100755 Binary files a/C++ProjectTemplate and b/C++ProjectTemplate differ diff --git a/entity.h b/entity.h index 7e432b9..3536459 100644 --- a/entity.h +++ b/entity.h @@ -20,6 +20,7 @@ namespace boost{ class Entity{ + public: struct pstats_t{ public: int HP=0; @@ -35,7 +36,6 @@ class Entity{ bool smart=false; bool dumb=false; }; - public: struct stats_t{ private: int HP=0; diff --git a/main.cpp b/main.cpp index 10cf115..2273c86 100644 --- a/main.cpp +++ b/main.cpp @@ -387,9 +387,11 @@ void SeasonI::SetupItemList() { //hpRecovery,ppRecovery,attack,dmgReduction,equi ITEMLIST[ItemName::SOME_STUPIDLY_LONG_FEATHER]=new Item("Some Stupidly Long Feather","Yeah, we don't know why this feather is so long either.",256,{attack:2,defense:3,equip:EquipSlot::ACCESSORY}); } +Entity::pstats_t partyMemberDefaultStats{HP:120,maxHP:120,PP:30,maxPP:30,baseAtk:8,speed:8,resistances:{0,0,0,0}}; + void SeasonI::SetupPartyMemberStats() { for (int i=0;i<7;i++) { - PARTY_MEMBER_STATS[i]=new Entity({HP:120,maxHP:120,PP:30,maxPP:30,baseAtk:8,speed:8,resistances:{0,0,0,0}},{MOVELIST[BattleMoveName::TESTMOVE1]}); + PARTY_MEMBER_STATS[i]=new Entity(partyMemberDefaultStats,{MOVELIST[BattleMoveName::TESTMOVE1]}); } PARTY_MEMBER_STATS[PLAYER]->statusEffects[Property::MUSHROOMIZED]=4; PARTY_MEMBER_STATS[PLAYER]->moveSet={ @@ -993,7 +995,7 @@ Decal*SeasonI::CreateSprite(std::string spriteName) { Object*SeasonI::CreateObjectInfo(Object*obj,std::string spriteFileName,int sprWidth,Flag enableFlag,Flag disableFlag) { if (!ANIMATIONS.count(spriteFileName)) { - ANIMATIONS[spriteFileName] = new Animation(SPRITES[spriteFileName]=CreateSprite(spriteFileName),sprWidth); + ANIMATIONS[spriteFileName] = new Animation(CreateSprite(spriteFileName),sprWidth); } obj->spr=ANIMATIONS[spriteFileName]; obj->SetScale(obj->GetScale()); diff --git a/test/test.cpp b/test/test.cpp index c453b1d..b0dd6e3 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -23,7 +23,11 @@ #include "../SeasonI.h" extern std::array PARTY_MEMBER_STATS; -extern std::mapMOVELIST; +extern Entity::pstats_t partyMemberDefaultStats; +extern std::map SPRITES; +extern std::map ANIMATIONS; +extern std::array PARTY_MEMBER_OBJ; +extern std::map OBJ_INFO; int testCount=0; @@ -34,12 +38,56 @@ void Test(std::string name,bool success) { std::cout<<" Passed"< sprList) { + for (int i=0;i sprList) { + for (int i=0;isprite->width!=0&&SPRITES["terrainmap.png"]->sprite->height!=0); + } +} +bool SeasonI::OnUserCreate(){ + for (int i=0;istats==defaults); + for (int i=0;istats==partyMemberDefaultStats); + } + TestSpriteUndefined({"terrainmap.png","pixel.png","bufficons.png","rollingcounter.png","additionalFont.png"}); + SetupAnimations(); + TestSpriteInitialized({"terrainmap.png","pixel.png","bufficons.png","rollingcounter.png","additionalFont.png"}); + Test("Player animation is undefined", + ANIMATIONS.count("player.png")==0); + Test("Party Member Object is not setup", + PARTY_MEMBER_OBJ[0]==nullptr); + vd2d testPos={0,0},testScale={2,2}; + CreateObjectInfo(new Standard_Obj(PLAYER,"player",testPos,nullptr,testScale,MAGENTA,32),"player.png",32); + Test("Player animation is defined", + ANIMATIONS["player.png"]!=nullptr); + Decal*playerAnimPointer=ANIMATIONS["player.png"]->spr; + Test("Player animation is setup correctly", + ANIMATIONS["player.png"]->frames>0&&ANIMATIONS["player.png"]->spr!=nullptr); + Test("Object Info database now has 1 entry", + OBJ_INFO.size()==1); + Test("Object Info is correctly assigned", + OBJ_INFO[0]->name=="player"&&OBJ_INFO[0]->id==PLAYER&&OBJ_INFO[0]->GetPos()==testPos&&OBJ_INFO[0]->GetScale()==testScale&&OBJ_INFO[0]->color==MAGENTA&&OBJ_INFO[0]->spr->width==32); + delete OBJ_INFO[PLAYER]; + OBJ_INFO.erase(PLAYER); + Test("Object Info is cleared", + OBJ_INFO.size()==0); + SetupObjectInfo(); + Test("Using the same sprite definition does not cause memory leak", + playerAnimPointer==OBJ_INFO[0]->spr->spr); return true; }