Skip to content

Instantly share code, notes, and snippets.

@Zerrien
Last active April 28, 2021 14:29
Show Gist options
  • Save Zerrien/4115a93a91674cd825b7bbdcf8ad298b to your computer and use it in GitHub Desktop.
Save Zerrien/4115a93a91674cd825b7bbdcf8ad298b to your computer and use it in GitHub Desktop.
/*
Steps for using:
1. Go to the level editor for the level.
2. Double click the Hero Placeholder to edit it.
3. Run the level so you have the child window open.
4. Make sure the equipment you have equipped matches the hero's equipment for for the course.
5. Copy paste the solution code from the level editor into level, press run/submit. (Just want all the frames to load and ensure it succeeds)
6. Put this script into the console of the level-editor tab/window
Now everything (seed, equipment, frames, hash) should be added to the solutions.
*/
(function () {
if(!currentView.subviews.thangs_tab_view.editThangView) throw "No thang selected, double click the hero placeholder."
var thangData = currentView.subviews.thangs_tab_view.editThangView.thangData
var oldPath = currentView.subviews.thangs_tab_view.editThangView.oldPath
var pComp = _.findWhere(thangData.components, function (elem) {return elem.config && elem.config.programmableMethods}).config.programmableMethods.plan
var solutionArray = pComp.solutions;
var solutions = {
"python":{},
"javascript":{}
//"lua":{},
//"coffeescript":{}
};
for(var i = 0; i < solutionArray.length; i++) {
solutions[solutionArray[i].language].solution = solutionArray[i];
solutions[solutionArray[i].language].index = i;
}
for(var key in solutions) {
var solution = solutions[key].solution;
console.log(solution);
if(!solution) {
solution = {};
}
var index = solutions[key].index;
if(!solution.source) {
if(key == "javascript") {
solution.source = "TODO WRITE SOLUTION: \n" + pComp.source;
} else {
solution.source = "TODO WRITE SOLUTION: \n" + pComp.languages[key];
}
}
solution.language = key;
solution.succeeds = true;
if(solution.passes) {
delete solution.passes
}
var childWindow = currentView.childWindow;
if(!childWindow) throw "No child window, press run.";
var dif = childWindow.currentView.session.get('state').difficulty;
if(dif) {
solution.difficulty = childWindow.currentView.session.get('state').difficulty;
}
solution.seed = childWindow.currentView.world.randomSeed;
var tInv = _.findWhere(currentView.subviews.thangs_tab_view.editThangView.thangData.components, function(elem) {return elem.config && elem.config.inventory})
if(tInv) {
tInv = tInv.config.inventory;
solution.heroConfig = {
inventory: tInv,
thangType: currentView.subviews.thangs_tab_view.editThangView.thangData.thangType
}
} else {
console.warn("No recommended inventory found, using the child window's equipped gear.")
solution.heroConfig = childWindow.currentView.session.get('heroConfig');
}
var hist = childWindow.currentView.session.get('state').flagHistory;
if(hist && hist.length > 0) {
solution.flagHistory = hist;
}
if(childWindow.currentView.world.frames.length >= 2) {
solution.lastHash = childWindow.currentView.world.frames[childWindow.currentView.world.frames.length - 2].hash;
}
solution.frameCount = childWindow.currentView.world.frames.length;
var goals = {};
for(var i = 0; i < childWindow.currentView.goalManager.goals.length; i++) {
goal = childWindow.currentView.goalManager.goals[i];
goals[goal.id] = childWindow.currentView.goalManager.getGoalState(goal.id);
}
solution.goals = goals;
if(index !== undefined && index !== null) {
pComp.solutions[index] = solution;
} else {
pComp.solutions.push(solution);
}
}
Backbone.Mediator.publish('editor:level-thang-edited', {thangData: $.extend(true, {}, thangData), oldPath: oldPath})
currentView.subviews.thangs_tab_view.editThangView.render()
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment