Skip to content

Commit

Permalink
Added texture encoding setting and texture quality selection. Fixed w…
Browse files Browse the repository at this point in the history
…rong transformation of sprites.
  • Loading branch information
Daniil-SV committed Jul 6, 2023
1 parent f5efb3e commit c689c8c
Show file tree
Hide file tree
Showing 21 changed files with 175 additions and 69 deletions.
2 changes: 1 addition & 1 deletion plugin/ThirdParty/SC
Submodule SC updated from 313c8f to 135d24
11 changes: 7 additions & 4 deletions plugin/Workspace.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@ configurations {
include "premake5.lua"
include "UITest/"

group "SC"
include "ThirdParty/SC/dependencies/Compression/"
include "ThirdParty/SC/"

group "SC/Compression"
group "Compression"
include "ThirdParty/SC/dependencies/Compression/dependencies/lzham"
include "ThirdParty/SC/dependencies/Compression/dependencies/lzma"
include "ThirdParty/SC/dependencies/Compression/dependencies/zstd"

group "Compression/Image"
include "ThirdParty/SC/dependencies/TextureLoader/ThirdParty/astc-encoder"
include "ThirdParty/SC/dependencies/TextureLoader/ThirdParty/ETCPACK"

group "Libraries"
include "ThirdParty/AtlasGenerator"
include "ThirdParty/SC/dependencies/Compression/"
include "ThirdParty/SC/"
include "ThirdParty/SC/dependencies/TextureLoader"

38 changes: 10 additions & 28 deletions plugin/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ if (!isWindows && !isMac) {

const args = process.argv;
const isDev = args[2] == "development";
console.log(args[2])
const outputPath = args[3];
mkdirSync(outputPath, { recursive: true });

Expand All @@ -30,15 +29,6 @@ const doctypeId = "com.scwmake.SupercellSWF";
const [MAJOR, MINOR, MAINTENANCE] = version.split(".");

function buildWindows() {
const sharedLibs = !isDev ?
[
"ThirdParty/OpenCV/lib/x86_64/windows/shared/opencv_world470.dll"
]
:
[
"ThirdParty/OpenCV/lib/x86_64/windows/shared/opencv_world470d.dll"
]

const msBuildPath = which.sync("msbuild");
if (msBuildPath.length <= 0) {
throw new Error("Failed to find MSBuild executable");
Expand All @@ -52,7 +42,7 @@ function buildWindows() {
throw new Error("Failed to find premake5 executable");
}

execSync(`generate.bat`, {stdio: [0, 1, 2], cwd: join(__dirname, "scripts")});
execSync(`generate.bat`, { stdio: [0, 1, 2], cwd: join(__dirname, "scripts") });
}

progress("Building with MSBuild...");
Expand All @@ -62,28 +52,18 @@ function buildWindows() {
}

try {
execSync(`"${msBuildPath}" "${solutionPath}" -property:Configuration=${isDev ? "Debug" : "Release"}`, {stdio: [0, 1, 2]})
execSync(`"${msBuildPath}" "${solutionPath}" -property:Configuration=${isDev ? "Debug" : "Release"}`, { stdio: [0, 1, 2] })
} catch (err) {
throw processExecError(err);
}

progress("Done");

if (!isDev) {
const binaryPath = join(__dirname, "bin/win/Plugin.fcm");
if (!binaryPath) {
throw new Error("Failed to get binary");
}

const fcmOutputFolder = join(libPath, "win");
mkdirSync(fcmOutputFolder, { recursive: true });
copyFileSync(binaryPath, join(fcmOutputFolder, "plugin.fcm"));

for (const filepath of sharedLibs) {
copyFileSync(join(__dirname, filepath), join(fcmOutputFolder, basename(filepath)))
}
copyDir(join(__dirname, "bin/win"), join(libPath, "win"))
}


}

function buildMac() {
Expand Down Expand Up @@ -112,10 +92,12 @@ writeFileSync(
)

const dstResourceFolder = join(libPath, "res");
if (isDev) {
makeLink(join(__dirname, "res"), dstResourceFolder);
} else {
copyDir("res", dstResourceFolder)
if (!existsSync(dstResourceFolder)) {
if (isDev) {
makeLink(join(__dirname, "res"), dstResourceFolder);
} else {
copyDir("res", dstResourceFolder)
}
}

if (isWindows) {
Expand Down
9 changes: 9 additions & 0 deletions plugin/include/Module/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ namespace sc {
UnusedMovieclips
};

enum class Quality : uint8_t {
Highest,
High,
Medium,
Low
};

struct Config {
PublisherMode mode = PublisherMode::Export;

Expand All @@ -42,8 +49,10 @@ namespace sc {

bool hasExternalTexture = 0;
uint8_t textureScaleFactor = 1;
Quality textureQuality = Quality::Highest;
uint32_t textureMaxWidth = 2048;
uint32_t textureMaxHeight = 2048;
SWFTexture::TextureEncoding textureEncoding = SWFTexture::TextureEncoding::Raw;

ExportsMode exportsMode = ExportsMode::AllMovieclips;

Expand Down
8 changes: 4 additions & 4 deletions plugin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions plugin/premake5.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,21 @@ filter {"system:windows", "configurations:Debug"}
links {
"ThirdParty/OpenCV/lib/%{cfg.architecture}/%{cfg.system}/static/opencv_world470d"
}
postbuildcommands {
'{COPYFILE} "ThirdParty/OpenCV/lib/%{cfg.architecture}/%{cfg.system}/shared/opencv_world470d.dll" "%{cfg.targetdir}" '
}
targetdir "../dist/com.scwmake.SupercellSWF/Plugin/lib/win"

filter {"system:windows", "configurations:Release"}
links {
"ThirdParty/OpenCV/lib/%{cfg.architecture}/%{cfg.system}/static/opencv_world470"
}
postbuildcommands {
'{COPYFILE} "ThirdParty/OpenCV/lib/%{cfg.architecture}/%{cfg.system}/shared/opencv_world470.dll" "%{cfg.targetdir}" '
}
targetdir "bin/win/"


filter "system:windows"
includedirs { "ThirdParty/wxWidget/include/msvc" }
libdirs { "ThirdParty/wxWidget/lib/vc_x64_lib" }
Expand Down
1 change: 1 addition & 0 deletions plugin/scripts/generate.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
cd ../
call premake5.exe vs2019 --file=Workspace.lua
popd
exit /b 0
2 changes: 1 addition & 1 deletion plugin/scripts/update_submodule.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@echo off
cd ../../
call git submodule update --recursive --remote --force
call git submodule update --recursive --remote --force --init
popd
pause
8 changes: 7 additions & 1 deletion plugin/src/Module/AppContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ namespace sc {

FCM::StringRep16 documentPathPtr;
document->GetPath(&documentPathPtr);
documentPath = fs::path((const char16_t*)documentPathPtr).remove_filename();
if (documentPathPtr != nullptr) {
documentPath = fs::path((const char16_t*)documentPathPtr);
}

if (documentPath.has_extension()) {
documentPath = documentPath.remove_filename();
}
falloc->Free(documentPathPtr);
};

Expand Down
8 changes: 8 additions & 0 deletions plugin/src/Module/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ namespace sc {
result.exportsMode = (ExportsMode)data["exportsMode"];
}

if (data["textureEncoding"].is_number_unsigned()) {
result.textureEncoding = (SWFTexture::TextureEncoding)data["textureEncoding"];
}

if (data["textureQuality"].is_number_unsigned()) {
result.textureQuality = (Quality)data["textureQuality"];
}

return result;
}
}
Expand Down
39 changes: 30 additions & 9 deletions plugin/src/Publisher/SWF/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,16 @@ namespace sc {
}

void Writer::LoadExternal() {
if (!fs::exists(m_context.config.exportToExternalPath)) {
m_context.trace("External file does not exist");
return;
}

fs::path filepath = m_context.config.exportToExternalPath;
if (filepath.is_relative()) {
filepath = m_context.documentPath / filepath;
}

if (!fs::exists(filepath)) {
m_context.trace("External file does not exist");
return;
}

SupercellSWF swf;
swf.load(filepath);

Expand Down Expand Up @@ -257,10 +257,10 @@ namespace sc {
vertex->v(point.uv.second / (float)textures[item.textureIndex].rows);

vertex->x(
point.xy.first * matrix.a + point.xy.second * matrix.b + matrix.tx
(matrix.a * point.xy.first) + (-matrix.b * point.xy.second) + matrix.tx
);
vertex->y(
point.xy.first * matrix.c + point.xy.second * matrix.d + matrix.ty
(-matrix.c * point.xy.first) + (matrix.d * point.xy.second) + matrix.ty
);

command->vertices.push_back(pShapeDrawBitmapCommandVertex(vertex));
Expand All @@ -286,8 +286,29 @@ namespace sc {
break;
}

texture->data = std::vector<uint8_t>(atlas.datastart, atlas.dataend);

texture->textureData = std::vector<uint8_t>(atlas.datastart, atlas.dataend);

if (m_context.config.textureEncoding == SWFTexture::TextureEncoding::Raw) {
switch (m_context.config.textureQuality)
{
case Quality::Highest:
texture->pixelFormat(SWFTexture::PixelFormat::RGBA8);
break;
case Quality::High:
case Quality::Medium:
texture->pixelFormat(SWFTexture::PixelFormat::RGBA4);
break;
case Quality::Low:
texture->pixelFormat(SWFTexture::PixelFormat::RGB5_A1);
break;
default:
break;
}
}
else {
texture->textureEncoding(m_context.config.textureEncoding);
}

m_swf.textures.push_back(pSWFTexture(texture));
}

Expand Down
7 changes: 3 additions & 4 deletions publisher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
"description": "",
"main": "src/index.tsx",
"scripts": {
"start": "webpack serve --mode development",
"build": "webpack",
"build:prod": "npm run build && ts-node build.ts production ",
"build:dev": "npm run build && ts-node build.ts development"
"start": "webpack serve --mode=development",
"build:prod": "webpack --mode=production && ts-node build.ts production ",
"build:dev": "webpack --mode=development && ts-node build.ts development"
},
"keywords": [],
"author": "DaniilSV",
Expand Down
2 changes: 1 addition & 1 deletion publisher/src/Components/Publisher/BasicSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default function BasicSettings() {
}
},
output,
method
process.env.NODE_ENV == "production" ? undefined : method

)
}
18 changes: 5 additions & 13 deletions publisher/src/Components/Publisher/settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ export default function Settings() {
)
State.data["exportToExternal"] = isExportToExternal;

let childrens = [
compressionType,
exportToExternal,
ExportsSettings(),
TextureSettings()
]

let externalFilePath = FileField(
Locale.Get("TID_SWF_SETTINGS_EXPORT_TO_EXTERNAL_PATH"),
"export_to_external_path",
Expand All @@ -56,17 +49,16 @@ export default function Settings() {
State.getParam("exportToExternalPath")
)


if (isExportToExternal) {
childrens.splice(3, 0, externalFilePath);
}

return SubMenu(
Locale.Get("TID_ADDITIONAL_SETTINGS_LABEL"),
"additional_settings",
{
marginBottom: "12px"
},
childrens
compressionType,
exportToExternal,
isExportToExternal ? externalFilePath : undefined,
ExportsSettings(),
TextureSettings()
)
}
Loading

0 comments on commit c689c8c

Please sign in to comment.