| 65 | } |
| 66 | |
| 67 | JSValue ScObjectManager::load(JSContext* ctx, JSValue thisVal, int argc, JSValue* argv) |
| 68 | { |
| 69 | auto context = GetContext(); |
| 70 | auto& objectRepository = context->GetObjectRepository(); |
| 71 | auto& objectManager = context->GetObjectManager(); |
| 72 | |
| 73 | if (JS_IsArray(argv[0])) |
| 74 | { |
| 75 | // load(identifiers) |
| 76 | JS_UNPACK_ARRAY(array, ctx, argv[0]); |
| 77 | std::vector<ObjectEntryDescriptor> descriptors; |
| 78 | int64_t length; |
| 79 | JS_GetLength(ctx, array, &length); |
| 80 | |
| 81 | for (int64_t i = 0; i < length; i++) |
| 82 | { |
| 83 | JSValue item = JS_GetPropertyInt64(ctx, array, i); |
| 84 | JS_UNPACK_STR(identifier, ctx, item); |
| 85 | descriptors.push_back(ObjectEntryDescriptor::Parse(identifier)); |
| 86 | } |
| 87 | |
| 88 | JSValue result = JS_NewArray(ctx); |
| 89 | int64_t index = 0; |
| 90 | for (const auto& descriptor : descriptors) |
| 91 | { |
| 92 | auto obj = objectManager.LoadObject(descriptor); |
| 93 | if (obj != nullptr) |
| 94 | { |
| 95 | MarkAsResearched(obj); |
| 96 | auto objIndex = objectManager.GetLoadedObjectEntryIndex(obj); |
| 97 | auto scLoadedObject = CreateScObject(ctx, obj->GetObjectType(), objIndex); |
| 98 | JS_SetPropertyInt64(ctx, result, index, scLoadedObject); |
| 99 | } |
| 100 | else |
| 101 | { |
| 102 | JS_SetPropertyInt64(ctx, result, index, JS_NULL); |
| 103 | } |
| 104 | index++; |
| 105 | } |
| 106 | RefreshResearchedItems(); |
| 107 | return result; |
| 108 | } |
| 109 | else |
| 110 | { |
| 111 | // load(identifier, index?) |
| 112 | JS_UNPACK_STR(identifier, ctx, argv[0]); |
| 113 | auto descriptor = ObjectEntryDescriptor::Parse(identifier); |
| 114 | |
| 115 | auto installedObject = objectRepository.FindObject(descriptor); |
| 116 | if (installedObject != nullptr) |
| 117 | { |
| 118 | if (argc > 1 && !JS_IsUndefined(argv[1])) |
| 119 | { |
| 120 | JS_UNPACK_UINT32(index, ctx, argv[1]); |
| 121 | |
| 122 | auto limit = getObjectTypeLimit(installedObject->Type); |
| 123 | if (index < limit) |
| 124 | { |
nothing calls this directly
no test coverage detected