-
Notifications
You must be signed in to change notification settings - Fork 1
/
anitakeutils.pas
96 lines (86 loc) · 2.78 KB
/
anitakeutils.pas
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
unit AniTakeUtils;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, CastleLog, JsonTools, CastleDownload, CastleTimeUtils;
type
{ TAniTake }
TAniTake = record
TakeName: String;
TakeStart: Integer;
TakeStop: Integer;
end;
PAniTake = ^TAniTake;
TAniTakeArray = Array of TAniTake;
const
AniDefaultTakeFPS: Cardinal = 30;
function AniTakeFromJson(const Json: TJsonNode): TAniTakeArray;
implementation
function AniTakeFromJson(const Json: TJsonNode): TAniTakeArray;
var
Node: TJsonNode;
Element: TJsonNode;
Data: TJsonNode;
Take: TAniTake;
I: Integer;
T:Integer;
begin
T := 0;
Result := nil;
for Node in Json do
begin
if (Node.Kind = nkArray) and (Node.Name = 'Animations') then
begin
WriteLnLog('AnimationCount : ' + IntToStr(Node.Count));
SetLength(Result, Node.Count);
for I := 0 to Node.Count - 1 do
begin
Element := Node.Child(I);
Take := default(TAniTake);
Take.TakeStart := -1; // To trap missing values
for Data in Element do
begin
case Data.Name of
'FromFrame':
begin
if Data.Kind = nkNumber then
Take.TakeStart := Data.AsInteger
else
raise Exception.Create('FromFrame is not numeric');
end;
'ToFrame':
begin
if Data.Kind = nkNumber then
Take.TakeStop := Data.AsInteger
else
raise Exception.Create('ToFrame is not numeric');
end;
'Action':
begin
if Data.Kind = nkString then
begin
Take.TakeName := Data.AsString;
if (Take.TakeName = EmptyStr) then
raise Exception.Create('Action is blank');
end
else
raise Exception.Create('Action is not a string');
end;
end;
end;
if not(Take.TakeName = EmptyStr) and not(Take.TakeStart = -1) and not(Take.TakeStop = 0) then
begin
Result[T] := Take;
Inc(T);
end{$ifdef AllowBadLines};{$else}
else
raise Exception.Create('Partial record found for Take #' + IntToStr(I));
{$endif}
end;
end
else
WriteLnLog('Node : ' + Node.Name + ' =>' + Node.KindAsString);
end;
SetLength(Result, T);
end;
end.