MCPcopy Create free account
hub / github.com/TheForceEngine/TheForceEngine / setVariableValue

Function setVariableValue

TheForceEngine/TFE_FrontEndUI/console.cpp:673–722  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

671 }
672
673 void setVariableValue(CVar* var, const char* value)
674 {
675 if (!var->valuePtr)
676 {
677 char errorMsg[CSTR_LEN];
678 sprintf(errorMsg, "set - Variable not initialized \"%s\"", var->name.c_str());
679 s_history.push_back({ c_historyErrorColor, errorMsg });
680 return;
681 }
682
683 char* endPtr;
684 char msg[CSTR_LEN];
685 msg[0] = 0;
686
687 switch (var->type)
688 {
689 case CVAR_INT:
690 *var->valueInt = strtol(value, &endPtr, 10);
691 sprintf(msg, "set %s = %d", var->name.c_str(), *var->valueInt);
692 break;
693 case CVAR_FLOAT:
694 *var->valueFloat = (f32)strtod(value, &endPtr);
695 sprintf(msg, "set %s = %f", var->name.c_str(), *var->valueFloat);
696 break;
697 case CVAR_BOOL:
698 if (strcasecmp(value, "true") == 0)
699 {
700 *var->valueBool = true;
701 }
702 else if (strcasecmp(value, "false") == 0)
703 {
704 *var->valueBool = false;
705 }
706 else
707 {
708 s32 intValue = strtol(value, &endPtr, 10);
709 *var->valueBool = intValue != 0;
710 }
711 sprintf(msg, "set %s = %s", var->name.c_str(), *var->valueBool ? "true" : "false");
712 break;
713 case CVAR_STRING:
714 const size_t sizeToCopy = std::min(strlen(value), (size_t)var->maxLen);
715 strncpy(var->valueString, value, sizeToCopy);
716 var->valueString[sizeToCopy] = 0;
717 sprintf(msg, "set %s = \"%s\"", var->name.c_str(), var->valueString);
718 break;
719 };
720
721 s_history.push_back({ c_historyDefaultColor, msg });
722 }
723
724 void setVariable(const char* name, const char* value)
725 {

Callers 1

setVariableFunction · 0.85

Calls 3

minFunction · 0.85
c_strMethod · 0.80
push_backMethod · 0.80

Tested by

no test coverage detected