Empeld
Empeld plugin documentation.
pluginbase.Objects.Syncable.Watchers Namespace Reference

Classes

class  ArraySync
 Syncable class that can synchronize other syncables that it can contain More...
 
class  ListSync
 
class  MutableSync
 A special syncable type where the type (T) is not assumed eg. This can sync an interface, as long as the implementing type is also a syncable, and the type along with the values will be sync'd More...
 
class  SmoothSync
 Class to synchronize primitives that support addition and multiplication Smoothing (Interpolation) the result across time. Great for linear interpolation of positions, rotation and other such variable data. More...
 
class  Sync
 
class  SyncBase
 

Functions

int Find (Func< T, bool > predicate)
 Find the index of an element in the array given the predicate otherwise returns -1 More...
 
int FindNull ()
 Find the index of the first available null spot Returns -1 if none exists More...
 
bool AddToNullSlot (T item)
 Add an element to first available null slot. Returns true on success. More...
 
bool Remove (T item)
 Remove the first occurance of an element in the array. Returns true on success. More...
 
void Sort< TKey > (Func< T, TKey > expression)
 Sorts the array with a given expression More...
 
sealed override void Persist (IPersistObject obj)
 
sealed override void Load (IReadPersistObject obj)
 

Function Documentation

◆ AddToNullSlot()

bool pluginbase.Objects.Syncable.Watchers.AddToNullSlot ( item)

Add an element to first available null slot. Returns true on success.

Returns
true, if to null slot was added, false otherwise.
Parameters
itemItem.
188  {
189  int slot = FindNull();
190  if (slot >= 0)
191  {
192  Set(slot, item);
193  return true;
194  }
195  return false;
196  }
int FindNull()
Find the index of the first available null spot Returns -1 if none exists
Definition: ArraySync.cs:172

◆ Find()

int pluginbase.Objects.Syncable.Watchers.Find ( Func< T, bool >  predicate)

Find the index of an element in the array given the predicate otherwise returns -1

Parameters
predicatePredicate.

Attribute: i].Value != null && predicate(_items[i

.Value))

158  {
159  for (int i=0; i<_items.Length; ++i)
160  {
161  if (_items[i].Value != null && predicate(_items[i].Value))
162  return i;
163  }
164  return -1;
165  }

◆ FindNull()

int pluginbase.Objects.Syncable.Watchers.FindNull ( )

Find the index of the first available null spot Returns -1 if none exists

Returns
The null.

Attribute: i

.Value == null)

173  {
174  for (int i=0; i<_items.Length; ++i)
175  {
176  if (_items[i].Value == null)
177  return i;
178  }
179  return -1;
180  }

◆ Load()

sealed override void pluginbase.Objects.Syncable.Watchers.Load ( IReadPersistObject  obj)
protected

Attribute: id

= new ItemData{

212  {
213  _nextId = obj.Get<ushort>("__nextId");
214  foreach(var item in obj.EnumerateList("items"))
215  {
216  try
217  {
218  ushort id = item.Get<ushort>("__id");
219  string typeName = item.Get<string>("__type");
220 
221  var instance = (T)Activator.CreateInstance(TypeSerializer.Deserialize(typeName));
222  instance.Watcher = this;
223  instance.Load(item.GetObject("item"));
224 
225  _items[id] = new ItemData{
226  Val = instance,
227  FQTypeName = typeName
228  };
229  }
230  catch
231  {
232 #if DEBUG
233  throw;
234 #endif
235  }
236  }
IEnumerable< IReadPersistObject > EnumerateList(string name)

◆ Persist()

sealed override void pluginbase.Objects.Syncable.Watchers.Persist ( IPersistObject  obj)
protected
199  {
200  obj.Set("__nextId", _nextId);
201  foreach(var kv in _items)
202  {
203  var listItem = obj.CreateListItem("items");
204  listItem.Set("__id", kv.Key);
205  listItem.Set("__type", kv.Value.FQTypeName);
206  var sub = listItem.GetOrCreateObject("item");
207  kv.Value.Val.Persist(sub);
208  }
209  }
IPersistObject CreateListItem(string listName)
IPersistObject GetOrCreateObject(string name)

◆ Remove()

bool pluginbase.Objects.Syncable.Watchers.Remove ( item)

Remove the first occurance of an element in the array. Returns true on success.

Parameters
itemItem.

Attribute: i

.Value == item)

203  {
204  for (int i=0; i<_items.Length; ++i)
205  {
206  if (_items[i].Value == item)
207  {
208  Set(i, null);
209  return true;
210  }
211  }
212  return false;
213  }

◆ Sort< TKey >()

void pluginbase.Objects.Syncable.Watchers.Sort< TKey > ( Func< T, TKey >  expression)

Sorts the array with a given expression

Parameters
expressionExpression.
Template Parameters
TKeyThe 1st type parameter.

Attribute: i] = sorted[i

;

Attribute: i

= new ArrItem{

221  {
222  var sorted = _items
223  .Where( x => x.Value != null )
224  .OrderBy( x => expression(x.Value) )
225  .ToArray();
226 
227  for (int i=0; i<_items.Length; ++i)
228  {
229  if (i < sorted.Length)
230  {
231  _items[i] = sorted[i];
232  }
233  else
234  {
235  _items[i] = new ArrItem{
236  ArrModified = true
237  };
238  }
239  OnItemChange(i);
240  }