Extension to parse text for image path

This commit is contained in:
PabstMirror 2015-05-03 13:44:02 -05:00
parent 5c556647ab
commit bdc967d3a9
5 changed files with 69 additions and 3 deletions

BIN
ace_parse_imagepath.dll Normal file

Binary file not shown.

View File

@ -68,7 +68,7 @@ for "_index" from 0 to ((count _configPath) - 1) do {
_actionMaxDistance = _actionMaxDistance + 0.5; //increase range slightly
_iconImage = "";
//todo: extension? (~75% of time doing this string shit!)
/* //todo: extension? (~75% of time doing this string shit!)
if (_actionDisplayNameDefault != "") then {
//something like: "<img image='\A3\Ui_f\data\IGUI\Cfg\Actions\open_door_ca.paa' size='2.5' />";
//find the end [.paa']
@ -84,8 +84,10 @@ for "_index" from 0 to ((count _configPath) - 1) do {
};
_startIndex = _startIndex - 1;
};
};
}; */
_iconImage = "ace_parse_imagepath" callExtension _actionDisplayNameDefault;
_actionOffset = [_actionPosition] call _fnc_getMemPointOffset;
_memPointIndex = _memPoints find _actionPosition;

View File

@ -57,5 +57,6 @@ set(GLOBAL_SOURCES ${GLOBAL_RC})
add_subdirectory(fcs)
add_subdirectory(break_line)
add_subdirectory(advanced_ballistics)
add_subdirectory(parse_imagepath)
message("Build Type: ${CMAKE_BUILD_TYPE}")

View File

@ -0,0 +1,11 @@
set(ACE_EXTENSION_NAME "ace_parse_imagepath")
file(GLOB SOURCES *.h *.hpp *.c *.cpp)
add_library( ${ACE_EXTENSION_NAME} SHARED ${GLOBAL_SOURCES} ${SOURCES})
add_dependencies(${ACE_EXTENSION_NAME} ace_common)
SET_TARGET_PROPERTIES(${ACE_EXTENSION_NAME} PROPERTIES PREFIX "")
if(CMAKE_COMPILER_IS_GNUCXX)
set_target_properties(${ACE_EXTENSION_NAME} PROPERTIES LINK_SEARCH_START_STATIC 1)
set_target_properties(${ACE_EXTENSION_NAME} PROPERTIES LINK_SEARCH_END_STATIC 1)
endif()

View File

@ -0,0 +1,52 @@
/*
* ace_parse_imagepath.cpp
* Author: PabstMirror
* Gets raw image path from structured text input.
*
* Takes:
* Structured text that usualy has an image:
* Example: "<img image='\A3\Ui_f\data\IGUI\Cfg\Actions\open_door_ca.paa' size='2.5' />";
*
* Returns:
* Just the image path or "" if none
*/
#include "ace_common.h"
#include <sstream>
#include <string>
extern "C" {
__declspec (dllexport) void __stdcall RVExtension(char *output, int outputSize, const char *function);
};
std::string getImagePathFromStructuredText(const std::string & input) {
std::string returnValue = "";
std::size_t endIndex = input.find(".paa");
std::size_t startIndex = endIndex - 1;
if ((endIndex != std::string::npos) && (endIndex > 1)) {
endIndex = endIndex + 4;
while ((startIndex > 0) && (returnValue == "")) {
if ((input[startIndex]) == '\'') {
returnValue = input.substr((startIndex + 1), (endIndex - startIndex - 1));
};
startIndex = startIndex - 1;
};
};
return returnValue;
}
// i like to live dangerously. jk, fix strncpy sometime pls.
#pragma warning( push )
#pragma warning( disable : 4996 )
void __stdcall RVExtension(char *output, int outputSize, const char *function) {
if (!strcmp(function, "version")) {
strncpy(output, ACE_FULL_VERSION_STR, outputSize);
} else {
strncpy(output, getImagePathFromStructuredText(function).c_str(), outputSize);
output[outputSize - 1] = '\0';
}
}
#pragma warning( pop )