aboutsummaryrefslogtreecommitdiff
path: root/src/ecs/predicted.moon
blob: b8bdd287c7398621bedcce564e77bd74f41919ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Component = require("ecs.component")

class PredictedComponent extends Component
	new: (name, properties, netc_name, calculate) =>
		super(name, properties)
		@netc_name = netc_name
		assert(calculate and type(calculate) == "table", "Calculate must be a table, was " .. type(calculate))
		@calculate = calculate
	join: (entity) =>
		@net = @entity\get(@netc_name)
		@node = am.group!
		@node\action(() ->
			@forward!
		)
		@@node\append(@node)
		super(entity)
	leave: (entity) =>
		@@node\remove(@node)
	forward: () =>
		for property, calculation in pairs(@calculate)
			@properties[property] = calculation(@)
	


PredictedComponent