Log In  
Follow
Offler
[ :: Read More :: ]

Picotronlike for backend

I’ve been spending some time trying to figure out a good design for how to let people build online services in the style of pico-8 or picotron.

If you are anything like me you want to see code before reading more:

MAX_MESSAGES = 5

function _serve(request, context, user)
    if not context then
        context = {
            messages = {}
        }
    end
    if request.query.post then
        local timestamp = os.date("%Y-%m-%d %H:%M:%S") 
        if not user then
            user = {
                name = request.query.user
            }
        end
        user.last_post = timestamp
        local newMessage = {
            user = user.name, 
            text = request.query.post,
            timestamp = timestamp
        }
        table.insert(context.messages, newMessage)
        if #context.messages > MAX_MESSAGES then
            table.remove(context.messages, 1)
        end
    end

    return {
        {body_object = {
            messages = context.messages
        }},
        context,
        user
    }
end

So accessing this server would be a fetch to http://whereitsat:3000/chat/?context=123&user=offe&post=Hey, assuming the project is called chat. Anything in the body_object of the first return value will be returned in JSON format. You can also just return a string in body.

Now there’s a first version of this server engine that I very much would like feedback on. The practical purpose is to simplify building things so picotron carts can have connectivity for collaboration tools and multiplayer games. People shouldn’t have to handle hosting, databases or cumbersome deployment. Also it's nice staying with Lua for the server as well.

The basic principle is that using this framework the developer writes a single Lua function that is called for every http request. The function is called _serve(), in line with pico-8 tradition. It’s possible to define more functions of course that can be called from _serve(). The handler is pure functional and does not have side effects. Instead the request information are given as input as well as two objects and the function returns the response and updated objects. The framework takes care of persisting the objects for future requests. Consistency is guaranteed even though the service can handle concurrent requests.

The developer does not have access to explicit database calls.

I don’t know if the interface is generic enough for actually building something very useful without fighting the design, but I hope that it will be simple and useful. It should support anyone who quickly wants to build a backend for turn based games, a game lobby, some kind of collaboration tool or a chat app. Since you code the request handler in Lua it’s easy to share code between the picotron app and the server which should be useful for some games.

The network interface is built to match picotron’s current fetch() behavior (GET with query parameters).

The interface

The two objects that are given as arguments and then returned modified are:

  • Context. This can be used as a game session, or a game lobby room or chat channel. Something where different clients share information with each other.
  • User. This represents the client. This allows the developer to manage authentication or storing information that needs to be transferred between different contexts.

To support these parameters there are two special query parameter:

  • context = the string id of the context
  • user = the string id of the user
    These are available to the service like normal query parameters, but they are also used to read from the database. So for each combination of projectId and contextId there can be an object in the database.

The server is probably very buggy at the moment. I’d really like if someone wanted to try it out and build something. I want to at least see if one person can make it work for them before letting more people hurt themselves, I'm expecting to fix a couple of sharp edges.

The developer experience and debugging functionality is very basic so far. I haven’t built a front end. So far the system only supports two things:

  • Accepting requests and running the Lua script
  • There’s an endpoint where people can upload new versions of the Lua script to a project if they have the project’s secret token:
curl -X POST "http://whereitsat:3000/api/projects/chat/uploadScript" \
     -H "Authorization: Bearer KH3XtSnWdCZB8iJnXnQmRjwcM0cv6OmtRteZ8z5w53Y1SAYK" \
     -H "Content-Type: application/octet-stream" \
     --data-binary "@chatserver.lua"

Other than that I’ll initially need to manage everything else manually.

If someone wants to try it out, please let me know what your service should be called (that’s the beginning of the path, "chat" in the examples above), and your email address (to [email protected]) so I can send you a project token allowing you to upload your script.

P#146648 2024-04-14 21:52 ( Edited 2024-04-14 21:53)

[ :: Read More :: ]

Cart #sploders-0 | 2024-03-21 | Embed ▽ | License: CC4-BY-NC-SA
4

My first Picotron project. It's a clone of a game called Chain Reaction I used to play on my C64 back in the day.

It's a two player game where you take turns in placing orbs on a tile grid. The object is to be the only player with orbs left on the board. Orbs can be placed on empty tiles and tiles where the player already has orbs. When there are one fewer orbs on one tile than there are neighbouring tiles the tile is said to be critical. Adding another orb to a critical tile will make the orbs splode. The orbs will be added to the neighbouring tiles. If they are occupied by the opponents orbs these change color.

Just try it, you'll understand despite my poor explanation.

TODO:

  • There's some code cleanup to do. I appreciate any tips and tricks from whoever wants to have a look.
  • Sound! I don't understand anything about the sound features of Picotron, so any help or pointers are appreciated.
  • AI. I found a heuristic on the web that I'll want to implement. Two player games are not the most useful without the ability to play an AI.
  • It would be fun to make it run in a window in Picotron, with the option of starting it full screen. We'll see.

Anyway, enjoy. I appreciate any feedback you all have.

P#144071 2024-03-21 19:59

[ :: Read More :: ]

This is perhaps a bit off topic, or maybe not.

I just deployed a rough, first version of an online pixelart drawing app: https://pixla.nu/?ps=DyIAIQESCSIBIIICIRILIoEgAg8iACENIgACNiIBAAACCyIAIAF3AHALIgAHAncAAgoihAcAcAcCCiKEBwBwBwIKIgAHAncAAgoihAdwAHcCCiKDIHAAcAsigyB4gHALIgAHAXcAcAUiBBEAEAJ3AHALEQIAAAF_EUUR

It's meant to be limited in features, a little bit like pico-8 actually. The canvas size is fixed to 32x32, and the palette is fixed to the (original) pico-8 palette. Left button draws, right button picks up the color under the mouse.

Perhaps the most special thing is that the pixels are saved in the URL, so the images can be saved by simply bookmarking the page. The links are also easily shared on social media, and the preview includes the image.

If it's not clear from the screenshot, I can't draw. So I hope some people with some pixel art skills will find the tool fun and useful. Please try it out, and let me know of any problems or feature requests you might have!

Oh, the name of the site is in swedish. "Pixla nu" means "Draw pixels, now!", where pixla is the verb form of pixel and nu means now.

P#78929 2020-07-05 11:23 ( Edited 2020-07-05 11:46)

[ :: Read More :: ]

I've been using PICO-8 to prototype a potential game for the Commodore 64. It's mostly testing out the graphics and exporting the tiles, map and sprites to asm source code. In the end having the wrong palette made things too confusing for me.

So I bring you PICO-64:

It is just PICO-8 with the palette changed into that of the VIC-II, the graphics chip of the Commodore 64.

On OS X the palette that PICO-8 is using is in the binary PICO-8.app/Contents/MacOS/pico8.dat file. Just search and replace to change. I used macvim and the Tools/Convert to HEX and Convert Back.

These colors:

1d2b53 7e2553 008751 ab5236 5f574f c2c3c7 fff1e8 ff004d ffa300 ffec27 00e436 29adff 83769c ff77a8 ffccaa

Needs to be changed into these (Pepto's VIC-II palette):

ffffff 68372b 70a4b2 6f3d86 588d43 352879 b8c76f 6f4f25 433900 9a6759 444444 6c6c6c 9ad284 6c5eb5 959595

To overcome the small screen I have been using PICO-8's mouse feature to scroll around a 320x200 pixel screen. Not optimal, but still usable.

If you try this out and start hacking binary files, don't blame me if something breaks!

P#43035 2017-08-03 18:28 ( Edited 2017-08-12 13:04)

[ :: Read More :: ]

Cart #42340 | 2017-07-11 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

Here's a game I started and abandoned quickly. It was supposed to be a furniture moving themed Sokoban/Traffic Jam style game. I kind of like the graphics, but it became too unclear to interact with.

Anyway. Instead of just keeping it to myself here it is. Perhaps something about it amuses someone.

P#42348 2017-07-10 20:40 ( Edited 2017-07-11 00:40)

[ :: Read More :: ]

So you have seven friends over and are in a hurry to make a 32x24 pixel artwork?

Before this cart it was not obvious how to handle the situation. Now it's easy. The eight of you can work together in Multi Paint!


This came to be because I'm working on a GalCon clone, and I wasn't happy with the controls. So I started making a cursor, but then I thought it would be cool with a "mouse pointer" for each player when playing multi player. When that was working I wanted to make something simple with it, so it became this rudimentary pixel art cart. The only fancy part is that you can use a foreground color with the first button, and then a background color with the second button, just like Deluxe Paint on the Amiga.

P#40473 2017-05-11 16:58 ( Edited 2017-05-11 20:58)

[ :: Read More :: ]

Cart #33060 | 2016-12-05 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
29

(Edit: I used the save @clip feature of pico-8 0.1.9b, but I noticed that I couldn't play it on the pocketchip. Now I saved a .p8.png old school style. Hope that works better. I also changed the cartridge label to a hopefully more selling one. )

This is my first pico-8 project, and also my first venture into LUA land. It is a game heavily inspired by Dice Wars by Taro Ito.

The characters are inspired by the main character in Kingdom of Nerea by Davit Mazia.

The game is not yet done, but perfectly playable. Please try it, and give me all the feedback you have. What's good, what's bad, what's missing, what's confusing?

Any feedback is greatly appreciated!

P#32932 2016-12-02 19:40 ( Edited 2016-12-03 00:40)

Follow Lexaloffle:          
Generated 2024-04-16 06:36:50 | 0.131s | Q:22