<commit_before>/*
 *  CompoundPart.cpp
 *  openc2e
 *
 *  Created by <NAME> on Tue May 25 2004.
 *  Copyright (c) 2004 <NAME>. All rights reserved.
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 */

#include "CompoundPart.h"
#include "CameraPart.h"
#include "Camera.h"
#include "World.h"
#include "Engine.h"
#include "c16Image.h"
#include "Backend.h"
#include "Agent.h"

bool partzorder::operator ()(const CompoundPart *s1, const CompoundPart *s2) const {
	// TODO: unsure about all of this, needs a check (but seems to work)
	if (s1->getParent()->getZOrder() == s2->getParent()->getZOrder()) {
		// part 0 is often at the same plane as other parts..
		// TODO: is this correct fix? I suspect not, we should be sorting by reaction order, not id.
		if (s1->getParent() == s2->getParent()) {
			return s1->id > s2->id;
		} else
			return s1->getZOrder() > s2->getZOrder();
	}
	return s1->getParent()->getZOrder() > s2->getParent()->getZOrder();
}

shared_ptr<creaturesImage> TextEntryPart::caretsprite;

void CompoundPart::render(Surface *renderer, int xoffset, int yoffset) {
	if (parent->visible) {
		partRender(renderer, xoffset + (int)parent->x, yoffset + (int)parent->y);
		if (parent->displaycore /*&& (id == 0)*/) {
			// TODO: tsk, this should be drawn along with the other craziness on the line plane, i expect
			int xoff = xoffset + (int)parent->x + x;
			int yoff = yoffset + (int)parent->y + y;
			renderer->renderLine(xoff + (getWidth() / 2), yoff, xoff + getWidth(), yoff + (getHeight() / 2), 0xFF0000CC);
			renderer->renderLine(xoff + getWidth(), yoff + (getHeight() / 2), xoff + (getWidth() / 2), yoff + getHeight(), 0xFF0000CC);
			renderer->renderLine(xoff + (getWidth() / 2), yoff + getHeight(), xoff, yoff + (getHeight() / 2), 0xFF0000CC);
			renderer->renderLine(xoff, yoff + (getHeight() / 2), xoff + (getWidth() / 2), yoff, 0xFF0000CC);
		}	
	}
}

bool CompoundPart::showOnRemoteCameras() {
	return !parent->camerashy();
}

void SpritePart::partRender(Surface *renderer, int xoffset, int yoffset) {
	assert(getCurrentSprite() < getSprite()->numframes());
	renderer->render(getSprite(), getCurrentSprite(), xoffset + x, yoffset + y, has_alpha, alpha, draw_mirrored);
}

void SpritePart::setFrameNo(unsigned int f) {
	assert(f < animation.size());
	assert(firstimg + base + animation[f] < getSprite()->numframes());
	
	frameno = f;
	pose = animation[f];
	spriteno = firstimg + base + pose;
}

void SpritePart::setPose(unsigned int p) {
	assert(firstimg + base + p < getSprite()->numframes());

	animation.clear();
	pose = p;
	spriteno = firstimg + base + pose;
}
		
void SpritePart::setBase(unsigned int b) {
	base = b;
}

bool SpritePart::transparentAt(unsigned int x, unsigned int y) {
	return getSprite()->transparentAt(getCurrentSprite(), x, y);
}

void SpritePart::handleClick(float clickx, float clicky) {
	parent->handleClick(clickx + parent->x, clicky + parent->y);
}

CompoundPart::CompoundPart(Agent *p, unsigned int _id, int _x, int _y, int _z) : parent(p), zorder(_z), id(_id) {
	addZOrder();	
	x = _x;
	y = _y;
	
	has_alpha = false;
}

CompoundPart::~CompoundPart() {
	world.zorder.erase(zorder_iter);
}

SpritePart::SpritePart(Agent *p, unsigned int _id, std::string spritefile, unsigned int fimg,
						int _x, int _y, unsigned int _z) : CompoundPart(p, _id, _x, _y, _z) {
	origsprite = sprite = world.gallery.getImage(spritefile);
	firstimg = fimg;
	caos_assert(sprite);<commit_msg>tweak adjusting of coords in SpritePart::handleClick - not sure if we should be adjusting coords at all there, but fixes bugs for now<commit_after>/*
 *  CompoundPart.cpp
 *  openc2e
 *
 *  Created by <NAME> on Tue May 25 2004.
 *  Copyright (c) 2004 <NAME>. All rights reserved.
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 */

#include "CompoundPart.h"
#include "CameraPart.h"
#include "Camera.h"
#include "World.h"
#include "Engine.h"
#include "c16Image.h"
#include "Backend.h"
#include "Agent.h"

bool partzorder::operator ()(const CompoundPart *s1, const CompoundPart *s2) const {
	// TODO: unsure about all of this, needs a check (but seems to work)
	if (s1->getParent()->getZOrder() == s2->getParent()->getZOrder()) {
		// part 0 is often at the same plane as other parts..
		// TODO: is this correct fix? I suspect not, we should be sorting by reaction order, not id.
		if (s1->getParent() == s2->getParent()) {
			return s1->id > s2->id;
		} else
			return s1->getZOrder() > s2->getZOrder();
	}
	return s1->getParent()->getZOrder() > s2->getParent()->getZOrder();
}

shared_ptr<creaturesImage> TextEntryPart::caretsprite;

void CompoundPart::render(Surface *renderer, int xoffset, int yoffset) {
	if (parent->visible) {
		partRender(renderer, xoffset + (int)parent->x, yoffset + (int)parent->y);
		if (parent->displaycore /*&& (id == 0)*/) {
			// TODO: tsk, this should be drawn along with the other craziness on the line plane, i expect
			int xoff = xoffset + (int)parent->x + x;
			int yoff = yoffset + (int)parent->y + y;
			renderer->renderLine(xoff + (getWidth() / 2), yoff, xoff + getWidth(), yoff + (getHeight() / 2), 0xFF0000CC);
			renderer->renderLine(xoff + getWidth(), yoff + (getHeight() / 2), xoff + (getWidth() / 2), yoff + getHeight(), 0xFF0000CC);
			renderer->renderLine(xoff + (getWidth() / 2), yoff + getHeight(), xoff, yoff + (getHeight() / 2), 0xFF0000CC);
			renderer->renderLine(xoff, yoff + (getHeight() / 2), xoff + (getWidth() / 2), yoff, 0xFF0000CC);
		}	
	}
}

bool CompoundPart::showOnRemoteCameras() {
	return !parent->camerashy();
}

void SpritePart::partRender(Surface *renderer, int xoffset, int yoffset) {
	assert(getCurrentSprite() < getSprite()->numframes());
	renderer->render(getSprite(), getCurrentSprite(), xoffset + x, yoffset + y, has_alpha, alpha, draw_mirrored);
}

void SpritePart::setFrameNo(unsigned int f) {
	assert(f < animation.size());
	assert(firstimg + base + animation[f] < getSprite()->numframes());
	
	frameno = f;
	pose = animation[f];
	spriteno = firstimg + base + pose;
}

void SpritePart::setPose(unsigned int p) {
	assert(firstimg + base + p < getSprite()->numframes());

	animation.clear();
	pose = p;
	spriteno = firstimg + base + pose;
}
		
void SpritePart::setBase(unsigned int b) {
	base = b;
}

bool SpritePart::transparentAt(unsigned int x, unsigned int y) {
	return getSprite()->transparentAt(getCurrentSprite(), x, y);
}

void SpritePart::handleClick(float clickx, float clicky) {
	parent->handleClick(clickx + x + parent->x, clicky + y + parent->y);
}

CompoundPart::CompoundPart(Agent *p, unsigned int _id, int _x, int _y, int _z) : parent(p), zorder(_z), id(_id) {
	addZOrder();	
	x = _x;
	y = _y;
	
	has_alpha = false;
}

CompoundPart::~CompoundPart() {
	world.zorder.erase(zorder_iter);
}

SpritePart::SpritePart(Agent *p, unsigned int _id, std::string spritefile, unsigned int fimg,
						int _x, int _y, unsigned int _z) : CompoundPart(p, _id, _x, _y, _z) {
	origsprite = sprite = world.gallery.getImage(spritefile);
	firstimg = fimg;
	caos_assert(sprite);
{'fraction_non_alphanumeric': 0.1459909228441755, 'fraction_numerical': 0.014120020171457387, 'mean_word_length': 4.381953867028494, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 81, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6388597', 'n_tokens_mistral': 2847, 'n_tokens_neox': 2719, 'n_words': 822}