openreplay/mobs/templates/tracker~tracker~src~common~messages.ts.erb

31 lines
1 KiB
Text

// Auto-generated, do not edit
import type { Writer, Message }from "./types.js";
export default Message
function bindNew<C extends { new(...args: A): T }, A extends any[], T>(
Class: C & { new(...args: A): T }
): C & ((...args: A) => T) {
function _Class(...args: A) {
return new Class(...args);
}
_Class.prototype = Class.prototype;
return <C & ((...args: A) => T)>_Class;
}
export const classes: Map<number, Function> = new Map();
<% $messages.select { |msg| msg.js }.each do |msg| %>
class _<%= msg.name %> implements Message {
readonly _id: number = <%= msg.id %>;
constructor(
<%= msg.attributes.map { |attr| "public #{attr.name.first_lower}: #{attr.type_js}" }.join ",\n " %>
) {}
encode(writer: Writer): boolean {
return writer.uint(<%= msg.id %>)<%= " &&" if msg.attributes.length() > 0 %>
<%= msg.attributes.map { |attr| "writer.#{attr.type}(this.#{attr.name.first_lower})" }.join " &&\n " %>;
}
}
export const <%= msg.name %> = bindNew(_<%= msg.name %>);
classes.set(<%= msg.id %>, <%= msg.name %>);
<% end %>