载入中...
搜索中...
未找到
PcgPhotoModeValues.cpp
浏览该文件的文档.
63 {"m_ambientSkyColor", PcgPhotoModeValueType::Color, PcgPhotoModeValue{PcgPhotoModeColor{0.7027151f,0.881016f,1.001631f,0.4192761f}}},
64 {"m_ambientEquatorColor", PcgPhotoModeValueType::Color, PcgPhotoModeValue{PcgPhotoModeColor{0.6302439f,0.7919513f,0.85f,0.0f}}},
65 {"m_ambientGroundColor", PcgPhotoModeValueType::Color, PcgPhotoModeValue{PcgPhotoModeColor{0.5f,0.4142857f,0.3321428f,0.0f}}},
73 {"m_pcgUnderwaterFogColor", PcgPhotoModeValueType::Color, PcgPhotoModeValue{PcgPhotoModeColor{0,0,0,1}}},
103 {"m_densityVolumeAlbedoColor", PcgPhotoModeValueType::Color, PcgPhotoModeValue{PcgPhotoModeColor{1,1,1,1}}},
112const PcgPhotoModeField* field(const std::string&n){for(const auto&f:fields())if(f.name==n)return &f;return nullptr;}
113template<class T> Result<void> setTyped(std::unordered_map<std::string,PcgPhotoModeValue>&v,const std::string&n,PcgPhotoModeValueType t,T x){auto*f=field(n);if(!f)return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,"unknown photo-mode field: "+n,{}, {},"ui.pcgPhotoModeValues"));if(f->type!=t)return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,"photo-mode field type mismatch: "+n,{}, {},"ui.pcgPhotoModeValues"));v[n]=std::move(x);return Result<void>::success();}
114template<class T> Result<T> getTyped(const std::unordered_map<std::string,PcgPhotoModeValue>&v,const std::string&n,PcgPhotoModeValueType t){auto*f=field(n);if(!f)return Result<T>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,"unknown photo-mode field: "+n,{}, {},"ui.pcgPhotoModeValues"));if(f->type!=t)return Result<T>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,"photo-mode field type mismatch: "+n,{}, {},"ui.pcgPhotoModeValues"));return Result<T>::success(std::get<T>(v.at(n)));}
117void PcgPhotoModeValues::resetDefaults(){std::unordered_map<std::string,PcgPhotoModeValue> next;for(const auto&f:fields())next.emplace(f.name,f.defaultValue);values_=std::move(next);selectedColor_={};}
119Result<std::string> PcgPhotoModeValues::getFieldName(uint64_t i)const{if(i>=fields().size())return Result<std::string>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,"photo-mode field index is out of range",{}, {},"ui.pcgPhotoModeValues"));return Result<std::string>::success(fields()[i].name);}
120Result<int> PcgPhotoModeValues::getFieldType(const std::string&n)const{auto*f=field(n);if(!f)return Result<int>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,"unknown photo-mode field: "+n,{}, {},"ui.pcgPhotoModeValues"));return Result<int>::success(static_cast<int>(f->type));}
121Result<void> PcgPhotoModeValues::setBool(const std::string&n,bool v){return setTyped(values_,n,PcgPhotoModeValueType::Bool,v);}
122Result<void> PcgPhotoModeValues::setInt(const std::string&n,int64_t v){return setTyped(values_,n,PcgPhotoModeValueType::Int,v);}
123Result<void> PcgPhotoModeValues::setFloat(const std::string&n,float v){if(!std::isfinite(v))return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,"photo-mode float must be finite",{}, {},"ui.pcgPhotoModeValues"));return setTyped(values_,n,PcgPhotoModeValueType::Float,v);}
124Result<void> PcgPhotoModeValues::setString(const std::string&n,const std::string&v){return setTyped(values_,n,PcgPhotoModeValueType::String,v);}
125Result<void> PcgPhotoModeValues::setColor(const std::string&n,float r,float g,float b,float a){if(!std::isfinite(r)||!std::isfinite(g)||!std::isfinite(b)||!std::isfinite(a))return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,"photo-mode color must be finite",{}, {},"ui.pcgPhotoModeValues"));return setTyped(values_,n,PcgPhotoModeValueType::Color,PcgPhotoModeColor{r,g,b,a});}
126Result<bool> PcgPhotoModeValues::getBool(const std::string&n)const{return getTyped<bool>(values_,n,PcgPhotoModeValueType::Bool);}
127Result<int64_t> PcgPhotoModeValues::getInt(const std::string&n)const{return getTyped<int64_t>(values_,n,PcgPhotoModeValueType::Int);}
128Result<float> PcgPhotoModeValues::getFloat(const std::string&n)const{return getTyped<float>(values_,n,PcgPhotoModeValueType::Float);}
129Result<std::string> PcgPhotoModeValues::getString(const std::string&n)const{return getTyped<std::string>(values_,n,PcgPhotoModeValueType::String);}
130Result<PcgPhotoModeValue> PcgPhotoModeValues::getValue(const std::string&n)const{if(!field(n))return Result<PcgPhotoModeValue>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,"unknown photo-mode field: "+n,{}, {},"ui.pcgPhotoModeValues"));return Result<PcgPhotoModeValue>::success(values_.at(n));}
131Result<void> PcgPhotoModeValues::selectColor(const std::string&n){auto r=getTyped<PcgPhotoModeColor>(values_,n,PcgPhotoModeValueType::Color);if(!r)return Result<void>::failure(*r.error());selectedColor_=r.value();return Result<void>::success();}
139 case PcgPhotoModeValueType::Color:{auto c=std::get<PcgPhotoModeColor>(v);encoded[f.name]=Value::Array{double(c.r),double(c.g),double(c.b),double(c.a)};break;}}}
140 return Value(Value::Object{{"schema","eve.ui.pcg-photo-mode-values"},{"values",std::move(encoded)},{"version",int64_t{1}}}).toJson();
143 if(json.size()>1024U*1024U)return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,"photo-mode values JSON exceeds size limit",{}, {},"ui.pcgPhotoModeValues"));
146 const auto*root=decoded.value().getIf<Value::Object>();if(!root||root->size()!=3||!root->contains("schema")||!root->contains("version")||!root->contains("values"))return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,"photo-mode values has missing or unknown root fields",{}, {},"ui.pcgPhotoModeValues"));
147 const auto*schema=root->at("schema").getIf<std::string>();const auto*version=root->at("version").getIf<int64_t>();const auto*object=root->at("values").getIf<Value::Object>();if(!schema||*schema!="eve.ui.pcg-photo-mode-values"||!version||*version!=1||!object||object->size()!=fields().size())return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,"photo-mode values has unsupported schema, version or field count",{}, {},"ui.pcgPhotoModeValues"));
148 PcgPhotoModeValues candidate;for(const auto&f:fields()){if(!object->contains(f.name))return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,"photo-mode values is missing field: "+f.name,{}, {},"ui.pcgPhotoModeValues"));const auto&v=object->at(f.name);switch(f.type){
149 case PcgPhotoModeValueType::Bool:{auto*x=v.getIf<bool>();if(!x)return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,"invalid bool field: "+f.name,{}, {},"ui.pcgPhotoModeValues"));candidate.values_[f.name]=*x;break;}
150 case PcgPhotoModeValueType::Int:{auto*x=v.getIf<int64_t>();if(!x)return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,"invalid int field: "+f.name,{}, {},"ui.pcgPhotoModeValues"));candidate.values_[f.name]=*x;break;}
151 case PcgPhotoModeValueType::Float:{auto*x=v.getIf<double>();if(!x||!std::isfinite(*x)||*x>std::numeric_limits<float>::max()||*x<-std::numeric_limits<float>::max())return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,"invalid float field: "+f.name,{}, {},"ui.pcgPhotoModeValues"));candidate.values_[f.name]=float(*x);break;}
152 case PcgPhotoModeValueType::String:{auto*x=v.getIf<std::string>();if(!x)return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,"invalid string field: "+f.name,{}, {},"ui.pcgPhotoModeValues"));candidate.values_[f.name]=*x;break;}
153 case PcgPhotoModeValueType::Color:{auto*x=v.getIf<Value::Array>();if(!x||x->size()!=4)return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,"invalid color field: "+f.name,{}, {},"ui.pcgPhotoModeValues"));double c[4];for(int i=0;i<4;++i){auto*n=(*x)[i].getIf<double>();if(!n||!std::isfinite(*n))return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,"invalid color component: "+f.name,{}, {},"ui.pcgPhotoModeValues"));c[i]=*n;}candidate.values_[f.name]=PcgPhotoModeColor{float(c[0]),float(c[1]),float(c[2]),float(c[3])};break;}}
156void exposePcgPhotoModeValuesBindings(ssq::Table&t){auto vm=t.getHandle();auto c=t.addClass("PcgPhotoModeValues",ssq::Class::Ctor<PcgPhotoModeValues()>());c.addFunc("resetDefaults",[](PcgPhotoModeValues*s){s->resetDefaults();});c.addFunc("getFieldCount",[](const PcgPhotoModeValues*s){return s->getFieldCount();});c.addFunc("getFieldName",[vm](const PcgPhotoModeValues*s,uint64_t i){return eve::script::projectResult(vm,s->getFieldName(i),[](const std::string&v){return v;});});c.addFunc("getFieldType",[vm](const PcgPhotoModeValues*s,const std::string&n){return eve::script::projectResult(vm,s->getFieldType(n),[](int v){return v;});});c.addFunc("setBool",[vm](PcgPhotoModeValues*s,const std::string&n,bool v){return eve::script::projectResult(vm,s->setBool(n,v));});c.addFunc("setInt",[vm](PcgPhotoModeValues*s,const std::string&n,int64_t v){return eve::script::projectResult(vm,s->setInt(n,v));});c.addFunc("setFloat",[vm](PcgPhotoModeValues*s,const std::string&n,float v){return eve::script::projectResult(vm,s->setFloat(n,v));});c.addFunc("setString",[vm](PcgPhotoModeValues*s,const std::string&n,const std::string&v){return eve::script::projectResult(vm,s->setString(n,v));});c.addFunc("setColor",[vm](PcgPhotoModeValues*s,const std::string&n,float r,float g,float b,float a){return eve::script::projectResult(vm,s->setColor(n,r,g,b,a));});c.addFunc("getBool",[vm](const PcgPhotoModeValues*s,const std::string&n){return eve::script::projectResult(vm,s->getBool(n),[](bool v){return v;});});c.addFunc("getInt",[vm](const PcgPhotoModeValues*s,const std::string&n){return eve::script::projectResult(vm,s->getInt(n),[](int64_t v){return v;});});c.addFunc("getFloat",[vm](const PcgPhotoModeValues*s,const std::string&n){return eve::script::projectResult(vm,s->getFloat(n),[](float v){return v;});});c.addFunc("getString",[vm](const PcgPhotoModeValues*s,const std::string&n){return eve::script::projectResult(vm,s->getString(n),[](const std::string&v){return v;});});c.addFunc("selectColor",[vm](PcgPhotoModeValues*s,const std::string&n){return eve::script::projectResult(vm,s->selectColor(n));});c.addFunc("snapshotJson",[vm](const PcgPhotoModeValues*s){return eve::script::projectResult(vm,s->snapshotJson(),[](const std::string&v){return v;});});c.addFunc("restoreJson",[vm](PcgPhotoModeValues*s,const std::string&v){return eve::script::projectResult(vm,s->restoreJson(v));});c.addFunc("getColorR",[](const PcgPhotoModeValues*s){return s->getColorR();});c.addFunc("getColorG",[](const PcgPhotoModeValues*s){return s->getColorG();});c.addFunc("getColorB",[](const PcgPhotoModeValues*s){return s->getColorB();});c.addFunc("getColorA",[](const PcgPhotoModeValues*s){return s->getColorA();});}
The single Squirrel projection for common Result, Status and Value.
Owning, renderer-independent dynamic values.
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
static Result< Value > fromJson(std::string_view json)
Parse one strict JSON value into an owning Value.
Definition Value.cpp:57
Complete typed value set from Pcg PhotoModeProfile with exact defaults.
Definition PcgPhotoModeValues.h:20
Result< int > getFieldType(const std::string &name) const
Return field type: bool=0, int=1, float=2, string=3, color=4.
Definition PcgPhotoModeValues.cpp:120
Result< bool > getBool(const std::string &name) const
Read a typed boolean field.
Definition PcgPhotoModeValues.cpp:126
Result< void > setBool(const std::string &name, bool value)
Set a typed boolean field.
Definition PcgPhotoModeValues.cpp:121
Result< void > restoreJson(const std::string &json)
Atomically restore schema 1 JSON; unknown or missing fields are rejected.
Definition PcgPhotoModeValues.cpp:142
uint64_t getFieldCount() const noexcept
Return stable schema field count.
Definition PcgPhotoModeValues.cpp:118
Result< std::string > snapshotJson() const
Encode schema 1 JSON containing every field.
Definition PcgPhotoModeValues.cpp:132
Result< float > getFloat(const std::string &name) const
Read a typed float field.
Definition PcgPhotoModeValues.cpp:128
Result< int64_t > getInt(const std::string &name) const
Read a typed integer field.
Definition PcgPhotoModeValues.cpp:127
Result< PcgPhotoModeValue > getValue(const std::string &name) const
Read a field as its schema-declared native variant.
Definition PcgPhotoModeValues.cpp:130
Result< void > setString(const std::string &name, const std::string &value)
Set a typed string field.
Definition PcgPhotoModeValues.cpp:124
Result< void > selectColor(const std::string &name)
Select a color field for component reads.
Definition PcgPhotoModeValues.cpp:131
Result< void > setColor(const std::string &name, float r, float g, float b, float a)
Set a finite typed RGBA field.
Definition PcgPhotoModeValues.cpp:125
Result< void > setFloat(const std::string &name, float value)
Set a finite typed float field.
Definition PcgPhotoModeValues.cpp:123
Result< void > setInt(const std::string &name, int64_t value)
Set a typed integer or enum field.
Definition PcgPhotoModeValues.cpp:122
Result< std::string > getFieldName(uint64_t index) const
Return schema field name by declaration order.
Definition PcgPhotoModeValues.cpp:119
Result< std::string > getString(const std::string &name) const
Read a typed string field.
Definition PcgPhotoModeValues.cpp:129
const EditorValue * field(const EditorValue &value, const char *name)
Definition RoadNetworkEditTarget.cpp:15
ssq::Table projectResult(HSQUIRRELVM vm, Result< void > &&result)
Consume and project a void native Result using the common schema.
Definition SquirrelBinding.cpp:470
Definition Component.cpp:5
void exposePcgPhotoModeValuesBindings(ssq::Table &t)
Register complete Pcg photo-mode value bindings.
Definition PcgPhotoModeValues.cpp:156
std::variant< bool, int64_t, float, std::string, PcgPhotoModeColor > PcgPhotoModeValue
Definition PcgPhotoModeValues.h:16
@ InvalidArgument