MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / JSGetImageInfo

Function JSGetImageInfo

src/openrct2-ui/scripting/CustomImages.cpp:145–173  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

143 }
144
145 JSValue JSGetImageInfo(JSContext* ctx, ImageIndex id)
146 {
147 auto* g1 = GfxGetG1Element(id);
148 if (g1 == nullptr)
149 {
150 return JS_UNDEFINED;
151 }
152
153 JSValue obj = JS_NewObject(ctx);
154 JS_SetPropertyStr(ctx, obj, "id", JS_NewInt32(ctx, id));
155 JS_SetPropertyStr(ctx, obj, "offset", ToJSValue(ctx, ScreenCoordsXY{ g1->xOffset, g1->yOffset }));
156 JS_SetPropertyStr(ctx, obj, "width", JS_NewInt32(ctx, g1->width));
157 JS_SetPropertyStr(ctx, obj, "height", JS_NewInt32(ctx, g1->height));
158
159 JS_SetPropertyStr(ctx, obj, "hasTransparent", JS_NewBool(ctx, g1->flags.has(G1Flag::hasTransparency)));
160 JS_SetPropertyStr(ctx, obj, "isRLE", JS_NewBool(ctx, g1->flags.has(G1Flag::hasRLECompression)));
161 JS_SetPropertyStr(ctx, obj, "isPalette", JS_NewBool(ctx, g1->flags.has(G1Flag::isPalette)));
162 JS_SetPropertyStr(ctx, obj, "noZoom", JS_NewBool(ctx, g1->flags.has(G1Flag::noZoomDraw)));
163
164 if (g1->flags.has(G1Flag::hasZoomSprite))
165 {
166 JS_SetPropertyStr(ctx, obj, "nextZoomId", JS_NewInt32(ctx, id - g1->zoomedOffset));
167 }
168 else
169 {
170 JS_SetPropertyStr(ctx, obj, "nextZoomId", JS_UNDEFINED);
171 }
172 return obj;
173 }
174
175 static std::string_view GetPixelDataTypeForG1(const G1Element& g1)
176 {

Callers 2

getImageInfoMethod · 0.85
getImageMethod · 0.85

Calls 3

GfxGetG1ElementFunction · 0.85
hasMethod · 0.65
ToJSValueFunction · 0.50

Tested by

no test coverage detected