Debian Codegraph @

tests/code/testcases/testcastleresources.pas

raw
1 // -*- compile-command: "./test_single_testcase.sh TTestCastleResources" -*-
2 {
3 Copyright 2020-2022 Michalis Kamburelis.
4
5 This file is part of "Castle Game Engine".
6
7 "Castle Game Engine" is free software; see the file COPYING.txt,
8 included in this distribution, for details about the copyright.
9
10 "Castle Game Engine" is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
14 ----------------------------------------------------------------------------
15 }
16
17 { Test CastleResources unit. }
18 unit TestCastleResources;
19
20 interface
21
22 uses
23 Classes, SysUtils,
24 CastleTester;
25
26 type
27 TTestCastleResources = class(TCastleTestCase)
28 published
29 procedure TestResourceFromCode;
30 end;
31
32 implementation
33
34 uses CastleResources, CastleCreatures, CastleLevels, CastleViewport, CastleVectors;
35
36 procedure TTestCastleResources.TestResourceFromCode;
37 var
38 Res: TStillCreatureResource;
39 MyCreature: TCreature;
40 Viewport: TCastleViewport;
41 Level: TLevel;
42 begin
43 // set all variables to nil, to allow easy "finally" clause
44 Res := nil;
45 Viewport := nil;
46 Level := nil;
47 MyCreature := nil;
48
49 try
50 Res := TStillCreatureResource.Create(nil);
51 Res.Name := 'KnightCreatedFromCodeTest';
52 Res.ModelURL := 'castle-data:/knight_resource/knight.gltf';
53 Res.Animations.FindName('idle').AnimationName := 'Idle';
54
55 AssertEquals(1.0, Res.ScaleMin);
56 AssertEquals(1.0, Res.ScaleMax);
57
58 // create creature from this resource
59
60 Resources.Clear;
61 Resources.Add(Res);
62
63 Viewport := TCastleViewport.Create(nil);
64
65 Levels.Clear;
66 Levels.LoadFromFiles('castle-data:/game/level_without_loading_image');
67
68 Level := TLevel.Create(nil);
69 Level.Viewport := Viewport;
70 Level.Load('level_without_loading_image');
71
72 Resources.Prepare(Viewport.PrepareParams, 'resources');
73
74 MyCreature := Res.CreateCreature(Level,
75 { Translation } Vector3(0, 0, 0),
76 { Direction } Vector3(0, 0, 1));
77 finally
78 FreeAndNil(MyCreature);
79 FreeAndNil(Level);
80 FreeAndNil(Viewport);
81
82 Resources.Clear;
83 // FreeAndNil(Res); // Resources owns it
84 end;
85 end;
86
87 initialization
88 RegisterTest(TTestCastleResources);
89 end.