1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "gfCJigsawComponentCutter.h"

#include <fsCore/src/fsNCoreUtils.h>
#include <fsCore/src/fsNRnd.h>

#include "gfCJigsawMinigameComponent.h"
#include "gfCJigsawStencilTextures.h"
#include "gfCJigsawStencil.h"

const fsCUniqueId gfCJigsawComponentCutter::mTypeId("gfCJigsawComponentCutter");
const fsStr gfCJigsawComponentCutter::mEntityPrefix("CUJ");


fsStr gfCJigsawComponentCutter::minigamePieceNameGet() const
{
	return gfCJigsawMinigameComponent::mEntityPrefix;
}

gfIStencil* const gfCJigsawComponentCutter::stencilRestore()
{
	return new gfCJigsawStencil(mStencilTextures, parentGet());
}

void gfCJigsawComponentCutter::doSetup(const fsCVariableTable& pStyle, const fsStr& pLevelName)
{
	if ((mStencilTextures = gfCJigsawStencilTextures::create(pStyle)))
	{
		mPieceWidth = mStencilTextures->topTongue()->dimensionsGet().x;
		mPieceHeight = mStencilTextures->rightTongue()->dimensionsGet().y;
		mCols = mSourceImage->dimensionsGet().x / mPieceWidth;
		mRows = mSourceImage->dimensionsGet().y / mPieceHeight;
	}
}

void gfCJigsawComponentCutter::doCut(fsCEntity* const pEnt, gfIStencil* const pStencil, fsBool pFirstTime)
{
	if (auto* const jigComp = pEnt->componentGet<gfCJigsawMinigameComponent>())
	{
		jigComp->cut(mSourceImage, pStencil);
		jigComp->homePositonModify(fsPoint(pStencil->drawXGet(), pStencil->drawYGet()), pFirstTime);
	}
}

void gfCJigsawComponentCutter::stencilsCreate()
{
	std::vector<gfCJigsawStencil::eEDGE> lastRowBottomEdges(mCols, gfCJigsawStencil::eSTRAIGHT);

	for (fsS32 currRow = 0; currRow < mRows; ++currRow)
	{
		const fsBool topEdge = (currRow == 0);
		const fsBool bottomEdge = (currRow == mRows - 1);

		gfCJigsawStencil::eEDGE left = gfCJigsawStencil::eSTRAIGHT;<--- Variable 'left' is assigned a value that is never used.
		gfCJigsawStencil::eEDGE right = (fsNRnd::uInt32GetWithLimit(2))
			                                ? gfCJigsawStencil::eTONGUE
			                                : gfCJigsawStencil::eGROOVE;
		gfCJigsawStencil::eEDGE top = gfCJigsawStencil::eSTRAIGHT;<--- Variable 'top' is assigned a value that is never used.
		gfCJigsawStencil::eEDGE bottom = gfCJigsawStencil::eSTRAIGHT;<--- Variable 'bottom' is assigned a value that is never used.

		for (fsS32 currCol = 0; currCol < mCols; ++currCol)
		{
			left = gfCJigsawStencil::complimentGet(right);

			(fsNRnd::uInt32GetWithLimit(2)) ? right = gfCJigsawStencil::eTONGUE : right = gfCJigsawStencil::eGROOVE;

			top = gfCJigsawStencil::complimentGet(lastRowBottomEdges[currCol]);

			(fsNRnd::uInt32GetWithLimit(2)) ? bottom = gfCJigsawStencil::eTONGUE : bottom = gfCJigsawStencil::eGROOVE;
			lastRowBottomEdges[currCol] = bottom;


			const fsBool rightEdge = (currCol == mCols - 1);
			const fsBool leftEdge = (currCol == 0);
			if (rightEdge)
			{
				right = gfCJigsawStencil::eSTRAIGHT;
			}
			else if (leftEdge)
			{
				left = gfCJigsawStencil::eSTRAIGHT;
			}

			if (topEdge)
			{
				top = gfCJigsawStencil::eSTRAIGHT;
			}
			else if (bottomEdge)
			{
				bottom = gfCJigsawStencil::eSTRAIGHT;
			}

			gfCJigsawStencil* stencil = new gfCJigsawStencil(mStencilTextures, mPieceWidth, mPieceHeight,
			                                                 top, right, bottom, left, currRow * mPieceWidth,
			                                                 currCol * mPieceHeight);
			mStencils.push_back(stencil);
		}
	}
}

fsIComponent* gfCJigsawComponentCutter::create(fsCEntity* pParent)
{
	return new gfCJigsawComponentCutter(pParent);
}

gfCJigsawComponentCutter::gfCJigsawComponentCutter(fsCEntity* const pParent) :
	gfICutterComponent(pParent),
	mStencilTextures(nullptr)
{
}

gfCJigsawComponentCutter::~gfCJigsawComponentCutter()
{
	delete mStencilTextures;
	fsNCoreUtils::clearSequenceContainerOfPtrs(mStencils);
}