| 1 |
{%MainUnit x3dloadinternalspine.pas} |
| 2 |
{ |
| 3 |
Copyright 2019-2023 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 |
{ Extract extra information from Spine URL. |
| 18 |
See https://castle-engine.io/spine . |
| 19 |
For example for URL 'my_animation.json#skin:my_skin_name,atlas:my_atlas_name', |
| 20 |
it returns 'my_skin_name' as SkinName, |
| 21 |
and returns 'my_atlas_name' as CustomAtlasName. } |
| 22 |
procedure URIExtractInfo(const BaseUrl: String; out SkinName, CustomAtlasName: String); |
| 23 |
|
| 24 |
procedure ProcessAnchorPart(const Part: String); |
| 25 |
var |
| 26 |
Semicolon: Integer; |
| 27 |
PartName, PartValue: String; |
| 28 |
begin |
| 29 |
Semicolon := Pos(':', Part); |
| 30 |
|
| 31 |
if Semicolon = 0 then |
| 32 |
begin |
| 33 |
WritelnWarning('Spine URL anchor is not empty, and it does not contain a semicolon: "%s". To specify Spine skin, use the new syntax "xxx.json#skin:my_skin_name" instead of "xxx.json#my_skin_name", IOW add the "skin:" specifier.', [ |
| 34 |
UriDisplay(BaseUrl) |
| 35 |
]); |
| 36 |
if SkinName <> '' then |
| 37 |
WritelnWarning('Multiple skin names given in Spine URL "%s"', [UriDisplay(BaseUrl)]); |
| 38 |
SkinName := Part; |
| 39 |
end else |
| 40 |
begin |
| 41 |
PartName := Copy(Part, 1, Semicolon - 1); |
| 42 |
PartValue := SEnding(Part, Semicolon + 1); |
| 43 |
|
| 44 |
if PartName = 'skin' then |
| 45 |
begin |
| 46 |
if SkinName <> '' then |
| 47 |
WritelnWarning('Multiple skin names given in Spine URL "%s"', [UriDisplay(BaseUrl)]); |
| 48 |
SkinName := PartValue; |
| 49 |
end else |
| 50 |
|
| 51 |
if PartName = 'atlas' then |
| 52 |
begin |
| 53 |
if CustomAtlasName <> '' then |
| 54 |
WritelnWarning('Multiple atlas names given in Spine URL "%s"', [UriDisplay(BaseUrl)]); |
| 55 |
CustomAtlasName := PartValue; |
| 56 |
end else |
| 57 |
|
| 58 |
WritelnWarning('Not recognized part name "%s" in Spine URL "%s"', [PartName, UriDisplay(BaseUrl)]); |
| 59 |
end; |
| 60 |
end; |
| 61 |
|
| 62 |
var |
| 63 |
Anchor, AnchorPart: String; |
| 64 |
SeekPos: Integer; |
| 65 |
begin |
| 66 |
URIGetAnchor(BaseUrl, Anchor); |
| 67 |
|
| 68 |
SkinName := ''; |
| 69 |
CustomAtlasName := ''; |
| 70 |
|
| 71 |
SeekPos := 1; |
| 72 |
repeat |
| 73 |
AnchorPart := NextToken(Anchor, SeekPos, [',']); |
| 74 |
if AnchorPart = '' then Break; |
| 75 |
ProcessAnchorPart(AnchorPart); |
| 76 |
until false; |
| 77 |
end; |