0

I'm working on a webapp (python/javascript) to modify a game's save file. The file has certain bytes representing player information, such as the gun, the equipment, etc. The idea is to show an interface representing the information in the file, allow the user to make changes, send the data back to the server, which modifies the file, and allows the user to download it.

My problem is that I don't know which functions should be handled in javascript, and which in Python. I need python for reading the file, but does that mean I should use it to handle the data? If I read the information into relevant variables to send back with JSON, is it redundant because I'm not doing anything with the information in Python other than sending it back?

I've currently been indecisive about two possible ways to go about it. One, and this is the way I currently have it set up, is to handle the file with Python; figure where certain things are, read them into dictionaries, turn it into json, send that to javascript, and then parse the json and update the gui. As I said before, this feels like the wrong way to do it.

The other thing I was considering was to just read the entire file and send that back to javascript to work with. This also seems really incorrect. Javascript (at least as it's implemented in browsers) isn't meant to handle files, and packing/unpacking functions would have to be custom - one of the things I'm seeing as a red flag about this method.

The files are only about 1-2kb, so that wouldn't be a reason not to send it back to the page. In fact, the json I'm sending back is larger than just the contents of the file would be. Still though, I don't much like the idea.

So what do I do? I'm also having trouble organizing the actual code. I know it's bad practice to stick a lot of code into a single function, but dividing into many other functions has made it hard to keep track of things. Is there a good language-agnostic book that will help me with this?

1 Answer 1

1

There is no 'one right way' to handle save files, or any other data. The right way to proceed is largely shaped by the particular pressures that apply in your situation.

For instance, you say that both the packed and the expanded version of the save information is small, so it doesn't cost much to send the data to the browser either way; therefore, access speed is not a consideration for where to locate your code. However, unpacking and parsing seems to be a pressure: you have preexisting libraries or methods to do it in Python, but not in Javascript. This is a clear indicator that you should do much of the processing on the server. Other pressures that might apply are security, responsiveness, etc.

You also say that using parsing, sending and then displaying the data this 'feels wrong' to you; this is harder to judge, but if there are real concerns that would make this solution harder to work with in the future - for you or others - then it can be a pressure that outweighs the other considerations. A prototype implementation of just one feature might help you to judge whether this is the case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.