TeamWizardry / LibrarianLib

A library for the TeamWizardry mods
GNU Lesser General Public License v3.0
26 stars 21 forks source link

Create Facade containers #147

Closed thecodewarrior closed 3 years ago

thecodewarrior commented 4 years ago

Facade currently doesn't have container GUIs, so this needs to be added and, as usual, given the LibLib polish. A lot of the LibLib 4 implementation can be brought over, though some aspects could use being rebuilt or improved.

One notable addition I would like to do is making GUI <-> Container interaction easier through "messaging". Messaging will allow directly invoking (only annotated!) methods on the server or client. Here's an example of what this might look like:

class MyContainerScreen: FacadeContainerScreen {
    init {
        main.add(PastryButton("Perform action") { 
            this.sendMessage("doAction", 10, "text", Blocks.DIRT)
        })
    }
}

class MyContainer: FacadeContainer {
    @GuiMessage
    fun doAction(number: Int, text: String, block: Block) {
        // this will be invoked on the client-side container and a
        // packet will be sent to invoke it on the server-side container 
    }
}

It may even be viable to create delegates that will automatically sync value changes in one or both directions, along with providing value changed callbacks so GUIs can respond to syncs. Both synced values and message parameters must be binary serializable so they can be sent via packets.

thecodewarrior commented 3 years ago

This has been implemented in 1.15-dev