pub struct SketchwareProject {
pub project: Project,
pub file: File,
pub library: Library,
pub resource: Resource,
pub view: View,
pub logic: Logic,
pub resource_files: Option<ResourceFiles>,
}Expand description
Represents a parsed sketchware project that contains
project::Project, file::File, library::Library, resource::Resource,
view::View, and logic::Logic
Fields§
§project: Project§file: File§library: Library§resource: Resource§view: View§logic: Logic§resource_files: Option<ResourceFiles>The resource files attached to this project. If None, that means the resource files are ignored
Implementations§
Source§impl SketchwareProject
impl SketchwareProject
Sourcepub fn parse_from(
raw_swproj: RawSketchwareProject,
) -> Result<Self, SketchwareProjectParseError>
pub fn parse_from( raw_swproj: RawSketchwareProject, ) -> Result<Self, SketchwareProjectParseError>
Parses a RawSketchwareProject into SketchwareProject
Examples found in repository?
examples/api_demo1.rs (lines 41-43)
9fn main() {
10 let mut args = std::env::args();
11 args.next();
12
13 let project = read(args.next().expect("File path of a project data file to parse")).expect("Invalid project path given");
14 let file = read(args.next().expect("File path of a file data file to parse")).expect("Invalid file path given");
15 let library = read(args.next().expect("File path of a library data file to parse")).expect("Invalid library path given");
16 let resource = read(args.next().expect("File path of a resource data file to parse")).expect("Invalid resource path given");
17 let view = read(args.next().expect("File path of a view data file to parse")).expect("Invalid view path given");
18 let logic = read(args.next().expect("File path of a logic data file to parse")).expect("Invalid logic path given");
19
20 // decrypt them
21
22 let project = swrs::decrypt_sw_encrypted(&project).expect("Unable to decrypt project");
23 let file = swrs::decrypt_sw_encrypted(&file).expect("Unable to decrypt file");
24 let library = swrs::decrypt_sw_encrypted(&library).expect("Unable to decrypt library");
25 let resource = swrs::decrypt_sw_encrypted(&resource).expect("Unable to decrypt resource");
26 let view = swrs::decrypt_sw_encrypted(&view).expect("Unable to decrypt view");
27 let logic = swrs::decrypt_sw_encrypted(&logic).expect("Unable to decrypt logic");
28
29 // turn them into strings
30
31 let project = String::from_utf8(project).expect("Invalid charset for project");
32 let file = String::from_utf8(file).expect("Invalid charset for file");
33 let library = String::from_utf8(library).expect("Invalid charset for library");
34 let resource = String::from_utf8(resource).expect("Invalid charset for resource");
35 let view = String::from_utf8(view).expect("Invalid charset for view");
36 let logic = String::from_utf8(logic).expect("Invalid charset for logic");
37
38 // and parse them
39
40 let sketchware_project = SketchwareProject::try_from(
41 ParsedSketchwareProject::parse_from(
42 RawSketchwareProject::new(project, file, library, resource, view, logic, vec![])
43 ).expect("Corrupted sketchware project")
44 ).expect("Corrupted sketchware project");
45
46 println!("Screens:");
47
48 for screen in sketchware_project.screens {
49 println!(" Screen {} or {}:", screen.layout_name, screen.java_name);
50 println!(" Events:");
51
52 for event in screen.events {
53 println!(" - Event {}, type: {:?}, blocks:", event.name, event.event_type);
54
55 fn print_blocks(indentation: u32, blocks: Blocks) {
56 for block in blocks {
57 println!("{}Block #{} opcode {}", " ".repeat(indentation as usize), block.op_code, block.content.to_string());
58
59 if let Some(blocks_ss1) = block.sub_stack1 {
60 println!("{}substack1: ", " ".repeat(indentation as usize));
61 print_blocks(indentation + 2, blocks_ss1);
62 }
63
64 if let Some(blocks_ss2) = block.sub_stack2 {
65 println!("{}substack2: ", " ".repeat(indentation as usize));
66 print_blocks(indentation + 2, blocks_ss2);
67 }
68 }
69
70 println!();
71 }
72
73 print_blocks(8, event.code);
74 }
75 }
76}Sourcepub fn parse(
project: String,
file: String,
library: String,
resource: String,
view: String,
logic: String,
resource_files: Vec<ResourceFileWrapper>,
) -> Result<Self, SketchwareProjectParseError>
pub fn parse( project: String, file: String, library: String, resource: String, view: String, logic: String, resource_files: Vec<ResourceFileWrapper>, ) -> Result<Self, SketchwareProjectParseError>
Parses a list of project data into SketchwareProject
Sourcepub fn parse_wo_res(
project: String,
file: String,
library: String,
resource: String,
view: String,
logic: String,
) -> Result<Self, SketchwareProjectParseError>
pub fn parse_wo_res( project: String, file: String, library: String, resource: String, view: String, logic: String, ) -> Result<Self, SketchwareProjectParseError>
Parses a list of project data into SketchwareProject without resource files (they’ll be
ignored on API)
Trait Implementations§
Source§impl Clone for SketchwareProject
impl Clone for SketchwareProject
Source§fn clone(&self) -> SketchwareProject
fn clone(&self) -> SketchwareProject
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SketchwareProject
impl Debug for SketchwareProject
Source§impl From<SketchwareProject> for SketchwareProject
impl From<SketchwareProject> for SketchwareProject
Source§fn from(val: SketchwareProject) -> Self
fn from(val: SketchwareProject) -> Self
Converts to this type from the input type.
Source§impl PartialEq for SketchwareProject
impl PartialEq for SketchwareProject
Source§fn eq(&self, other: &SketchwareProject) -> bool
fn eq(&self, other: &SketchwareProject) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl TryFrom<SketchwareProject> for SketchwareProject
impl TryFrom<SketchwareProject> for SketchwareProject
Source§type Error = APISketchwareProjectConversionError
type Error = APISketchwareProjectConversionError
The type returned in the event of a conversion error.
Source§impl TryInto<RawSketchwareProject> for SketchwareProject
impl TryInto<RawSketchwareProject> for SketchwareProject
Source§type Error = SketchwareProjectReconstructionError
type Error = SketchwareProjectReconstructionError
The type returned in the event of a conversion error.
impl StructuralPartialEq for SketchwareProject
Auto Trait Implementations§
impl Freeze for SketchwareProject
impl RefUnwindSafe for SketchwareProject
impl Send for SketchwareProject
impl Sync for SketchwareProject
impl Unpin for SketchwareProject
impl UnsafeUnpin for SketchwareProject
impl UnwindSafe for SketchwareProject
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more