type data_file tag as String value as string endtype function VisualEditor_LoadProject ( fileName as string ) // load a project if GetFileExists ( fileName ) = 0 Message ( "Error - project file cannot be opened" ) end endif //parse projectdata.value data as data_file VisualEditor_Entities.length = -1 data_type$ = "settings" entity_type$ = "" file = OpenToRead (fileName) while (FileEOF (file) = 0) //Remove the tags and white space and parse the remaining text line$ = ReadLine (file) line$ = ReplaceString(line$, "", "", -1) line$ = GetStringToken2(line$, "<", 2) data.tag = GetStringToken2(line$, ">", 1) data.value = GetStringToken2(line$, ">", 2) if data.tag = "settings" data_type$ = "settings" elseif data.tag = "/settings" data_type$ = "" endif if data.tag = "entity" data_type$ = "entity" file_enity as tVisualEditor_FileEntity VisualEditor_Entities.insert(file_enity) elseif data.tag = "/entity" data_type$ = "" elseif data_type$ = "settings" VisualEditor_ParseSettingsData(data) elseif data_type$ = "entity" entity_type$ = VisualEditor_ParseEntityData(data, entity_type$) endif endwhile CloseFile(file) endfunction function VisualEditor_ParseSettingsData (data as data_file) // we have found an entity, look through all supported data, if we find // a match then store the data.value in the entities array select data.tag case "width": VisualEditor_BaseWidth = val (data.value) endcase case "height": VisualEditor_BaseHeight = val (data.value) endcase case "custom res": VisualEditor_CustomResolutions = data.value endcase case "scene colours": VisualEditor_SceneColours = data.value endcase case "orientation": if data.value = "Portrait" SetOrientationAllowed ( 1, 1, 0, 0 ) elseif data.value = "Landscape" SetOrientationAllowed ( 0, 0, 1, 1 ) else SetOrientationAllowed ( 1, 1, 1, 1 ) endif endcase endselect endfunction 0 function VisualEditor_ParseEntityData (data as data_file, entity_type as string) // we have found an entity, look through all supported data, if we find // a match then store the data.value in the entities array //check for valid data.value type that specific to that entity type select entity_type case "sprite": entity_property_found = set_sprite_enity_data(data) endcase case "text": entity_property_found = set_text_enity_data(data) endcase case "particles": set_particles_enity_data(data) endcase case "button": entity_property_found = set_button_enity_data(data) endcase case "editbox": entity_property_found = set_editbox_enity_data(data) endcase endselect //If the entity property was not specific to any entity type check to see if its a shared entity value if entity_property_found = 0 entity_index = VisualEditor_Entities.length select data.tag case "type": VisualEditor_Entities [entity_index].sType = data.value entity_type = data.value endcase case "scene": VisualEditor_Entities [entity_index].scene = val (data.value) endcase case "name": VisualEditor_Entities [entity_index].sName = data.value endcase case "x": VisualEditor_Entities [entity_index].x = val (data.value) endcase case "y": VisualEditor_Entities [entity_index].y = val (data.value) endcase case "size x": VisualEditor_Entities [entity_index].sizeX = val (data.value) endcase case "size y": VisualEditor_Entities [entity_index].sizeY = val (data.value) endcase case "scale x": VisualEditor_Entities [entity_index].scaleX = val (data.value) endcase case "scale y": VisualEditor_Entities [entity_index].scaleY = val (data.value) endcase case "offset x:": VisualEditor_Entities [entity_index].offsetX = val (data.value) endcase case "offset y": VisualEditor_Entities [entity_index].offsetY = val (data.value) endcase case "angle": VisualEditor_Entities [entity_index].angle = val (data.value) endcase case "depth": VisualEditor_Entities [entity_index].depth = val (data.value) endcase case "visible": VisualEditor_Entities [entity_index].visible = val (data.value) endcase case "red": VisualEditor_Entities [entity_index].red = val (data.value) endcase case "green": VisualEditor_Entities [entity_index].green = val (data.value) endcase case "blue": VisualEditor_Entities [entity_index].blue = val (data.value) endcase case "alpha": VisualEditor_Entities [entity_index].alpha = val (data.value) endcase case "fixed": VisualEditor_Entities [entity_index].fixed = val (data.value) endcase case "text": VisualEditor_Entities [entity_index].sText = VisualEditor_Entities [entity_index].sText +data.value+ chr ( 10 ) endcase case "custom": VisualEditor_Entities [entity_index].custom.length = VisualEditor_Entities [entity_index].custom.length + 1 VisualEditor_Entities [entity_index].custom [ VisualEditor_Entities [entity_index].custom.length ] = data.value endcase endselect endif endfunction entity_type function set_sprite_enity_data(data as data_file) entity_index = VisualEditor_Entities.length select data.tag case "image": VisualEditor_Entities [entity_index].sImage = ReplaceString ( data.value, "media/", "", 1 ) exitfunction 1 endcase case "angle": VisualEditor_Entities [entity_index].angle = val (data.value) exitfunction 1 endcase case "physics": VisualEditor_Entities [entity_index].physics = val (data.value) exitfunction 1 endcase case "fliph": VisualEditor_Entities [entity_index].flipH = val (data.value) exitfunction 1 endcase case "flipv": VisualEditor_Entities [entity_index].flipV = val (data.value) exitfunction 1 endcase case "active": VisualEditor_Entities [entity_index].active = val (data.value) exitfunction 1 endcase case "collision": VisualEditor_Entities [entity_index].collision = val (data.value) // vedata.valueis polygon, circle, box, no shape // agk is no shape, circle, box, polygon select VisualEditor_Entities [entity_index].collision case 0: VisualEditor_Entities [entity_index].collision = 3 : endcase case 3: VisualEditor_Entities [entity_index].collision = 0 : endcase endselect exitfunction 1 endcase case "angulardamping": VisualEditor_Entities [entity_index].angularDamping = val (data.value) exitfunction 1 endcase case "centreofmassx": VisualEditor_Entities [entity_index].centreOfMassX = val (data.value) exitfunction 1 endcase case "centreofmassy": VisualEditor_Entities [entity_index].centreOfMassY = val (data.value) exitfunction 1 endcase case "canrotate": VisualEditor_Entities [entity_index].canRotate = val (data.value) exitfunction 1 endcase case "damping": VisualEditor_Entities [entity_index].damping = val (data.value) exitfunction 1 endcase case "friction": VisualEditor_Entities [entity_index].friction = val (data.value) exitfunction 1 endcase case "isbullet": VisualEditor_Entities [entity_index].isBullet = val (data.value) exitfunction 1 endcase case "issensor": VisualEditor_Entities [entity_index].isSensor = val (data.value) exitfunction 1 endcase case "mass": VisualEditor_Entities [entity_index].mass = val (data.value) exitfunction 1 endcase case "restitution": VisualEditor_Entities [entity_index].restitution = val (data.value) exitfunction 1 endcase endselect endfunction 0 function set_text_enity_data(data as data_file) entity_index = VisualEditor_Entities.length select data.tag case "alignment": VisualEditor_Entities [entity_index].alignment = val (data.value) exitfunction 1 endcase case "text size": VisualEditor_Entities [entity_index].textSize = val (data.value) exitfunction 1 endcase endselect endfunction 0 function set_button_enity_data(data as data_file) entity_index = VisualEditor_Entities.length select data.tag case "button text": VisualEditor_Entities [entity_index].buttonText = data.value exitfunction 1 endcase case "button down": VisualEditor_Entities [entity_index].buttonDown = ReplaceString ( data.value, "media/", "", 1 ) exitfunction 1 endcase case "button up": VisualEditor_Entities [entity_index].buttonUp = ReplaceString ( data.value, "media/", "", 1 ) exitfunction 1 endcase case "button goto": VisualEditor_Entities [entity_index].textSize = val (data.value) exitfunction 1 endcase endselect endfunction 0 function set_particles_enity_data(data as data_file) entity_index = VisualEditor_Entities.length select data.tag case "particle image": VisualEditor_Entities [entity_index].sImage = ReplaceString ( data.value, "media/", "", 1 ) exitfunction 1 endcase case "particle size": VisualEditor_Entities [entity_index].particleSize = val ( data.value ) exitfunction 1 endcase case "particle life": VisualEditor_Entities [entity_index].particleLife = val (data.value) exitfunction 1 endcase case "particle max": VisualEditor_Entities [entity_index].particleMax = val (data.value) exitfunction 1 endcase case "particle frequency": VisualEditor_Entities [entity_index].particleFrequency = val (data.value) exitfunction 1 endcase case "particle emit angle": VisualEditor_Entities [entity_index].particleEmitAngle = val (data.value) exitfunction 1 endcase case "particle face dir": VisualEditor_Entities [entity_index].particleFaceDirection = val (data.value) exitfunction 1 endcase case "particle transparency": VisualEditor_Entities [entity_index].particleTransparency = val (data.value) exitfunction 1 endcase case "particle dir x": VisualEditor_Entities [entity_index].particleDirX = val (data.value) exitfunction 1 endcase case "particle dir y": VisualEditor_Entities [entity_index].particleDirY = val (data.value) exitfunction 1 endcase case "particle rot x": VisualEditor_Entities [entity_index].particleRotX = val (data.value) exitfunction 1 endcase case "particle rot y": VisualEditor_Entities [entity_index].particleRotY = val (data.value) exitfunction 1 endcase case "particle x1": VisualEditor_Entities [entity_index].particleX1 = val (data.value) exitfunction 1 endcase case "particle y1": VisualEditor_Entities [entity_index].particleY1 = val (data.value) exitfunction 1 endcase case "particle x2": VisualEditor_Entities [entity_index].particleX2 = val (data.value) exitfunction 1 endcase case "particle y2": VisualEditor_Entities [entity_index].particleY2 = val (data.value) exitfunction 1 endcase case "particle vel x": VisualEditor_Entities [entity_index].particleVelX = val (data.value) exitfunction 1 endcase case "particle vel y": VisualEditor_Entities [entity_index].particleVelY = val (data.value) exitfunction 1 endcase case "particle colours": VisualEditor_Entities [entity_index].particleColourKeyFrames = data.value exitfunction 1 endcase case "particle scales": VisualEditor_Entities [entity_index].particleScaleKeyFrames = data.value exitfunction 1 endcase case "particle forces": VisualEditor_Entities [entity_index].particleForces = data.value exitfunction 1 endcase endselect endfunction 0 function set_editbox_enity_data(data as data_file) entity_index = VisualEditor_Entities.length select data.tag case "edit size": VisualEditor_Entities [entity_index].editSize = val (data.value) exitfunction 1 endcase case "edit colour red": VisualEditor_Entities [entity_index].editColourRed = val (data.value) exitfunction 1 endcase case "edit colour green": VisualEditor_Entities [entity_index].editColourGreen = val (data.value) exitfunction 1 endcase case "edit colour blue": VisualEditor_Entities [entity_index].editColourBlue = val (data.value) exitfunction 1 endcase case "edit background red": VisualEditor_Entities [entity_index].editBackgroundRed = val (data.value) exitfunction 1 endcase case "edit background green": VisualEditor_Entities [entity_index].editBackgroundGreen = val (data.value) exitfunction 1 endcase case "edit background blue": VisualEditor_Entities [entity_index].editBackgroundBlue = val (data.value) exitfunction 1 endcase case "edit background alpha": VisualEditor_Entities [entity_index].editBackgroundAlpha = val (data.value) exitfunction 1 endcase case "edit border red": VisualEditor_Entities [entity_index].editBorderRed = val (data.value) exitfunction 1 endcase case "edit border green": VisualEditor_Entities [entity_index].editBorderGreen = val (data.value) exitfunction 1 endcase case "edit border blue": VisualEditor_Entities [entity_index].editBorderBlue = val (data.value) exitfunction 1 endcase case "edit border alpha": VisualEditor_Entities [entity_index].editBorderAlpha = val (data.value) exitfunction 1 endcase case "edit border size": VisualEditor_Entities [entity_index].editBorderSize = val (data.value) exitfunction 1 endcase case "edit max characters": VisualEditor_Entities [entity_index].editMaxCharacters = val (data.value) exitfunction 1 endcase case "edit max lines": VisualEditor_Entities [entity_index].editMaxLines = val (data.value) exitfunction 1 endcase case "edit multi line": VisualEditor_Entities [entity_index].editMultiLine = val (data.value) exitfunction 1 endcase case "edit password": VisualEditor_Entities [entity_index].editPassword = val (data.value) exitfunction 1 endcase case "edit cursor red": VisualEditor_Entities [entity_index].editCursorRed = val (data.value) exitfunction 1 endcase case "edit cursor green": VisualEditor_Entities [entity_index].editCursorGreen = val (data.value) exitfunction 1 endcase case "edit cursor blue": VisualEditor_Entities [entity_index].editCursorBlue = val (data.value) exitfunction 1 endcase case "edit cursor width": VisualEditor_Entities [entity_index].editCursorWidth = val (data.value) exitfunction 1 endcase case "edit cursor wrap": VisualEditor_Entities [entity_index].editCursorWrap = val (data.value) exitfunction 1 endcase endselect endfunction 0