mirror of
https://github.com/isledecomp/isle.git
synced 2024-11-26 01:28:30 -05:00
lego: fix/match SetColorString (#72)
* lego: fix/match SetColorString * explicitly cast to float to avoid warning * style fixes * remove superfluous includes * Update legobackgroundcolor.cpp
This commit is contained in:
parent
9415bd18bb
commit
d64a04705c
2 changed files with 38 additions and 41 deletions
|
@ -4,53 +4,50 @@
|
||||||
#include "legoutil.h"
|
#include "legoutil.h"
|
||||||
#include "legovideomanager.h"
|
#include "legovideomanager.h"
|
||||||
|
|
||||||
const char *Delimiter = "\t";
|
const char *g_delimiter = "\t";
|
||||||
const char *set = "set";
|
const char *g_set = "set";
|
||||||
const char *reset = "reset";
|
const char *g_reset = "reset";
|
||||||
|
|
||||||
// OFFSET: LEGO1 0x1003bfb0
|
// OFFSET: LEGO1 0x1003bfb0
|
||||||
LegoBackgroundColor::LegoBackgroundColor(const char *name, const char *colorString)
|
LegoBackgroundColor::LegoBackgroundColor(const char *p_name, const char *p_colorString)
|
||||||
{
|
{
|
||||||
m_name = name;
|
m_name = p_name;
|
||||||
m_name.ToUpperCase();
|
m_name.ToUpperCase();
|
||||||
SetColorString(colorString);
|
SetColorString(p_colorString);
|
||||||
}
|
}
|
||||||
|
|
||||||
// OFFSET: LEGO1 0x1003c070
|
// OFFSET: LEGO1 0x1003c070
|
||||||
void LegoBackgroundColor::SetColorString(const char *colorString)
|
void LegoBackgroundColor::SetColorString(const char *p_colorString)
|
||||||
{
|
{
|
||||||
m_name = colorString;
|
m_string = p_colorString;
|
||||||
m_string.ToLowerCase();
|
m_string.ToLowerCase();
|
||||||
|
|
||||||
float converted_r;
|
|
||||||
float converted_b;
|
|
||||||
float converted_g;
|
|
||||||
LegoVideoManager *videomanager = VideoManager();
|
LegoVideoManager *videomanager = VideoManager();
|
||||||
|
if (!videomanager || !p_colorString)
|
||||||
|
return;
|
||||||
|
|
||||||
|
float converted_r, converted_g, converted_b;
|
||||||
|
char *colorStringCopy = strcpy(new char[strlen(p_colorString) + 1], p_colorString);
|
||||||
|
char *colorStringSplit = strtok(colorStringCopy, g_delimiter);
|
||||||
|
|
||||||
|
if (!strcmp(colorStringSplit, g_set)) {
|
||||||
|
colorStringSplit = strtok(0, g_delimiter);
|
||||||
|
if (colorStringSplit)
|
||||||
|
h = (float) (atoi(colorStringSplit) * 0.01);
|
||||||
|
colorStringSplit = strtok(0, g_delimiter);
|
||||||
|
if (colorStringSplit)
|
||||||
|
s = (float) (atoi(colorStringSplit) * 0.01);
|
||||||
|
colorStringSplit = strtok(0, g_delimiter);
|
||||||
|
if (colorStringSplit)
|
||||||
|
v = (float) (atoi(colorStringSplit) * 0.01);
|
||||||
|
|
||||||
if (videomanager && colorString)
|
|
||||||
{
|
|
||||||
int length = strlen(colorString) + 1;
|
|
||||||
char *colorStringCopy = new char[length];
|
|
||||||
strcpy(colorStringCopy, colorString);
|
|
||||||
char *colorStringSplit = strtok(colorStringCopy, Delimiter);
|
|
||||||
if (!strcmp(colorStringSplit, set))
|
|
||||||
{
|
|
||||||
char *hue = strtok(0, Delimiter);
|
|
||||||
if (hue)
|
|
||||||
h = atoi(hue) * 0.01;
|
|
||||||
char *sat = strtok(0, Delimiter);
|
|
||||||
if (sat)
|
|
||||||
s = atoi(sat) * 0.01;
|
|
||||||
char *val = strtok(0, Delimiter);
|
|
||||||
if (val)
|
|
||||||
v = atoi(val) * 0.01;
|
|
||||||
}
|
|
||||||
else if (!strcmp(colorStringSplit, reset))
|
|
||||||
{
|
|
||||||
// reset it
|
|
||||||
ConvertHSVToRGB(this->h, this->s, this->v, &converted_r, &converted_g, &converted_b);
|
ConvertHSVToRGB(this->h, this->s, this->v, &converted_r, &converted_g, &converted_b);
|
||||||
videomanager->SetSkyColor(converted_r, converted_g, converted_b);
|
videomanager->SetSkyColor(converted_r, converted_g, converted_b);
|
||||||
}
|
}
|
||||||
delete[] colorStringCopy;
|
else if (!strcmp(colorStringSplit, g_reset)) {
|
||||||
|
ConvertHSVToRGB(this->h, this->s, this->v, &converted_r, &converted_g, &converted_b);
|
||||||
|
videomanager->SetSkyColor(converted_r, converted_g, converted_b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete[] colorStringCopy;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
#ifndef LEGOBACKGROUNDCOLOR_H
|
#ifndef LEGOBACKGROUNDCOLOR_H
|
||||||
#define LEGOBACKGROUNDCOLOR_H
|
#define LEGOBACKGROUNDCOLOR_H
|
||||||
#include "mxstring.h"
|
|
||||||
#include "mxcore.h"
|
|
||||||
#include "mxstringvariable.h"
|
#include "mxstringvariable.h"
|
||||||
|
|
||||||
class LegoBackgroundColor : public MxStringVariable
|
class LegoBackgroundColor : public MxStringVariable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
__declspec(dllexport) LegoBackgroundColor(const char *, const char *);
|
__declspec(dllexport) LegoBackgroundColor(const char *p_name, const char *p_colorString);
|
||||||
void SetColorString(const char *colorString);
|
void SetColorString(const char *p_colorString);
|
||||||
protected:
|
|
||||||
|
private:
|
||||||
float h;
|
float h;
|
||||||
float s;
|
float s;
|
||||||
float v;
|
float v;
|
||||||
|
|
Loading…
Reference in a new issue