Skip to content

Commit

Permalink
Changed ModIOMod to Resource instead of Dictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
aNaOH committed Apr 29, 2024
1 parent 064ea40 commit b33b3ac
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 73 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mod_io"
version = "0.1.1"
version = "0.2.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand All @@ -9,7 +9,7 @@ edition = "2021"
crate-type = ["cdylib"]

[patch."https://github.com/godot-rust/godot4-prebuilt"]
godot4-prebuilt = { git = "https://github.com//godot-rust/godot4-prebuilt", branch = "4.1.2"}
godot4-prebuilt = { git = "https://github.com//godot-rust/godot4-prebuilt", branch = "4.2.1"}

[dependencies]
godot = { git = "https://github.com/godot-rust/gdext", branch = "master" }
Expand Down
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

![Mod.io For Godot](https://github.com/aNaOH/modio-godot/blob/main/logo.svg?raw=true)

The main branch contains the lastest working version of the plugin, the master branch contains the lastest version of the code, even if it not works or if I'm stuck with something.
Expand All @@ -19,17 +20,18 @@ Currently supports:
var modio = ModIO.new()
modio.connect(api_key, game_id)
var mods = modio.get_mods(query, page, per_page)

get_mods() returns an array of dictioraries, the dictionary is formed by:

- id
- name (Thanks to @d10sfan for adding it!)
- submitter (Thanks to @d10sfan for adding it!)
- date_updated
- date_live
- profile_url
- modfile_url
- modfile_name
- modfile_size
- tags
- id
- name (Thanks to @d10sfan for adding it!)
- submitter (Thanks to @d10sfan for adding it!)
- date_updated
- date_live
- profile_url
- modfile_url
- modfile_name
- modfile_size
- tags

get_mods() needs an string argument for the search query, if you want to list all mods just use "" as the argument
62 changes: 3 additions & 59 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ impl INode for ModIO {
}
}

#[derive(GodotClass)]
#[class(tool, init, base=Resource)]
struct ModIOMod {
pub id: u64,
pub name: GString,
Expand Down Expand Up @@ -87,64 +89,6 @@ impl ModIOMod {

}

impl GodotConvert for ModIOMod {
type Via = Dictionary;
}

impl ToGodot for ModIOMod {


fn into_godot(self) -> Self::Via {
let mut dictionary = Dictionary::new();
dictionary.insert("id", self.id);
dictionary.insert("name", self.name.clone());
dictionary.insert("submitter", self.submitter.clone());
dictionary.insert("date_updated", self.date_updated);
dictionary.insert("date_live", self.date_live);
dictionary.insert("profile_url", self.profile_url.clone());
dictionary.insert("modfile_url", self.modfile_url.clone());
dictionary.insert("modfile_name", self.modfile_name.clone());
dictionary.insert("modfile_size", self.modfile_size.clone());
dictionary.insert("tags", self.tags.clone());


dictionary
}

fn to_variant(&self) -> Variant {
let mut dictionary = Dictionary::new();
dictionary.insert("id", self.id);
dictionary.insert("name", self.name.clone());
dictionary.insert("submitter", self.submitter.clone());
dictionary.insert("date_updated", self.date_updated);
dictionary.insert("date_live", self.date_live);
dictionary.insert("profile_url", self.profile_url.clone());
dictionary.insert("modfile_url", self.modfile_url.clone());
dictionary.insert("modfile_name", self.modfile_name.clone());
dictionary.insert("modfile_size", self.modfile_size.clone());
dictionary.insert("tags", self.tags.clone());

Variant::from(dictionary)
}

fn to_godot(&self) -> Self::Via {
let mut dictionary = Dictionary::new();
dictionary.insert("id", self.id);
dictionary.insert("name", self.name.clone());
dictionary.insert("submitter", self.submitter.clone());
dictionary.insert("date_updated", self.date_updated);
dictionary.insert("date_live", self.date_live);
dictionary.insert("profile_url", self.profile_url.clone());
dictionary.insert("modfile_url", self.modfile_url.clone());
dictionary.insert("modfile_name", self.modfile_name.clone());
dictionary.insert("modfile_size", self.modfile_size.clone());
dictionary.insert("tags", self.tags.clone());


dictionary
}
}

#[godot_api]
impl ModIO {
#[func]
Expand Down Expand Up @@ -182,7 +126,7 @@ impl ModIO {
let mut mod_vec = Array::new();
for m in mods {

mod_vec.insert(mod_vec.len(), ModIOMod::from_mod(&m).to_godot())
mod_vec.insert(mod_vec.len(), ModIOMod::from_mod(&m))
}

Some(mod_vec)
Expand Down

0 comments on commit b33b3ac

Please sign in to comment.