Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<script src="js/jquery-1.11.3.js"></script>
<script type="text/javascript" src="Buttons/js/buttons.js"></script>
<script type="text/javascript" src="js/bonsai-0.4.1.min.js"></script>
<script type = "text/javascript" src="js/saveload.js"></script>
<script type ="text/javascript" src="js/userInterface.js" ></script>
<script type = "text/javascript" src="js/saveload.js"></script>
<script type ="text/javascript" src="js/parser.js" ></script>
<script type ="text/javascript" src="js/evaluation.js" ></script>
<script type = "text/javascript" src="js/world.js"></script>
Expand Down
9 changes: 6 additions & 3 deletions js/saveload.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ function handleFileLoad(event){
console.log("JSON is Valid syntax - Loading file");
gitems.push(JSON.parse(reader.result));
}
if(gitems.length <= 1){
loadLocal(gitems);
}
});
reader.readAsText(f);



}
console.log("hi");

loadLocal(gitems);
}


Expand Down Expand Up @@ -69,8 +72,8 @@ function saveLocal(){

//Local Load - is called by handleFileLoad
function loadLocal(json){


console.log("hello");
generateWorldFromFile(json);

}

Expand Down
63 changes: 62 additions & 1 deletion js/world.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var selected_object;

//block dealing with loading from JSON
function buildWorld(){
generateRandomWorld(20);
generateRandomWorld(0); //This should be removed or modified to always draw a set world
}

function getSelectedObject(){
Expand All @@ -34,6 +34,67 @@ function getEvalWorld(){
return scope;
}

//THIS METHOD NEEDS TO BE CALLED ON RECEPTION OF MESSAGE TO WORKER THREAD rather than directly from saveload.js in order to get scope of bonsai
//gets passed a tree structure from saveload - TODO: Make sure library is loaded before user uploads world - will want to add check from library name of world load to library name on server
function generateWorldFromFile(worldTree){
console.log("gets to here...");
loadedLibrary = null;
var worldObjects = [];
var obj_list = []; //List of objects to draw to screen
var ind_list = []; //List of indexes mapped to same position as obj_list
if(loadedLibrary == null){
loadedLibrary = worldTree[0]; //The library should be the only file in the buffer
}


for(var i = 0; i<loadedLibrary.library.length; i++){
worldObjects[i] = loadedLibrary.library[i];//populate each loaded object into buffer - Can be set as the main world buffer at the end of this function to keep concurrent with evaluator
console.log(worldObjects[i]);
var obj = worldObjects[i];
var lib_index = null;
for(var index = 0; index < library.length;index++){
if(library[i].type == obj.type){
lib_index = i;
}
}
if(lib_index == null){
alert("Your loaded world has an object not supported in the current library");
return false;
}

obj_list.push(obj);
ind_list.push(lib_index);
//TODO: nullchecking for above vars



}

for(var i = 0; i<obj_list.length;i++){

if(obj_list[i] != null && ind_list[i] != null){

console.log("Printed a: " + obj_list[i].type + " " +ind_list[i] + " " + obj_list[i].colour);
addObject(ind_list[i], obj_list[i].x, obj_list[i].y, obj_list[i].width, obj_list[i].height, obj_list[i].colour);
}
}

}















function generateRandomWorld(size){
for (var i = 0; i < size; i++)
{
Expand Down
48 changes: 48 additions & 0 deletions lib/geometry/geometry_world.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{"library_name":"Geometry",
"bg_colour":"White",
"library":[
{"type":"Rectangle",
"colour":"Black",
"x":5,
"y":10,
"width":40,
"height":60,
"image":"\\poly",
"field_key":[
"Sides"
],
"field_vals":[
4
]
},
{"type":"Triangle",
"colour":"Blue",
"image":"\\poly",
"x":50,
"y":70,
"width":40,
"height":60,
"field_key":[
"Sides"
],
"field_vals":[
3
]
},
{"type":"Circle",
"colour":"Yellow",
"image":"\\poly",
"x":100,
"y":210,
"width":40,
"height":60,
"field_key":[
"Sides"
],
"field_vals":[
0
]
}

]
}