-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Poulpinou/Release_v0.0.4
Release v0.0.4
- Loading branch information
Showing
8 changed files
with
122 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using System; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace DGTools.Database { | ||
/// <summary> | ||
/// Fills a <see cref="IFillable{Titem}"/> container with database results. Can be executed asynchronously | ||
/// </summary> | ||
public class FillRequest<Titem> : GetRequest<Titem>, IRequestAsyncable where Titem : IDatabasable, new() | ||
{ | ||
public IFillable<Titem> container { get; protected set; } | ||
|
||
public FillRequest(Func<JToken, bool> filter, IFillable<Titem> container) : base(filter) | ||
{ | ||
this.container = container; | ||
} | ||
|
||
public IEnumerator OnExecuteAsync() | ||
{ | ||
float startTime = Time.realtimeSinceStartup; | ||
int lastResultIndex = 0; | ||
IEnumerator<List<Titem>> execution = table.GetManyAsync(filter); | ||
|
||
while (execution.MoveNext()) | ||
{ | ||
int diff = execution.Current.Count - lastResultIndex; | ||
if (diff > 0) | ||
{ | ||
for (int i = lastResultIndex; i < lastResultIndex + diff; i++) | ||
{ | ||
container.AddItem(execution.Current[i]); | ||
} | ||
lastResultIndex += diff - 1; | ||
} | ||
|
||
if (Time.realtimeSinceStartup - startTime > Database.Settings.coroutinesMaxExecutionTime) | ||
{ | ||
yield return new WaitForEndOfFrame(); | ||
startTime = Time.realtimeSinceStartup; | ||
} | ||
} | ||
} | ||
|
||
protected override void OnExecute() | ||
{ | ||
container.AddItems(table.GetMany(filter).ToArray()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters