elthran / RPG-Game

0 stars 1 forks source link

Decouple JS client code from Python command code. #362

Open klondikemarlen opened 5 years ago

klondikemarlen commented 5 years ago

Current JS code calls Python code directly. This is obviously very fragile and insecure, but I couldn't figure out how else to do it at the time.

I would like to change it to:

  1. JS code is simplified and more specific.
  2. Intermendiary translation and validation code in Python.
  3. Python object code that actually manipulates game objects.

e.g.

Current code

In templates\store.html

<button onclick="sendToPy(event, itemPurchasedPopup, 'buy_item', {'id': {{ item.id }}});">Buy</button>

In commands\buy_item.py

-calls this code directly def buy_item(hero, data=None, *args, **kwargs):

New concept

  1. simplify JS/html and make it more specific. <button onclick="buyItem(itemPurchasedPopup, {'id': {{ item.id }}});">Buy</button> -should call python translation and/or verification module.

  2. which would convert this into Python: -tranlation step

  3. Call this code controller\store.py def buy(hero, item):