Currently, I'm developing a browser-based text adventure game that takes inspiration from classics like Hitchhiker's Guide to the Galaxy and the Zork series. In order to allow players to save their progress, I store important objects such as locations and player data in localStorage.
To handle circular references within these objects during saving process, I've implemented the use of CircularJSON.
The challenge arises when these saved objects are parsed back, as they default to being of the Object type. This poses an issue for functions associated with specific types like Area:
var Area = function (tempdescription, tempinitialDesc, tempobjArr) {
// Area object properties and methods
};
Area.prototype.getIndex = function (tempstr) {
// Method to get index of a specified string in the objArr array
};
and Player:
var Player = function (defaultLocation) {
// Player object properties and methods
};
Player.prototype.getIndex = function (tempstr) {
// Method to get index of a specified string in the inv array
};
In my game, it is crucial for objects like Area and Player, which I have defined myself, to maintain their correct types for the rest of the code to function properly.
Given that there will be numerous instances of these objects by the end of development, I am looking for a simple method to change their types efficiently while retaining their structure.
Is there any way to modify the type of a JavaScript object without extensive manual adjustments?