| 1342 | #endif |
| 1343 | |
| 1344 | Asset::LoadResult VisualScript::load() |
| 1345 | { |
| 1346 | PROFILE_MEM(ScriptingVisual); |
| 1347 | |
| 1348 | // Build Visual Script typename that is based on asset id |
| 1349 | String typeName = _id.ToString(); |
| 1350 | StringUtils::ConvertUTF162ANSI(typeName.Get(), _typenameChars, 32); |
| 1351 | _typenameChars[32] = 0; |
| 1352 | _typename = StringAnsiView(_typenameChars, 32); |
| 1353 | |
| 1354 | // Load metadata |
| 1355 | const auto metadataChunk = GetChunk(1); |
| 1356 | if (metadataChunk == nullptr) |
| 1357 | return LoadResult::MissingDataChunk; |
| 1358 | MemoryReadStream metadataStream(metadataChunk->Get(), metadataChunk->Size()); |
| 1359 | int32 version; |
| 1360 | metadataStream.Read(version); |
| 1361 | switch (version) |
| 1362 | { |
| 1363 | case 1: |
| 1364 | { |
| 1365 | metadataStream.Read(Meta.BaseTypename, 31); |
| 1366 | metadataStream.Read((int32&)Meta.Flags); |
| 1367 | break; |
| 1368 | } |
| 1369 | default: |
| 1370 | LOG(Error, "Unknown Visual Script \'{1}\' metadata version {0}.", version, ToString()); |
| 1371 | return LoadResult::InvalidData; |
| 1372 | } |
| 1373 | |
| 1374 | // Load graph |
| 1375 | const auto surfaceChunk = GetChunk(0); |
| 1376 | if (surfaceChunk == nullptr) |
| 1377 | return LoadResult::MissingDataChunk; |
| 1378 | MemoryReadStream surfaceStream(surfaceChunk->Get(), surfaceChunk->Size()); |
| 1379 | if (Graph.Load(&surfaceStream, true)) |
| 1380 | { |
| 1381 | LOG(Warning, "Failed to load graph \'{0}\'", ToString()); |
| 1382 | return LoadResult::Failed; |
| 1383 | } |
| 1384 | |
| 1385 | // Find method nodes |
| 1386 | for (auto& node : Graph.Nodes) |
| 1387 | { |
| 1388 | switch (node.Type) |
| 1389 | { |
| 1390 | case GRAPH_NODE_MAKE_TYPE(16, 3): |
| 1391 | { |
| 1392 | // Override method |
| 1393 | auto& method = _methods.AddOne(); |
| 1394 | method.Script = this; |
| 1395 | method.Node = &node; |
| 1396 | method.Name = StringAnsi((StringView)node.Values[0]); |
| 1397 | method.MethodFlags = (MethodFlags)((byte)MethodFlags::Virtual | (byte)MethodFlags::Override); |
| 1398 | method.Signature.Name = method.Name; |
| 1399 | method.Signature.IsStatic = false; |
| 1400 | method.Signature.Params.Resize(node.Values[1].AsInt); |
| 1401 | method.ParamNames.Resize(method.Signature.Params.Count()); |
nothing calls this directly
no test coverage detected