Install
pip install pyxel-server
or
https://pypi.org/project/pyxel-server/
Reference
Note: pyxel_server’s intended features are not fully implemented yet.
server
System
run(Host, Port, AppWidth, AppHeight, AppFPS, UpdateScript, [WebScript], [InitScript], [Variables])
Initializes the server and runs it.
Host: The ip or domain of the server. e.g.Host="127.0.0.1"
Port: The port to be opened in theHost. e.g.Port="5000"
AppWidth: The width of the client’s window when connected. e.g.AppWidth=256
AppHeight: The height of the client’s window when connected. e.g.AppHeight=144
AppFPS: The FPS of the client’s window when connected. e.g.AppFPS=24
UpdateScript: The function to run every 1/AppFPS. e.g.UpdateScript=update
Note: The function must have the parameterself.
WebScript: The custom flask events and routes. e.g.WebScript=web
Note: The function must have the parameterself&app.
InitScript: The custom initialization function that will be called whenserver()is called. e.g.InitScript=init
Note: The function must have the parameterself.
Variables: A dictionary of variables needed. e.g.Variables={"Name": "Value"}Connection
sendObj(obj)
Converts obj to a json format and sends to all of the clients connected.
obj: Thepyxelobj.obje.g.obj=pyxelobj.obj()Data
variables
A class of all of the global variables.
Note: The class will not be created if no global variables are specified inself.run()
e.g.
variables.Name = "Value"Users
Users.__getuser__(user)
Returns the User’s class.
user: The name of the user e.g.user="Name"Users.__getallusers__()
Returns all of the Users in a dictionary in a format like this:{"Name": <Class>, "Name": <Class>, ...}User
User.variablesA class of all of the user’s variables.User.keyThe user’s key.User.input
A dictionary of all of the keys pressed in a format like this:{"Button Number": Bool, "Button Number": Bool, ...}
Note: In the client, you must usebtnp(button)forUser.inputto update.client
Connection
run(Host, Port)
Initializes the client with necessary information.
Host: The ip or domain of the server. e.g.Host="127.0.0.1"
Port: The port to be opened in theHost. e.g.Port="5000"
Note: You must run this command before anything that needs to use theclient.connect(Username)
Connects the client to the necessary information.
User: The username e.g.User="Name"
Note: You must run this command afterrunbefore using anything from theclient.request.post(Route, json)
Posts data to a specified route and returns json back.
Route: The path to post e.g.Route="/var"
json: The json to post to theRoutee.g.json={"Name": "Value"}Data
getGlobalvar(Variable, [Value])
Returns & optionaly changes a global variable from the server.
Variable: The variable name e.g.Variable="Name"
Value: The value of variable e.g.Value="Value"
Note: The variable will be changed before it returns.getLocalvar(Variable, [Value])
Returns & optionaly changes a local variable only accessible to the client from the server.
Variable: The variable name e.g.Variable="Name"
Value: The value of variable e.g.Value="Value"
Note: The variable will be changed before it returns.Input
btnp(button)
Checks for a button press (see pyxel documentation) then sends result to the server and returns result
button: The button to press e.g.button=pyxel.KEY_SPACEbtnr(button)
Checks for a button release (see pyxel documentation) then sends result to the server and returns result
button: The button to press e.g.button=pyxel.KEY_SPACEObjects
renderAll()
Renders all of the objects inclient.objectsaddObject(obj)
Adds an object toclient.objects
obj: Thepyxelobj.obje.g.obj=pyxelobj.obj()addObject(objname)
Removes an object fromclient.objectspredict(obj)
Predicts an object’s next location by addingobj.addXtoobj.xandobj.addYtoobj.y
obj: Thepyxelobj.obje.g.obj=pyxelobj.obj(json)
Removes an object fromclient.objects
objname: The name of the object to remove e.g.objname="Name"Used software
- python3
- pyxel
- flask
- requests