|
Last change
on this file was 402, checked in by alloc, 3 years ago |
- Major refactoring
- Using Utf8Json for (de)serialization
- Moving APIs to REST
- Removing dependencies from WebServer and MapRenderer to ServerFixes
|
|
File size:
971 bytes
|
| Line | |
|---|
| 1 | using System;
|
|---|
| 2 | using System.Collections.Generic;
|
|---|
| 3 |
|
|---|
| 4 | namespace Webserver.LiveData {
|
|---|
| 5 | public abstract class EntityFilterList<T> where T : Entity {
|
|---|
| 6 | public void Get (List<T> _list) {
|
|---|
| 7 | _list.Clear ();
|
|---|
| 8 | try {
|
|---|
| 9 | List<Entity> entities = GameManager.Instance.World.Entities.list;
|
|---|
| 10 | for (int i = 0; i < entities.Count; i++) {
|
|---|
| 11 | Entity entity = entities [i];
|
|---|
| 12 |
|
|---|
| 13 | T element = predicate (entity);
|
|---|
| 14 | if (element != null) {
|
|---|
| 15 | _list.Add (element);
|
|---|
| 16 | }
|
|---|
| 17 | }
|
|---|
| 18 | } catch (Exception e) {
|
|---|
| 19 | Log.Exception (e);
|
|---|
| 20 | }
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | public int GetCount () {
|
|---|
| 24 | int count = 0;
|
|---|
| 25 | try {
|
|---|
| 26 | List<Entity> entities = GameManager.Instance.World.Entities.list;
|
|---|
| 27 | for (int i = 0; i < entities.Count; i++) {
|
|---|
| 28 | Entity entity = entities [i];
|
|---|
| 29 |
|
|---|
| 30 | if (predicate (entity) != null) {
|
|---|
| 31 | count++;
|
|---|
| 32 | }
|
|---|
| 33 | }
|
|---|
| 34 | } catch (Exception e) {
|
|---|
| 35 | Log.Exception (e);
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | return count;
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | protected abstract T predicate (Entity _e);
|
|---|
| 42 | }
|
|---|
| 43 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.