Skip to content

Commit cbc8d9a

Browse files
move new_from_name into game::import
1 parent 01ef95e commit cbc8d9a

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

src/game/import/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,21 @@ pub fn find_game_exe(possible: &[String], base_path: &Path) -> Option<PathBuf> {
125125
.find(|x| x.is_file())
126126
}
127127

128+
/// Convert the provided game id and platform name to a full GamePlatform instance, if
129+
/// one can be found in the ecosystem schema.
130+
pub async fn plat_from_name(game_id: &str, plat_name: &str) -> Result<GamePlatform, Error> {
131+
let ecosystem = ecosystem::get_schema().await?;
132+
let game = ecosystem.games.get(game_id)
133+
.ok_or(GameError::BadGameId(game_id.into()))?;
134+
135+
game
136+
.distributions
137+
.iter()
138+
.find(|x| x.get_platform_name() == plat_name)
139+
.ok_or(GameError::NotSupported(game_id.into(), plat_name.into()).into())
140+
.cloned()
141+
}
142+
128143
pub fn construct_data(base: ImportBase, dist: ActiveDistribution) -> GameData {
129144
GameData {
130145
identifier: base

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ async fn main() -> Result<(), Error> {
190190
let import_base = ImportBase::new(&game_id).await?.with_overrides(overrides);
191191

192192
if let Some(platform) = platform {
193-
let platform = GamePlatform::new_from_name(&game_id, &platform).await?;
193+
let platform = game::import::plat_from_name(&game_id, &platform).await?;
194194
let dist = import_base.get_active_dist(&platform)?;
195195

196196
if dist.is_none() {

src/ts/v1/models/ecosystem.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -97,22 +97,6 @@ impl GamePlatform {
9797
"other",
9898
]
9999
}
100-
101-
/// Create a new instance of self from the provided platform name and identifier, if
102-
/// a valid one can be found.
103-
pub async fn new_from_name(game_id: &str, plat_name: &str) -> Result<Self, Error> {
104-
let ecosystem = ecosystem::get_schema().await?;
105-
let game = ecosystem.games.get(game_id)
106-
.ok_or(GameError::BadGameId(game_id.into()))?;
107-
108-
game
109-
.distributions
110-
.iter()
111-
.find(|x| x.get_platform_name() == plat_name)
112-
.ok_or(GameError::NotSupported(game_id.into(), plat_name.into()).into())
113-
.cloned()
114-
}
115-
116100
}
117101

118102
#[derive(Serialize, Deserialize, Debug, Clone)]

0 commit comments

Comments
 (0)