All keys tested

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent 7a9ca378ea
commit 62b26a740d
  1. BIN
      C++ProjectTemplate
  2. 5
      SeasonI.h
  3. 7
      cutscene.h
  4. 32
      main.cpp
  5. 5
      object.h
  6. 174
      test/test.cpp

Binary file not shown.

@ -132,7 +132,7 @@ class SeasonI:public PixelGameEngine{
bool Collision(vd2d pos);
void DrawInventory();
void ChoiceMade(int choice);
void StartCutscene(Cutscene*cutscene);
void StartCutscene(Cutscene*cutscene);
void DrawTriggers();
void SaveGameSaveData(int saveSlot);
void LoadGameSaveData(int saveSlot);
@ -146,9 +146,8 @@ class SeasonI:public PixelGameEngine{
char GetTileDegreeSafely(std::vector<std::vector<TILE*>>&data);
//When using for testing, make sure you RELEASE the key when you are done!
void PressTestKey(Key k);
//When using for testing, make sure you RELEASE the key when you are done!
void HoldTestKey(Key k);
void ReleaseTestKey(Key k);
void PressTestKeyAndRun(Key k);
void ResetTestKeys();
};
extern SeasonI*GAME;

@ -378,6 +378,13 @@ class Cutscene{
void LockAction() {
actionIsActive=true;
}
ActionType PeekNextAction(){
if (actionMarker+1<actions.size()) {
return actions[actionMarker+1]->GetActionType();
} else {
return ActionType::NONE;
}
}
void AdvanceAction(){
actionIsActive=false;
actionMarker++;

@ -178,6 +178,7 @@ std::string CUTSCENE_DISPLAY_TEXT="";
int CUTSCENE_DISPLAY_TEXT_DELAY_TIME=0;
int TILEMAP_EDITOR_OFFSET=0;
HWButton TESTKEYS[128]={{false,false,false}};
int OBJECT_DESTRUCTION_COUNT=0;
/*
[Choice1,Choice2,Choice3]
@ -2712,6 +2713,9 @@ void SeasonI::keyUpdates() {
}
reset:
ANYKEYPRESSED=ACTIONKEYPRESSED=false;
for (int i=0;i<128;i++) {
TESTKEYS[i].bPressed=TESTKEYS[i].bReleased=false;
}
if (KEY_LASTPRESSED!=NONE) {
lastRepeatedFrame=frameCount;
}
@ -4102,8 +4106,8 @@ bool SeasonI::RightPressed(){
TESTKEYS[D].bPressed||TESTKEYS[RIGHT].bPressed||TESTKEYS[NP6].bPressed;
}
bool SeasonI::BackPressed(){
return GetKey(BACK).bPressed||GetKey(ESCAPE).bPressed||GetKey(X).bPressed||GetKey(CTRL).bPressed||GetKey(DEL).bPressed||GetKey(END).bPressed||GetKey(NP_DECIMAL).bPressed||GetKey(NP_SUB).bPressed||GetKey(MINUS).bPressed||GetKey(PAUSE).bPressed||GetKey(TAB).bPressed||
TESTKEYS[BACK].bPressed||TESTKEYS[ESCAPE].bPressed||TESTKEYS[X].bPressed||TESTKEYS[CTRL].bPressed||TESTKEYS[DEL].bPressed||TESTKEYS[END].bPressed||TESTKEYS[NP_DECIMAL].bPressed||TESTKEYS[NP_SUB].bPressed||TESTKEYS[MINUS].bPressed||TESTKEYS[PAUSE].bPressed||TESTKEYS[TAB].bPressed;
return GetKey(BACK).bPressed||GetKey(ESCAPE).bPressed||GetKey(X).bPressed||GetKey(CTRL).bPressed||GetKey(DEL).bPressed||GetKey(END).bPressed||GetKey(NP_DECIMAL).bPressed||GetKey(NP_SUB).bPressed||GetKey(MINUS).bPressed||GetKey(PAUSE).bPressed||GetKey(TAB).bPressed||GetKey(CAPS_LOCK).bPressed||
TESTKEYS[BACK].bPressed||TESTKEYS[ESCAPE].bPressed||TESTKEYS[X].bPressed||TESTKEYS[CTRL].bPressed||TESTKEYS[DEL].bPressed||TESTKEYS[END].bPressed||TESTKEYS[NP_DECIMAL].bPressed||TESTKEYS[NP_SUB].bPressed||TESTKEYS[MINUS].bPressed||TESTKEYS[PAUSE].bPressed||TESTKEYS[TAB].bPressed||TESTKEYS[CAPS_LOCK].bPressed;
}
bool SeasonI::UpHeld(){
return GetKey(W).bHeld||GetKey(UP).bHeld||GetKey(NP8).bHeld||MOUSE_DOWN&&GetMouseY()<=HEIGHT-128+32&&GetMouseY()>=HEIGHT-128&&GetMouseX()<=HEIGHT-128||
@ -4111,7 +4115,7 @@ bool SeasonI::UpHeld(){
}
bool SeasonI::DownHeld(){
return GetKey(S).bHeld||GetKey(DOWN).bHeld||GetKey(NP5).bHeld||GetKey(NP2).bHeld||MOUSE_DOWN&&GetMouseY()<=HEIGHT&&GetMouseY()>=HEIGHT-32&&GetMouseX()<=HEIGHT-128||
TESTKEYS[S].bHeld||TESTKEYS[DOWN].bHeld||TESTKEYS[NP5].bHeld;
TESTKEYS[S].bHeld||TESTKEYS[DOWN].bHeld||TESTKEYS[NP5].bHeld||TESTKEYS[NP2].bHeld;
}
bool SeasonI::LeftHeld(){
return GetKey(A).bHeld||GetKey(LEFT).bHeld||GetKey(NP4).bHeld||MOUSE_DOWN&&GetMouseX()<=32&&GetMouseX()>=0&&GetMouseY()>=HEIGHT-128||
@ -4122,8 +4126,8 @@ bool SeasonI::RightHeld(){
TESTKEYS[D].bHeld||TESTKEYS[RIGHT].bHeld||TESTKEYS[NP6].bHeld;
}
bool SeasonI::BackHeld(){
return GetKey(BACK).bHeld||GetKey(ESCAPE).bHeld||GetKey(X).bHeld||GetKey(CTRL).bHeld||GetKey(DEL).bHeld||GetKey(END).bHeld||GetKey(NP_DECIMAL).bHeld||GetKey(NP_SUB).bHeld||GetKey(MINUS).bHeld||GetKey(PAUSE).bHeld||GetKey(TAB).bHeld||
TESTKEYS[BACK].bHeld||TESTKEYS[ESCAPE].bHeld||TESTKEYS[X].bHeld||TESTKEYS[CTRL].bHeld||TESTKEYS[DEL].bHeld||TESTKEYS[END].bHeld||TESTKEYS[NP_DECIMAL].bHeld||TESTKEYS[NP_SUB].bHeld||TESTKEYS[MINUS].bHeld||TESTKEYS[PAUSE].bHeld||TESTKEYS[TAB].bHeld;
return GetKey(BACK).bHeld||GetKey(ESCAPE).bHeld||GetKey(X).bHeld||GetKey(CTRL).bHeld||GetKey(DEL).bHeld||GetKey(END).bHeld||GetKey(NP_DECIMAL).bHeld||GetKey(NP_SUB).bHeld||GetKey(MINUS).bHeld||GetKey(PAUSE).bHeld||GetKey(TAB).bHeld||GetKey(CAPS_LOCK).bHeld||
TESTKEYS[BACK].bHeld||TESTKEYS[ESCAPE].bHeld||TESTKEYS[X].bHeld||TESTKEYS[CTRL].bHeld||TESTKEYS[DEL].bHeld||TESTKEYS[END].bHeld||TESTKEYS[NP_DECIMAL].bHeld||TESTKEYS[NP_SUB].bHeld||TESTKEYS[MINUS].bHeld||TESTKEYS[PAUSE].bHeld||TESTKEYS[TAB].bHeld||TESTKEYS[CAPS_LOCK].bHeld;
}
bool SeasonI::UpReleased(){
return GetKey(W).bReleased||GetKey(UP).bReleased||GetKey(NP8).bReleased||MOUSE_RELEASED&&GetMouseY()<=HEIGHT-128+32&&GetMouseY()>=HEIGHT-128&&GetMouseX()<=HEIGHT-128||
@ -4142,8 +4146,8 @@ bool SeasonI::RightReleased(){
TESTKEYS[D].bReleased||TESTKEYS[RIGHT].bReleased||TESTKEYS[NP6].bReleased;
}
bool SeasonI::BackReleased(){
return GetKey(BACK).bReleased||GetKey(ESCAPE).bReleased||GetKey(X).bReleased||GetKey(CTRL).bReleased||GetKey(DEL).bReleased||GetKey(END).bReleased||GetKey(NP_DECIMAL).bReleased||GetKey(NP_SUB).bReleased||GetKey(MINUS).bReleased||GetKey(PAUSE).bReleased||GetKey(TAB).bReleased||
TESTKEYS[BACK].bReleased||TESTKEYS[ESCAPE].bReleased||TESTKEYS[X].bReleased||TESTKEYS[CTRL].bReleased||TESTKEYS[DEL].bReleased||TESTKEYS[END].bReleased||TESTKEYS[NP_DECIMAL].bReleased||TESTKEYS[NP_SUB].bReleased||TESTKEYS[MINUS].bReleased||TESTKEYS[PAUSE].bReleased||TESTKEYS[TAB].bReleased;
return GetKey(BACK).bReleased||GetKey(ESCAPE).bReleased||GetKey(X).bReleased||GetKey(CTRL).bReleased||GetKey(DEL).bReleased||GetKey(END).bReleased||GetKey(NP_DECIMAL).bReleased||GetKey(NP_SUB).bReleased||GetKey(MINUS).bReleased||GetKey(PAUSE).bReleased||GetKey(TAB).bReleased||GetKey(CAPS_LOCK).bReleased||
TESTKEYS[BACK].bReleased||TESTKEYS[ESCAPE].bReleased||TESTKEYS[X].bReleased||TESTKEYS[CTRL].bReleased||TESTKEYS[DEL].bReleased||TESTKEYS[END].bReleased||TESTKEYS[NP_DECIMAL].bReleased||TESTKEYS[NP_SUB].bReleased||TESTKEYS[MINUS].bReleased||TESTKEYS[PAUSE].bReleased||TESTKEYS[TAB].bReleased||TESTKEYS[CAPS_LOCK].bReleased;
}
bool SeasonI::PlayerCanMove(){
@ -5277,6 +5281,9 @@ void SeasonI::GetAnyKeyPress(olc::Key keypress){
INTERACTING_WITH->DialogClosed();
INTERACTING_WITH=nullptr;
}
if (CurrentCutscene!=nullptr&&CurrentAction==ActionType::DIALOG) {
CurrentCutscene->AdvanceAction();
}
if (HEALING_OVERWORLD_MEMBERS) {
if (HEALING_OVERWORLD_MEMBER==0||HEALING_OVERWORLD_MEMBER==2) {
DisplayMessageBox("");
@ -5600,14 +5607,10 @@ char SeasonI::GetTileDegreeSafely(std::vector<std::vector<TILE*>>&data){
}
void SeasonI::PressTestKey(Key k) {
TESTKEYS[k].bPressed=true;
TESTKEYS[k].bPressed=TESTKEYS[k].bHeld=true;
TESTKEYS[k].bReleased=false;
}
void SeasonI::HoldTestKey(Key k) {
TESTKEYS[k].bHeld=true;
}
void SeasonI::ReleaseTestKey(Key k) {
TESTKEYS[k].bPressed=false;
TESTKEYS[k].bReleased=true;
@ -5620,6 +5623,11 @@ void SeasonI::ResetTestKeys() {
}
}
void SeasonI::PressTestKeyAndRun(Key k) {
PressTestKey(k);
updateGame();
}
#ifndef TEST_SUITE
int main()
{

@ -25,12 +25,17 @@ struct ObjectExtraData{
double moveSpd;
};
extern int OBJECT_DESTRUCTION_COUNT;
class Object{
private:
vd2d scale={1,1};
vd2d pos;
vd2d startPos; //Where the object was first located. The object will be put back here if we enter the editor.
public:
~Object(){
OBJECT_DESTRUCTION_COUNT++;
}
int id;
Animation*spr;
int animationSubIndex=0; //Which animation within the animation we are on.

@ -32,6 +32,7 @@ extern Cutscene*CurrentCutscene;
extern ActionType CurrentAction;
extern vd2d cameraPos;
extern bool messageBoxVisible;
extern std::string messageBoxText;
extern std::array<Entity*,7> PARTY_MEMBER_STATS;
extern Entity::pstats_t partyMemberDefaultStats;
extern std::map<std::string,Decal*> SPRITES;
@ -48,6 +49,111 @@ int testCount=0;
int MAX_ITERATIONS=1000;
int iterations=0;
enum KeyIdentifier{
UP,
RIGHT,
DOWN,
LEFT,
BACK,
};
struct TestKey{
Key k;
std::string keyName;
KeyIdentifier id;
bool operator==(TestKey&other){
return id==other.id;
}
};
namespace key{
TestKey UP{Key::UP,"UP",KeyIdentifier::UP};
TestKey DOWN{Key::DOWN,"DOWN",KeyIdentifier::DOWN};
TestKey LEFT{Key::LEFT,"LEFT",KeyIdentifier::LEFT};
TestKey RIGHT{Key::RIGHT,"RIGHT",KeyIdentifier::RIGHT};
TestKey BACK{Key::BACK,"BACKSPACE",KeyIdentifier::BACK};
TestKey ESCAPE{Key::ESCAPE,"ESCAPE",KeyIdentifier::BACK};
TestKey X{Key::X,"X",KeyIdentifier::BACK};
TestKey CTRL{Key::CTRL,"CTRL",KeyIdentifier::BACK};
TestKey DEL{Key::DEL,"DEL",KeyIdentifier::BACK};
TestKey END{Key::END,"END",KeyIdentifier::BACK};
TestKey NP_DECIMAL{Key::NP_DECIMAL,"Numpad Decimal",KeyIdentifier::BACK};
TestKey NP_SUB{Key::NP_SUB,"Numpad Subtract",KeyIdentifier::BACK};
TestKey MINUS{Key::MINUS,"MINUS",KeyIdentifier::BACK};
TestKey PAUSE{Key::PAUSE,"PAUSE",KeyIdentifier::BACK};
TestKey TAB{Key::TAB,"TAB",KeyIdentifier::BACK};
TestKey CAPS_LOCK{Key::CAPS_LOCK,"CAPS LOCK",KeyIdentifier::BACK};
TestKey W{Key::W,"W",KeyIdentifier::UP};
TestKey A{Key::A,"A",KeyIdentifier::LEFT};
TestKey S{Key::S,"S",KeyIdentifier::DOWN};
TestKey D{Key::D,"D",KeyIdentifier::RIGHT};
TestKey NP8{Key::NP8,"NP8",KeyIdentifier::UP};
TestKey NP4{Key::NP4,"NP4",KeyIdentifier::LEFT};
TestKey NP5{Key::NP5,"NP5",KeyIdentifier::DOWN};
TestKey NP6{Key::NP6,"NP6",KeyIdentifier::RIGHT};
TestKey NP2{Key::NP2,"NP2",KeyIdentifier::DOWN};
}
bool GetKeyPressed(SeasonI&instance,TestKey&k) {
if (k==key::UP) {
return instance.UpPressed();
}
if (k==key::DOWN) {
return instance.DownPressed();
}
if (k==key::RIGHT) {
return instance.RightPressed();
}
if (k==key::LEFT) {
return instance.LeftPressed();
}
if (k==key::BACK) {
return instance.BackPressed();
}
std::cerr<<"Something went terribly wrong! THIS SHOULD NOT BE HAPPENING!\n";
return false;
}
bool GetKeyHeld(SeasonI&instance,TestKey&k) {
if (k==key::UP) {
return instance.UpHeld();
}
if (k==key::DOWN) {
return instance.DownHeld();
}
if (k==key::RIGHT) {
return instance.RightHeld();
}
if (k==key::LEFT) {
return instance.LeftHeld();
}
if (k==key::BACK) {
return instance.BackHeld();
}
std::cerr<<"Something went terribly wrong! THIS SHOULD NOT BE HAPPENING!\n";
return false;
}
bool GetKeyReleased(SeasonI&instance,TestKey&k) {
if (k==key::UP) {
return instance.UpReleased();
}
if (k==key::DOWN) {
return instance.DownReleased();
}
if (k==key::RIGHT) {
return instance.RightReleased();
}
if (k==key::LEFT) {
return instance.LeftReleased();
}
if (k==key::BACK) {
return instance.BackReleased();
}
std::cerr<<"Something went terribly wrong! THIS SHOULD NOT BE HAPPENING!\n";
return false;
}
void Test(std::string name,bool success) {
testCount++;
std::cout<<"Test ("<<testCount<<") "<<name<<"..."<<std::endl;
@ -296,7 +402,7 @@ bool SeasonI::OnUserCreate(){
SetFlagWhenCutsceneEnds(Flag::TEST_FLAG3),
SetFlag(Flag::TEST_FLAG2,true),
PanCamera({128,128},BOTH,1),
MoveCutsceneObjectAsync(1,{80,64},5),
MoveCutsceneObjectAsync(1,{80,64},50),
PanCameraAsync({64,0},BOTH),
DialogBoxAsync(R"(Hello!
This is a test message that lets us trigger straight from a cutscene! Cool!)"),
@ -382,7 +488,7 @@ bool SeasonI::OnUserCreate(){
messageBoxVisible);
GetAnyKeyPress(H);
GetAnyKeyPress(H);
Test("Pressing any key that is a valid action key twice should close the message box",
Test("Pressing any key should close the message box",
!messageBoxVisible);
updateGame();
Test("Next cutscene action should be Modify Object 0",
@ -395,8 +501,68 @@ bool SeasonI::OnUserCreate(){
prevCutsceneObjPosition=CurrentCutscene->GetCutsceneObjects()[1]->GetPos();
updateGame();
Test("Cutscene Object 1 is moving towards position {320,64}",
CurrentCutscene->GetCutsceneObjects()[1]->GetPos().x<prevCutsceneObjPosition.x&&CurrentCutscene->GetCutsceneObjects()[1]->GetPos().y<prevCutsceneObjPosition.y);
CurrentCutscene->GetCutsceneObjects()[1]->GetPos().x>prevCutsceneObjPosition.x&&CurrentCutscene->GetCutsceneObjects()[1]->GetPos().y==prevCutsceneObjPosition.y);
TestWhile("Move Cutscene Object should finish",CurrentAction==ActionType::MOVE_CUTSCENE_OBJ) {
updateGame();
}
Test("Cutscene Object 1 should be at position {320,64}",
CurrentCutscene->GetCutsceneObjects()[1]->GetPos().x==320&&CurrentCutscene->GetCutsceneObjects()[1]->GetPos().y==64);
Test("Next cutscene action is Dialog Box",
CurrentAction==ActionType::DIALOG);
Test("Dialog box should be visible",
messageBoxVisible);
GetAnyKeyPress(S);
Test("Pressing a key should show the entire message",
messageBoxText=="Hello!");
GetAnyKeyPress(S);
Test("Pressing a key should close the message box",
!messageBoxVisible);
int prevDestructionCount=OBJECT_DESTRUCTION_COUNT;
updateGame();
Test("Next cutscene action should be loading a map",
CurrentAction==ActionType::LOAD_MAP);
Test("Current Map should now be TWOSON",
CURRENT_MAP==MAPS[MapName::TWOSON]);
Test("All temporary objects should now be destroyed",
OBJECT_DESTRUCTION_COUNT-3==prevDestructionCount);
updateGame();
Test("Next action should be moving player objects",
CurrentAction==ActionType::MOVE_PLAYER_OBJS);
Test("All player objects should now be at position {16,16}",
PARTY_MEMBER_OBJ[0]->GetPos().x==16&&PARTY_MEMBER_OBJ[0]->GetPos().y==16);
Test("Next cutscene action should be cleanup",
CurrentCutscene->CurrentAction()==ActionType::CLEANUP);
updateGame();
Test("All cutscene and action variables should be cleaned up",
CurrentCutscene==nullptr&&
CurrentAction==ActionType::NONE);
TestKey testkeys[] = {key::UP,key::DOWN,key::LEFT,key::RIGHT,key::W,key::A,key::S,key::D,key::NP8,key::NP4,key::NP5,key::NP6,key::NP2,key::BACK,key::ESCAPE,key::X,key::CTRL,key::DEL,key::END,key::NP_DECIMAL,key::NP_SUB,key::MINUS,key::PAUSE,key::TAB,key::CAPS_LOCK};
for (TestKey k : testkeys) {
PressTestKey(k.k);
Test(k.keyName+" key is pressed",
GetKeyPressed(*this,k));
updateGame();
Test(k.keyName+" key is no longer pressed",
!GetKeyPressed(*this,k));
Test(k.keyName+" key is held down",
GetKeyHeld(*this,k));
updateGame();
Test(k.keyName+" key is still held down",
GetKeyHeld(*this,k));
for (int i=0;i<50;i++) {
updateGame();
}
Test(k.keyName+" key is still held down after multiple updates",
GetKeyHeld(*this,k));
ReleaseTestKey(k.k);
Test(k.keyName+" key is no longer held down",
!GetKeyHeld(*this,k));
Test(k.keyName+" key is released",
GetKeyReleased(*this,k));
updateGame();
Test(k.keyName+" key is no longer released",
!GetKeyReleased(*this,k));
}
return true;
}

Loading…
Cancel
Save