Skip to content

Commit

Permalink
internal: support both server-side and client-side objects in wip_sp3…
Browse files Browse the repository at this point in the history
….js (#2206)
  • Loading branch information
Pospelove authored Nov 4, 2024
1 parent e74b27b commit f98f767
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions misc/wip_sp3.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,30 @@ function verifyTickIds(api, args, spPrivate, className, functionName) {
}
}

let assign = (targetObject, sourceObject) => {
if (sourceObject.desc !== undefined) {
// Server-side/gamemode raw objects have desc and type properties
targetObject.desc = sourceObject.desc;
targetObject.type = sourceObject.type;

// Never check it in runtime again
assign = (targetObject, sourceObject) => {
targetObject.desc = sourceObject.desc;
targetObject.type = sourceObject.type;
};

} else if (sourceObject._skyrimPlatform_indexInPool !== undefined) {
// Client-side objects have _skyrimPlatform_indexInPool property starting with SP3 Update in 2024
// In previous version, they were completely native objects, without javascript properties
targetObject._skyrimPlatform_indexInPool = sourceObject._skyrimPlatform_indexInPool;

// Never check it in runtime again
assign = (targetObject, sourceObject) => {
targetObject._skyrimPlatform_indexInPool = sourceObject._skyrimPlatform_indexInPool;
};
}
}

function createSkyrimPlatform(api) {
const sp = {};
const spPrivate = {
Expand Down Expand Up @@ -120,8 +144,7 @@ function createSkyrimPlatform(api) {
spPrivate.isCtorEnabled = true;
const resWithClass = new ctor();
spPrivate.isCtorEnabled = false;
resWithClass.type = resWithoutClass.type;
resWithClass.desc = resWithoutClass.desc;
assign(resWithClass, resWithoutClass);
return resWithClass;
};
});
Expand All @@ -140,8 +163,7 @@ function createSkyrimPlatform(api) {
spPrivate.isCtorEnabled = true;
const resWithClass = new ctor();
spPrivate.isCtorEnabled = false;
resWithClass.type = resWithoutClass.type;
resWithClass.desc = resWithoutClass.desc;
assign(resWithClass, resWithoutClass);
return resWithClass;
};
});
Expand All @@ -152,8 +174,7 @@ function createSkyrimPlatform(api) {
spPrivate.isCtorEnabled = true;
const resWithClass = new f();
spPrivate.isCtorEnabled = false;
resWithClass.type = obj.type;
resWithClass.desc = obj.desc;
assign(resWithClass, obj);
return resWithClass;
}
return null;
Expand Down

0 comments on commit f98f767

Please sign in to comment.