Simplify content controls and add vehicle roles; record Workshop 0.0.144
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
Discover installed mod vehicles and save independent garage, traffic, patrol and convoy assignments. Retire the superseded RHS 1.9 overrides. Include native menu, crew/driving and publication evidence.
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
"""Exercise per-admin catalog navigation; discovery itself is checked natively."""
|
||||
from policy_harness import ROOT, body, run
|
||||
core=ROOT/'addons/core/Scripts/Game/ERR/00_Core'
|
||||
s=body(core/'ERR_AdminSession.c','protected bool ItemCatalogCommand(')
|
||||
s=body(core/'ERR_AdminSession.c','protected bool ItemCatalogCommand(')+'\n'+body(core/'ERR_AdminSession.c','protected bool VehicleCatalogCommand(')
|
||||
for a,b in [('protected ',''),('array<string> replies','Array<string>& replies'),('array<string> parts','Array<string> parts'),('ERR_ServerItemCatalog catalog','Catalog* catalog'),('GetGame().ERR_ServerItems()','GetCatalog()'),('GetGame().ERR_ItemSelections().','preferences.'),('catalog.','catalog->'),('ERR_CommandArguments.Integer','Integer')]:s=s.replace(a,b)
|
||||
s=s.replace('query.Length()', 'int(query.size())').replace('ERR_ServerVehicleCatalog catalog', 'Catalog* catalog').replace('GetGame().ERR_ServerVehicles()', 'GetCatalog()')
|
||||
run(r'''
|
||||
#include <cassert>
|
||||
#include <string>
|
||||
@@ -10,12 +11,12 @@ run(r'''
|
||||
#include <sstream>
|
||||
struct string;
|
||||
template<class T>struct Array:std::vector<T>{using std::vector<T>::vector;bool IsEmpty(){return this->empty();}int Count(){return this->size();}void Insert(T x){this->push_back(x);}};
|
||||
struct string:std::string{using std::string::string;string(std::string s):std::string(s){}void Split(string,Array<string>& out,bool){std::istringstream in(*this);std::string word;while(in>>word)out.push_back(word);}};
|
||||
struct Catalog{bool Contains(string a,string i){return a=="loaded-a"&&i=="known-item";}void Start(void*){}bool Find(string s){return s=="loaded-a"||s=="loaded-b";}} catalog;
|
||||
struct string:std::string{using std::string::string;string(std::string s):std::string(s){}bool IsEmpty(){return empty();}void Split(string,Array<string>& out,bool){std::istringstream in(*this);std::string word;while(in>>word)out.push_back(word);}};
|
||||
struct Catalog{bool Contains(string a,string i){return a=="loaded-a"&&i=="known-item";}bool Capable(string i,int r){return i=="known-item"&&r!=4;}void Start(void* unused=nullptr){}bool Find(string s){return s=="loaded-a"||s=="loaded-b";}} catalog;
|
||||
Catalog* GetCatalog(){return &catalog;}
|
||||
bool Integer(string s,int& n){try{size_t p;n=std::stoi(s,&p);return p==s.size();}catch(...){return false;}}
|
||||
struct Preferences{int edits=0;bool Preset(string action,string name){edits++;return action=="save"&&name=="test";}bool Set(string,string,bool){edits++;return true;}bool SetWeight(string,string,int){edits++;return true;}} preferences;
|
||||
struct Session{void* m_Mode=nullptr;string m_ItemAddon;int m_ItemPage=0;
|
||||
struct Preferences{int edits=0;bool Preset(string action,string name){edits++;return action=="save"&&name=="test";}bool Set(string,string,bool){edits++;return true;}bool SetVehicleRole(string,string,int,bool){edits++;return true;}bool SetSwitch(string,string,bool){edits++;return true;}bool SetWeight(string,string,int){edits++;return true;}} preferences;
|
||||
struct Session{void* m_Mode=nullptr;string m_ItemAddon;int m_ItemPage=0,m_ItemFilter=0;string m_ItemQuery,m_VehicleAddon,m_VehicleQuery;int m_VehiclePage=0,m_VehicleFilter=0,m_VehicleRole=0;
|
||||
''' + s + r'''
|
||||
};
|
||||
int main(){Session a,b;Array<string> replies;
|
||||
@@ -36,6 +37,21 @@ int main(){Session a,b;Array<string> replies;
|
||||
a.ItemCatalogCommand("items weight loaded-a * 100",replies);assert(preferences.edits==4);
|
||||
a.ItemCatalogCommand("items weight loaded-a known-item 0",replies);assert(preferences.edits==5);
|
||||
assert(a.m_ItemAddon=="loaded-a"&&a.m_ItemPage==0);
|
||||
a.ItemCatalogCommand("items browse loaded-a 2 2 first aid",replies);
|
||||
assert(a.m_ItemPage==2&&a.m_ItemFilter==2&&a.m_ItemQuery=="first aid");
|
||||
a.VehicleCatalogCommand("vehicles browse loaded-b 1 1 2 red",replies);
|
||||
assert(a.m_VehicleAddon=="loaded-b"&&a.m_VehiclePage==1&&a.m_VehicleQuery=="red"&&a.m_ItemAddon=="loaded-a");
|
||||
b.VehicleCatalogCommand("vehicles browse loaded-a 0 0 1",replies);assert(a.m_VehicleAddon=="loaded-b");
|
||||
a.VehicleCatalogCommand("vehicles role unknown 0 * 0",replies);assert(preferences.edits==5);
|
||||
a.VehicleCatalogCommand("vehicles role loaded-a 0 unknown-item 0",replies);assert(preferences.edits==5);
|
||||
a.ItemCatalogCommand("items browse loaded-a 2 3",replies);assert(a.m_ItemFilter==2);
|
||||
a.ItemCatalogCommand("items mod loaded-a 0",replies);assert(preferences.edits==6);
|
||||
a.ItemCatalogCommand("items mod unknown 0",replies);assert(preferences.edits==6);
|
||||
a.VehicleCatalogCommand("vehicles role loaded-a 2 known-item 0",replies);assert(preferences.edits==7);
|
||||
for(string bad:{"vehicles role loaded-a 4 known-item 1","vehicles role loaded-a 5 known-item 1","vehicles role loaded-a -1 * 1","vehicles role loaded-a 2 known-item 2"})a.VehicleCatalogCommand(bad,replies);
|
||||
assert(preferences.edits==7&&a.m_VehicleRole==2&&b.m_VehicleRole==1);
|
||||
a.VehicleCatalogCommand("vehicles browse loaded-a 0 0 5",replies);assert(a.m_VehicleRole==2);
|
||||
a.VehicleCatalogCommand("vehicles role loaded-a 3 * 0",replies);assert(preferences.edits==8);
|
||||
}
|
||||
''')
|
||||
command=body(core/'ERR_AdminSession.c','void Command(')
|
||||
|
||||
Reference in New Issue
Block a user