CSC510-2015-Axitron / maze

Main repo for maze game
0 stars 2 forks source link

Make mazeMenu.js talk to the new DB server via client API #53

Closed macluo closed 9 years ago

macluo commented 9 years ago

Once the API client #48 is completed, mazeMenu.js should be modified to access user contents on DB server.

meneal commented 9 years ago

Sorry to not respond to this yet. I'm still kind of thinking about how to go about it. I'll post this tutorial tonight and if you can make it work I'm all for it.

On Wed, Mar 18, 2015 at 1:14 PM, Mark Luo notifications@github.com wrote:

I am not sure if this is part of API client, if not, feel free to assign it to me.

— Reply to this email directly or view it on GitHub https://github.com/CSC510-2015-Axitron/maze/issues/53.

meneal commented 9 years ago

The apiClient is in master now. If you want to give it a shot that would be great.

macluo commented 9 years ago

That is great! I won't have time to work on it until tomorrow. Since you have the inside knowledge of how this API works, if you would like to make it work for the maze please go ahead and do so. :D

meneal commented 9 years ago

IN all honesty I'm really completely confused right now. Something really weird is happening between my tests and the test of the maze menu. If I remove that file all of my tests pass, but with it they fail randomly. Any idea why that might happen?

On Fri, Mar 20, 2015 at 12:52 PM, Mark Luo notifications@github.com wrote:

That is great! I won't have time to work on it until tomorrow. Since you have the inside knowledge of how this API works, if you would like to make it work for the maze please go ahead and do so. :D

— Reply to this email directly or view it on GitHub https://github.com/CSC510-2015-Axitron/maze/issues/53#issuecomment-84067331 .

meneal commented 9 years ago

They all run fine alone too. I just checked that.

On Fri, Mar 20, 2015 at 12:53 PM, Matthew Neal meneal@gmail.com wrote:

IN all honesty I'm really completely confused right now. Something really weird is happening between my tests and the test of the maze menu. If I remove that file all of my tests pass, but with it they fail randomly. Any idea why that might happen?

On Fri, Mar 20, 2015 at 12:52 PM, Mark Luo notifications@github.com wrote:

That is great! I won't have time to work on it until tomorrow. Since you have the inside knowledge of how this API works, if you would like to make it work for the maze please go ahead and do so. :D

— Reply to this email directly or view it on GitHub https://github.com/CSC510-2015-Axitron/maze/issues/53#issuecomment-84067331 .

meneal commented 9 years ago

It appears to have something to do with leftover objects after the mainmenu test finishes. Does it depend on some sort of ordering of the tests?

On Fri, Mar 20, 2015 at 12:54 PM, Matthew Neal meneal@gmail.com wrote:

They all run fine alone too. I just checked that.

On Fri, Mar 20, 2015 at 12:53 PM, Matthew Neal meneal@gmail.com wrote:

IN all honesty I'm really completely confused right now. Something really weird is happening between my tests and the test of the maze menu. If I remove that file all of my tests pass, but with it they fail randomly. Any idea why that might happen?

On Fri, Mar 20, 2015 at 12:52 PM, Mark Luo notifications@github.com wrote:

That is great! I won't have time to work on it until tomorrow. Since you have the inside knowledge of how this API works, if you would like to make it work for the maze please go ahead and do so. :D

— Reply to this email directly or view it on GitHub https://github.com/CSC510-2015-Axitron/maze/issues/53#issuecomment-84067331 .

macluo commented 9 years ago

Before you posted the response I ran the test and they all passed. And then another npm test indicated apiClient.checkInfo() failed, which is different from what Travis-CI has reported. I think the failing is sporadic and must have something to do with internet delay or something.

macluo commented 9 years ago

I run npm test twice just now and they all pass.

meneal commented 9 years ago

I really think there's something else going on here. If I run all of these test without test-mazemenu they pass every time.

On Fri, Mar 20, 2015 at 1:00 PM, Mark Luo notifications@github.com wrote:

Before you posted the response I ran the test and they all passed. And then another npm test indicated apiClient.checkInfo() failed, which is different from what Travis-CI has reported. I think the failing is sporadic and must have something to do with internet delay or something.

— Reply to this email directly or view it on GitHub https://github.com/CSC510-2015-Axitron/maze/issues/53#issuecomment-84070571 .

meneal commented 9 years ago

That's weird. I'm getting the same random failures.

On Fri, Mar 20, 2015 at 1:02 PM, Mark Luo notifications@github.com wrote:

I run npm test twice just now and they all pass.

— Reply to this email directly or view it on GitHub https://github.com/CSC510-2015-Axitron/maze/issues/53#issuecomment-84071067 .

macluo commented 9 years ago

Maybe the timeout is not long enough? I know Heroku could be very slow at time.

meneal commented 9 years ago

The time out is actually very long. There is a file in the test folder now that sets a global timeout of 5 seconds.

On Fri, Mar 20, 2015 at 1:04 PM, Mark Luo notifications@github.com wrote:

Maybe the timeout is not enough? I know Heroku could be very slow at time.

— Reply to this email directly or view it on GitHub https://github.com/CSC510-2015-Axitron/maze/issues/53#issuecomment-84071691 .

macluo commented 9 years ago

I think the 2 second delay performed by test-mazeMenu may have something to do with it but I don't know why the delay could cause random failure on Apiclient test. The test is performed twice, so it actually needs about 4 seconds to finish the test. Could this be the reason?

meneal commented 9 years ago

It looks like in the mazeMenu test you are assuming that the test runs last right? Why is that?

On Fri, Mar 20, 2015 at 1:05 PM, Matthew Neal meneal@gmail.com wrote:

The time out is actually very long. There is a file in the test folder now that sets a global timeout of 5 seconds.

On Fri, Mar 20, 2015 at 1:04 PM, Mark Luo notifications@github.com wrote:

Maybe the timeout is not enough? I know Heroku could be very slow at time.

— Reply to this email directly or view it on GitHub https://github.com/CSC510-2015-Axitron/maze/issues/53#issuecomment-84071691 .

meneal commented 9 years ago

Not sure about that. It's actually five seconds for each individual test. The tough thing is that these tests files are run in a random order, so I can't do anything to actually separate them. One idea could be to have two runs, but it would be better to figure out what's happening.

On Fri, Mar 20, 2015 at 1:25 PM, Mark Luo notifications@github.com wrote:

I think the 2 second delay performed by test-mazeMenu may have something to do with it but I don't know why the delay could cause random failure on Apiclient test. The test is performed twice, so it actually needs about 4 seconds to finish the test. Could this be the reason?

— Reply to this email directly or view it on GitHub https://github.com/CSC510-2015-Axitron/maze/issues/53#issuecomment-84079010 .

macluo commented 9 years ago

Right now test-mazeMenu doesn't have to be the last one because all test can share the jQuery mock object now. I changed the filename from test-theMenu to test-mazeMenu so it gets executed before test-nodeAPI.js

meneal commented 9 years ago

Oh wait so it runs them alphabetically?

On Fri, Mar 20, 2015 at 1:30 PM, Mark Luo notifications@github.com wrote:

Right now test-mazeMenu doesn't have to be the last one because all test can share the jQuery mock object now. I changed the filename from test-theMenu to test-mazeMenu so it gets executed before test-nodeAPI.js

— Reply to this email directly or view it on GitHub https://github.com/CSC510-2015-Axitron/maze/issues/53#issuecomment-84080695 .

macluo commented 9 years ago

If you want to change the order, rename your test-nodeAPI.js and make it run before test-mazeMenu.

macluo commented 9 years ago

or change test-mazeMenu back to test-theMenu.

meneal commented 9 years ago

Fixed. There is something weird there though. I'm not sure what it is, but something about that test running before the apiclient test completely breaks it. Hopefully this fixes it in Travis too.

On Fri, Mar 20, 2015 at 1:30 PM, Mark Luo notifications@github.com wrote:

If you want to change the order, rename your test-nodeAPI.js and make it run before test-mazeMenu.

— Reply to this email directly or view it on GitHub https://github.com/CSC510-2015-Axitron/maze/issues/53#issuecomment-84081006 .

meneal commented 9 years ago

I'll try to fix the db dev branch too. I think that travis is trying to run the tests and there are files to be tested.

On Fri, Mar 20, 2015 at 1:33 PM, Mark Luo notifications@github.com wrote:

or change test-mazeMenu back to test-theMenu.

— Reply to this email directly or view it on GitHub https://github.com/CSC510-2015-Axitron/maze/issues/53#issuecomment-84082031 .

meneal commented 9 years ago

Both branches are fixed. Builds passing. Thanks for your patience on this Mark. It took me awhile to figure out some of that.

On Fri, Mar 20, 2015 at 1:37 PM, Matthew Neal meneal@gmail.com wrote:

I'll try to fix the db dev branch too. I think that travis is trying to run the tests and there are files to be tested.

On Fri, Mar 20, 2015 at 1:33 PM, Mark Luo notifications@github.com wrote:

or change test-mazeMenu back to test-theMenu.

— Reply to this email directly or view it on GitHub https://github.com/CSC510-2015-Axitron/maze/issues/53#issuecomment-84082031 .

meneal commented 9 years ago

This is started in a branch called apiuser. Basically what's going on in there right now is that if have browserified the apiClient.js file and it is being sent to a folder called dist. By the way the actual function of browserify in this context is as follows:

browserify apiClient.js --s apiClient > dist/apiClient.js

That generates the browser ready file is being loaded up in index.html. Mazemenu is currently set to only load maze 13. The reason for that is that it's a known maze with some data in it. I adjusted mazeModel to take the number of the maze as a parameter and then load that maze. It's working in the root folder version of index.html. It still obviously needs tons of work, but I need to switch gears since I have a bunch of gameAI related work to do over this weekend. Let me know if you have questions. I'm not sure that it really makes sense to do more until the db is loaded with the current levels.

duh102 commented 9 years ago

Do you think it'd be a better idea to just use normal AJAX calls? No need to mess around with this browserify stuff, you can use the far simpler $.ajax method that I outlined in #48, which works without any compilation steps. I can even rewrite the API for you with it (though that might take a while since I'll be funeral-ing and traveling again tomorrow until late at night).

meneal commented 9 years ago

I would normally say yes. But at this point I've put in a pretty considerable amount of time to get the client working using browserify. I would mention too that at this point you'd only need to do any compilation if changes were made to apiClient.js. So really now it's ready to go. The file that is in the apiuser branch is ready to use and can be put in index.html the same way as using Jquery or really anything else. If you really feel like it's a bad idea though to use it let me know.

On Fri, Mar 20, 2015 at 10:43 PM, Will Morrow notifications@github.com wrote:

Do you think it'd be a better idea to just use normal AJAX calls? No need to mess around with this browserify stuff, you can use the far simpler $.ajax method that I outlined in #48 https://github.com/CSC510-2015-Axitron/maze/issues/48, which works without any compilation steps. I can even rewrite the API for you with it (though that might take a while since I'll be funeral-ing and traveling again tomorrow until late at night).

— Reply to this email directly or view it on GitHub https://github.com/CSC510-2015-Axitron/maze/issues/53#issuecomment-84222461 .

meneal commented 9 years ago

I just checked it out a bit and it's loading mazes without a problem using the api now. But the only way I could get it to work was to send an integer for the maze number to the mazeModel load function. I messed around in mazeMenu a bit but I just kept breaking stuff. The nice thing about the way it's set up now is that you can just pull the array of mazes in a particular category and then just send the number of the maze to the load command of the mazeModel to load a maze. I just don't know how to change the code that is in the mazemenu to do that sequentially without breaking everything else in there.

On Fri, Mar 20, 2015 at 10:49 PM, Matthew Neal meneal@gmail.com wrote:

I would normally say yes. But at this point I've put in a pretty considerable amount of time to get the client working using browserify. I would mention too that at this point you'd only need to do any compilation if changes were made to apiClient.js. So really now it's ready to go. The file that is in the apiuser branch is ready to use and can be put in index.html the same way as using Jquery or really anything else. If you really feel like it's a bad idea though to use it let me know.

On Fri, Mar 20, 2015 at 10:43 PM, Will Morrow notifications@github.com wrote:

Do you think it'd be a better idea to just use normal AJAX calls? No need to mess around with this browserify stuff, you can use the far simpler $.ajax method that I outlined in #48 https://github.com/CSC510-2015-Axitron/maze/issues/48, which works without any compilation steps. I can even rewrite the API for you with it (though that might take a while since I'll be funeral-ing and traveling again tomorrow until late at night).

— Reply to this email directly or view it on GitHub https://github.com/CSC510-2015-Axitron/maze/issues/53#issuecomment-84222461 .

macluo commented 9 years ago

I saw what you did on MazeModel. :) I will give it a try tomorrow afternoon from my end. When I need help I will ask.

meneal commented 9 years ago

Awesome. I appreciate it!

On Sat, Mar 21, 2015 at 1:21 AM, Mark Luo notifications@github.com wrote:

I saw what you did on MazeModel. :) I will give it a try tomorrow afternoon from my end. When I need help I will ask.

— Reply to this email directly or view it on GitHub https://github.com/CSC510-2015-Axitron/maze/issues/53#issuecomment-84257730 .

duh102 commented 9 years ago

So how is this coming along? I'm assuming this is being developed on a branch other than master because I don't see any updates there. Is this close to being merged in?

macluo commented 9 years ago

The branch is f23ca2d366dd29d2fcfdd95dbbd2688851b11260 I had trouble using async & callback so I ended up creating a new remoteDB method inside the mazeMenu.js to access remote db. Right now the mazeMenu.js will load all the maps from the remote site.

macluo commented 9 years ago

There are 9 mazes on remote DB, the maze no. 27 is actually the maze no. 19. Is it possible to remove it?

macluo commented 9 years ago

Let me know if there is any issue. If it all works fine, I will merge it to the master. I guess login & user mazes should be the next task to be worked on.

duh102 commented 9 years ago

Yes, I can remove any maze you like. I should actually add a delete function so the tests can delete the mazes they make afterward... I'll put that in tomorrow, as well as a similar one for user accounts (this will cascade delete all user-submitted mazes).

macluo commented 9 years ago

No. 27 is the duplicated one but the maze is messed up. lol I made mazeMenu circle all the mazes so players will get stuck there.

{
    "mazeno": 27,
    "displayName": "Pit",
    "userForMaze": 1,
    "height": 3,
    "width": 2,
    "mazeJSON": "{\"width\":2,\"height\":3,\"start\":[0,1],\"end\":[1,2],\"board\":[[6,5,6],[12,1,8]]}",
    "category": 1
}
duh102 commented 9 years ago

You should just be able to use the /mazes/category/1 path to get all mazes in the "official" category 1 and iterate through those, and that should exclude all user-created mazes.

macluo commented 9 years ago

Thanks. That was quick.

macluo commented 9 years ago

Merged. 11119de8792e120ddb3e7ea720bcc714e7d1db92 But authentication & user contents need to be added. I will open an issue ticket for that so anyone likes to work on it can go ahead and assign yourself. I will close this issue for now. Open a new issue if you find bugs.

macluo commented 9 years ago

Just improved getNextMaze() to actually look up maze no. from the maze category 9ad4d70505f5e056e50211dd1acc4214bff58a5b