hgame 0.26.4

CG production management structs, e.g. of assets, personnels, progress, etc.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
pub extern crate bson;
pub extern crate crossbeam_channel;
pub extern crate mkutil;

#[cfg(feature = "gui")]
pub extern crate egui_extras;

#[cfg(feature = "gui")]
pub extern crate mktree;

#[cfg(any(feature = "shotgrid", feature = "shotgrid_async_test"))]
pub extern crate shotgrid_rs;

#[cfg(any(feature = "egui_demo", feature = "easy_mark"))]
pub extern crate egui_demo_lib;

#[cfg(feature = "collab")]
pub extern crate futures_util;

#[cfg(feature = "collab")]
pub extern crate tokio_tungstenite;

#[cfg(feature = "collab")]
pub extern crate quick_protobuf;

mod asset;
pub mod media;
pub mod prelude;
pub mod production;
pub mod user;

#[cfg(feature = "collab")]
pub mod collab;

#[cfg(feature = "review_item")]
pub mod review_item;

#[cfg(feature = "stage_graph")]
pub mod stage;

#[cfg(feature = "alert")]
pub mod alert;

#[cfg(feature = "query_message")]
pub mod query_msg;

#[cfg(feature = "ticket")]
pub mod ticket;

#[cfg(any(feature = "shotgrid", feature = "shotgrid_async_test"))]
pub mod shotgrid;

pub use asset::*;
use prelude::*;
pub use production::Project;
pub use user::*;

#[cfg(feature = "image_processing")]
use hconf::once_cell::sync::OnceCell;

#[allow(unused_imports)]
use hconf::{
    colored::Colorize,
    log::{debug, error, info, warn},
    ClientCfgCel,
};

#[cfg(feature = "gui")]
pub use mktree::egui;
pub use mkutil::{aquamarine, glob};

use anyhow::{anyhow, Context, Result as AnyResult};
use async_trait::async_trait;
use bson::oid::ObjectId;
use chrono::{
    prelude::{DateTime, Local, Utc},
    Duration,
};
use dyn_clone::DynClone;

#[allow(unused_imports)]
#[cfg(feature = "gui")]
use egui::{Align, Color32, Layout, RichText, TextStyle};

#[cfg(all(feature = "image_processing", feature = "gui"))]
use egui::{ImageButton, Widget};

#[cfg(feature = "image_processing")]
use egui_extras::RetainedImage;

#[cfg(any(feature = "query_message", feature = "review_item"))]
use egui_extras::DatePickerButton;

use serde::{Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};
use std::{
    cmp::Ordering,
    collections::{BTreeSet, HashMap, HashSet},
    fmt,
    path::{Path, PathBuf},
};
use strum::IntoEnumIterator;

// to add day of the week, use `%a`
pub const DAY_MONTH_YEAR_FORMAT: &str = "%d %b %Y %H:%M";
pub const MONTH_DAY_YEAR_FORMAT: &str = "%b %d %Y %H:%M";
pub const YEAR_MONTH_DAY_FORMAT: &str = "%Y-%m-%d %H:%M";

/// Any object that holds an [`ObjectId`].
pub trait BsonId {
    fn bson_id_as_ref(&self) -> Option<&ObjectId>;

    fn bson_id(&self) -> AnyResult<&ObjectId>;
}

#[derive(Debug, Clone)]
/// A source of database. Since Asset Wrangler is normally used by a certain team/department within a large studio,
/// the concept of "Pan-project Umbrella" is employed, where the "umbrella" defines which subset of all the running productions
/// are presented to the user.
pub struct DbSource {
    pub label: String,
    pub dbi: Option<Box<dyn DbConnect>>,
    pub default_pp_umbrella: Option<String>,
    pub pp_members: Result<Vec<Project>, DatabaseError>,
}

impl Default for DbSource {
    fn default() -> Self {
        Self {
            label: String::new(),
            dbi: None,
            default_pp_umbrella: None,
            pp_members: Err(DatabaseError::Uninitialized),
        }
    }
}

impl DbSource {
    pub fn empty(label: &str) -> Self {
        Self {
            label: label.to_owned(),
            ..Default::default()
        }
    }

    #[cfg(feature = "gui")]
    pub fn pp_umbrella_debug_ui(&mut self, ui: &mut egui::Ui) {
        // Pan-project Umbrella
        match &self.default_pp_umbrella {
            Some(umbrella) => {
                ui.label(format!(
                    "☂ {} default Pan-project Umbrella: {}",
                    self.label, &umbrella
                ));
            }
            None => {
                ui.colored_label(
                    Color32::RED,
                    format!("🚫 {}: UNDEFINED default umbrella", self.label),
                );
            }
        };
    }

    #[cfg(feature = "gui")]
    pub fn pp_member_error(&mut self, ui: &mut egui::Ui) {
        if let Err(e) = &self.pp_members {
            // Pan-project Members error
            ui.colored_label(Color32::RED, format!("🚫 {} members: {}", self.label, e));
        };
    }
}

// ----------------------------------------------------------------------------
#[async_trait]
/// Interface to Hunter database client, e.g. MongoDB or Zou/Kitsu.
pub trait DbConnect: DynClone + fmt::Debug + Send + Sync {
    /// Retries connection, maybe by reading config file and reconstructs internal data all over again.
    async fn try_connect(&mut self) -> Result<(), DatabaseError>;

    /// Gets names of all the databases.
    async fn list_all_productions(&self) -> Result<Vec<Project>, DatabaseError>;

    /// Gets names of all the projects under Pan-project Umbrella.
    async fn list_panproject_members(
        &self,
        pp_umbrella: Option<String>,
    ) -> Result<Vec<Project>, DatabaseError>;
}

dyn_clone::clone_trait_object!(DbConnect);

// ----------------------------------------------------------------------------
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, PartialOrd, Ord)]
/// Three states a thing which allows for editing should have.
pub enum MediaMode {
    #[default]
    Read,
    WriteSuggest,
    WriteCompose,
    WriteEdit,
}

#[derive(Debug, Clone, Default, PartialEq, Eq, strum::AsRefStr, strum::EnumIter)]
pub enum Genesis {
    #[default]
    Create,
    Update,
    Delete,
}

#[cfg(feature = "gui")]
pub fn genesis_stage_options_ui(ui: &mut egui::Ui, mode: &mut Genesis) {
    ui.horizontal(|ui| {
        for m in Genesis::iter() {
            ui.selectable_value(
                mode,
                m.clone(),
                RichText::new(m.as_ref()).text_style(TextStyle::Heading),
            );
        }
    });
}

// ----------------------------------------------------------------------------
#[derive(Debug, Clone, Default, PartialEq, Eq, strum::AsRefStr, strum::EnumIter)]
pub enum GenesisSimple {
    Create,
    #[default]
    Edit,
}

#[cfg(feature = "gui")]
pub fn genesis_simple_options_ui(ui: &mut egui::Ui, mode: &mut GenesisSimple) {
    ui.horizontal(|ui| {
        for m in GenesisSimple::iter() {
            ui.selectable_value(
                mode,
                m.clone(),
                RichText::new(m.as_ref()).text_style(TextStyle::Heading),
            );
        }
    });
}

// ----------------------------------------------------------------------------
/// Something which shows different UI depending on its internal `MediaMode` value.
pub trait ReadWriteSuggest {
    /// A thing that invites users to its authoring.
    fn write_suggest() -> Self;

    /// Builder which should mutate a `MediaMode`.
    fn with_mode(self, mode: MediaMode) -> Self;

    /// Its current `MediaMode` getter.
    fn mode(&self) -> &MediaMode;

    #[allow(unused_variables)]
    /// Its current `MediaMode` setter. Optional.
    fn mode_mut(&mut self, mode: MediaMode) {}

    #[cfg(feature = "gui")]
    /// UI for display only. Optional.
    fn read_mode_ui(&mut self, _ui: &mut egui::Ui) {}

    #[cfg(feature = "gui")]
    /// UI that suggests for composing, e.g. a "âž• New" button. Optinal.
    fn write_suggest_ui(&mut self, _ui: &mut egui::Ui) {}

    #[cfg(feature = "gui")]
    /// UI for actual composing process. Optional.
    fn write_compose_ui(&mut self, _ui: &mut egui::Ui) {}

    #[cfg(feature = "gui")]
    /// UI for editing existing data. Optional.
    fn write_edit_ui(&mut self, _ui: &mut egui::Ui) {}
}

// ----------------------------------------------------------------------------
#[derive(Debug, Clone)]
pub enum ReadState {
    Read,
    Unread,
}

#[derive(Debug, Clone)]
pub enum InstantiationState {
    Instantiated,
    Uninstantiated,
}

// ----------------------------------------------------------------------------
#[derive(Debug, Clone, Default, PartialEq, strum::AsRefStr, strum::EnumIter)]
#[cfg_attr(feature = "persistence", derive(Serialize, Deserialize))]
/// Format of date and time.
pub enum ChronoFormat {
    #[default]
    #[strum(serialize = "Day-M-Y")]
    DayMonthYear,

    #[strum(serialize = "Month-D-Y")]
    MonthDayYear,

    #[strum(serialize = "Year-M-D")]
    YearMonthDay,
}

impl ChronoFormat {
    pub fn to_format_str(&self) -> &str {
        match self {
            ChronoFormat::DayMonthYear => DAY_MONTH_YEAR_FORMAT,
            ChronoFormat::MonthDayYear => MONTH_DAY_YEAR_FORMAT,
            ChronoFormat::YearMonthDay => YEAR_MONTH_DAY_FORMAT,
        }
    }
}

// ----------------------------------------------------------------------------
#[derive(Debug, Clone, Default)]
pub enum CreatedAtOrdering {
    #[default]
    NewestFirst,
    OldestFirst,
}

// -------------------------------------------------------------------------------
#[derive(Debug, Clone, Default, PartialEq, Eq, strum::AsRefStr, strum::EnumIter)]
pub enum FilterOp {
    #[strum(serialize = "All (AND)")]
    All,

    #[default]
    #[strum(serialize = "Any (OR)")]
    Any,
}

impl FilterOp {
    pub fn hint(&self) -> &str {
        match &self {
            FilterOp::All => "Intersection",
            FilterOp::Any => "Union",
        }
    }

    #[cfg(feature = "gui")]
    fn hover_text(&self) -> &str {
        match &self {
            FilterOp::All => "\"Intersection\" behaviour",
            FilterOp::Any => "\"Union\" behaviour",
        }
    }
}

#[cfg(feature = "gui")]
pub fn filter_operation_options_ui(op: &mut FilterOp, ui: &mut egui::Ui) {
    for p in FilterOp::iter() {
        ui.selectable_value(op, p.clone(), p.as_ref())
            .on_hover_text(p.hover_text());
    }
}

// ----------------------------------------------------------------------------
#[derive(Debug, Clone, Default, PartialEq)]
pub enum DetailLevel {
    #[default]
    Stub,
    Full,
}

// ----------------------------------------------------------------------------
/// Version of a file.
/// LEGACY DESIGN: old version-control system.
#[derive(Debug, Clone, PartialEq)]
pub enum VcsLiteVersion {
    V(u16),
    Last,
}

impl VcsLiteVersion {
    pub fn as_str(&self) -> String {
        format!("{}", self)
    }
}

/// LEGACY DESIGN: DO NOT change display outputs.
impl fmt::Display for VcsLiteVersion {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        let version = match self {
            VcsLiteVersion::V(num) => format!("{:>3}", num),
            VcsLiteVersion::Last => "last".to_string(),
        };
        write!(f, "{}", version)
    }
}

// ----------------------------------------------------------------------------
#[derive(Debug, Clone, PartialEq, Eq, strum::AsRefStr)]
/// Phases of work in the old animation pipeline at Virtuos-SPARX*.
/// Most of the time the variants relevant to Asset Department are
/// `Self::Wip`, `Self::Review`, and `Self::Render`.
/// LEGACY DESIGN: old version-control system.
pub enum VcsLiteSession {
    #[strum(serialize = "WIP")]
    Wip,
    Review,
    Draft,
    Full,
    Ingest,
    Store,
    Publish,
    Render,
}

// ----------------------------------------------------------------------------
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "mongo", derive(Serialize, Deserialize))]
pub struct HtmlLink {
    text: String,
    href: String,
}

// ----------------------------------------------------------------------------
pub trait CacheClear {
    fn clear_cache(&mut self) {}
}

// #[cfg(test)]
// mod tests {}