A simple to use API for integration between your Pyxel games with servers.
Project description
pyxel_server
A simple to use API for integration between your Pyxel games with servers.
Usage
Code
client.py
import pyxel_server
import pyxel
class App:
def __init__(self):
self.client = pyxel_server.client("127.0.0.1", "5000")
pyxel.init(self.client.width, self.client.height, fps=self.client.fps)
self.text = "Client text"
pyxel.run(self.update, self.draw)
def update(self):
if pyxel.btnr(pyxel.KEY_SPACE):
self.text = self.client.var("text")
def draw(self):
pyxel.cls(0)
pyxel.text(10, round(self.client.height / 2), self.text, 7)
App()
server.py
import pyxel_server
def update(self):
self.variables["text"] = str(self.frame_count)
variables = {
"text": "Server Text"
}
pyxel_server.server("127.0.0.1", "5000", 256, 144, 24, update, variables=variables)
What will happen
When you press space in the client, it will get the server's text variable and the text on the screen will change to the server's frame_count
.
What are they doing
client.py
- Imports necessary modules.
__init__()
- Initializes the client with the server
Host
andPort
by getting necessary information including the width and height of the client. - Initializes pyxel application with the client's recieved
self.client.width
andself.client.height
. - Sets local variable called
text
with some text. - Runs pyxel application.
- Initializes the client with the server
update()
- Checks if the space bar is pressed
- If pressed, it will set the local
text
variable to the server'stext
variable
draw()
- Clears screen
- Draws text from local
text
variable
server.py
- Imports necessary modules.
- Creates a dictionary with needed variables for the server.
- Initializes the server to run on
Host
andPort
, sets default pyxelAppWidth
,AppHeight
andAppFPS
,
serverupdate()
function to run localupdate()
,
and server variables with thevariables
dictionary.
update()
- Sets server variable
text
to the currentframe_count
.
- Sets server variable
Reference
Note: pyxel_server
's intended features are not fully implemented yet.
Server
server(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"}
Client
client(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
class.var(Variable, [Value])
Returns & optionaly changes a 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.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 theRoute
e.g.json={"Name": "Value"}
get(Route)
Gets data from a specified route
Route
: The path to post e.g.Route="/var"
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyxel_server-0.0.1.tar.gz
(4.5 kB
view hashes)
Built Distribution
Close
Hashes for pyxel_server-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1ddcfcba5dc53e399861b818808b85924928fa286378efa9002f3c9c648eec6 |
|
MD5 | ef6cbacf346394c01def04ef35222048 |
|
BLAKE2b-256 | 31cc295ea4831e5a62ab9133755f9423d972ebe4e4dcfbec7732c9bfaeb84a51 |