Bundle mission speech with an admin mute option and fix live audio downloads
This commit is contained in:
@@ -4,10 +4,10 @@ p = ROOT/'addons/core/Scripts/Game/ERR/00_Core/ERR_WelcomeVoice.c'
|
||||
url = body(p, 'static bool URL(')
|
||||
connection = 'class Connection { bool m_Attempted=false; public: ' + '\n'.join(body(p,s) for s in ['void MainMenu()', 'bool Claim()', 'bool Attempted()']) + '};'
|
||||
tick = body(p, 'void Tick(')
|
||||
for old,new in [('m_Connection.', 'm_Connection->'), ('m_Callback.', 'm_Callback->'),
|
||||
for old,new in [('m_Mode.', 'm_Mode->'), ('m_Connection.', 'm_Connection->'), ('m_Callback.', 'm_Callback->'),
|
||||
('context.', 'context->'), ('RestContext context', 'RestContext* context'),
|
||||
('GetGame().GetRestApi().GetContext', 'game.api.GetContext'),
|
||||
('null', 'nullptr'), ('ERR_WelcomeVoiceRules.URL', 'Rules::URL'), ('ERR_WelcomeVoiceRules.HTTPReady', 'Rules::HTTPReady'),
|
||||
('null', 'nullptr'), ('ERR_WelcomeVoiceRules.URL', 'Rules::URL'), ('ERR_WelcomeVoiceRules.HTTPReady', 'Rules::HTTPReady'), ('ERR_WelcomeVoiceRules.Source', 'Rules::Source'), ('ERR_BakedSpeech.Graph', 'ERR_BakedSpeech::Graph'), ('ResourceName', 'string'),
|
||||
('FileIO.DeleteFile', 'FileIO::DeleteFile'), ('LogLevel.WARNING','0')]:
|
||||
tick=tick.replace(old,new)
|
||||
run(r'''
|
||||
@@ -17,8 +17,10 @@ struct string:std::string { using std::string::string; string(std::string s):std
|
||||
bool IsEmpty(){return empty();} int Length(){return size();}
|
||||
int IndexOf(string s){auto p=find(s);return p==npos?-1:int(p);}
|
||||
};
|
||||
struct ERR_BakedSpeech { static string Graph(string value){return value=="baked:welcome"?"bundled.acp":"";} };
|
||||
struct Mode {bool enabled=true;bool ERR_RecordingsEnabled(){return enabled;}} mode;
|
||||
bool httpReady=true;
|
||||
struct Rules { static bool HTTPReady(){return httpReady;} '''+url+r''' };
|
||||
struct Rules { static bool HTTPReady(){return httpReady;} static bool Source(string value){return URL(value)||!ERR_BakedSpeech::Graph(value).IsEmpty();} '''+url+r''' };
|
||||
'''+connection+r'''
|
||||
struct RestCallback { void SetOnSuccess(int){} void SetOnError(int){} };
|
||||
int requests=0;
|
||||
@@ -27,7 +29,11 @@ struct Api { RestContext* GetContext(string){return &context;} };
|
||||
struct Game { Api api; } game;
|
||||
struct FileIO { static void DeleteFile(string){} };
|
||||
void Print(string,int=0){}
|
||||
struct ERR_VoiceTransfer {};
|
||||
struct Client {
|
||||
ERR_VoiceTransfer* m_Transfer=nullptr; string m_DownloadURL,m_BakedGraph;
|
||||
void RequestPart(){requests++;}
|
||||
Mode* m_Mode=&mode;void Stop(){m_Stopped=true;m_Downloaded=false;}
|
||||
Connection* m_Connection; bool m_Stopped=false,m_Downloaded=false,m_Started=false,current=true;
|
||||
float m_Wait=0; string m_Path,m_Text; RestCallback* m_Callback=nullptr; int Downloaded=0,Failed=0,plays=0;
|
||||
Client(Connection* c):m_Connection(c){} ~Client(){delete m_Callback;}
|
||||
@@ -35,6 +41,16 @@ struct Client {
|
||||
'''+tick+r'''
|
||||
};
|
||||
int main(){
|
||||
Connection mutedConnection;Client muted(&mutedConnection);mode.enabled=false;
|
||||
muted.Tick(60,true,"baked:welcome","");assert(!mutedConnection.Attempted()&&!muted.m_Downloaded&&requests==0);
|
||||
mode.enabled=true;muted.Tick(3,true,"baked:welcome","");assert(muted.m_Downloaded);
|
||||
mode.enabled=false;muted.Tick(1,true,"baked:welcome","");assert(muted.m_Stopped&&muted.plays==0);
|
||||
Connection liveConnection;Client live(&liveConnection);live.Tick(3,true,"http://voice/clip","");assert(requests==1);requests=0;
|
||||
mode.enabled=true;
|
||||
Connection local;Client baked(&local);httpReady=false;int before=requests;
|
||||
baked.Tick(3,true,"baked:welcome","Generic welcome");assert(requests==before&&baked.m_Downloaded);
|
||||
baked.Tick(1,false,"baked:welcome","");assert(baked.plays==0);
|
||||
baked.Tick(1,true,"baked:welcome","");assert(baked.plays==1&&requests==before);httpReady=true;
|
||||
Connection connection;
|
||||
Client first(&connection);
|
||||
httpReady=false; first.Tick(60,true,"http://voice/clip", ""); assert(requests==0 && !connection.Attempted()); httpReady=true;
|
||||
|
||||
Reference in New Issue
Block a user