Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maniac Patch: Implement Load, Save, SaveInfo and Mouse input #2623

Merged
merged 9 commits into from
Sep 13, 2021
39 changes: 39 additions & 0 deletions src/async_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class AsyncOp {
eToTitle,
eExitGame,
eTerminateBattle,
eSave,
eLoad
};

AsyncOp() = default;
Expand All @@ -64,6 +66,12 @@ class AsyncOp {
/** @return a TerminateBattle async operation */
static AsyncOp MakeTerminateBattle(int result);

/** @return a Save async operation */
static AsyncOp MakeSave(int save_slot, int save_result_var);

/** @return a Load async operation */
static AsyncOp MakeLoad(int save_slot);

/** @return the type of async operation */
Type GetType() const;

Expand Down Expand Up @@ -100,6 +108,18 @@ class AsyncOp {
**/
int GetBattleResult() const;

/**
* @return the desired slot to save or load
* @pre If GetType() is not eSave or eLoad, the return value is undefined.
**/
int GetSaveSlot() const;

/**
* @return the variable to set to 1 when the save was a success.
* @pre If GetType() is not eSave, the return value is undefined.
**/
int GetSaveResultVar() const;

private:
Type _type = eNone;
int _args[3] = {};
Expand Down Expand Up @@ -142,6 +162,17 @@ inline int AsyncOp::GetBattleResult() const {
return _args[0];
}

inline int AsyncOp::GetSaveSlot() const {
assert(GetType() == eSave || GetType() == eLoad);
return _args[0];
}

inline int AsyncOp::GetSaveResultVar() const {
assert(GetType() == eSave);
return _args[1];
}


template <typename... Args>
inline AsyncOp::AsyncOp(Type type, Args&&... args)
: _type(type), _args{std::forward<Args>(args)...}
Expand Down Expand Up @@ -175,5 +206,13 @@ inline AsyncOp AsyncOp::MakeTerminateBattle(int transition_type) {
return AsyncOp(eTerminateBattle, transition_type);
}

inline AsyncOp AsyncOp::MakeSave(int save_slot, int save_result_var) {
return AsyncOp(eSave, save_slot, save_result_var);
}

inline AsyncOp AsyncOp::MakeLoad(int save_slot) {
return AsyncOp(eLoad, save_slot);
}

#endif

Loading