nyan icon indicating copy to clipboard operation
nyan copied to clipboard

Python API

Open TheJJ opened this issue 6 years ago • 2 comments

nyan needs a Python API in order to be used from Python code, like the openage-converter. Best to use Cython. It can be done with the traditional Cython approach by just wrapping the C++-code with pyx and pxd files.

Using openage's Python interface is probably overkill (no need to call back and forth easily, translate exceptions from Py to C++, ...).

TheJJ avatar Sep 08 '19 15:09 TheJJ

It will be interesting if you can make some metaclass like (also this syntax is if function in nyan are the same declaration then python etc)

Health:
  _hp = 0
  _shield = 10 // the shield don't regen
  function __get__():
    return _hp

  funciton __set__(value):
    _hp = value

  function __add__(value):
    _hp += value

  function __sub__(value):
    if _shield < 0:
      _hp -= value
    else:
      _shield -= value

Strider(Unit):
    hp = Health
    hp = 10
    hp += 10 // so now hp == 20
    hp -= 10 // hp still 20 because shield
    hp -= 5 // hp == 15 because shield is below 0
    animation = "./assets/strider.ani"

coco875 avatar Aug 07 '23 17:08 coco875

please open a separate issue for this feature request :) then we can discuss it independently of the python api.

TheJJ avatar Aug 08 '23 18:08 TheJJ