Giter Club home page Giter Club logo

godot-colyseus's Introduction

godot-colyseus

Colyseus SDK for GODOT.

Try the online mode of this demo: https://gsioteam.github.io/ActionGame/

Usage

var client = colyseus.Client.new("ws://localhost:2567")
var promise = client.join_or_create(RoomState, "state_handler")
yield(promise, "completed")
if promise.get_state() == promise.State.Failed:
    print("Failed")
    return
var room: colyseus.Room = promise.get_result()
var state: RoomState = room.get_state()
state.listen('players:add').on(funcref(self, "_on_players_add"))
room.on_state_change.on(funcref(self, "_on_state"))
room.on_message("hello").on(funcref(self, "_on_message"))

Documentation

Totaly the API is same as colyseus.js. There are only two points to note.

Schema

Define a schema class only needs to inherit colyseus.Schema and implement the define_fields method.

class RoomState extends colyseus.Schema:
  static func define_fields():
    return [
      colyseus.Field.new("players", colyseus.MAP, Player),
    ]

Get players by state.players. And the collection classes are defined in godot_colyseus/lib/collections.gd.

Event Listener

Use listen method to observe the change of attrbites. The structure of first argument path is like this path/to/attribue:action. The path part can be empty like :replace, that means listening this node.

Actions:

Action Description Arguments
add A attrbite or element of this schema object is created or added. _on_add(current: Schema, new_value: any, key: String\int)
remove A attrbite or element of this schema object is removed. _on_remove(current: Schema, old_value: any, key: String\int)
replace A attrbite or element of this schema object is replaced. _on_replace(current: Schema, new_value: any, key: String\int)
delete The schema object which at the path is deleted. _on_deleted(current: Schema)
create The schema object which at the path is created. _on_created(current: Schema)
change The schema object which at the path is changed. _on_changed(current: Schema)
clear The schema object which at the path is cleared. _on_clear(current: Schema)

godot-colyseus's People

Contributors

gsioteam avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.