Skip to content

Instantly share code, notes, and snippets.

@Bryukh
Forked from Zerrien/test-harness-solution-ripper.js
Last active April 7, 2025 04:09
Show Gist options
  • Save Bryukh/8a3d56f176e7b405ca790baad21ac62d to your computer and use it in GitHub Desktop.
Save Bryukh/8a3d56f176e7b405ca790baad21ac62d 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 world = childWindow.application.router.viewLoad.view.vueComponent.$children[0].$children[0].$children[0].$children[0].backboneViewInstance.world;
var goalManager = childWindow.application.router.viewLoad.view.vueComponent.$children[0].$children[0].$children[0].$children[0].backboneViewInstance.goalManager;
solution.seed = world.randomSeed;
if(world.frames.length >= 2) {
solution.lastHash = world.frames[world.frames.length - 2].hash;
}
solution.frameCount = world.frames.length;
var goals = {};
for(var i = 0; i < goalManager.goals.length; i++) {
goal = goalManager.goals[i];
goals[goal.id] = 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