/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Factory class: base for all part factories
var BaseFactory = Container.expand(function () {
var self = Container.call(this);
self.level = 1;
self.production = 1; // per click
self.upgradeCost = 100;
self.partType = null;
// Production time in frames (default 30, halves every 5 levels, min 5)
self.getProductionTime = function () {
// Each 5 levels halves the time, min 5 frames
var base = 30;
var speedup = Math.floor((self.level - 1) / 5);
var prodTime = Math.floor(base / Math.pow(2, speedup));
if (prodTime < 5) {
prodTime = 5;
}
return prodTime;
};
// Use unique factory image for each partType if available
var factoryImageId = 'factory';
if (self.partType) {
if (LK.hasAsset && LK.hasAsset('factory_' + self.partType)) {
factoryImageId = 'factory_' + self.partType;
} else if (LK.getAsset && LK.getAsset('factory_' + self.partType, {
anchorX: 0.5,
anchorY: 0.5
})) {
factoryImageId = 'factory_' + self.partType;
}
}
self.attachAsset(factoryImageId, {
anchorX: 0.5,
anchorY: 0.5
});
// Part icon
var partIcon = null;
if (self.partType) {
partIcon = self.attachAsset('part_' + self.partType, {
anchorX: 0.5,
anchorY: 0.5,
y: -60,
scaleX: 0.7,
scaleY: 0.7
});
}
// Level text
var levelTxt = new Text2('Lv.' + self.level, {
size: 40,
fill: '#fff'
});
levelTxt.anchor.set(0.5, 0);
levelTxt.y = 90;
self.addChild(levelTxt);
self.upgrade = function () {
if (money >= self.upgradeCost) {
money -= self.upgradeCost;
self.level += 1;
self.production += 1;
self.upgradeCost = Math.floor(self.upgradeCost * 3.5);
levelTxt.setText('Lv.' + self.level);
updateMoneyText();
// Reset autoTick so production interval is not skipped after upgrade
self.autoTick = 0;
// --- Reduce production time by 10% after each upgrade, if customProductionTime is present ---
if (typeof self.customProductionTime === "number") {
self.customProductionTime = Math.max(Math.floor(self.customProductionTime * 0.9), 60); // min 1s (60 frames)
}
// Update production time text if present
if (self._prodTimeTxt) {
var prodTime = self.getProductionTime ? self.getProductionTime() : 30;
var prodTimeSec = (prodTime / 60).toFixed(2);
self._prodTimeTxt.setText("Üretim: " + prodTimeSec + " sn");
}
}
};
self.setPartType = function (type) {
self.partType = type;
if (partIcon) {
partIcon.destroy();
}
partIcon = self.attachAsset('part_' + type, {
anchorX: 0.5,
anchorY: 0.5,
y: -60,
scaleX: 0.7,
scaleY: 0.7
});
};
return self;
});
// Create a factory class for each part type
// Mine class: produces raw materials over time
var Mine = Container.expand(function () {
var self = Container.call(this);
self.level = 1;
self.type = 'copper'; // 'copper', 'silicon', 'iron'
self.production = 1; // per tick
self.timer = 0;
self.upgradeCost = 50;
self.attachAsset('mine', {
anchorX: 0.5,
anchorY: 0.5
});
// Ore icon
var oreIcon = self.attachAsset('ore_' + self.type, {
anchorX: 0.5,
anchorY: 0.5,
y: 60,
scaleX: 0.7,
scaleY: 0.7
});
// Level text
var levelTxt = new Text2('Lv.' + self.level, {
size: 40,
fill: '#fff'
});
levelTxt.anchor.set(0.5, 0);
levelTxt.y = 90;
self.addChild(levelTxt);
self.setType = function (type) {
self.type = type;
oreIcon.destroy();
var newOre = self.attachAsset('ore_' + type, {
anchorX: 0.5,
anchorY: 0.5,
y: 60,
scaleX: 0.7,
scaleY: 0.7
});
};
self.upgrade = function () {
if (money >= self.upgradeCost) {
money -= self.upgradeCost;
self.level += 1;
self.production += 1;
self.upgradeCost = Math.floor(self.upgradeCost * 2.975);
levelTxt.setText('Lv.' + self.level);
updateMoneyText();
}
};
self.update = function () {
self.timer++;
// No automatic production
};
return self;
});
// Store class: sells computer parts to customers
var Store = Container.expand(function () {
var self = Container.call(this);
self.level = 1;
self.sellSpeed = 1; // customers per 2s
self.upgradeCost = 120;
self.attachAsset('store', {
anchorX: 0.5,
anchorY: 0.5
});
// Level text
var levelTxt = new Text2('Lv.' + self.level, {
size: 48,
//{1Y} // 40'tan 48'e büyütüldü
fill: '#fff'
});
levelTxt.anchor.set(0.5, 0);
levelTxt.y = 90;
self.addChild(levelTxt);
self.upgrade = function () {
if (money >= self.upgradeCost) {
money -= self.upgradeCost;
self.level += 1;
self.sellSpeed += 1;
self.upgradeCost = Math.floor(self.upgradeCost * 3.85);
levelTxt.setText('Lv.' + self.level);
updateMoneyText();
}
};
// Add auto-sell tick for automatic sales
self.autoSellTick = 0;
self.autoSellInterval = function () {
// Satış aralığı: 120 frame / sellSpeed (daha yüksek seviye daha hızlı)
return Math.max(30, Math.floor(120 / self.sellSpeed));
};
self.tryAutoSell = function () {
self.autoSellTick++;
if (self.autoSellTick >= self.autoSellInterval()) {
// Satılacak ürün bul (stokta olanlardan rastgele seç)
var availableParts = [];
for (var i = 0; i < partTypes.length; i++) {
if (parts[partTypes[i]] > 0) {
availableParts.push(i);
}
}
if (availableParts.length > 0) {
var randIdx = availableParts[Math.floor(Math.random() * availableParts.length)];
var salePrice = 30 + Math.floor(Math.random() * 20);
parts[partTypes[randIdx]] -= 1;
money += salePrice;
if (typeof updateMoneyText === "function") {
updateMoneyText();
}
if (typeof updatePartsText === "function") {
updatePartsText();
}
// Satış animasyonu (mağaza hafif büyüsün)
tween(self, {
scaleX: 1.08,
scaleY: 1.08
}, {
duration: 80,
onFinish: function onFinish() {
tween(self, {
scaleX: 0.82,
scaleY: 0.82
}, {
duration: 80
});
}
});
// --- Ava: Show sold product image above store for 5 seconds ---
// Panel açıkken satılan ürün resmi gösterilmesin
if (!(typeof magazaPanel !== "undefined" && magazaPanel.visible) && !(typeof yatirimPanel !== "undefined" && yatirimPanel.visible) && !(typeof magazalarPanel !== "undefined" && magazalarPanel.visible) && !(typeof madenlerPanel !== "undefined" && madenlerPanel.visible) && !(typeof newPagePanel !== "undefined" && newPagePanel.visible) && !(typeof mevduatPopupPanel !== "undefined" && mevduatPopupPanel.visible) && !(typeof languagesPanel !== "undefined" && languagesPanel.visible) && !(typeof infoPanel !== "undefined" && infoPanel.visible)) {
if (typeof self.soldImage !== "undefined" && self.soldImage) {
self.soldImage.destroy();
self.soldImage = undefined;
}
var soldImgId = 'part_' + partTypes[randIdx];
var soldImg = LK.getAsset(soldImgId, {
anchorX: 0.5,
anchorY: 1,
x: self.x,
y: self.y - 120,
scaleX: 0.6,
// 1.2 * 0.5 = 0.6, %50 oranında küçültüldü
scaleY: 0.6
});
soldImg.visible = true;
if (typeof game !== "undefined" && game.addChild) {
game.addChild(soldImg);
}
self.soldImage = soldImg;
if (typeof game !== "undefined" && game.setChildIndex) {
game.setChildIndex(soldImg, game.children.length - 1);
}
LK.setTimeout(function () {
if (soldImg && soldImg.destroy) {
soldImg.destroy();
}
if (self) {
self.soldImage = undefined;
}
}, 300); // 5 seconds = 300 frames at 60fps
}
}
self.autoSellTick = 0;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x181818
});
/****
* Game Code
****/
// Defensive: Only use offerPanel's width/height/x/y if offerPanel is defined and has those properties
// --- Mevduat (Deposit) Panel: Internet Teklif panelinin üstüne hizalanacak şekilde ekle ---
// Panel içeriğine göre genişlik/uzunluk ayarla ve ortala
var mevduatPanelTitleText = 'Mevduat';
var mevduatPanelFaizText = '2 dakikada %10 faiz';
var mevduatPanelTitleObj = new Text2(mevduatPanelTitleText, {
size: 32,
fill: '#fff'
});
var mevduatPanelFaizObj = new Text2(mevduatPanelFaizText, {
size: 28,
fill: '#bff'
});
var mevduatPanelContentWidth = Math.max(mevduatPanelTitleObj.width, mevduatPanelFaizObj.width, 340) + 80;
var mevduatPanelContentHeight = 40 + mevduatPanelTitleObj.height + 10 + mevduatPanelFaizObj.height + 10 + 40 + 60 + 80;
var mevduatPanelWidth = mevduatPanelContentWidth;
var mevduatPanelHeight = mevduatPanelContentHeight;
var mevduatPanelX = typeof offerPanel !== "undefined" && offerPanel && typeof offerPanel.x === "number" ? offerPanel.x : 120;
var mevduatPanelY = typeof offerPanel !== "undefined" && offerPanel && typeof offerPanel.y === "number" && typeof offerPanel.height === "number" ? offerPanel.y - offerPanel.height / 2 - mevduatPanelHeight / 2 - 40 : 1366 - 340 / 2 - mevduatPanelHeight / 2 - 40;
var mevduatPanel = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: mevduatPanelWidth,
height: mevduatPanelHeight,
x: mevduatPanelX,
y: mevduatPanelY
});
game.addChild(mevduatPanel);
// Panel başlığı
var mevduatPanelTitle = new Text2(mevduatPanelTitleText, {
size: 32,
fill: '#fff'
});
mevduatPanelTitle.anchor.set(0.5, 0);
mevduatPanelTitle.x = mevduatPanel.x + 32;
mevduatPanelTitle.y = mevduatPanel.y - mevduatPanel.height / 2 + 20;
game.addChild(mevduatPanelTitle);
// Faiz ibaresi
var mevduatPanelFaiz = new Text2(mevduatPanelFaizText, {
size: 28,
fill: '#bff'
});
mevduatPanelFaiz.anchor.set(0.5, 0);
mevduatPanelFaiz.x = mevduatPanel.x + 32;
mevduatPanelFaiz.y = mevduatPanelTitle.y + mevduatPanelTitle.height + 10;
game.addChild(mevduatPanelFaiz);
// Mevduat tutarı
var mevduatTutar = typeof mevduatTutar !== "undefined" ? mevduatTutar : 0;
var mevduatTxt = new Text2('Mevduat: ₺' + mevduatTutar, {
size: 28,
fill: '#ffb'
});
mevduatTxt.anchor.set(0.5, 0.5);
mevduatTxt.x = mevduatPanel.x + 32;
mevduatTxt.y = mevduatPanelFaiz.y + mevduatPanelFaiz.height + 30;
game.addChild(mevduatTxt);
function updateMevduatTxt() {
mevduatTxt.setText('Mevduat: ₺' + Math.floor(mevduatTutar * 100) / 100);
}
// Mevduat yatır ve çek butonları
var mevduatYatirBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 120,
height: 60,
x: mevduatPanel.x - 80 + 32,
y: mevduatTxt.y + 60
});
game.addChild(mevduatYatirBtn);
var mevduatYatirBtnTxt = new Text2('Yatır', {
size: 28,
fill: '#fff'
});
mevduatYatirBtnTxt.anchor.set(0.5, 0.5);
mevduatYatirBtnTxt.x = mevduatYatirBtn.x;
mevduatYatirBtnTxt.y = mevduatYatirBtn.y;
game.addChild(mevduatYatirBtnTxt);
var mevduatCekBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 120,
height: 60,
x: mevduatPanel.x + 80 + 32,
y: mevduatTxt.y + 60
});
game.addChild(mevduatCekBtn);
var mevduatCekBtnTxt = new Text2('Çek', {
size: 28,
fill: '#fff'
});
mevduatCekBtnTxt.anchor.set(0.5, 0.5);
mevduatCekBtnTxt.x = mevduatCekBtn.x;
mevduatCekBtnTxt.y = mevduatCekBtn.y;
game.addChild(mevduatCekBtnTxt);
// Mevduat yatırma: 1000 TL ve katları
mevduatYatirBtn.down = function (x, y, obj) {
if (money >= 1000) {
money -= 1000;
mevduatTutar += 1000;
updateMoneyText && updateMoneyText();
updateMevduatTxt && updateMevduatTxt();
tween(mevduatYatirBtn, {
scaleX: 1.12,
scaleY: 1.12
}, {
duration: 80,
onFinish: function onFinish() {
tween(mevduatYatirBtn, {
scaleX: 1,
scaleY: 1
}, {
duration: 80
});
}
});
} else {
tween(mevduatYatirBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(mevduatYatirBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
}
};
// Mevduat çekme: 1000 TL ve katları
mevduatCekBtn.down = function (x, y, obj) {
if (mevduatTutar >= 1000) {
mevduatTutar -= 1000;
money += 1000;
updateMoneyText && updateMoneyText();
updateMevduatTxt && updateMevduatTxt();
tween(mevduatCekBtn, {
scaleX: 1.12,
scaleY: 1.12
}, {
duration: 80,
onFinish: function onFinish() {
tween(mevduatCekBtn, {
scaleX: 1,
scaleY: 1
}, {
duration: 80
});
}
});
} else {
tween(mevduatCekBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(mevduatCekBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
}
};
// Mevduat faizi: 7200 saniyede %10 faiz (her 7200 saniyede bir %10 artış)
LK.setInterval(function () {
// 7200 saniye = 2 saat = 432000 frame (60fps)
// Her 7200 saniyede bir %10 faiz ekle
if (mevduatTutar > 0) {
var faizOran = 0.10;
var faizKazanc = mevduatTutar * faizOran;
if (typeof mevduatFaizKalan === "undefined") {
window.mevduatFaizKalan = 0;
}
window.mevduatFaizKalan += faizKazanc;
if (window.mevduatFaizKalan >= 0.01) {
var eklenecek = Math.floor(window.mevduatFaizKalan * 100) / 100;
mevduatTutar += eklenecek;
window.mevduatFaizKalan -= eklenecek;
updateMevduatTxt && updateMevduatTxt();
}
}
}, 432000); // 7200 saniye (60fps * 7200s = 432000)
// mor
// turuncu
// yeşil
// mavi
// kırmızımsı
// Her çalışana farklı renkli box tanımla
// Create a factory class for each part type
// Button
// Customer
// Factory, Store, Mine icons
// Raw materials (3 types)
// Computer parts (10 types)
// Unique mine images for each ore type
// Example: Use existing factory image for mouse
// Example: Use GPU part image as factory image
// Example: Use RAM part image as factory image
// Example: Use SSD part image as factory image
// Example: Use PSU part image as factory image
// Example: Use MB part image as factory image
// Example: Use CASE part image as factory image
// Example: Use FAN part image as factory image
// Example: Use HDD part image as factory image
// Example: Use COOLER part image as factory image
function _typeof(o) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
return typeof o;
} : function (o) {
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
}, _typeof(o);
}
function _defineProperty(e, r, t) {
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
value: t,
enumerable: !0,
configurable: !0,
writable: !0
}) : e[r] = t, e;
}
function _toPropertyKey(t) {
var i = _toPrimitive(t, "string");
return "symbol" == _typeof(i) ? i : i + "";
}
function _toPrimitive(t, r) {
if ("object" != _typeof(t) || !t) {
return t;
}
var e = t[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t, r || "default");
if ("object" != _typeof(i)) {
return i;
}
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return ("string" === r ? String : Number)(t);
}
var partTypes = ['mouse', 'klavye', 'ram', 'ssd', 'psu', 'mb', 'cpu', 'gpu', 'monitor', 'case'];
var oreTypes = ['copper', 'silicon', 'iron', 'silver', 'nikel', 'gold'];
var FactoryClasses = {};
var partProductionTimes = [];
for (var i = 0; i < partTypes.length; i++) {
partProductionTimes[i] = (i + 1) * 2 * 60; // 2,4,6,...,20 saniye (frame cinsinden)
}
for (var i = 0; i < partTypes.length; i++) {
(function (type, idx) {
FactoryClasses[type] = Container.expand(function () {
var self = BaseFactory.call(this);
self.setPartType(type);
self.customProductionTime = partProductionTimes[idx];
self.getProductionTime = function () {
// Use the customProductionTime, which is reduced by 10% on each upgrade
var prodTime = self.customProductionTime;
// Each 5 levels halves the time, min 1s (60 frames)
var speedup = Math.floor((self.level - 1) / 5);
prodTime = Math.floor(prodTime / Math.pow(2, speedup));
if (prodTime < 60) {
prodTime = 60;
}
return prodTime;
};
return self;
});
})(partTypes[i], i);
}
// Inventory
var rawMaterials = {
copper: 10,
silicon: 10,
iron: 10,
silver: 10,
nikel: 10,
gold: 10
};
var parts = {};
for (var i = 0; i < partTypes.length; i++) {
parts[partTypes[i]] = 0;
}
// Money
var money = 5000;
// UI Texts
var moneyTxt = new Text2('₺' + money, {
size: 50,
fill: '#fff'
});
moneyTxt.anchor.set(0.5, 0);
moneyTxt.y = 10;
LK.gui.top.addChild(moneyTxt);
// --- Mağaza Button ---
// Mağaza butonunu Patron butonundan önce tanımla ki, Patron butonu konumunu doğru alsın
var magazaBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 180,
height: 70
});
magazaBtn.x = moneyTxt.x - 220;
magazaBtn.y = 40;
LK.gui.top.addChild(magazaBtn);
var magazaBtnTxt = new Text2('Mağaza', {
size: 36,
fill: '#fff'
});
magazaBtnTxt.anchor.set(0.5, 0.5);
magazaBtnTxt.x = magazaBtn.x;
magazaBtnTxt.y = magazaBtn.y;
LK.gui.top.addChild(magazaBtnTxt);
// --- PATRON Button and Panel ---
// Place PATRON button below Mağaza button (with 20px gap)
// Defensive: Ensure magazaBtn is defined before using its x/y, otherwise use fallback values
var patronBtnX = typeof magazaBtn !== "undefined" && typeof magazaBtn.x === "number" ? magazaBtn.x : 120;
var patronBtnY = typeof magazaBtn !== "undefined" && typeof magazaBtn.y === "number" && typeof magazaBtn.height === "number" ? magazaBtn.y + magazaBtn.height / 2 + 20 + 70 / 2 : 120 + 70 + 20 + 70 / 2;
var patronBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 180,
height: 70,
x: patronBtnX,
y: patronBtnY
});
LK.gui.top.addChild(patronBtn);
var patronBtnTxt = new Text2('PATRON', {
size: 36,
fill: '#fff'
});
patronBtnTxt.anchor.set(0.5, 0.5);
patronBtnTxt.x = patronBtn.x;
patronBtnTxt.y = patronBtn.y;
LK.gui.top.addChild(patronBtnTxt);
// Patron panelini Madenler paneli ile aynı boyut, arkaplan ve kapat butonu düzenine getir
// Madenler paneli ile aynı panel boyutları ve konumlandırma
var patronPanelWidth = Math.floor(2048 * 0.9);
var patronPanelHeight = Math.floor(2732 * 0.9);
var patronPanelX = Math.floor((2048 - patronPanelWidth) / 2);
var patronPanelY = Math.floor((2732 - patronPanelHeight) / 2);
var patronPanel = LK.getAsset('button', {
anchorX: 0,
anchorY: 0,
width: patronPanelWidth,
height: patronPanelHeight,
x: patronPanelX,
y: patronPanelY
});
patronPanel.visible = false;
game.addChild(patronPanel);
// Panel başlığı üstte ortalı, madenlerPanelTitle ile aynı font ve konumda
var patronPanelTitle = new Text2('PATRON', {
size: 44,
fill: '#fff'
});
patronPanelTitle.anchor.set(0.5, 0);
patronPanelTitle.x = 2048 / 2;
patronPanelTitle.y = patronPanelY + 40;
patronPanelTitle.visible = false;
game.addChild(patronPanelTitle);
// Panel merkez X'i güncelle
var patronPanelCenterX = 2048 / 2;
// --- Patron Panel: Toplu Sipariş Sistemi (Kurumsal Müşteri) ---
// 20 farklı elektronik şirket ismi
var patronSirketler = ["TeknoMarket", "DijitalA.Ş.", "MegaElektronik", "BilişimX", "Elektronix", "TeknolojiPark", "BilgiNet", "SmartTech", "Elektronika", "DijitalDepo", "TeknoPlus", "ElektronikEv", "BilişimDünyası", "TeknoStar", "DijitalOfis", "ElektronikAda", "TeknoZone", "BilişimExpress", "ElektronikMarket", "DijitalTek"];
// Sipariş state
var patronSiparis = {
sirket: null,
urunler: [],
// [{part, adet}]
toplamAdet: 0,
bonus: 0,
aktif: false,
tamamlandi: false
};
// Panelde gösterilecek sipariş metni
var patronSiparisTxt = new Text2('', {
size: 45,
fill: '#fff',
lineHeight: 60,
wordWrap: true,
wordWrapWidth: patronPanelWidth - 120 // Panel kenarlarından daha fazla boşluk bırak
});
patronSiparisTxt.anchor.set(0.5, 0);
patronSiparisTxt.x = patronPanelCenterX;
patronSiparisTxt.y = patronPanelTitle.y + patronPanelTitle.height + 36;
patronSiparisTxt.visible = false;
game.addChild(patronSiparisTxt);
// Bilgilendirici yazı (panelin altına, satır aralığı ve hizası iyileştirildi)
var patronInfoTxt = new Text2("Kurumsal müşterilerden toplu siparişler alırsınız.\n" + "Siparişi tamamladığınızda %2-%10 arası ek kazanç elde edersiniz.\n" + "Sipariş tamamlanmadan başka teklif gelmez.\n" + "Redderseniz %5 ceza ödersiniz.\n" + "Sipariş tamamlanmadan kazanç verilmez.", {
size: 45,
fill: '#bff',
lineHeight: 60,
wordWrap: true,
wordWrapWidth: patronPanelWidth - 120 // Panel kenarlarından daha fazla boşluk bırak
});
patronInfoTxt.anchor.set(0.5, 0);
patronInfoTxt.x = patronPanelCenterX;
// Bilgi yazısı ile butonlar arasında en fazla 5 satır boşluk olacak şekilde hizala
// 5 satır * 60px = 300px boşluk bırakıyoruz
patronInfoTxt.y = patronPanelY + patronPanelHeight - 160 - 300 - 90 - 60 - 3 * 60; // 3 satır yukarı (3*60px)
patronInfoTxt.visible = false;
game.addChild(patronInfoTxt);
// Siparişi tamamla butonu
var patronSiparisTamamlaBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 260,
height: 90,
x: patronPanelCenterX - 180,
// 2 satır yukarı: 2 * 60px = 120px
y: patronPanelY + patronPanelHeight - 160 - 90 - 120,
color: 0x83de44,
borderColor: 0x222222,
borderWidth: 6
});
patronSiparisTamamlaBtn.visible = false;
game.addChild(patronSiparisTamamlaBtn);
var patronSiparisTamamlaBtnTxt = new Text2('Siparişi Tamamla', {
size: 45,
fill: '#fff'
});
patronSiparisTamamlaBtnTxt.anchor.set(0.5, 0.5);
patronSiparisTamamlaBtnTxt.x = patronSiparisTamamlaBtn.x;
// 2 satır yukarı: 2 * 60px = 120px
patronSiparisTamamlaBtnTxt.y = patronSiparisTamamlaBtn.y;
patronSiparisTamamlaBtnTxt.visible = false;
game.addChild(patronSiparisTamamlaBtnTxt);
// --- Tamamlanınca Toplam Kazanç Yazısı ---
var patronSiparisKazancTxt = new Text2('', {
size: 45,
fill: '#ffb',
lineHeight: 60,
wordWrap: true,
wordWrapWidth: patronPanelWidth - 120
});
patronSiparisKazancTxt.anchor.set(0.5, 0.5);
patronSiparisKazancTxt.x = patronPanelCenterX;
// 2 satır yukarı: 2 * 60px = 120px
patronSiparisKazancTxt.y = patronSiparisTamamlaBtn.y - 80;
patronSiparisKazancTxt.visible = false;
game.addChild(patronSiparisKazancTxt);
// Siparişi reddet butonu
var patronSiparisReddetBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 260,
height: 90,
x: patronPanelCenterX + 180,
// 2 satır yukarı: 2 * 60px = 120px
y: patronPanelY + patronPanelHeight - 160 - 90 - 120,
color: 0xd83318,
borderColor: 0x222222,
borderWidth: 6
});
patronSiparisReddetBtn.visible = false;
game.addChild(patronSiparisReddetBtn);
var patronSiparisReddetBtnTxt = new Text2('Reddet (%5 Ceza)', {
size: 45,
fill: '#fff'
});
patronSiparisReddetBtnTxt.anchor.set(0.5, 0.5);
patronSiparisReddetBtnTxt.x = patronSiparisReddetBtn.x;
// 2 satır yukarı: 2 * 60px = 120px
patronSiparisReddetBtnTxt.y = patronSiparisReddetBtn.y;
patronSiparisReddetBtnTxt.visible = false;
game.addChild(patronSiparisReddetBtnTxt);
// Paneldeki eski metni kaldır
// patronPanelText artık kullanılmıyor, referans kaldırıldı
// Sipariş oluşturucu
function generatePatronSiparis() {
if (patronSiparis.aktif) return; // Sipariş varken yenisi gelmez
// Şirket seç
var sirket = patronSirketler[Math.floor(Math.random() * patronSirketler.length)];
// 2-10 farklı ürün, her biri 20-300 adet
var urunSayisi = 2 + Math.floor(Math.random() * 9); // 2-10
var secilenler = [];
var secilenIndexler = [];
while (secilenler.length < urunSayisi) {
var idx = Math.floor(Math.random() * partTypes.length);
if (secilenIndexler.indexOf(idx) === -1) {
secilenIndexler.push(idx);
var adet = 20 + Math.floor(Math.random() * 281); // 20-300
secilenler.push({
part: partTypes[idx],
adet: adet
});
}
}
// Bonus: %2-%10 arası
var bonus = 2 + Math.floor(Math.random() * 9); // 2-10
patronSiparis.sirket = sirket;
patronSiparis.urunler = secilenler;
patronSiparis.toplamAdet = 0;
for (var i = 0; i < secilenler.length; i++) {
patronSiparis.toplamAdet += secilenler[i].adet;
}
patronSiparis.bonus = bonus;
patronSiparis.aktif = true;
patronSiparis.tamamlandi = false;
updatePatronSiparisPanel();
}
// Panelde siparişi güncelle
function updatePatronSiparisPanel() {
if (!patronPanel.visible) return;
if (!patronSiparis.aktif) {
patronSiparisTxt.setText("Şu anda aktif bir kurumsal sipariş yok.\nYeni sipariş için bekleyin.");
patronSiparisTamamlaBtn.visible = false;
patronSiparisTamamlaBtnTxt.visible = false;
patronSiparisReddetBtn.visible = false;
patronSiparisReddetBtnTxt.visible = false;
patronInfoTxt.visible = true;
return;
}
// Sipariş metni
var txt = "[Kurumsal Müşteri: " + patronSiparis.sirket + "]\n";
txt += "Toplu ürün siparişi:\n";
for (var i = 0; i < patronSiparis.urunler.length; i++) {
var p = patronSiparis.urunler[i];
var label = p.part === "mouse" ? "MOUSE" : p.part === "klavye" ? "KLAVYE" : p.part === "cpu" ? "CPU" : p.part === "gpu" ? "GPU" : p.part === "monitor" ? "MONITOR" : p.part === "case" ? "KASA" : p.part.toUpperCase();
txt += "- " + label + ": " + p.adet + " adet (Stok: " + (parts[p.part] || 0) + ")\n";
}
txt += "\nSipariş tamamlandığında: %" + patronSiparis.bonus + " ek kazanç!";
patronSiparisTxt.setText(txt);
patronSiparisTamamlaBtn.visible = true;
patronSiparisTamamlaBtnTxt.visible = true;
patronSiparisReddetBtn.visible = true;
patronSiparisReddetBtnTxt.visible = true;
patronInfoTxt.visible = true;
// Butonları aktif/pasif yap
var tamamlanabilir = true;
for (var i = 0; i < patronSiparis.urunler.length; i++) {
var p = patronSiparis.urunler[i];
if ((parts[p.part] || 0) < p.adet) {
tamamlanabilir = false;
break;
}
}
patronSiparisTamamlaBtn.alpha = tamamlanabilir ? 1 : 0.5;
patronSiparisTamamlaBtnTxt.setText(tamamlanabilir ? "Siparişi Tamamla" : "Stok Yetersiz");
patronSiparisTamamlaBtn.downEnabled = tamamlanabilir;
// --- Tamamlanınca Toplam Kazanç Yazısı ---
// Sipariş tamamlanabilir ise toplam kazancı ve bonusu göster
if (typeof patronSiparisKazancTxt !== "undefined") {
if (patronSiparis.aktif && tamamlanabilir) {
var toplamKazanc = 0;
for (var i = 0; i < patronSiparis.urunler.length; i++) {
toplamKazanc += patronSiparis.urunler[i].adet * 45;
}
var bonusKazanc = Math.floor(toplamKazanc * patronSiparis.bonus / 100);
patronSiparisKazancTxt.setText("Tamamlanınca Toplam Kazanç: ₺" + (toplamKazanc + bonusKazanc) + "\n(Bonus: ₺" + bonusKazanc + ")");
patronSiparisKazancTxt.visible = true;
} else {
patronSiparisKazancTxt.visible = false;
}
}
}
// Siparişi tamamla butonu
patronSiparisTamamlaBtn.down = function (x, y, obj) {
if (!patronSiparis.aktif) return;
// Tüm ürünler stokta mı?
var tamamlanabilir = true;
for (var i = 0; i < patronSiparis.urunler.length; i++) {
var p = patronSiparis.urunler[i];
if ((parts[p.part] || 0) < p.adet) {
tamamlanabilir = false;
break;
}
}
if (!tamamlanabilir) {
tween(patronSiparisTamamlaBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(patronSiparisTamamlaBtn, {
tint: 0x83de44
}, {
duration: 120
});
}
});
return;
}
// Ürünleri düş
for (var i = 0; i < patronSiparis.urunler.length; i++) {
var p = patronSiparis.urunler[i];
parts[p.part] -= p.adet;
}
updatePartsText && updatePartsText();
// Kazanç: toplam ürün adedi * 45 TL (ortalama satış fiyatı) * bonus/100
var toplamKazanc = 0;
for (var i = 0; i < patronSiparis.urunler.length; i++) {
toplamKazanc += patronSiparis.urunler[i].adet * 45;
}
var bonusKazanc = Math.floor(toplamKazanc * patronSiparis.bonus / 100);
money += toplamKazanc + bonusKazanc;
updateMoneyText && updateMoneyText();
patronSiparis.aktif = false;
patronSiparis.tamamlandi = true;
patronSiparisTxt.setText("Sipariş başarıyla tamamlandı!\nKazanç: ₺" + (toplamKazanc + bonusKazanc) + " (Bonus: ₺" + bonusKazanc + ")");
// Toplam kazanç yazısını göster
if (typeof patronSiparisKazancTxt !== "undefined") {
patronSiparisKazancTxt.setText("Toplam Kazanç: ₺" + (toplamKazanc + bonusKazanc));
patronSiparisKazancTxt.visible = true;
}
// Butonları gizle
patronSiparisTamamlaBtn.visible = false;
patronSiparisTamamlaBtnTxt.visible = false;
patronSiparisReddetBtn.visible = false;
patronSiparisReddetBtnTxt.visible = false;
// Yeni sipariş gelene kadar toplam kazanç yazısı 3 saniye görünsün, sonra gizle
if (typeof patronSiparisKazancTxt !== "undefined") {
LK.setTimeout(function () {
patronSiparisKazancTxt.visible = false;
}, 180); // 3 saniye (60fps * 3)
}
// Yeni sipariş 1-2 dakika sonra gelsin
LK.setTimeout(function () {
generatePatronSiparis();
updatePatronSiparisPanel();
}, (60 + Math.floor(Math.random() * 61)) * 60);
};
// Siparişi reddet butonu
patronSiparisReddetBtn.down = function (x, y, obj) {
if (!patronSiparis.aktif) return;
// Ceza: tüm ürünlerin toplam bedelinin %5'i kadar para düş
var toplamBedel = 0;
for (var i = 0; i < patronSiparis.urunler.length; i++) {
toplamBedel += patronSiparis.urunler[i].adet * 45;
}
var ceza = Math.floor(toplamBedel * 0.05);
money -= ceza;
if (money < 0) money = 0;
updateMoneyText && updateMoneyText();
patronSiparis.aktif = false;
patronSiparis.tamamlandi = false;
patronSiparisTxt.setText("Sipariş reddedildi.\nCeza: ₺" + ceza + " ödendi.");
patronSiparisTamamlaBtn.visible = false;
patronSiparisTamamlaBtnTxt.visible = false;
patronSiparisReddetBtn.visible = false;
patronSiparisReddetBtnTxt.visible = false;
// Yeni sipariş 1-2 dakika sonra gelsin
LK.setTimeout(function () {
generatePatronSiparis();
updatePatronSiparisPanel();
}, (60 + Math.floor(Math.random() * 61)) * 60);
};
// Panel açıldığında siparişi göster
patronBtn.down = function (x, y, obj) {
patronPanel.visible = true;
patronPanelTitle.visible = true;
patronSiparisTxt.visible = true;
patronInfoTxt.visible = true;
patronKapatBtn.visible = true;
patronKapatBtnTxt.visible = true;
patronSiparisTamamlaBtn.visible = patronSiparis.aktif;
patronSiparisTamamlaBtnTxt.visible = patronSiparis.aktif;
patronSiparisReddetBtn.visible = patronSiparis.aktif;
patronSiparisReddetBtnTxt.visible = patronSiparis.aktif;
updatePatronSiparisPanel();
// Hide homepage UI (including PATRON button)
if (typeof patronBtn !== "undefined") patronBtn.visible = false;
if (typeof patronBtnTxt !== "undefined") patronBtnTxt.visible = false;
// Disable all factory buttons while patron panel is open
if (typeof factoryBtns !== "undefined" && Array.isArray(factoryBtns)) {
for (var i = 0; i < factoryBtns.length; i++) {
if (factoryBtns[i]) {
if (factoryBtns[i]._origDown === undefined && factoryBtns[i].down) {
factoryBtns[i]._origDown = factoryBtns[i].down;
}
factoryBtns[i].down = function () {
return true;
};
}
}
}
if (typeof factoryUnlockBtns !== "undefined" && Array.isArray(factoryUnlockBtns)) {
for (var i = 0; i < factoryUnlockBtns.length; i++) {
if (factoryUnlockBtns[i]) {
if (factoryUnlockBtns[i]._origDown === undefined && factoryUnlockBtns[i].down) {
factoryUnlockBtns[i]._origDown = factoryUnlockBtns[i].down;
}
factoryUnlockBtns[i].down = function () {
return true;
};
}
}
}
if (typeof prodBtns !== "undefined" && Array.isArray(prodBtns)) {
for (var i = 0; i < prodBtns.length; i++) {
if (prodBtns[i]) {
if (prodBtns[i]._origDown === undefined && prodBtns[i].down) {
prodBtns[i]._origDown = prodBtns[i].down;
}
prodBtns[i].down = function () {
return true;
};
}
}
}
if (typeof factoryAutoBtns !== "undefined" && Array.isArray(factoryAutoBtns)) {
for (var i = 0; i < factoryAutoBtns.length; i++) {
if (factoryAutoBtns[i]) {
if (factoryAutoBtns[i]._origDown === undefined && factoryAutoBtns[i].down) {
factoryAutoBtns[i]._origDown = factoryAutoBtns[i].down;
}
factoryAutoBtns[i].down = function () {
return true;
};
}
}
}
// Defensive: bring panel to front
if (game.setChildIndex) {
game.setChildIndex(patronPanel, game.children.length - 1);
game.setChildIndex(patronPanelTitle, game.children.length - 1);
game.setChildIndex(patronSiparisTxt, game.children.length - 1);
game.setChildIndex(patronInfoTxt, game.children.length - 1);
game.setChildIndex(patronKapatBtn, game.children.length - 1);
game.setChildIndex(patronKapatBtnTxt, game.children.length - 1);
game.setChildIndex(patronSiparisTamamlaBtn, game.children.length - 1);
game.setChildIndex(patronSiparisTamamlaBtnTxt, game.children.length - 1);
game.setChildIndex(patronSiparisReddetBtn, game.children.length - 1);
game.setChildIndex(patronSiparisReddetBtnTxt, game.children.length - 1);
}
};
// Panel kapatınca butonları gizle
if (typeof patronKapatBtn !== "undefined" && patronKapatBtn) {
patronKapatBtn.down = function (x, y, obj) {
patronPanel.visible = false;
patronPanelTitle.visible = false;
patronSiparisTxt.visible = false;
patronInfoTxt.visible = false;
patronKapatBtn.visible = false;
patronKapatBtnTxt.visible = false;
patronSiparisTamamlaBtn.visible = false;
patronSiparisTamamlaBtnTxt.visible = false;
patronSiparisReddetBtn.visible = false;
patronSiparisReddetBtnTxt.visible = false;
if (typeof patronBtn !== "undefined") patronBtn.visible = true;
if (typeof patronBtnTxt !== "undefined") patronBtnTxt.visible = true;
// Re-enable all factory buttons when patron panel closes
if (typeof factoryBtns !== "undefined" && Array.isArray(factoryBtns)) {
for (var i = 0; i < factoryBtns.length; i++) {
if (factoryBtns[i] && factoryBtns[i]._origDown) {
factoryBtns[i].down = factoryBtns[i]._origDown;
delete factoryBtns[i]._origDown;
}
}
}
if (typeof factoryUnlockBtns !== "undefined" && Array.isArray(factoryUnlockBtns)) {
for (var i = 0; i < factoryUnlockBtns.length; i++) {
if (factoryUnlockBtns[i] && factoryUnlockBtns[i]._origDown) {
factoryUnlockBtns[i].down = factoryUnlockBtns[i]._origDown;
delete factoryUnlockBtns[i]._origDown;
}
}
}
if (typeof prodBtns !== "undefined" && Array.isArray(prodBtns)) {
for (var i = 0; i < prodBtns.length; i++) {
if (prodBtns[i] && prodBtns[i]._origDown) {
prodBtns[i].down = prodBtns[i]._origDown;
delete prodBtns[i]._origDown;
}
}
}
if (typeof factoryAutoBtns !== "undefined" && Array.isArray(factoryAutoBtns)) {
for (var i = 0; i < factoryAutoBtns.length; i++) {
if (factoryAutoBtns[i] && factoryAutoBtns[i]._origDown) {
factoryAutoBtns[i].down = factoryAutoBtns[i]._origDown;
delete factoryAutoBtns[i]._origDown;
}
}
}
};
}
// Oyun başında ilk siparişi oluştur
LK.setTimeout(function () {
if (!patronSiparis.aktif) {
generatePatronSiparis();
}
}, 120);
// Paneldeki eski metni kaldır
// (patronPanelText artık kullanılmıyor)
// Patron panel close button (bottom center) - Madenler paneli ile aynı şekilde, büyük ve kırmızı çerçeveli
var patronKapatBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 360,
height: 180,
x: patronPanel.x + patronPanel.width / 2,
y: patronPanel.y + patronPanel.height - 60,
color: 0xffffff,
borderColor: 0xff2222,
borderWidth: 8
});
patronKapatBtn.visible = false;
game.addChild(patronKapatBtn);
// Kapat butonu için X simgesi (Unicode heavy multiplication X)
var patronKapatBtnIcon = new Text2("\u2716", {
size: 81,
fill: '#ff2222'
});
patronKapatBtnIcon.anchor.set(1, 0.5);
patronKapatBtnIcon.x = patronKapatBtn.x - 60;
patronKapatBtnIcon.y = patronKapatBtn.y;
patronKapatBtnIcon.visible = false;
game.addChild(patronKapatBtnIcon);
var patronKapatBtnTxt = new Text2('Kapat', {
size: 96,
fill: '#ff2222'
});
patronKapatBtnTxt.anchor.set(0.5, 0.5);
patronKapatBtnTxt.x = patronKapatBtn.x;
patronKapatBtnTxt.y = patronKapatBtn.y;
patronKapatBtnTxt.visible = false;
game.addChild(patronKapatBtnTxt);
// Patron button opens panel
patronBtn.down = function (x, y, obj) {
// Patron Paneli arkaplan ve içeriğini sıfırla
// Paneli ve tüm içeriğini görünmez yap, sonra sadece gerekli olanları aç
patronPanel.visible = false;
patronPanelTitle.visible = false;
patronSiparisTxt.visible = false;
patronInfoTxt.visible = false;
patronKapatBtn.visible = false;
patronKapatBtnTxt.visible = false;
if (typeof patronKapatBtnIcon !== "undefined") patronKapatBtnIcon.visible = false;
patronSiparisTamamlaBtn.visible = false;
patronSiparisTamamlaBtnTxt.visible = false;
patronSiparisReddetBtn.visible = false;
patronSiparisReddetBtnTxt.visible = false;
if (typeof patronSiparisKazancTxt !== "undefined") patronSiparisKazancTxt.visible = false;
// Paneli ve başlığı tekrar aç
patronPanel.visible = true;
patronPanelTitle.visible = true;
patronSiparisTxt.visible = true;
patronInfoTxt.visible = true;
patronKapatBtn.visible = true;
patronKapatBtnTxt.visible = true;
if (typeof patronKapatBtnIcon !== "undefined") patronKapatBtnIcon.visible = true;
patronSiparisTamamlaBtn.visible = patronSiparis.aktif;
patronSiparisTamamlaBtnTxt.visible = patronSiparis.aktif;
patronSiparisReddetBtn.visible = patronSiparis.aktif;
patronSiparisReddetBtnTxt.visible = patronSiparis.aktif;
updatePatronSiparisPanel();
// Hide homepage UI (including PATRON button)
if (typeof patronBtn !== "undefined") patronBtn.visible = false;
if (typeof patronBtnTxt !== "undefined") patronBtnTxt.visible = false;
// Defensive: bring panel to front
if (game.setChildIndex) {
game.setChildIndex(patronPanel, game.children.length - 1);
game.setChildIndex(patronPanelTitle, game.children.length - 1);
game.setChildIndex(patronSiparisTxt, game.children.length - 1);
game.setChildIndex(patronInfoTxt, game.children.length - 1);
game.setChildIndex(patronKapatBtn, game.children.length - 1);
game.setChildIndex(patronKapatBtnTxt, game.children.length - 1);
if (typeof patronKapatBtnIcon !== "undefined") game.setChildIndex(patronKapatBtnIcon, game.children.length - 1);
game.setChildIndex(patronSiparisTamamlaBtn, game.children.length - 1);
game.setChildIndex(patronSiparisTamamlaBtnTxt, game.children.length - 1);
game.setChildIndex(patronSiparisReddetBtn, game.children.length - 1);
game.setChildIndex(patronSiparisReddetBtnTxt, game.children.length - 1);
}
};
// Patron panel close button
patronKapatBtn.down = function (x, y, obj) {
patronPanel.visible = false;
patronPanelTitle.visible = false;
patronSiparisTxt.visible = false;
patronInfoTxt.visible = false;
patronKapatBtn.visible = false;
patronKapatBtnTxt.visible = false;
if (typeof patronKapatBtnIcon !== "undefined") patronKapatBtnIcon.visible = false;
patronSiparisTamamlaBtn.visible = false;
patronSiparisTamamlaBtnTxt.visible = false;
patronSiparisReddetBtn.visible = false;
patronSiparisReddetBtnTxt.visible = false;
// Restore homepage UI (including PATRON button)
if (typeof patronBtn !== "undefined") patronBtn.visible = true;
if (typeof patronBtnTxt !== "undefined") patronBtnTxt.visible = true;
};
// --- Hide PATRON button when any panel is open ---
// Helper: list of all panels that should hide PATRON button when open
function updatePatronBtnVisibility() {
// Patron butonunun görünürlüğünü kontrol et: Sadece patronPanel açıkken gizle, diğer panelleri hariç tut
var anyPanelOpen = patronPanel.visible;
if (typeof patronBtn !== "undefined") patronBtn.visible = !anyPanelOpen;
if (typeof patronBtnTxt !== "undefined") patronBtnTxt.visible = !anyPanelOpen;
}
// Patch all panel open/close logic to call updatePatronBtnVisibility
// (Do this with a timer for robustness)
LK.setInterval(updatePatronBtnVisibility, 10);
// overlays and overlay logic removed
function showPanelOverlay(panelObj) {}
function hidePanelOverlay() {}
// --- Ava: Helper to hide all homepage/anasayfa UI and disable all their input when any panel is open ---
// Also disables all factory buttons (upgrade, unlock, prod, auto) and disables factory panel clicks when any panel is open
function setHomepageUIEnabled(enabled) {
// (fullscreen overlay logic removed)
// List all homepage/anasayfa UI elements including all game elements
var homepageUI = [magazaBtn, magazaBtnTxt, yatirimBtn, yatirimBtnTxt, bankBtn, bankBtnTxt, soundBtn, soundBtnTxt, newPageBtn, newPageBtnTxt, madenlerBtn, madenlerBtnTxt, madenlerBtnMineImg, calisanlarBtnImg, /* infoBtn, infoBtnTxt, howToBtn, howToBtnTxt, */borcOdeBtn, borcOdeBtnTxt, moneyTxt, borcTxt, borcTimeTxt, partsTxt, partsPanel, offerPanel, offerTitle, offerPartTxt, offerAmountTxt, offerPriceTxt, offerBtn, offerBtnTxt, offerTimeTxt, sellPanel, sellTitle, sellPartTxt, sellAmountTxt, sellPriceTxt, sellBtn, sellBtnTxt, sellOfferTimeTxt];
// Hide all factories, mines, stores and their UI elements
if (typeof factories !== "undefined") {
for (var i = 0; i < factories.length; i++) {
if (factories[i]) homepageUI.push(factories[i]);
}
}
if (typeof mines !== "undefined") {
for (var i = 0; i < mines.length; i++) {
if (mines[i]) homepageUI.push(mines[i]);
}
}
if (typeof store !== "undefined") homepageUI.push(store);
if (typeof store2 !== "undefined") homepageUI.push(store2);
if (typeof store3 !== "undefined") homepageUI.push(store3);
if (typeof store4 !== "undefined") homepageUI.push(store4);
// Add raw material texts
if (typeof copperRawTxt !== "undefined") homepageUI.push(copperRawTxt);
if (typeof siliconRawTxt !== "undefined") homepageUI.push(siliconRawTxt);
if (typeof ironRawTxt !== "undefined") homepageUI.push(ironRawTxt);
for (var i = 0; i < homepageUI.length; i++) {
if (typeof homepageUI[i] !== "undefined" && homepageUI[i] && typeof homepageUI[i].visible === "boolean") {
homepageUI[i].visible = !!enabled;
}
// Defensive: also disable input by removing .down/.move/.up handlers if disabled
if (typeof homepageUI[i] !== "undefined" && homepageUI[i]) {
if (!enabled) {
if (homepageUI[i]._origDown === undefined && homepageUI[i].down) {
homepageUI[i]._origDown = homepageUI[i].down;
}
if (homepageUI[i]._origMove === undefined && homepageUI[i].move) {
homepageUI[i]._origMove = homepageUI[i].move;
}
if (homepageUI[i]._origUp === undefined && homepageUI[i].up) {
homepageUI[i]._origUp = homepageUI[i].up;
}
homepageUI[i].down = function () {
return true;
};
homepageUI[i].move = function () {
return true;
};
homepageUI[i].up = function () {
return true;
};
} else {
if (homepageUI[i]._origDown) {
homepageUI[i].down = homepageUI[i]._origDown;
}
if (homepageUI[i]._origMove) {
homepageUI[i].move = homepageUI[i]._origMove;
}
if (homepageUI[i]._origUp) {
homepageUI[i].up = homepageUI[i]._origUp;
}
}
}
}
// --- Ava: Disable all factory buttons and factory panel clicks when any panel is open ---
if (typeof factoryBtns !== "undefined" && Array.isArray(factoryBtns)) {
for (var i = 0; i < factoryBtns.length; i++) {
if (factoryBtns[i]) {
if (!enabled) {
if (factoryBtns[i]._origDown === undefined && factoryBtns[i].down) {
factoryBtns[i]._origDown = factoryBtns[i].down;
}
factoryBtns[i].down = function () {
return true;
};
} else {
if (factoryBtns[i]._origDown) {
factoryBtns[i].down = factoryBtns[i]._origDown;
delete factoryBtns[i]._origDown;
}
}
}
}
}
if (typeof factoryUnlockBtns !== "undefined" && Array.isArray(factoryUnlockBtns)) {
for (var i = 0; i < factoryUnlockBtns.length; i++) {
if (factoryUnlockBtns[i]) {
if (!enabled) {
if (factoryUnlockBtns[i]._origDown === undefined && factoryUnlockBtns[i].down) {
factoryUnlockBtns[i]._origDown = factoryUnlockBtns[i].down;
}
factoryUnlockBtns[i].down = function () {
return true;
};
} else {
if (factoryUnlockBtns[i]._origDown) {
factoryUnlockBtns[i].down = factoryUnlockBtns[i]._origDown;
delete factoryUnlockBtns[i]._origDown;
}
}
}
}
}
if (typeof prodBtns !== "undefined" && Array.isArray(prodBtns)) {
for (var i = 0; i < prodBtns.length; i++) {
if (prodBtns[i]) {
if (!enabled) {
if (prodBtns[i]._origDown === undefined && prodBtns[i].down) {
prodBtns[i]._origDown = prodBtns[i].down;
}
prodBtns[i].down = function () {
return true;
};
} else {
if (prodBtns[i]._origDown) {
prodBtns[i].down = prodBtns[i]._origDown;
delete prodBtns[i]._origDown;
}
}
}
}
}
if (typeof factoryAutoBtns !== "undefined" && Array.isArray(factoryAutoBtns)) {
for (var i = 0; i < factoryAutoBtns.length; i++) {
if (factoryAutoBtns[i]) {
if (!enabled) {
if (factoryAutoBtns[i]._origDown === undefined && factoryAutoBtns[i].down) {
factoryAutoBtns[i]._origDown = factoryAutoBtns[i].down;
}
factoryAutoBtns[i].down = function () {
return true;
};
} else {
if (factoryAutoBtns[i]._origDown) {
factoryAutoBtns[i].down = factoryAutoBtns[i]._origDown;
delete factoryAutoBtns[i]._origDown;
}
}
}
}
}
// Defensive: also disable click on the factory panel itself (the big image)
if (typeof factories !== "undefined" && Array.isArray(factories)) {
for (var i = 0; i < factories.length; i++) {
if (factories[i]) {
if (!enabled) {
if (factories[i]._origDown === undefined && factories[i].down) {
factories[i]._origDown = factories[i].down;
}
factories[i].down = function () {
return true;
};
} else {
if (factories[i]._origDown) {
factories[i].down = factories[i]._origDown;
delete factories[i]._origDown;
}
}
}
}
}
// --- Ava: Show Mevduat button and text again when all panels except Mevduat are closed ---
if (enabled) {
if (typeof mevduatBtn !== "undefined") mevduatBtn.visible = true;
if (typeof mevduatBtnTxt !== "undefined") mevduatBtnTxt.visible = true;
// Info and How To Play buttons are never shown
}
}
// --- Mağaza Button ---
var magazaBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 180,
height: 70
});
magazaBtn.x = moneyTxt.x - 220;
magazaBtn.y = 40;
LK.gui.top.addChild(magazaBtn);
var magazaBtnTxt = new Text2('Mağaza', {
size: 36,
fill: '#fff'
});
magazaBtnTxt.anchor.set(0.5, 0.5);
magazaBtnTxt.x = magazaBtn.x;
magazaBtnTxt.y = magazaBtn.y;
LK.gui.top.addChild(magazaBtnTxt);
// Mağaza butonuna tıklanınca açılır pencereyi göster
// --- Ava: Resize and center all popup/panel windows to 90% of screen and center them ---
var panelWidth = Math.floor(2048 * 0.9);
var panelHeight = Math.floor(2732 * 0.9);
var panelX = Math.floor(2048 / 2);
var panelY = Math.floor(2732 / 2);
var magazaPanel = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: panelWidth,
height: panelHeight,
x: panelX,
y: panelY
});
magazaPanel.visible = false;
game.addChild(magazaPanel);
var magazaPanelTitle = new Text2('Mağaza', {
size: 36,
fill: '#fff'
});
magazaPanelTitle.anchor.set(0.5, 0);
magazaPanelTitle.x = magazaPanel.x;
magazaPanelTitle.y = magazaPanel.y - magazaPanel.height / 2 + 30;
magazaPanelTitle.visible = false;
game.addChild(magazaPanelTitle);
var magazaPanelText = new Text2('Burada mağaza ile ilgili içerik veya açıklama eklenebilir.', {
size: 36,
fill: '#fff'
});
magazaPanelText.anchor.set(0.5, 0.5);
magazaPanelText.x = magazaPanel.x;
magazaPanelText.y = magazaPanel.y - 120;
magazaPanelText.visible = false;
game.addChild(magazaPanelText);
// Muhasebe bilgileri başlığı
var magazaMuhasebeTitle = new Text2('Muhasebe Bilgileri', {
size: 36,
fill: '#ffb'
});
magazaMuhasebeTitle.anchor.set(0.5, 0);
magazaMuhasebeTitle.x = magazaPanel.x;
magazaMuhasebeTitle.y = magazaPanel.y - 30;
magazaMuhasebeTitle.visible = false;
game.addChild(magazaMuhasebeTitle);
// Muhasebe detayları
var magazaMuhasebeText = new Text2('', {
size: 36,
fill: '#fff'
});
magazaMuhasebeText.anchor.set(0.5, 0);
magazaMuhasebeText.x = magazaPanel.x;
magazaMuhasebeText.y = magazaPanel.y + 20;
magazaMuhasebeText.visible = false;
game.addChild(magazaMuhasebeText);
// Muhasebe bilgilerini güncelleyen fonksiyon
function updateMagazaMuhasebeText() {
// Toplam satış adedi ve toplam gelir hesapla
var toplamSatis = 0;
var toplamGelir = 0;
for (var i = 0; i < partTypes.length; i++) {
// Her part için satılan miktarı ve gelirini hesapla
// Satışlar, parts dizisinden değil, toplam üretilen - elde kalan ile bulunabilir
// Basit bir örnek: toplam üretilen ve satılanı takip etmiyorsak, sadece mevcut stoğu göster
// Gelişmiş: Satışları takip etmek için global değişkenler eklenebilir
// Burada örnek olarak sadece mevcut stok ve para gösterelim
// Gelişmiş takip için satılan miktarları ayrıca bir dizi ile tutmak gerekir
// Şimdilik sadece mevcut stok ve para gösterelim
toplamSatis += parts[partTypes[i]];
}
// Toplam gelir olarak mevcut parayı gösterelim (örnek)
toplamGelir = money;
magazaMuhasebeText.setText("Mevcut Stok (adet): " + toplamSatis + "\nKasadaki Para: ₺" + toplamGelir + (typeof borc !== "undefined" && borc > 0 ? "\nBorç: ₺" + borc : ""));
}
// Paneli aç/kapat fonksiyonları
magazaBtn.down = function (x, y, obj) {
if (newPagePanel && newPagePanel.visible) {
return;
}
if (isSoundOn && LK.getSound) {
var clickSound = LK.getSound('ClickSesi');
if (clickSound) {
clickSound.play();
}
}
magazaPanel.visible = true;
magazaPanelTitle.visible = true;
magazaPanelText.visible = true;
magazaKapatBtn.visible = true;
magazaKapatBtnTxt.visible = true;
magazaMuhasebeTitle.visible = true;
magazaMuhasebeText.visible = true;
updateMagazaMuhasebeText();
// --- Ava: Hide only the background elements under the panel area, keep other elements visible ---
// Save which elements are hidden for this panel
if (!magazaPanel._hiddenBackgrounds) magazaPanel._hiddenBackgrounds = [];
for (var i = 0; i < game.children.length; i++) {
var child = game.children[i];
// Hide only if: visible, not the panel or its content, not a Text2, not a button, and is under the panel area
if (child && typeof child.visible === "boolean" && child.visible && child !== magazaPanel && child !== magazaPanelTitle && child !== magazaPanelText && child !== magazaKapatBtn && child !== magazaKapatBtnTxt && child !== magazaKapatBtnIcon && child !== magazaMuhasebeTitle && child !== magazaMuhasebeText && !(child instanceof Text2) && !(child.assetId && child.assetId.indexOf("button") === 0) &&
// Check if child is under the panel area
typeof child.x === "number" && typeof child.y === "number" && child.x + (child.width || 0) > magazaPanel.x - magazaPanel.width / 2 && child.x < magazaPanel.x + magazaPanel.width / 2 && child.y + (child.height || 0) > magazaPanel.y - magazaPanel.height / 2 && child.y < magazaPanel.y + magazaPanel.height / 2) {
child._oldVisible = child.visible;
child.visible = false;
magazaPanel._hiddenBackgrounds.push(child);
}
}
// Paneli ve tüm içeriğini en öne getir (butonlar dahil)
if (game.setChildIndex) {
game.setChildIndex(magazaPanel, game.children.length - 1);
game.setChildIndex(magazaPanelTitle, game.children.length - 1);
game.setChildIndex(magazaPanelText, game.children.length - 1);
game.setChildIndex(magazaMuhasebeTitle, game.children.length - 1);
game.setChildIndex(magazaMuhasebeText, game.children.length - 1);
// Kapat butonu ve X simgesi ve yazısı en önde
game.setChildIndex(magazaKapatBtn, game.children.length - 1);
game.setChildIndex(magazaKapatBtnTxt, game.children.length - 1);
if (typeof magazaKapatBtnIcon !== "undefined") {
game.setChildIndex(magazaKapatBtnIcon, game.children.length - 1);
}
}
};
// Paneli kapatmak için bir kapat butonu ekle
// --- Kapat butonu: sağ üstte, %100 büyüklükte, kırmızı çerçeveli ---
// Panelin sağ üst köşesine hizala, %100 büyüklükte (240x120)
var magazaKapatBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 360,
//{4g} // %50 artırıldı
height: 180,
//{4h} // %50 artırıldı
// Alt orta: panelin alt kenarının ortası, 60px yukarıda
x: magazaPanel.x,
y: magazaPanel.y + magazaPanel.height / 2 - 60,
color: 0xffffff,
borderColor: 0xff2222,
borderWidth: 8
});
magazaKapatBtn.visible = false;
game.addChild(magazaKapatBtn);
// Kapat butonu için X simgesi (Unicode heavy multiplication X)
var magazaKapatBtnIcon = new Text2("\u2716", {
size: 81,
//{4o} // %50 artırıldı
fill: '#ff2222'
});
magazaKapatBtnIcon.anchor.set(1, 0.5);
magazaKapatBtnIcon.x = magazaKapatBtn.x - 60;
magazaKapatBtnIcon.y = magazaKapatBtn.y;
magazaKapatBtnIcon.visible = false;
game.addChild(magazaKapatBtnIcon);
var magazaKapatBtnTxt = new Text2('Kapat', {
size: 96,
//{4r} // %50 artırıldı
fill: '#ff2222'
});
magazaKapatBtnTxt.anchor.set(0.5, 0.5);
magazaKapatBtnTxt.x = magazaKapatBtn.x;
magazaKapatBtnTxt.y = magazaKapatBtn.y;
magazaKapatBtnTxt.visible = false;
game.addChild(magazaKapatBtnTxt);
magazaKapatBtn.down = function (x, y, obj) {
if (isSoundOn && LK.getSound) {
var clickSound = LK.getSound('ClickSesi');
if (clickSound) {
clickSound.play();
}
}
magazaPanel.visible = false;
magazaPanelTitle.visible = false;
magazaPanelText.visible = false;
magazaKapatBtn.visible = false;
magazaKapatBtnTxt.visible = false;
magazaMuhasebeTitle.visible = false;
magazaMuhasebeText.visible = false;
// --- Ava: Restore background elements hidden under the panel area ---
if (magazaPanel._hiddenBackgrounds && magazaPanel._hiddenBackgrounds.length) {
for (var i = 0; i < magazaPanel._hiddenBackgrounds.length; i++) {
var child = magazaPanel._hiddenBackgrounds[i];
if (child && typeof child.visible === "boolean") {
if (typeof child._oldVisible !== "undefined") {
child.visible = child._oldVisible;
delete child._oldVisible;
} else {
child.visible = true;
}
}
}
magazaPanel._hiddenBackgrounds = [];
}
// Restore all homepage elements
setHomepageUIEnabled(true);
};
// --- Yatırım Button ve Açılır Pencere ---
// Yatırım butonunu mağaza butonunun soluna ekle
var yatirimBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 180,
height: 70
});
yatirimBtn.x = magazaBtn.x - 220;
yatirimBtn.y = magazaBtn.y;
LK.gui.top.addChild(yatirimBtn);
var yatirimBtnTxt = new Text2('Yatırım', {
size: 36,
fill: '#fff'
});
yatirimBtnTxt.anchor.set(0.5, 0.5);
yatirimBtnTxt.x = yatirimBtn.x;
yatirimBtnTxt.y = yatirimBtn.y;
LK.gui.top.addChild(yatirimBtnTxt);
// Açılır pencereyi oluştur (başta görünmez) - EKRANIN EN ÜSTÜNDE
// Yatırım panelini tam ekranın ortasına ve %90 genişlikte/ekran yüksekliğinin %70'i kadar yap
var yatirimPanelWidth = Math.floor(2048 * 0.9);
var yatirimPanelHeight = Math.floor(2732 * 0.7);
var yatirimPanelX = Math.floor(2048 / 2);
var yatirimPanelY = Math.floor(2732 / 2);
var yatirimPanel = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: yatirimPanelWidth,
height: yatirimPanelHeight,
x: yatirimPanelX,
y: yatirimPanelY
});
yatirimPanel.visible = false;
// Yatırım panelini ve başlığını en önde göstermek için game üstünde en sona ekle
game.addChild(yatirimPanel);
game.setChildIndex(yatirimPanel, game.children.length - 1);
var yatirimTitle = new Text2('Yatırım - Popüler Coinler', {
size: 40,
fill: '#fff'
});
yatirimTitle.anchor.set(0.5, 0);
// Panelin üst kenarına ortalı hizala
yatirimTitle.x = yatirimPanel.x;
yatirimTitle.y = yatirimPanel.y - yatirimPanel.height / 2 + 20;
yatirimTitle.visible = false;
game.addChild(yatirimTitle);
game.setChildIndex(yatirimTitle, game.children.length - 1);
// 12 popüler coin listesi
var coinList = [{
name: "Bitcoin",
symbol: "BTC"
}, {
name: "Ethereum",
symbol: "ETH"
}, {
name: "Tether",
symbol: "USDT"
}, {
name: "BNB",
symbol: "BNB"
}, {
name: "Solana",
symbol: "SOL"
}, {
name: "XRP",
symbol: "XRP"
}, {
name: "Dogecoin",
symbol: "DOGE"
}, {
name: "Cardano",
symbol: "ADA"
}, {
name: "Toncoin",
symbol: "TON"
}, {
name: "Shiba Inu",
symbol: "SHIB"
}, {
name: "Avalanche",
symbol: "AVAX"
}, {
name: "Polkadot",
symbol: "DOT"
}];
// Coin fiyatları ve kullanıcı bakiyesi
var coinPrices = [];
var coinHoldings = [];
for (var i = 0; i < coinList.length; i++) {
// Başlangıç fiyatları: BTC 1.000.000, ETH 50.000, diğerleri 10.000-1.000 arası
var base = 1000000;
if (i === 1) {
base = 50000;
} else if (i > 1) {
base = 10000 - i * 900;
}
coinPrices[i] = base;
coinHoldings[i] = 0;
}
// Coin ortalama maliyetlerini ve toplam harcanan tutarı tutan diziler
var coinTotalCost = [];
var coinAvgCost = [];
for (var i = 0; i < coinList.length; i++) {
coinTotalCost[i] = 0;
coinAvgCost[i] = 0;
}
// Coin fiyatlarını gösterecek ve al/sat butonları
var coinTxts = [];
var coinPriceTxts = [];
var coinHoldingTxts = [];
var coinBuyBtns = [];
var coinSellBtns = [];
var coinBuyBtnTxts = [];
var coinSellBtnTxts = [];
var coinBuyInputTxts = [];
var coinSellInputTxts = [];
var coinBuyAmounts = [];
var coinSellAmounts = [];
for (var i = 0; i < coinList.length; i++) {
// Coin adı (sadece parantez içindekiler, yani symbol)
var coinTxt = new Text2(i + 1 + ". " + coinList[i].symbol, {
size: 40,
fill: '#bff'
});
coinTxt.anchor.set(0, 0);
// Panelin soluna daha yakın hizala (daha sola çek)
coinTxt.x = yatirimPanel.x - yatirimPanel.width / 2 + 30;
coinTxt.y = yatirimPanel.y + 80 + i * 75;
coinTxt.visible = false;
game.addChild(coinTxt);
coinTxts.push(coinTxt);
// Fiyat
var coinPriceTxt = new Text2("₺" + coinPrices[i], {
size: 40,
fill: '#fff'
});
coinPriceTxt.anchor.set(0, 0);
// Panelin soluna daha yakın hizala
coinPriceTxt.x = yatirimPanel.x - yatirimPanel.width / 2 + 210;
coinPriceTxt.y = coinTxt.y;
coinPriceTxt.visible = false;
game.addChild(coinPriceTxt);
coinPriceTxts.push(coinPriceTxt);
// Kullanıcı bakiyesi
var coinHoldingTxt = new Text2("Adet: 0", {
size: 40,
fill: '#ffb'
});
coinHoldingTxt.anchor.set(0, 0);
// Panelin soluna daha yakın hizala
coinHoldingTxt.x = yatirimPanel.x - yatirimPanel.width / 2 + 370;
coinHoldingTxt.y = coinTxt.y;
coinHoldingTxt.visible = false;
game.addChild(coinHoldingTxt);
coinHoldingTxts.push(coinHoldingTxt);
// Al butonu
var buyBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 100,
height: 60,
// Panelin SAĞ kenarına hizala (yeni genişlik: 950)
x: yatirimPanel.x + yatirimPanel.width / 2 - 150,
y: coinTxt.y + 18
});
buyBtn.visible = false;
game.addChild(buyBtn);
coinBuyBtns.push(buyBtn);
var buyBtnTxt = new Text2('Al', {
size: 40,
fill: '#fff'
});
buyBtnTxt.anchor.set(0.5, 0.5);
buyBtnTxt.x = buyBtn.x;
buyBtnTxt.y = buyBtn.y;
buyBtnTxt.visible = false;
game.addChild(buyBtnTxt);
coinBuyBtnTxts.push(buyBtnTxt);
// Sat butonu
var sellBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 100,
height: 60,
// Panelin SAĞ kenarına hizala, buyBtn'in sağında 130px boşluk bırak (yeni genişlik: 950)
x: yatirimPanel.x + yatirimPanel.width / 2 - 50,
y: coinTxt.y + 18
});
sellBtn.visible = false;
game.addChild(sellBtn);
coinSellBtns.push(sellBtn);
var sellBtnTxt = new Text2('Sat', {
size: 40,
fill: '#fff'
});
sellBtnTxt.anchor.set(0.5, 0.5);
sellBtnTxt.x = sellBtn.x;
sellBtnTxt.y = sellBtn.y;
sellBtnTxt.visible = false;
game.addChild(sellBtnTxt);
coinSellBtnTxts.push(sellBtnTxt);
// Alım miktarı (sabit 1, artırmak için input yok, mobilde kolaylık için)
// Aradaki süre/label kaldırıldı
coinBuyAmounts[i] = 1;
coinSellAmounts[i] = 1;
}
// --- Mevduat (Deposit) Section removed from Yatırım panel ---
// Paneli kapatmak için bir kapat butonu ekle
// --- Kapat butonu: sağ üstte, %100 büyüklükte, kırmızı çerçeveli ---
var yatirimKapatBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 360,
//{6e} // %50 artırıldı
height: 180,
//{6f} // %50 artırıldı
// Alt orta: panelin alt kenarının ortası, 60px yukarıda
x: yatirimPanel.x,
y: yatirimPanel.y + yatirimPanel.height / 2 - 60,
color: 0xffffff,
borderColor: 0xff2222,
borderWidth: 8
});
yatirimKapatBtn.visible = false;
game.addChild(yatirimKapatBtn);
// Kapat butonu için X simgesi
var yatirimKapatBtnIcon = new Text2("\u2716", {
size: 81,
//{6n} // %50 artırıldı
fill: '#ff2222'
});
yatirimKapatBtnIcon.anchor.set(1, 0.5);
yatirimKapatBtnIcon.x = yatirimKapatBtn.x - 60;
yatirimKapatBtnIcon.y = yatirimKapatBtn.y;
yatirimKapatBtnIcon.visible = false;
game.addChild(yatirimKapatBtnIcon);
var yatirimKapatBtnTxt = new Text2('Kapat', {
size: 96,
//{6q} // %50 artırıldı
fill: '#ff2222'
});
yatirimKapatBtnTxt.anchor.set(0.5, 0.5);
yatirimKapatBtnTxt.x = yatirimKapatBtn.x;
yatirimKapatBtnTxt.y = yatirimKapatBtn.y;
yatirimKapatBtnTxt.visible = false;
game.addChild(yatirimKapatBtnTxt);
// Panel açma
yatirimBtn.down = function (x, y, obj) {
if (newPagePanel && newPagePanel.visible) {
return;
}
if (isSoundOn && LK.getSound) {
var clickSound = LK.getSound('ClickSesi');
if (clickSound) {
clickSound.play();
}
}
yatirimPanel.visible = true;
yatirimTitle.visible = true;
yatirimKapatBtn.visible = true;
yatirimKapatBtnTxt.visible = true;
// --- Ava: Hide only the background elements under the panel area, keep other elements visible ---
if (!yatirimPanel._hiddenBackgrounds) yatirimPanel._hiddenBackgrounds = [];
for (var i = 0; i < game.children.length; i++) {
var child = game.children[i];
if (child && typeof child.visible === "boolean" && child.visible && child !== yatirimPanel && child !== yatirimTitle && child !== yatirimKapatBtn && child !== yatirimKapatBtnTxt && !(child instanceof Text2) && !(child.assetId && child.assetId.indexOf("button") === 0) && typeof child.x === "number" && typeof child.y === "number" && child.x + (child.width || 0) > yatirimPanel.x - yatirimPanel.width / 2 && child.x < yatirimPanel.x + yatirimPanel.width / 2 && child.y + (child.height || 0) > yatirimPanel.y - yatirimPanel.height / 2 && child.y < yatirimPanel.y + yatirimPanel.height / 2) {
child._oldVisible = child.visible;
child.visible = false;
yatirimPanel._hiddenBackgrounds.push(child);
}
}
// Panelin merkezine göre coin paneli elemanlarını hizala
for (var i = 0; i < coinTxts.length; i++) {
// Panelin soluna hizala
coinTxts[i].x = yatirimPanel.x - yatirimPanel.width / 2 + 30;
coinTxts[i].y = yatirimPanel.y - yatirimPanel.height / 2 + 80 + i * 75;
coinPriceTxts[i].x = yatirimPanel.x - yatirimPanel.width / 2 + 210;
coinPriceTxts[i].y = coinTxts[i].y;
coinHoldingTxts[i].x = yatirimPanel.x - yatirimPanel.width / 2 + 370;
coinHoldingTxts[i].y = coinTxts[i].y;
// Al ve Sat butonlarını panelin sağ kenarına hizala (panelin sağ kenarından 180px ve 50px içeride)
coinBuyBtns[i].x = yatirimPanel.x + yatirimPanel.width / 2 - 180;
coinBuyBtns[i].y = coinTxts[i].y + 18;
coinSellBtns[i].x = yatirimPanel.x + yatirimPanel.width / 2 - 50;
coinSellBtns[i].y = coinTxts[i].y + 18;
coinBuyBtnTxts[i].x = coinBuyBtns[i].x;
coinBuyBtnTxts[i].y = coinBuyBtns[i].y;
coinSellBtnTxts[i].x = coinSellBtns[i].x;
coinSellBtnTxts[i].y = coinSellBtns[i].y;
coinTxts[i].visible = true;
coinPriceTxts[i].visible = true;
coinHoldingTxts[i].visible = true;
coinBuyBtns[i].visible = true;
coinSellBtns[i].visible = true;
coinBuyBtnTxts[i].visible = true;
coinSellBtnTxts[i].visible = true;
}
// Kapat butonunu panelin alt kenarının ortasına hizala
yatirimKapatBtn.x = yatirimPanel.x;
yatirimKapatBtn.y = yatirimPanel.y + yatirimPanel.height / 2 - 60;
yatirimKapatBtnTxt.x = yatirimKapatBtn.x;
yatirimKapatBtnTxt.y = yatirimKapatBtn.y;
yatirimTitle.x = yatirimPanel.x;
yatirimTitle.y = yatirimPanel.y - yatirimPanel.height / 2 + 20;
updateCoinPanel();
// Panel ve içeriğini en öne getir
if (game.setChildIndex) {
// Panel ve tüm içeriğini en öne getir (butonlar dahil)
game.setChildIndex(yatirimPanel, game.children.length - 1);
game.setChildIndex(yatirimTitle, game.children.length - 1);
// Kapat butonu ve X simgesi ve yazısı en önde
game.setChildIndex(yatirimKapatBtn, game.children.length - 1);
game.setChildIndex(yatirimKapatBtnTxt, game.children.length - 1);
if (typeof yatirimKapatBtnIcon !== "undefined") {
game.setChildIndex(yatirimKapatBtnIcon, game.children.length - 1);
}
for (var i = 0; i < coinTxts.length; i++) {
game.setChildIndex(coinTxts[i], game.children.length - 1);
game.setChildIndex(coinPriceTxts[i], game.children.length - 1);
game.setChildIndex(coinHoldingTxts[i], game.children.length - 1);
game.setChildIndex(coinBuyBtns[i], game.children.length - 1);
game.setChildIndex(coinSellBtns[i], game.children.length - 1);
game.setChildIndex(coinBuyBtnTxts[i], game.children.length - 1);
game.setChildIndex(coinSellBtnTxts[i], game.children.length - 1);
}
}
};
// Panel kapama
yatirimKapatBtn.down = function (x, y, obj) {
yatirimPanel.visible = false;
yatirimTitle.visible = false;
yatirimKapatBtn.visible = false;
yatirimKapatBtnTxt.visible = false;
// --- Ava: Restore background elements hidden under the panel area ---
if (yatirimPanel._hiddenBackgrounds && yatirimPanel._hiddenBackgrounds.length) {
for (var i = 0; i < yatirimPanel._hiddenBackgrounds.length; i++) {
var child = yatirimPanel._hiddenBackgrounds[i];
if (child && typeof child.visible === "boolean") {
if (typeof child._oldVisible !== "undefined") {
child.visible = child._oldVisible;
delete child._oldVisible;
} else {
child.visible = true;
}
}
}
yatirimPanel._hiddenBackgrounds = [];
}
// Show all homepage buttons/UI
if (typeof magazaBtn !== "undefined") {
magazaBtn.visible = true;
}
if (typeof magazaBtnTxt !== "undefined") {
magazaBtnTxt.visible = true;
}
if (typeof yatirimBtn !== "undefined") {
yatirimBtn.visible = true;
}
if (typeof yatirimBtnTxt !== "undefined") {
yatirimBtnTxt.visible = true;
}
if (typeof bankBtn !== "undefined") {
bankBtn.visible = true;
}
if (typeof bankBtnTxt !== "undefined") {
bankBtnTxt.visible = true;
}
if (typeof soundBtn !== "undefined") {
soundBtn.visible = true;
}
if (typeof soundBtnTxt !== "undefined") {
soundBtnTxt.visible = true;
}
// Restore Çalışanlar and Madenler buttons and images when Yatırım panel closes
if (typeof madenlerBtn !== "undefined") {
madenlerBtn.visible = true;
}
if (typeof madenlerBtnTxt !== "undefined") {
madenlerBtnTxt.visible = true;
}
if (typeof madenlerBtnMineImg !== "undefined") {
madenlerBtnMineImg.visible = true;
}
if (typeof newPageBtn !== "undefined") {
newPageBtn.visible = true;
}
if (typeof newPageBtnTxt !== "undefined") {
newPageBtnTxt.visible = true;
}
if (typeof calisanlarBtnImg !== "undefined") {
calisanlarBtnImg.visible = true;
}
if (typeof newPageBtn !== "undefined") {
newPageBtn.visible = true;
}
if (typeof newPageBtnTxt !== "undefined") {
newPageBtnTxt.visible = true;
}
if (typeof madenlerBtn !== "undefined") {
madenlerBtn.visible = true;
}
if (typeof madenlerBtnTxt !== "undefined") {
madenlerBtnTxt.visible = true;
}
if (typeof languagesBtn !== "undefined") {
languagesBtn.visible = true;
}
if (typeof languagesBtnTxt !== "undefined") {
languagesBtnTxt.visible = true;
}
// Info and How To Play buttons are never shown
// Show Borç Öde button again when Yatırım panel is closed
if (typeof borcOdeBtn !== "undefined") {
borcOdeBtn.visible = true;
}
if (typeof borcOdeBtnTxt !== "undefined") {
borcOdeBtnTxt.visible = true;
}
for (var i = 0; i < coinTxts.length; i++) {
coinTxts[i].visible = false;
coinPriceTxts[i].visible = false;
coinHoldingTxts[i].visible = false;
coinBuyBtns[i].visible = false;
coinSellBtns[i].visible = false;
coinBuyBtnTxts[i].visible = false;
coinSellBtnTxts[i].visible = false;
}
};
// Coin panelini güncelle
function updateCoinPanel() {
for (var i = 0; i < coinList.length; i++) {
coinPriceTxts[i].setText("₺" + coinPrices[i]);
// Ortalama maliyet gösterimi
if (coinHoldings[i] > 0) {
coinHoldingTxts[i].setText("Adet: " + coinHoldings[i] + "\nMaliyet: ₺" + Math.round(coinAvgCost[i]));
} else {
coinHoldingTxts[i].setText("Adet: 0");
}
}
}
// Bakiye detayları için global değişkenler
var toplamCoinAlim = 0;
var toplamCoinSatisGeliri = 0;
var toplamBorcOdeme = 0;
var toplamYatirimHarcamasi = 0;
var toplamFabrikaYukseltme = 0;
var toplamMadenYukseltme = 0;
var toplamStoreYukseltme = 0;
var toplamInternetTeklifHarcamasi = 0;
var toplamTopluSatisGeliri = 0;
var toplamMusteriSatisGeliri = 0;
// Coin alım-satım butonları
for (var i = 0; i < coinList.length; i++) {
// Al
coinBuyBtns[i].down = function (idx) {
return function (x, y, obj) {
var adet = coinBuyAmounts[idx];
var tutar = coinPrices[idx] * adet;
if (money >= tutar) {
money -= tutar;
toplamCoinAlim += tutar;
// Ortalama maliyet ve toplam maliyet güncelle
coinTotalCost[idx] += tutar;
coinHoldings[idx] += adet;
coinAvgCost[idx] = coinHoldings[idx] > 0 ? coinTotalCost[idx] / coinHoldings[idx] : 0;
updateMoneyText();
updateCoinPanel();
// Buton animasyonu
if (isSoundOn && LK.getSound) {
var clickSound = LK.getSound('ClickSesi');
if (clickSound) {
clickSound.play();
}
}
tween(coinBuyBtns[idx], {
scaleX: 1.15,
scaleY: 1.15
}, {
duration: 80,
onFinish: function onFinish() {
tween(coinBuyBtns[idx], {
scaleX: 1,
scaleY: 1
}, {
duration: 80
});
}
});
} else {
// Yetersiz bakiye animasyonu
if (isSoundOn && LK.getSound) {
var clickSound = LK.getSound('ClickSesi');
if (clickSound) {
clickSound.play();
}
}
tween(coinBuyBtns[idx], {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(coinBuyBtns[idx], {
tint: 0x222222
}, {
duration: 120
});
}
});
}
};
}(i);
// Sat
coinSellBtns[i].down = function (idx) {
return function (x, y, obj) {
var adet = coinSellAmounts[idx];
// Zararına satış aktif: coinHoldings >= adet ise, maliyet bakılmaksızın satış yapılır
if (coinHoldings[idx] >= adet) {
var tutar = coinPrices[idx] * adet;
toplamCoinSatisGeliri += tutar;
// Satışta ortalama maliyeti azalt (FIFO: en basit haliyle, toplam maliyetten orantılı azalt)
if (coinHoldings[idx] > 0) {
var costPer = coinAvgCost[idx];
coinTotalCost[idx] -= costPer * adet;
if (coinTotalCost[idx] < 0) {
coinTotalCost[idx] = 0;
}
}
coinHoldings[idx] -= adet;
if (coinHoldings[idx] > 0) {
coinAvgCost[idx] = coinTotalCost[idx] / coinHoldings[idx];
} else {
coinAvgCost[idx] = 0;
coinTotalCost[idx] = 0;
}
money += tutar;
updateMoneyText();
updateCoinPanel();
// Buton animasyonu
if (isSoundOn && LK.getSound) {
var clickSound = LK.getSound('ClickSesi');
if (clickSound) {
clickSound.play();
}
}
tween(coinSellBtns[idx], {
scaleX: 1.15,
scaleY: 1.15
}, {
duration: 80,
onFinish: function onFinish() {
tween(coinSellBtns[idx], {
scaleX: 1,
scaleY: 1
}, {
duration: 80
});
}
});
// Satış işlemi anında gerçekleşir, bekleme süresi yok.
} else {
// Yetersiz coin animasyonu
if (isSoundOn && LK.getSound) {
var clickSound = LK.getSound('ClickSesi');
if (clickSound) {
clickSound.play();
}
}
tween(coinSellBtns[idx], {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(coinSellBtns[idx], {
tint: 0x222222
}, {
duration: 120
});
}
});
}
};
}(i);
}
// Coin fiyatları başlangıç fiyatından maksimum %10 yükselip düşebilir, rastgele değişim uygula (her 2 saniyede bir)
var coinBasePrices = [];
for (var i = 0; i < coinList.length; i++) {
// Başlangıç fiyatlarını coinPrices oluşturulurkenki ile aynı şekilde ata
var base = 1000000;
if (i === 1) {
base = 50000;
} else if (i > 1) {
base = 10000 - i * 900;
}
coinBasePrices[i] = base;
}
// Her 40 saniyede bir coin fiyatlarını güncelle (2 saniyeden 40 saniyeye çıkarıldı, %95 yavaşlatıldı)
LK.setInterval(function () {
for (var i = 0; i < coinPrices.length; i++) {
// Rastgele -%2.5 ile +%2.5 arası değişim uygula
var degisim = 1 + (Math.random() * 0.05 - 0.025);
var yeniFiyat = coinPrices[i] * degisim;
// Sınırları uygula: min %10 düşüş, max %10 artış
var minFiyat = Math.floor(coinBasePrices[i] * 0.9);
var maxFiyat = Math.ceil(coinBasePrices[i] * 1.1);
if (yeniFiyat < minFiyat) {
yeniFiyat = minFiyat;
}
if (yeniFiyat > maxFiyat) {
yeniFiyat = maxFiyat;
}
coinPrices[i] = Math.floor(yeniFiyat);
}
updateCoinPanel();
}, 2400); // 40 saniye (60fps * 40)
function updateMoneyText() {
moneyTxt.setText('₺' + money);
updateBorcText && updateBorcText();
if (magazaMuhasebeText && magazaMuhasebeText.visible) {
updateMagazaMuhasebeText();
}
// Bakiye detaylarını güncelleme kodu kaldırıldı.
}
// --- Banka Button & Borç Logic ---
var bankBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 180,
height: 70
});
bankBtn.x = moneyTxt.x + 220;
bankBtn.y = 40;
LK.gui.top.addChild(bankBtn);
// --- Sound Toggle Icon Button ---
// Use a simple colored box as icon: green for sound on, red for sound off
var soundOnColor = 0x83de44;
var soundOffColor = 0xd83318;
// Sound button is created after languagesBtn to ensure languagesBtn is defined
// Ava: Move soundBtn and soundBtnTxt creation after languagesBtn to fix undefined errors and ensure correct button order
// (Moved below languagesBtn and languagesBtnTxt creation)
var bankBtnTxt = new Text2('%10 Borç Al', {
size: 36,
fill: '#fff'
});
bankBtnTxt.anchor.set(0.5, 0.5);
bankBtnTxt.x = bankBtn.x;
bankBtnTxt.y = bankBtn.y;
LK.gui.top.addChild(bankBtnTxt);
var borc = 0;
var borcTxt = new Text2('', {
size: 32,
fill: '#ffb'
});
borcTxt.anchor.set(0.5, 0);
borcTxt.x = moneyTxt.x + 420;
borcTxt.y = 10;
LK.gui.top.addChild(borcTxt);
// Borç Öde button
var borcOdeBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 140,
height: 54
});
borcOdeBtn.x = borcTxt.x + 180;
borcOdeBtn.y = borcTxt.y + 28;
LK.gui.top.addChild(borcOdeBtn);
var borcOdeBtnTxt = new Text2('Borç Öde', {
size: 28,
fill: '#fff'
});
borcOdeBtnTxt.anchor.set(0.5, 0.5);
borcOdeBtnTxt.x = borcOdeBtn.x;
borcOdeBtnTxt.y = borcOdeBtn.y;
LK.gui.top.addChild(borcOdeBtnTxt);
// --- Mağazalar Button below Borç Öde button ---
// Mevduat butonu ve paneli tamamen kaldırıldı
// --- Mağazalar Panel (initially hidden) ---
var magazalarPanelWidth = Math.floor(panelWidth * 0.9);
var magazalarPanelHeight = Math.floor(panelHeight * 0.9);
var magazalarPanelX = Math.floor((2048 - magazalarPanelWidth) / 2);
var magazalarPanelY = Math.floor((2732 - magazalarPanelHeight) / 2);
var magazalarPanel = LK.getAsset('button', {
anchorX: 0,
anchorY: 0,
width: magazalarPanelWidth,
height: magazalarPanelHeight,
x: magazalarPanelX,
y: magazalarPanelY
});
magazalarPanel.visible = false;
game.addChild(magazalarPanel);
var magazalarPanelTitle = new Text2('Mağazalar', {
size: 36,
fill: '#fff'
});
magazalarPanelTitle.anchor.set(0.5, 0);
magazalarPanelTitle.x = 2048 / 2;
magazalarPanelTitle.y = magazalarPanelY + 40;
magazalarPanelTitle.visible = false;
game.addChild(magazalarPanelTitle);
var magazalarPanelText = new Text2('Tüm mağazalar ve müşteriler burada görüntülenir.', {
size: 36,
fill: '#bff',
lineHeight: 44
});
magazalarPanelText.anchor.set(0.5, 0);
magazalarPanelText.x = 2048 / 2;
magazalarPanelText.y = magazalarPanelTitle.y + magazalarPanelTitle.height + 10;
magazalarPanelText.visible = false;
game.addChild(magazalarPanelText);
// Kapat butonu
var magazalarKapatBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 360,
//{aG} // %50 artırıldı
height: 180,
//{aH} // %50 artırıldı
// Alt orta: panelin alt kenarının ortası, 60px yukarıda
x: magazalarPanel.x + magazalarPanel.width / 2,
y: magazalarPanel.y + magazalarPanel.height - 60,
color: 0xffffff,
borderColor: 0xff2222,
borderWidth: 8
});
magazalarKapatBtn.visible = false;
game.addChild(magazalarKapatBtn);
var magazalarKapatBtnIcon = new Text2("\u2716", {
size: 81,
//{aO} // %50 artırıldı
fill: '#ff2222'
});
magazalarKapatBtnIcon.anchor.set(1, 0.5);
magazalarKapatBtnIcon.x = magazalarKapatBtn.x - 60;
magazalarKapatBtnIcon.y = magazalarKapatBtn.y;
magazalarKapatBtnIcon.visible = false;
game.addChild(magazalarKapatBtnIcon);
var magazalarKapatBtnTxt = new Text2('Kapat', {
size: 96,
//{aS} // %50 artırıldı
fill: '#ff2222'
});
magazalarKapatBtnTxt.anchor.set(0.5, 0.5);
magazalarKapatBtnTxt.x = magazalarKapatBtn.x;
magazalarKapatBtnTxt.y = magazalarKapatBtn.y;
magazalarKapatBtnTxt.visible = false;
game.addChild(magazalarKapatBtnTxt);
// --- Move both stores and their customers to the Mağazalar panel ---
function showMagazalarPanel() {
magazalarPanel.visible = true;
magazalarPanelTitle.visible = true;
magazalarPanelText.visible = true;
magazalarKapatBtn.visible = true;
magazalarKapatBtnIcon.visible = true;
magazalarKapatBtnTxt.visible = true;
// Hide all homepage buttons/UI
if (typeof magazaBtn !== "undefined") {
magazaBtn.visible = false;
}
if (typeof magazaBtnTxt !== "undefined") {
magazaBtnTxt.visible = false;
}
if (typeof yatirimBtn !== "undefined") {
yatirimBtn.visible = false;
}
if (typeof yatirimBtnTxt !== "undefined") {
yatirimBtnTxt.visible = false;
}
if (typeof bankBtn !== "undefined") {
bankBtn.visible = false;
}
if (typeof bankBtnTxt !== "undefined") {
bankBtnTxt.visible = false;
}
if (typeof soundBtn !== "undefined") {
soundBtn.visible = false;
}
if (typeof soundBtnTxt !== "undefined") {
soundBtnTxt.visible = false;
}
if (typeof newPageBtn !== "undefined") {
newPageBtn.visible = false;
}
if (typeof newPageBtnTxt !== "undefined") {
newPageBtnTxt.visible = false;
}
if (typeof madenlerBtn !== "undefined") {
madenlerBtn.visible = false;
}
if (typeof madenlerBtnTxt !== "undefined") {
madenlerBtnTxt.visible = false;
}
if (typeof magazalarBtn !== "undefined") {
magazalarBtn.visible = false;
}
if (typeof magazalarBtnTxt !== "undefined") {
magazalarBtnTxt.visible = false;
}
if (typeof languagesBtn !== "undefined") {
languagesBtn.visible = false;
}
if (typeof languagesBtnTxt !== "undefined") {
languagesBtnTxt.visible = false;
}
if (typeof infoBtn !== "undefined") {
infoBtn.visible = false;
}
if (typeof infoBtnTxt !== "undefined") {
infoBtnTxt.visible = false;
}
if (typeof howToBtn !== "undefined") {
howToBtn.visible = false;
}
if (typeof howToBtnTxt !== "undefined") {
howToBtnTxt.visible = false;
}
if (typeof borcOdeBtn !== "undefined") {
borcOdeBtn.visible = false;
}
if (typeof borcOdeBtnTxt !== "undefined") {
borcOdeBtnTxt.visible = false;
}
if (typeof mevduatBtn !== "undefined") {
mevduatBtn.visible = false;
}
if (typeof mevduatBtnTxt !== "undefined") {
mevduatBtnTxt.visible = false;
}
// Prevent hiding store purchase buttons on homepage when Mağazalar panel opens
if (typeof store2PurchaseBtn !== "undefined") {
store2PurchaseBtn.visible = !store2Purchased;
}
if (typeof store2PurchaseBtnTxt !== "undefined" && store2PurchaseBtnTxt && typeof store2PurchaseBtnTxt.visible === "boolean") {
store2PurchaseBtnTxt.visible = !store2Purchased;
}
if (typeof store3PurchaseBtn !== "undefined") {
store3PurchaseBtn.visible = !store3Purchased;
}
if (typeof store3PurchaseBtnTxt !== "undefined") {
store3PurchaseBtnTxt.visible = !store3Purchased;
}
if (typeof store3PurchaseBtnIcon !== "undefined") {
store3PurchaseBtnIcon.visible = !store3Purchased;
}
if (typeof store4PurchaseBtn !== "undefined") {
store4PurchaseBtn.visible = !store4Purchased;
}
if (typeof store4PurchaseBtnTxt !== "undefined") {
store4PurchaseBtnTxt.visible = !store4Purchased;
}
if (typeof store4PurchaseBtnIcon !== "undefined") {
store4PurchaseBtnIcon.visible = !store4Purchased;
}
// Show all store purchase buttons (store2, store3, store4) and bring them to front when Mağazalar panel opens
if (typeof store2PurchaseBtn !== "undefined" && typeof store2PurchaseBtnTxt !== "undefined") {
if (typeof store2PurchaseBtn !== "undefined" && store2PurchaseBtn) {
store2PurchaseBtn.visible = !store2Purchased;
}
if (typeof store2PurchaseBtnTxt !== "undefined" && store2PurchaseBtnTxt) {
store2PurchaseBtnTxt.visible = !store2Purchased;
}
if (game.setChildIndex) {
game.setChildIndex(store2PurchaseBtn, game.children.length - 1);
game.setChildIndex(store2PurchaseBtnTxt, game.children.length - 1);
}
}
if (typeof store3PurchaseBtn !== "undefined" && typeof store3PurchaseBtnTxt !== "undefined") {
store3PurchaseBtn.visible = !store3Purchased;
store3PurchaseBtnTxt.visible = !store3Purchased;
if (typeof store3PurchaseBtnIcon !== "undefined") {
store3PurchaseBtnIcon.visible = !store3Purchased;
}
// Ensure button and text are brought to front
if (game.setChildIndex) {
game.setChildIndex(store3PurchaseBtn, game.children.length - 1);
game.setChildIndex(store3PurchaseBtnTxt, game.children.length - 1);
if (typeof store3PurchaseBtnIcon !== "undefined") {
game.setChildIndex(store3PurchaseBtnIcon, game.children.length - 1);
}
}
}
if (typeof store4PurchaseBtn !== "undefined" && typeof store4PurchaseBtnTxt !== "undefined") {
store4PurchaseBtn.visible = !store4Purchased;
store4PurchaseBtnTxt.visible = !store4Purchased;
if (typeof store4PurchaseBtnIcon !== "undefined") {
store4PurchaseBtnIcon.visible = !store4Purchased;
}
// Ensure button and text are brought to front
if (game.setChildIndex) {
game.setChildIndex(store4PurchaseBtn, game.children.length - 1);
game.setChildIndex(store4PurchaseBtnTxt, game.children.length - 1);
if (typeof store4PurchaseBtnIcon !== "undefined") {
game.setChildIndex(store4PurchaseBtnIcon, game.children.length - 1);
}
}
}
// --- Mağazalar panelinde 2'li sıra halinde alt alta ve ortalı hizalama ---
// Grid ayarları
var storeCols = 2;
var storeRows = 2;
var storeCellWidth = magazalarPanel.width / storeCols;
var storeCellHeight = magazalarPanel.height / 3.5; // 3.5 ile daha sıkışık, 4 ile daha geniş
var storeStartX = magazalarPanel.x + storeCellWidth / 2;
var storeStartY = magazalarPanelText.y + magazalarPanelText.height + 60 + storeCellHeight; // Başlık ve açıklama altı, 1 satır aşağı kaydırıldı
// Mağazaları ve butonları gridde sırala
var storeList = [store, store2, store3, store4];
var storeBtnList = [storeBtn, store2Btn, store3Btn, store4Btn];
var storeBtnTxtList = [storeBtnTxt, store2BtnTxt, store3BtnTxt, store4BtnTxt];
var storePurchaseBtnList = [null, store2PurchaseBtn, store3PurchaseBtn, store4PurchaseBtn];
var storePurchaseBtnTxtList = [null, store2PurchaseBtnTxt, store3PurchaseBtnTxt, store4PurchaseBtnTxt];
var storePurchasedList = [true, store2Purchased, store3Purchased, store4Purchased];
for (var i = 0; i < 4; i++) {
var row = Math.floor(i / storeCols);
var col = i % storeCols;
var cx = storeStartX + col * storeCellWidth;
var cy = storeStartY + row * storeCellHeight;
// Mağaza görseli
if (typeof storeList[i] !== "undefined") {
storeList[i].x = cx;
storeList[i].y = cy;
storeList[i].visible = true;
game.setChildIndex(storeList[i], game.children.length - 1);
}
// Seviye yazısı (her mağaza için)
var levelTxt = null;
if (typeof storeList[i] !== "undefined" && typeof storeList[i].children !== "undefined") {
for (var ch = 0; ch < storeList[i].children.length; ch++) {
if (storeList[i].children[ch] && typeof storeList[i].children[ch].setText === "function" && storeList[i].children[ch].getText && (storeList[i].children[ch].getText() + "").indexOf("Lv.") === 0) {
levelTxt = storeList[i].children[ch];
break;
}
}
}
var levelY = cy + 90;
if (levelTxt) {
levelTxt.x = cx;
levelTxt.y = levelY;
}
// Yükseltme butonu (her mağaza için) -- seviye yazısının altına hizala
if (typeof storeBtnList[i] !== "undefined") {
storeBtnList[i].x = cx;
storeBtnList[i].y = levelY + 60;
// Sadece satın alındıysa göster
storeBtnList[i].visible = i === 0 ? true : !!storePurchasedList[i];
if (game.setChildIndex) {
game.setChildIndex(storeBtnList[i], game.children.length - 1);
}
}
if (typeof storeBtnTxtList[i] !== "undefined") {
storeBtnTxtList[i].x = cx;
storeBtnTxtList[i].y = levelY + 80;
storeBtnTxtList[i].visible = i === 0 ? true : !!storePurchasedList[i];
if (game.setChildIndex) {
game.setChildIndex(storeBtnTxtList[i], game.children.length - 1);
}
}
// Satın al butonu (store2, store3, store4) -- seviye yazısının altına hizala
if (i > 0 && typeof storePurchaseBtnList[i] !== "undefined" && typeof storePurchaseBtnTxtList[i] !== "undefined") {
storePurchaseBtnList[i].x = cx;
storePurchaseBtnList[i].y = levelY + 120;
storePurchaseBtnTxtList[i].x = cx;
storePurchaseBtnTxtList[i].y = levelY + 140;
// Defensive: always set visible based on purchase state
if (i === 2) {
// Store3
storePurchaseBtnList[i].visible = !store3Purchased;
storePurchaseBtnTxtList[i].visible = !store3Purchased;
if (typeof store3PurchaseBtnIcon !== "undefined") {
store3PurchaseBtnIcon.visible = !store3Purchased;
}
} else if (i === 3) {
// Store4
storePurchaseBtnList[i].visible = !store4Purchased;
storePurchaseBtnTxtList[i].visible = !store4Purchased;
if (typeof store4PurchaseBtnIcon !== "undefined") {
store4PurchaseBtnIcon.visible = !store4Purchased;
}
} else {
storePurchaseBtnList[i].visible = !storePurchasedList[i];
storePurchaseBtnTxtList[i].visible = !storePurchasedList[i];
}
if (game.setChildIndex) {
game.setChildIndex(storePurchaseBtnList[i], game.children.length - 1);
game.setChildIndex(storePurchaseBtnTxtList[i], game.children.length - 1);
}
}
}
// --- Ava: Bring Store3 and Store4 purchase buttons and icons to the very front above overlay and panel when Mağazalar panel opens ---
if (game.setChildIndex) {
// First, bring panel to front
game.setChildIndex(magazalarPanel, game.children.length - 1);
// Then, bring Store3 and Store4 purchase buttons, their texts, and icons to the very front
if (typeof store3PurchaseBtn !== "undefined") {
game.setChildIndex(store3PurchaseBtn, game.children.length - 1);
}
if (typeof store3PurchaseBtnIcon !== "undefined") {
game.setChildIndex(store3PurchaseBtnIcon, game.children.length - 1);
}
if (typeof store3PurchaseBtnTxt !== "undefined") {
game.setChildIndex(store3PurchaseBtnTxt, game.children.length - 1);
}
if (typeof store4PurchaseBtn !== "undefined") {
game.setChildIndex(store4PurchaseBtn, game.children.length - 1);
}
if (typeof store4PurchaseBtnIcon !== "undefined") {
game.setChildIndex(store4PurchaseBtnIcon, game.children.length - 1);
}
if (typeof store4PurchaseBtnTxt !== "undefined") {
game.setChildIndex(store4PurchaseBtnTxt, game.children.length - 1);
}
}
// Bring panel and its content to front
if (game.setChildIndex) {
game.setChildIndex(magazalarPanel, game.children.length - 1);
game.setChildIndex(magazalarPanelTitle, game.children.length - 1);
game.setChildIndex(magazalarPanelText, game.children.length - 1);
// Kapat butonu ve X simgesi ve yazısı en önde
game.setChildIndex(magazalarKapatBtn, game.children.length - 1);
game.setChildIndex(magazalarKapatBtnIcon, game.children.length - 1);
game.setChildIndex(magazalarKapatBtnTxt, game.children.length - 1);
if (typeof store !== "undefined") {
game.setChildIndex(store, game.children.length - 1);
}
if (typeof store2 !== "undefined") {
game.setChildIndex(store2, game.children.length - 1);
}
if (typeof store3 !== "undefined") {
game.setChildIndex(store3, game.children.length - 1);
}
if (typeof store4 !== "undefined") {
game.setChildIndex(store4, game.children.length - 1);
}
if (typeof storeBtn !== "undefined") {
game.setChildIndex(storeBtn, game.children.length - 1);
}
if (typeof storeBtnTxt !== "undefined") {
game.setChildIndex(storeBtnTxt, game.children.length - 1);
}
if (typeof store2Btn !== "undefined") {
game.setChildIndex(store2Btn, game.children.length - 1);
}
if (typeof store2BtnTxt !== "undefined") {
game.setChildIndex(store2BtnTxt, game.children.length - 1);
}
if (typeof store2PurchaseBtn !== "undefined") {
game.setChildIndex(store2PurchaseBtn, game.children.length - 1);
}
if (typeof store2PurchaseBtnTxt !== "undefined") {
game.setChildIndex(store2PurchaseBtnTxt, game.children.length - 1);
}
if (typeof store3Btn !== "undefined") {
game.setChildIndex(store3Btn, game.children.length - 1);
}
if (typeof store3BtnTxt !== "undefined") {
game.setChildIndex(store3BtnTxt, game.children.length - 1);
}
if (typeof store4Btn !== "undefined") {
game.setChildIndex(store4Btn, game.children.length - 1);
}
if (typeof store4BtnTxt !== "undefined") {
game.setChildIndex(store4BtnTxt, game.children.length - 1);
}
// Customer logic removed: no customers to bring to front.
}
}
// Show panel on button press
// Mağazalar butonu event handler'ları kaldırıldı
// Kapat butonu logic
magazalarKapatBtn.down = function (x, y, obj) {
magazalarPanel.visible = false;
magazalarPanelTitle.visible = false;
magazalarPanelText.visible = false;
magazalarKapatBtn.visible = false;
magazalarKapatBtnIcon.visible = false;
magazalarKapatBtnTxt.visible = false;
// Restore all homepage buttons/UI
if (typeof magazaBtn !== "undefined") {
magazaBtn.visible = true;
}
if (typeof magazaBtnTxt !== "undefined") {
magazaBtnTxt.visible = true;
}
if (typeof yatirimBtn !== "undefined") {
yatirimBtn.visible = true;
}
if (typeof yatirimBtnTxt !== "undefined") {
yatirimBtnTxt.visible = true;
}
if (typeof bankBtn !== "undefined") {
bankBtn.visible = true;
}
if (typeof bankBtnTxt !== "undefined") {
bankBtnTxt.visible = true;
}
if (typeof soundBtn !== "undefined") {
soundBtn.visible = true;
}
if (typeof soundBtnTxt !== "undefined") {
soundBtnTxt.visible = true;
}
if (typeof newPageBtn !== "undefined") {
newPageBtn.visible = true;
}
if (typeof newPageBtnTxt !== "undefined") {
newPageBtnTxt.visible = true;
}
if (typeof madenlerBtn !== "undefined") {
madenlerBtn.visible = true;
}
if (typeof madenlerBtnTxt !== "undefined") {
madenlerBtnTxt.visible = true;
}
if (typeof magazalarBtn !== "undefined") {
magazalarBtn.visible = true;
}
if (typeof magazalarBtnTxt !== "undefined") {
magazalarBtnTxt.visible = true;
}
if (typeof languagesBtn !== "undefined") {
languagesBtn.visible = true;
}
if (typeof languagesBtnTxt !== "undefined") {
languagesBtnTxt.visible = true;
}
// Info and How To Play buttons are never shown
if (typeof borcOdeBtn !== "undefined") {
borcOdeBtn.visible = true;
}
if (typeof borcOdeBtnTxt !== "undefined") {
borcOdeBtnTxt.visible = true;
}
if (typeof mevduatBtn !== "undefined") {
mevduatBtn.visible = true;
}
if (typeof mevduatBtnTxt !== "undefined") {
mevduatBtnTxt.visible = true;
}
// Move stores and customers back to their original positions
if (typeof store !== "undefined") {
store.x = 1850;
store.y = 600;
store.visible = true; // Anasayfa'da mağazaları göster
store2.visible = true; // Anasayfa'da mağazaları göster
store3.visible = true; // Anasayfa'da mağazaları göster
store4.visible = true; // Anasayfa'da mağazaları göster
store2.visible = true;
store3.visible = true;
if (typeof store4 !== "undefined") {
store4.visible = true;
}
}
if (typeof store2 !== "undefined") {
store2.x = 1850;
store2.y = 950;
store2.visible = true;
}
if (typeof store !== "undefined") {
store.x = 1850;
store.y = 600;
store.visible = true;
}
if (typeof store3 !== "undefined") {
store3.x = 1850;
store3.y = 1300;
store3.visible = true;
}
if (typeof store4 !== "undefined") {
store4.x = 1850;
store4.y = 1650;
store4.visible = true;
}
// Customer logic removed: no customers to reposition on Mağazalar panel close.
};
// --- Mevduat paneli ve tüm ilgili UI/logic tamamen kaldırıldı ---
// --- New Page Button below Banka button ---
var newPageBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 140,
height: 54
});
// --- Madenler butonunu bağımsız olarak konumlandır (Çalışanlar ile bağlantı yok) ---
if (typeof madenlerBtn !== "undefined" && madenlerBtn) {
// Borç öde butonunun altına, kendi sabit bir konuma yerleştir
var madenlerBtnGapY = 20;
madenlerBtn.x = borcOdeBtn.x;
madenlerBtn.y = borcOdeBtn.y + borcOdeBtn.height / 2 + madenlerBtnGapY + madenlerBtn.height / 2;
if (typeof madenlerBtnTxt !== "undefined") {
madenlerBtnTxt.x = madenlerBtn.x;
madenlerBtnTxt.y = madenlerBtn.y;
}
if (typeof madenlerBtnMineImg !== "undefined") {
madenlerBtnMineImg.x = madenlerBtn.x;
madenlerBtnMineImg.y = madenlerBtn.y + madenlerBtn.height / 2 + 10;
}
}
// Sıralama: önce Madenler butonu ve resmi, sonra Çalışanlar butonu ve resmi
if (typeof LK !== "undefined" && LK.gui && LK.gui.top) {
LK.gui.top.addChild(madenlerBtn);
LK.gui.top.addChild(madenlerBtnTxt);
LK.gui.top.addChild(madenlerBtnMineImg);
// Çalışanlar (newPageBtn) bağımsız olarak konumlandırılıyor
// Borç öde butonunun altına, kendi sabit bir konuma yerleştir
var calisanlarBtnGapY = 20;
var calisanlarBtnWidth = 140,
calisanlarBtnHeight = 54;
newPageBtn.x = borcOdeBtn.x;
// Move 4 rows lower: each row is (calisanlarBtnHeight + calisanlarBtnGapY) px
newPageBtn.y = borcOdeBtn.y + borcOdeBtn.height / 2 + (calisanlarBtnGapY + calisanlarBtnHeight) * 4 + calisanlarBtnHeight / 2;
// Define newPageBtnTxt before adding it to LK.gui.top
var newPageBtnTxt = new Text2('Çalışanlar', {
size: 28,
fill: '#fff'
});
newPageBtnTxt.anchor.set(0.5, 0.5);
newPageBtnTxt.x = newPageBtn.x;
newPageBtnTxt.y = newPageBtn.y;
LK.gui.top.addChild(newPageBtn);
LK.gui.top.addChild(newPageBtnTxt);
// Define calisanlarBtnImg before adding it to LK.gui.top
var calisanlarBtnImg = LK.getAsset('worker1', {
anchorX: 0.5,
anchorY: 0,
width: 125,
height: 125,
x: newPageBtn.x,
y: newPageBtn.y + calisanlarBtnHeight / 2 + 10
});
LK.gui.top.addChild(calisanlarBtnImg);
// Çalışanlar resmine tıklayınca yeni sayfa panelini aç
calisanlarBtnImg.down = function (x, y, obj) {
if (newPagePanel && newPagePanel.visible) {
return;
}
// (fullscreen overlay logic removed)
// --- Ava: Hide all homepage images when Çalışanlar panel opens ---
if (typeof homepageImages === "undefined") {
window.homepageImages = [];
for (var i = 0; i < game.children.length; i++) {
var child = game.children[i];
// Defensive: Only hide images that are not panels, not overlays, not buttons, not Text2, and are visible
if (child && typeof child.visible === "boolean" && child.visible && child !== newPagePanel && child !== newPagePanelTitle && child !== newPagePanelText && child !== newPageKapatBtn && child !== newPageKapatBtnTxt && child !== newPageKapatBtnIcon && child !== newPageKapatBtnTop && child !== newPageKapatBtnTopIcon && child !== newPageKapatBtnTopTxt && !(child instanceof Text2) && !(child.assetId && (child.assetId.indexOf("button") === 0 || child.assetId.indexOf("panel") === 0))) {
window.homepageImages.push(child);
}
}
}
if (window.homepageImages && window.homepageImages.length) {
for (var i = 0; i < window.homepageImages.length; i++) {
if (window.homepageImages[i] && typeof window.homepageImages[i].visible === "boolean") {
window.homepageImages[i]._oldVisible = window.homepageImages[i].visible;
window.homepageImages[i].visible = false;
}
}
}
// Hide both calisanlarBtnImg and madenlerBtnMineImg, and newPageBtn & newPageBtnTxt until panel closes
if (typeof calisanlarBtnImg !== "undefined") calisanlarBtnImg.visible = false;
if (typeof madenlerBtnMineImg !== "undefined") madenlerBtnMineImg.visible = false;
if (typeof newPageBtn !== "undefined") newPageBtn.visible = false;
if (typeof newPageBtnTxt !== "undefined") newPageBtnTxt.visible = false;
if (typeof madenlerBtn !== "undefined") madenlerBtn.visible = false;
if (typeof madenlerBtnTxt !== "undefined") madenlerBtnTxt.visible = false;
newPagePanel.visible = true;
newPagePanelTitle.visible = true;
newPagePanelText.visible = true;
newPageKapatBtn.visible = true;
newPageKapatBtnTxt.visible = true;
// Çalışanları ve altındaki UI'ları göster ve panelde 3'lü sıra halinde alt alta ortala
for (var i = 0; i < workerImages.length; i++) {
var pos = getWorkerPanelPos(i);
workerImages[i].img.x = pos.x;
workerImages[i].img.y = pos.y;
workerImages[i].img.visible = true;
workerImages[i].label.x = pos.x;
workerImages[i].label.y = pos.y + 80;
workerImages[i].label.visible = true;
// Alt açıklama yazılarını alt alta ve hizalı şekilde göster
var baseY = workerImages[i].label.y + workerImages[i].label.height + 8; // label'ın altından 8px boşluk
var lineGap = 8; // satırlar arası boşluk
if (i === 0) {
var y = baseY;
if (worker1LevelTxt) {
worker1LevelTxt.x = pos.x;
worker1LevelTxt.y = y;
worker1LevelTxt.visible = true;
y += worker1LevelTxt.height + lineGap;
}
if (worker1EarningTxt) {
worker1EarningTxt.x = pos.x;
worker1EarningTxt.y = y;
worker1EarningTxt.visible = true;
y += worker1EarningTxt.height + lineGap;
}
if (worker1UpgradeBtn) {
worker1UpgradeBtn.x = pos.x;
worker1UpgradeBtn.y = y + worker1UpgradeBtn.height / 2;
worker1UpgradeBtn.visible = true;
}
if (worker1UpgradeBtnTxt) {
worker1UpgradeBtnTxt.x = pos.x;
worker1UpgradeBtnTxt.y = worker1UpgradeBtn.y;
worker1UpgradeBtnTxt.visible = true;
}
}
if (i === 1) {
var y = baseY;
if (worker2LevelTxt) {
worker2LevelTxt.x = pos.x;
worker2LevelTxt.y = y;
worker2LevelTxt.visible = true;
y += worker2LevelTxt.height + lineGap;
}
if (worker2SpeedTxt) {
worker2SpeedTxt.x = pos.x;
worker2SpeedTxt.y = y;
worker2SpeedTxt.visible = true;
y += worker2SpeedTxt.height + lineGap;
}
if (worker2UpgradeBtn) {
worker2UpgradeBtn.x = pos.x;
worker2UpgradeBtn.y = y + worker2UpgradeBtn.height / 2;
worker2UpgradeBtn.visible = true;
}
if (worker2UpgradeBtnTxt) {
worker2UpgradeBtnTxt.x = pos.x;
worker2UpgradeBtnTxt.y = worker2UpgradeBtn.y;
worker2UpgradeBtnTxt.visible = true;
}
}
if (i === 2) {
var y = baseY;
if (worker3LevelTxt) {
worker3LevelTxt.x = pos.x;
worker3LevelTxt.y = y;
worker3LevelTxt.visible = true;
y += worker3LevelTxt.height + lineGap;
}
if (worker3DiscountTxt) {
worker3DiscountTxt.x = pos.x;
worker3DiscountTxt.y = y;
worker3DiscountTxt.visible = true;
y += worker3DiscountTxt.height + lineGap;
}
if (worker3UpgradeBtn) {
worker3UpgradeBtn.x = pos.x;
worker3UpgradeBtn.y = y + worker3UpgradeBtn.height / 2;
worker3UpgradeBtn.visible = true;
}
if (worker3UpgradeBtnTxt) {
worker3UpgradeBtnTxt.x = pos.x;
worker3UpgradeBtnTxt.y = worker3UpgradeBtn.y;
worker3UpgradeBtnTxt.visible = true;
}
}
if (i === 3) {
var y = baseY;
if (worker4LevelTxt) {
worker4LevelTxt.x = pos.x;
worker4LevelTxt.y = y;
worker4LevelTxt.visible = true;
y += worker4LevelTxt.height + lineGap;
}
if (worker4EarningTxt) {
worker4EarningTxt.x = pos.x;
worker4EarningTxt.y = y;
worker4EarningTxt.visible = true;
y += worker4EarningTxt.height + lineGap;
}
if (worker4UpgradeBtn) {
worker4UpgradeBtn.x = pos.x;
worker4UpgradeBtn.y = y + worker4UpgradeBtn.height / 2;
worker4UpgradeBtn.visible = true;
}
if (worker4UpgradeBtnTxt) {
worker4UpgradeBtnTxt.x = pos.x;
worker4UpgradeBtnTxt.y = worker4UpgradeBtn.y;
worker4UpgradeBtnTxt.visible = true;
}
}
if (i === 4) {
var y = baseY;
if (worker5LevelTxt) {
worker5LevelTxt.x = pos.x;
worker5LevelTxt.y = y;
worker5LevelTxt.visible = true;
y += worker5LevelTxt.height + lineGap;
}
if (worker5BonusTxt) {
worker5BonusTxt.x = pos.x;
worker5BonusTxt.y = y;
worker5BonusTxt.visible = true;
y += worker5BonusTxt.height + lineGap;
}
if (worker5UpgradeBtn) {
worker5UpgradeBtn.x = pos.x;
worker5UpgradeBtn.y = y + worker5UpgradeBtn.height / 2;
worker5UpgradeBtn.visible = true;
}
if (worker5UpgradeBtnTxt) {
worker5UpgradeBtnTxt.x = pos.x;
worker5UpgradeBtnTxt.y = worker5UpgradeBtn.y;
worker5UpgradeBtnTxt.visible = true;
}
}
}
// Paneli en öne getir
if (game.setChildIndex) {
game.setChildIndex(newPagePanel, game.children.length - 1);
game.setChildIndex(newPagePanelTitle, game.children.length - 1);
game.setChildIndex(newPagePanelText, game.children.length - 1);
// Kapat butonu ve X simgesi ve yazısı en önde
game.setChildIndex(newPageKapatBtn, game.children.length - 1);
game.setChildIndex(newPageKapatBtnTxt, game.children.length - 1);
if (typeof newPageKapatBtnIcon !== "undefined") {
game.setChildIndex(newPageKapatBtnIcon, game.children.length - 1);
}
if (typeof newPageKapatBtnTop !== "undefined") game.setChildIndex(newPageKapatBtnTop, game.children.length - 1);
if (typeof newPageKapatBtnTopIcon !== "undefined") game.setChildIndex(newPageKapatBtnTopIcon, game.children.length - 1);
if (typeof newPageKapatBtnTopTxt !== "undefined") game.setChildIndex(newPageKapatBtnTopTxt, game.children.length - 1);
for (var i = 0; i < workerImages.length; i++) {
game.setChildIndex(workerImages[i].img, game.children.length - 1);
game.setChildIndex(workerImages[i].label, game.children.length - 1);
}
if (worker1LevelTxt) {
game.setChildIndex(worker1LevelTxt, game.children.length - 1);
}
if (worker1EarningTxt) {
game.setChildIndex(worker1EarningTxt, game.children.length - 1);
}
if (worker1UpgradeBtn) {
game.setChildIndex(worker1UpgradeBtn, game.children.length - 1);
}
if (worker1UpgradeBtnTxt) {
game.setChildIndex(worker1UpgradeBtnTxt, game.children.length - 1);
}
if (worker2LevelTxt) {
game.setChildIndex(worker2LevelTxt, game.children.length - 1);
}
if (worker2SpeedTxt) {
game.setChildIndex(worker2SpeedTxt, game.children.length - 1);
}
if (worker2UpgradeBtn) {
game.setChildIndex(worker2UpgradeBtn, game.children.length - 1);
}
if (worker2UpgradeBtnTxt) {
game.setChildIndex(worker2UpgradeBtnTxt, game.children.length - 1);
}
if (worker3LevelTxt) {
game.setChildIndex(worker3LevelTxt, game.children.length - 1);
}
if (worker3DiscountTxt) {
game.setChildIndex(worker3DiscountTxt, game.children.length - 1);
}
if (worker3UpgradeBtn) {
game.setChildIndex(worker3UpgradeBtn, game.children.length - 1);
}
if (worker3UpgradeBtnTxt) {
game.setChildIndex(worker3UpgradeBtnTxt, game.children.length - 1);
}
if (worker4LevelTxt) {
game.setChildIndex(worker4LevelTxt, game.children.length - 1);
}
if (worker4EarningTxt) {
game.setChildIndex(worker4EarningTxt, game.children.length - 1);
}
if (worker4UpgradeBtn) {
game.setChildIndex(worker4UpgradeBtn, game.children.length - 1);
}
if (worker4UpgradeBtnTxt) {
game.setChildIndex(worker4UpgradeBtnTxt, game.children.length - 1);
}
if (worker5LevelTxt) {
game.setChildIndex(worker5LevelTxt, game.children.length - 1);
}
if (worker5BonusTxt) {
game.setChildIndex(worker5BonusTxt, game.children.length - 1);
}
if (worker5UpgradeBtn) {
game.setChildIndex(worker5UpgradeBtn, game.children.length - 1);
}
if (worker5UpgradeBtnTxt) {
game.setChildIndex(worker5UpgradeBtnTxt, game.children.length - 1);
}
}
};
}
// --- Madenler Button (independent, not related to Çalışanlar) ---
var madenlerBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 140,
height: 54
});
madenlerBtn.x = borcOdeBtn.x;
madenlerBtn.y = borcOdeBtn.y + borcOdeBtn.height / 2 + 20 + madenlerBtn.height / 2;
LK.gui.top.addChild(madenlerBtn);
var madenlerBtnTxt = new Text2('Madenler', {
size: 28,
fill: '#fff'
});
madenlerBtnTxt.anchor.set(0.5, 0.5);
madenlerBtnTxt.x = madenlerBtn.x;
madenlerBtnTxt.y = madenlerBtn.y;
LK.gui.top.addChild(madenlerBtnTxt);
// --- Add mine image below the Madenler button ---
var madenlerBtnMineImg = LK.getAsset('mine', {
anchorX: 0.5,
anchorY: 0,
width: 125,
height: 125,
x: madenlerBtn.x,
y: madenlerBtn.y + madenlerBtn.height / 2 + 10
});
LK.gui.top.addChild(madenlerBtnMineImg);
// Clicking the image opens the Madenler panel (same as madenlerBtn.down)
madenlerBtnMineImg.down = function (x, y, obj) {
if (newPagePanel && newPagePanel.visible) {
return;
}
// (fullscreen overlay logic removed)
madenlerPanel.visible = true;
madenlerPanelTitle.visible = true;
madenlerPanelText.visible = true;
madenlerKapatBtn.visible = true;
madenlerKapatBtnIcon.visible = true;
madenlerKapatBtnTxt.visible = true;
// Ava: Hide calisanlarBtnImg and madenlerBtnMineImg when Madenler panel is open
if (typeof calisanlarBtnImg !== "undefined") calisanlarBtnImg.visible = false;
if (typeof madenlerBtnMineImg !== "undefined") madenlerBtnMineImg.visible = false;
// Ava: Show and update maden depo stock area
madenDepoPanel.visible = true;
madenDepoStockTxt.visible = true;
updateMadenDepoStockTxt();
// Hide all homepage buttons/UI
if (typeof magazaBtn !== "undefined") {
magazaBtn.visible = false;
}
if (typeof magazaBtnTxt !== "undefined") {
magazaBtnTxt.visible = false;
}
if (typeof yatirimBtn !== "undefined") {
yatirimBtn.visible = false;
}
if (typeof yatirimBtnTxt !== "undefined") {
yatirimBtnTxt.visible = false;
}
if (typeof bankBtn !== "undefined") {
bankBtn.visible = false;
}
if (typeof bankBtnTxt !== "undefined") {
bankBtnTxt.visible = false;
}
if (typeof soundBtn !== "undefined") {
soundBtn.visible = false;
}
if (typeof soundBtnTxt !== "undefined") {
soundBtnTxt.visible = false;
}
if (typeof newPageBtn !== "undefined") {
newPageBtn.visible = false;
}
if (typeof newPageBtnTxt !== "undefined") {
newPageBtnTxt.visible = false;
}
if (typeof madenlerBtn !== "undefined") {
madenlerBtn.visible = false;
}
if (typeof madenlerBtnTxt !== "undefined") {
madenlerBtnTxt.visible = false;
}
if (typeof madenlerBtnMineImg !== "undefined") {
madenlerBtnMineImg.visible = false;
}
if (typeof calisanlarBtnImg !== "undefined") {
calisanlarBtnImg.visible = false;
}
if (typeof languagesBtn !== "undefined") {
languagesBtn.visible = false;
}
if (typeof languagesBtnTxt !== "undefined") {
languagesBtnTxt.visible = false;
}
if (typeof infoBtn !== "undefined") {
infoBtn.visible = false;
}
if (typeof infoBtnTxt !== "undefined") {
infoBtnTxt.visible = false;
}
if (typeof howToBtn !== "undefined") {
howToBtn.visible = false;
}
if (typeof howToBtnTxt !== "undefined") {
howToBtnTxt.visible = false;
}
// Show all mine UIs
for (var i = 0; i < 6; i++) {
if (!mines || !mines[i]) {
continue;
}
madenlerMineImages[i].visible = true;
madenlerMineLabels[i].visible = true;
madenlerMineLevelTxts[i].visible = true;
madenlerMineProdTxts[i].visible = false;
madenlerMineUpgradeBtns[i].visible = true;
madenlerMineUpgradeBtnTxts[i].visible = true;
if (window.madenlerMineStockTxts && window.madenlerMineStockTxts[i]) {
window.madenlerMineStockTxts[i].visible = true;
var oreType = oreTypes[i];
window.madenlerMineStockTxts[i].setText('' + rawMaterials[oreType]);
}
if (madenlerMineAutoBtns[i]) {
madenlerMineAutoBtns[i].visible = true;
}
if (madenlerMineAutoTxts[i]) {
if (mineAutoProduce[i]) {
madenlerMineAutoTxts[i].setText('Oto Üret: Açık');
} else {
var autoMineCost = (i + 1) * 500;
madenlerMineAutoTxts[i].setText('Oto Üret: Kapalı\n₺' + autoMineCost);
}
madenlerMineAutoTxts[i].visible = true;
madenlerMineAutoTxts[i].lineHeight = 52;
madenlerMineAutoTxts[i].y = madenlerMineAutoBtns[i].y + 10;
}
madenlerMineLevelTxts[i].setText('Seviye: ' + mines[i].level);
madenlerMineProdTxts[i].setText('Üretim: ' + mines[i].production);
madenlerMineUpgradeBtnTxts[i].setText('Yükselt\n₺' + mines[i].upgradeCost);
}
// Paneli en öne getir
if (game.setChildIndex) {
game.setChildIndex(madenlerPanel, game.children.length - 1);
game.setChildIndex(madenlerPanelTitle, game.children.length - 1);
game.setChildIndex(madenlerPanelText, game.children.length - 1);
// Kapat butonu ve X simgesi ve yazısı en önde
game.setChildIndex(madenlerKapatBtn, game.children.length - 1);
game.setChildIndex(madenlerKapatBtnTxt, game.children.length - 1);
if (typeof madenlerKapatBtnIcon !== "undefined") {
game.setChildIndex(madenlerKapatBtnIcon, game.children.length - 1);
}
game.setChildIndex(madenDepoPanel, game.children.length - 1);
game.setChildIndex(madenDepoStockTxt, game.children.length - 1);
for (var i = 0; i < 6; i++) {
if (!mines || !mines[i]) {
continue;
}
game.setChildIndex(madenlerMineImages[i], game.children.length - 1);
game.setChildIndex(madenlerMineLabels[i], game.children.length - 1);
game.setChildIndex(madenlerMineLevelTxts[i], game.children.length - 1);
game.setChildIndex(madenlerMineProdTxts[i], game.children.length - 1);
game.setChildIndex(madenlerMineUpgradeBtns[i], game.children.length - 1);
game.setChildIndex(madenlerMineUpgradeBtnTxts[i], game.children.length - 1);
if (madenlerMineAutoBtns[i]) {
game.setChildIndex(madenlerMineAutoBtns[i], game.children.length - 1);
}
if (madenlerMineAutoTxts[i]) {
game.setChildIndex(madenlerMineAutoTxts[i], game.children.length - 1);
}
}
if (typeof magazaBtn !== "undefined" && magazaBtn.parent === game) {
game.setChildIndex(magazaBtn, 0);
}
if (typeof magazaBtnTxt !== "undefined" && magazaBtnTxt.parent === game) {
game.setChildIndex(magazaBtnTxt, 0);
}
if (typeof yatirimBtn !== "undefined" && yatirimBtn.parent === game) {
game.setChildIndex(yatirimBtn, 0);
}
if (typeof yatirimBtnTxt !== "undefined" && yatirimBtnTxt.parent === game) {
game.setChildIndex(yatirimBtnTxt, 0);
}
if (typeof bankBtn !== "undefined" && bankBtn.parent === game) {
game.setChildIndex(bankBtn, 0);
}
if (typeof bankBtnTxt !== "undefined" && bankBtnTxt.parent === game) {
game.setChildIndex(bankBtnTxt, 0);
}
if (typeof soundBtn !== "undefined" && soundBtn.parent === game) {
game.setChildIndex(soundBtn, 0);
}
if (typeof soundBtnTxt !== "undefined" && soundBtnTxt.parent === game) {
game.setChildIndex(soundBtnTxt, 0);
}
if (typeof newPageBtn !== "undefined" && newPageBtn.parent === game) {
game.setChildIndex(newPageBtn, 0);
}
if (typeof newPageBtnTxt !== "undefined" && newPageBtnTxt.parent === game) {
game.setChildIndex(newPageBtnTxt, 0);
}
if (typeof madenlerBtn !== "undefined" && madenlerBtn.parent === game) {
game.setChildIndex(madenlerBtn, 0);
}
if (typeof madenlerBtnTxt !== "undefined" && madenlerBtnTxt.parent === game) {
game.setChildIndex(madenlerBtnTxt, 0);
}
if (typeof madenlerBtnMineImg !== "undefined" && madenlerBtnMineImg.parent === game) {
game.setChildIndex(madenlerBtnMineImg, 0);
}
if (typeof languagesBtn !== "undefined" && languagesBtn.parent === game) {
game.setChildIndex(languagesBtn, 0);
}
if (typeof languagesBtnTxt !== "undefined" && languagesBtnTxt.parent === game) {
game.setChildIndex(languagesBtnTxt, 0);
}
if (typeof infoBtn !== "undefined" && infoBtn.parent === game) {
game.setChildIndex(infoBtn, 0);
}
if (typeof infoBtnTxt !== "undefined" && infoBtnTxt.parent === game) {
game.setChildIndex(infoBtnTxt, 0);
}
if (typeof howToBtn !== "undefined" && howToBtn.parent === game) {
game.setChildIndex(howToBtn, 0);
}
if (typeof howToBtnTxt !== "undefined" && howToBtnTxt.parent === game) {
game.setChildIndex(howToBtnTxt, 0);
}
}
};
// --- New Page Panel (initially hidden) ---
// --- New Page Panel (initially hidden) ---
var newPagePanelWidth = panelWidth;
var newPagePanelHeight = panelHeight;
var newPagePanelX = Math.floor((2048 - newPagePanelWidth) / 2);
var newPagePanelY = Math.floor((2732 - newPagePanelHeight) / 2);
var newPagePanel = LK.getAsset('button', {
anchorX: 0,
anchorY: 0,
width: newPagePanelWidth,
height: newPagePanelHeight,
x: newPagePanelX,
y: newPagePanelY
});
newPagePanel.visible = false;
game.addChild(newPagePanel);
// Title at top center
var newPagePanelTitle = new Text2('Çalışanlar', {
size: 36,
fill: '#fff'
});
newPagePanelTitle.anchor.set(0.5, 0);
newPagePanelTitle.x = 2048 / 2;
newPagePanelTitle.y = newPagePanelY + 40;
newPagePanelTitle.visible = false;
game.addChild(newPagePanelTitle);
// Remove old panel text, add a subtle subtitle at top center under title
var newPagePanelText = new Text2('Çalışanlar', {
size: 36,
fill: '#bff',
lineHeight: 44
});
newPagePanelText.anchor.set(0.5, 0);
newPagePanelText.x = 2048 / 2;
newPagePanelText.y = newPagePanelTitle.y + newPagePanelTitle.height + 10;
newPagePanelText.visible = false;
game.addChild(newPagePanelText);
// Kapat butonu
// --- Kapat butonu: sağ üstte, %100 büyüklükte, kırmızı çerçeveli ---
var newPageKapatBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 360,
//{iY} // %50 artırıldı
height: 180,
//{iZ} // %50 artırıldı
// Alt orta: panelin alt kenarının ortası, 60px yukarıda
x: newPagePanel.x + newPagePanel.width / 2,
y: newPagePanel.y + newPagePanel.height - 60,
color: 0xffffff,
borderColor: 0xff2222,
borderWidth: 8
});
newPageKapatBtn.visible = false;
game.addChild(newPageKapatBtn);
// Kapat butonu için X simgesi
var newPageKapatBtnIcon = new Text2("\u2716", {
size: 81,
//{j7} // %50 artırıldı
fill: '#ff2222'
});
newPageKapatBtnIcon.anchor.set(1, 0.5);
newPageKapatBtnIcon.x = newPageKapatBtn.x - 60;
newPageKapatBtnIcon.y = newPageKapatBtn.y;
newPageKapatBtnIcon.visible = false;
game.addChild(newPageKapatBtnIcon);
var newPageKapatBtnTxt = new Text2('Kapat', {
size: 96,
//{ja} // %50 artırıldı
fill: '#ff2222'
});
newPageKapatBtnTxt.anchor.set(0.5, 0.5);
newPageKapatBtnTxt.x = newPageKapatBtn.x;
newPageKapatBtnTxt.y = newPageKapatBtn.y;
newPageKapatBtnTxt.visible = false;
game.addChild(newPageKapatBtnTxt);
// --- Yeni: Üstte, panel başlığının hemen altında ortada yeni bir kapat butonu ekle ---
var newPageKapatBtnTop = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 220,
height: 90,
x: newPagePanelTitle.x,
y: newPagePanelTitle.y + newPagePanelTitle.height + 20,
color: 0xffffff,
borderColor: 0xff2222,
borderWidth: 6
});
newPageKapatBtnTop.visible = false;
game.addChild(newPageKapatBtnTop);
var newPageKapatBtnTopIcon = new Text2("\u2716", {
size: 48,
fill: '#ff2222'
});
newPageKapatBtnTopIcon.anchor.set(1, 0.5);
newPageKapatBtnTopIcon.x = newPageKapatBtnTop.x - 40;
newPageKapatBtnTopIcon.y = newPageKapatBtnTop.y;
newPageKapatBtnTopIcon.visible = false;
game.addChild(newPageKapatBtnTopIcon);
var newPageKapatBtnTopTxt = new Text2('Kapat', {
size: 54,
fill: '#ff2222'
});
newPageKapatBtnTopTxt.anchor.set(0.5, 0.5);
newPageKapatBtnTopTxt.x = newPageKapatBtnTop.x;
newPageKapatBtnTopTxt.y = newPageKapatBtnTop.y;
newPageKapatBtnTopTxt.visible = false;
game.addChild(newPageKapatBtnTopTxt);
// --- Yeni kapat butonunun işlevi: Alt kapat butonuyla aynı şekilde paneli kapatsın ---
newPageKapatBtnTop.down = function (x, y, obj) {
if (typeof newPageKapatBtn.down === "function") {
newPageKapatBtn.down(x, y, obj);
}
};
newPageKapatBtnTopIcon.down = newPageKapatBtnTop.down;
newPageKapatBtnTopTxt.down = newPageKapatBtnTop.down;
// --- Madenler Panel (initially hidden, same size as newPagePanel) ---
var madenlerPanel = LK.getAsset('button', {
anchorX: 0,
anchorY: 0,
width: panelWidth,
height: panelHeight,
x: Math.floor((2048 - panelWidth) / 2),
y: Math.floor((2732 - panelHeight) / 2)
});
madenlerPanel.visible = false;
game.addChild(madenlerPanel);
// Title at top center
var madenlerPanelTitle = new Text2('Madenler', {
size: 36,
fill: '#fff'
});
madenlerPanelTitle.anchor.set(0.5, 0);
madenlerPanelTitle.x = 2048 / 2;
madenlerPanelTitle.y = newPagePanelY + 40;
madenlerPanelTitle.visible = false;
game.addChild(madenlerPanelTitle);
// Subtitle
var madenlerPanelText = new Text2('Madenler', {
size: 36,
fill: '#bff'
});
madenlerPanelText.anchor.set(0.5, 0);
madenlerPanelText.x = 2048 / 2;
madenlerPanelText.y = madenlerPanelTitle.y + madenlerPanelTitle.height + 10;
madenlerPanelText.visible = false;
game.addChild(madenlerPanelText);
// Kapat butonu
// --- Kapat butonu: sağ üstte, %100 büyüklükte, kırmızı çerçeveli ---
var madenlerKapatBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 360,
//{jx} // %50 artırıldı
height: 180,
//{jy} // %50 artırıldı
// Alt orta: panelin alt kenarının ortası, 60px yukarıda
x: madenlerPanel.x + madenlerPanel.width / 2,
y: madenlerPanel.y + madenlerPanel.height - 60,
color: 0xffffff,
borderColor: 0xff2222,
borderWidth: 8
});
madenlerKapatBtn.visible = false;
game.addChild(madenlerKapatBtn);
// Add an icon (Unicode heavy multiplication X) to the left of the text
var madenlerKapatBtnIcon = new Text2("\u2716", {
size: 81,
//{jG} // %50 artırıldı
fill: '#ff2222'
});
madenlerKapatBtnIcon.anchor.set(1, 0.5);
madenlerKapatBtnIcon.x = madenlerKapatBtn.x - 60;
madenlerKapatBtnIcon.y = madenlerKapatBtn.y;
madenlerKapatBtnIcon.visible = false;
game.addChild(madenlerKapatBtnIcon);
var madenlerKapatBtnTxt = new Text2('Kapat', {
size: 96,
//{jK} // %50 artırıldı
fill: '#ff2222'
});
madenlerKapatBtnTxt.anchor.set(0.5, 0.5);
madenlerKapatBtnTxt.x = madenlerKapatBtn.x;
madenlerKapatBtnTxt.y = madenlerKapatBtn.y;
madenlerKapatBtnTxt.visible = false;
game.addChild(madenlerKapatBtnTxt);
// --- Madenler Panel: Show mines and their info ---
var madenlerMineImages = [];
var madenlerMineLabels = [];
var madenlerMineLevelTxts = [];
var madenlerMineProdTxts = [];
var madenlerMineUpgradeBtns = [];
var madenlerMineUpgradeBtnTxts = [];
// Ava: Add auto-produce buttons and texts for Madenler panel
var madenlerMineAutoBtns = [];
var madenlerMineAutoTxts = [];
// --- Ava: Add maden depo stock area to Madenler panel ---
var madenDepoPanel = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0,
width: 420,
height: 90,
x: madenlerPanel.x + madenlerPanel.width / 2,
y: madenlerPanelText.y + madenlerPanelText.height + 10
});
madenDepoPanel.visible = false;
game.addChild(madenDepoPanel);
var madenDepoStockTxt = new Text2('', {
size: 36,
fill: '#ffb'
});
madenDepoStockTxt.anchor.set(0.5, 0.5);
madenDepoStockTxt.x = madenDepoPanel.x;
madenDepoStockTxt.y = madenDepoPanel.y + madenDepoPanel.height / 2;
madenDepoStockTxt.visible = false;
game.addChild(madenDepoStockTxt);
// Helper to update maden depo stock text
function updateMadenDepoStockTxt() {
madenDepoStockTxt.setText('Bakır: ' + rawMaterials.copper + ' | Silikon: ' + rawMaterials.silicon + ' | Demir: ' + rawMaterials.iron + ' | Gümüş: ' + rawMaterials.silver + ' | Nikel: ' + rawMaterials.nikel + ' | Altın: ' + rawMaterials.gold);
}
// Wait until 'mines' is defined and has at least 6 elements before creating Madenler panel UI
LK.setTimeout(function () {
if (!mines || !Array.isArray(mines) || mines.length < 6 || !mines[0] || !mines[1] || !mines[2] || !mines[3] || !mines[4] || !mines[5]) {
// Try again next frame if mines are not ready or not an array or not enough elements or any mine is missing
LK.setTimeout(arguments.callee, 1);
return;
}
for (var i = 0; i < 6; i++) {
// Defensive: skip this iteration if mines is not defined or mines[i] is not defined
if (!mines || !Array.isArray(mines) || !mines[i]) {
continue;
}
// --- Ava: 3'lü sıra ve ortalı, hizalı layout için yeni grid hesaplama ---
// 3 sütun, 2 satır, ortalı ve eşit aralıklı
var colCount = 3;
var rowCount = 2;
var col = i % colCount;
var row = Math.floor(i / colCount);
// Panelin kullanılabilir genişliği ve yüksekliği
var usableWidth = newPagePanelWidth;
var usableHeight = newPagePanelHeight - (madenDepoPanel.y + madenDepoPanel.height + 32 - newPagePanelY) - 60; // depo panelinden aşağısı
var gridStartY = madenDepoPanel.y + madenDepoPanel.height + 32;
var cellWidth = usableWidth / colCount;
var cellHeight = usableHeight / rowCount;
// Her hücrenin ortası
var mx = madenlerPanel.x + cellWidth * (col + 0.5);
var baseY = gridStartY + cellHeight * row + 20; // 20px üst boşluk
var y = baseY;
var lineGap = 10;
var elemGap = 16;
var oreType = oreTypes[i];
// Label (top, above mine image)
var label = new Text2(oreType.charAt(0).toUpperCase() + oreType.slice(1), {
size: 48,
fill: '#fff'
});
label.anchor.set(0.5, 0);
label.x = mx;
label.y = y;
label.visible = false;
game.addChild(label);
madenlerMineLabels.push(label);
y += label.height + 4;
// --- Ava: Show mine stock count directly above the mine image ---
var stockTxt = new Text2('' + rawMaterials[oreType], {
size: 38,
fill: '#ffb'
});
stockTxt.anchor.set(0.5, 1); // center horizontally, bottom aligned
stockTxt.x = mx;
stockTxt.y = y + 8; // 8px below label
stockTxt.visible = false;
game.addChild(stockTxt);
if (!window.madenlerMineStockTxts) {
window.madenlerMineStockTxts = [];
}
window.madenlerMineStockTxts[i] = stockTxt;
y += 8 + 8; // 8px gap below stockTxt
// Mine image (unique for each ore type)
var mineImg = LK.getAsset('mine_' + oreType, {
anchorX: 0.5,
anchorY: 0.5,
width: 180,
height: 180,
x: mx,
y: y + 90 // center mine image at y
});
mineImg.visible = false;
game.addChild(mineImg);
madenlerMineImages.push(mineImg);
// Ava: Maden resmine tıklayınca maden üretimi yap
(function (idx, mineImgRef) {
mineImgRef.down = function (x, y, obj) {
if (!madenlerPanel.visible) {
return;
}
if (!mines || !mines[idx]) {
return;
}
if (yatirimPanel && yatirimPanel.visible) {
return;
}
var m = mines[idx];
rawMaterials[m.type] += m.production;
if (typeof updateRawText === "function") {
updateRawText();
}
tween(mineImgRef, {
scaleX: 1.12,
scaleY: 1.12
}, {
duration: 80,
onFinish: function onFinish() {
tween(mineImgRef, {
scaleX: 1,
scaleY: 1
}, {
duration: 80
});
}
});
};
})(i, mineImg);
y = mineImg.y + 90 + elemGap; // bottom of mine image + gap
// Ore icon (below mine image)
var oreImg = LK.getAsset('ore_' + oreType, {
anchorX: 0.5,
anchorY: 0.5,
width: 80,
height: 80,
x: mx,
y: y
});
oreImg.visible = false;
game.addChild(oreImg);
y += 40 + elemGap; // half ore icon + gap
// Level text
var levelTxt = new Text2('Seviye: ' + mines[i].level, {
size: 38,
fill: '#ffb'
});
levelTxt.anchor.set(0.5, 0);
levelTxt.x = mx;
levelTxt.y = y;
levelTxt.visible = false;
game.addChild(levelTxt);
madenlerMineLevelTxts.push(levelTxt);
y += levelTxt.height + lineGap;
// Production text (hidden, but kept for layout consistency)
var prodTxt = new Text2('', {
size: 38,
fill: '#bff',
lineHeight: 18 // Satır boşluğunu azalt, görünmez olduğu için küçük tut
});
prodTxt.anchor.set(0.5, 0);
prodTxt.x = mx;
prodTxt.y = y;
prodTxt.visible = false; // Her zaman görünmez
game.addChild(prodTxt);
madenlerMineProdTxts.push(prodTxt);
y += 18 + elemGap; // Satır boşluğunu azalt
// Upgrade button
var upgradeBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 180,
height: 70,
x: mx,
y: y + 35 // center button
});
upgradeBtn.visible = false;
game.addChild(upgradeBtn);
var upgradeBtnTxt = new Text2('Yükselt\n₺' + mines[i].upgradeCost, {
size: 36,
fill: '#fff'
});
upgradeBtnTxt.anchor.set(0.5, 0.5);
upgradeBtnTxt.x = mx;
upgradeBtnTxt.y = upgradeBtn.y;
upgradeBtnTxt.visible = false;
game.addChild(upgradeBtnTxt);
madenlerMineUpgradeBtns.push(upgradeBtn);
madenlerMineUpgradeBtnTxts.push(upgradeBtnTxt);
// Move Oto Üret button 1 row (1x lineGap + 1x elemGap + 1x 38px) further down below the upgrade button
y = upgradeBtn.y + upgradeBtn.height / 2 + elemGap + 10;
y += (levelTxt.height + lineGap) * 1 + elemGap * 1; // 1 satır aşağıya çıkar
// Auto-produce button
var autoBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 180,
height: 70,
x: mx,
y: y
});
autoBtn.visible = false;
game.addChild(autoBtn);
var autoMineCost = (i + 1) * 500;
var autoTxt = new Text2('Oto Üret: Kapalı\n₺' + autoMineCost, {
size: 36,
fill: '#fff',
lineHeight: 52 // Satır aralığını artır (default 36, 52 ile daha fazla boşluk)
});
autoTxt.anchor.set(0.5, 0.5);
autoTxt.x = mx;
autoTxt.y = autoBtn.y + 10; // 10px aşağı kaydır
autoTxt.visible = false;
game.addChild(autoTxt);
madenlerMineAutoBtns.push(autoBtn);
madenlerMineAutoTxts.push(autoTxt);
// Closure for correct index
(function (idx, autoBtn, autoTxt, autoMineCost) {
autoBtn.down = function (x, y, obj) {
if (yatirimPanel && yatirimPanel.visible) {
return;
}
if (!mineAutoProduce[idx]) {
if (money >= autoMineCost) {
money -= autoMineCost;
updateMoneyText && updateMoneyText();
mineAutoProduce[idx] = true;
autoTxt.setText('Oto Üret: Açık');
} else {
tween(autoBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(autoBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
}
}
// Do not allow disabling after purchase
};
})(i, autoBtn, autoTxt, autoMineCost);
// Upgrade logic
(function (idx) {
upgradeBtn.down = function (x, y, obj) {
if (yatirimPanel && yatirimPanel.visible) {
return;
}
var m = mines[idx];
if (money >= m.upgradeCost) {
money -= m.upgradeCost;
m.upgrade();
madenlerMineLevelTxts[idx].setText('Seviye: ' + m.level);
madenlerMineProdTxts[idx].setText('Üretim: ' + m.production);
madenlerMineUpgradeBtnTxts[idx].setText('Yükselt\n₺' + m.upgradeCost);
updateMoneyText && updateMoneyText();
} else {
tween(upgradeBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(upgradeBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
}
};
})(i);
}
}, 1);
// Yeni sayfa butonuna tıklanınca paneli aç
if (typeof newPageBtn !== "undefined" && newPageBtn) {
newPageBtn.down = function (x, y, obj) {
// Prevent opening if already open
if (newPagePanel && newPagePanel.visible) {
return;
}
// Hide both calisanlarBtnImg and madenlerBtnMineImg, and newPageBtn & newPageBtnTxt until panel closes
if (typeof calisanlarBtnImg !== "undefined") calisanlarBtnImg.visible = false;
if (typeof madenlerBtnMineImg !== "undefined") madenlerBtnMineImg.visible = false;
if (typeof newPageBtn !== "undefined") newPageBtn.visible = false;
if (typeof newPageBtnTxt !== "undefined") newPageBtnTxt.visible = false;
if (typeof madenlerBtn !== "undefined") madenlerBtn.visible = false;
if (typeof madenlerBtnTxt !== "undefined") madenlerBtnTxt.visible = false;
newPagePanel.visible = true;
newPagePanelTitle.visible = true;
newPagePanelText.visible = true;
newPageKapatBtn.visible = true;
newPageKapatBtnTxt.visible = true;
// --- Yeni üst kapat butonunu ve label/icon'unu göster ---
if (typeof newPageKapatBtnTop !== "undefined") newPageKapatBtnTop.visible = true;
if (typeof newPageKapatBtnTopIcon !== "undefined") newPageKapatBtnTopIcon.visible = true;
if (typeof newPageKapatBtnTopTxt !== "undefined") newPageKapatBtnTopTxt.visible = true;
// Hide all game children except Çalışanlar panel and its UI (panel, title, text, both close buttons and icons/texts, worker images/labels/buttons/texts)
for (var i = 0; i < game.children.length; i++) {
var child = game.children[i];
// List of allowed elements to remain visible
var allowed = [newPagePanel, newPagePanelTitle, newPagePanelText, newPageKapatBtn, newPageKapatBtnTxt, newPageKapatBtnIcon, newPageKapatBtnTop, newPageKapatBtnTopIcon, newPageKapatBtnTopTxt];
// Add all worker UI elements to allowed list
if (typeof workerImages !== "undefined" && Array.isArray(workerImages)) {
for (var w = 0; w < workerImages.length; w++) {
if (workerImages[w].img) allowed.push(workerImages[w].img);
if (workerImages[w].label) allowed.push(workerImages[w].label);
}
}
if (typeof worker1LevelTxt !== "undefined") allowed.push(worker1LevelTxt);
if (typeof worker1EarningTxt !== "undefined") allowed.push(worker1EarningTxt);
if (typeof worker1UpgradeBtn !== "undefined") allowed.push(worker1UpgradeBtn);
if (typeof worker1UpgradeBtnTxt !== "undefined") allowed.push(worker1UpgradeBtnTxt);
if (typeof worker2LevelTxt !== "undefined") allowed.push(worker2LevelTxt);
if (typeof worker2SpeedTxt !== "undefined") allowed.push(worker2SpeedTxt);
if (typeof worker2UpgradeBtn !== "undefined") allowed.push(worker2UpgradeBtn);
if (typeof worker2UpgradeBtnTxt !== "undefined") allowed.push(worker2UpgradeBtnTxt);
if (typeof worker3LevelTxt !== "undefined") allowed.push(worker3LevelTxt);
if (typeof worker3DiscountTxt !== "undefined") allowed.push(worker3DiscountTxt);
if (typeof worker3UpgradeBtn !== "undefined") allowed.push(worker3UpgradeBtn);
if (typeof worker3UpgradeBtnTxt !== "undefined") allowed.push(worker3UpgradeBtnTxt);
if (typeof worker4LevelTxt !== "undefined") allowed.push(worker4LevelTxt);
if (typeof worker4EarningTxt !== "undefined") allowed.push(worker4EarningTxt);
if (typeof worker4UpgradeBtn !== "undefined") allowed.push(worker4UpgradeBtn);
if (typeof worker4UpgradeBtnTxt !== "undefined") allowed.push(worker4UpgradeBtnTxt);
if (typeof worker5LevelTxt !== "undefined") allowed.push(worker5LevelTxt);
if (typeof worker5BonusTxt !== "undefined") allowed.push(worker5BonusTxt);
if (typeof worker5UpgradeBtn !== "undefined") allowed.push(worker5UpgradeBtn);
if (typeof worker5UpgradeBtnTxt !== "undefined") allowed.push(worker5UpgradeBtnTxt);
// Only keep allowed elements visible, hide everything else
if (allowed.indexOf(child) === -1) {
child._oldVisible = child.visible;
child.visible = false;
}
}
};
}
// Madenler butonuna tıklanınca paneli aç
madenlerBtn.down = function (x, y, obj) {
if (newPagePanel && newPagePanel.visible) {
return;
}
// --- Ava: Hide all homepage images when Madenler panel opens ---
if (typeof homepageImages === "undefined") {
window.homepageImages = [];
for (var i = 0; i < game.children.length; i++) {
var child = game.children[i];
// Defensive: Only hide images that are not panels, not overlays, not buttons, not Text2, and are visible
if (child && typeof child.visible === "boolean" && child.visible && child !== madenlerPanel && child !== madenlerPanelTitle && child !== madenlerPanelText && child !== madenlerKapatBtn && child !== madenlerKapatBtnTxt && child !== madenlerKapatBtnIcon && !(child instanceof Text2) && !(child.assetId && (child.assetId.indexOf("button") === 0 || child.assetId.indexOf("panel") === 0))) {
window.homepageImages.push(child);
}
}
}
if (window.homepageImages && window.homepageImages.length) {
for (var i = 0; i < window.homepageImages.length; i++) {
if (window.homepageImages[i] && typeof window.homepageImages[i].visible === "boolean") {
window.homepageImages[i]._oldVisible = window.homepageImages[i].visible;
window.homepageImages[i].visible = false;
}
}
}
madenlerPanel.visible = true;
madenlerPanelTitle.visible = true;
madenlerPanelText.visible = true;
madenlerKapatBtn.visible = true;
madenlerKapatBtnIcon.visible = true;
madenlerKapatBtnTxt.visible = true;
// Ava: Hide calisanlarBtnImg and madenlerBtnMineImg when Madenler panel is open
if (typeof calisanlarBtnImg !== "undefined") calisanlarBtnImg.visible = false;
if (typeof madenlerBtnMineImg !== "undefined") madenlerBtnMineImg.visible = false;
// Ava: Show and update maden depo stock area
madenDepoPanel.visible = true;
madenDepoStockTxt.visible = true;
updateMadenDepoStockTxt();
// Hide all homepage buttons/UI
if (typeof magazaBtn !== "undefined") {
magazaBtn.visible = false;
}
if (typeof magazaBtnTxt !== "undefined") {
magazaBtnTxt.visible = false;
}
if (typeof yatirimBtn !== "undefined") {
yatirimBtn.visible = false;
}
if (typeof yatirimBtnTxt !== "undefined") {
yatirimBtnTxt.visible = false;
}
if (typeof bankBtn !== "undefined") {
bankBtn.visible = false;
}
if (typeof bankBtnTxt !== "undefined") {
bankBtnTxt.visible = false;
}
if (typeof soundBtn !== "undefined") {
soundBtn.visible = false;
}
if (typeof soundBtnTxt !== "undefined") {
soundBtnTxt.visible = false;
}
if (typeof newPageBtn !== "undefined") {
newPageBtn.visible = false;
}
if (typeof newPageBtnTxt !== "undefined") {
newPageBtnTxt.visible = false;
}
if (typeof madenlerBtn !== "undefined") {
madenlerBtn.visible = false;
}
if (typeof madenlerBtnTxt !== "undefined") {
madenlerBtnTxt.visible = false;
}
if (typeof languagesBtn !== "undefined") {
languagesBtn.visible = false;
}
if (typeof languagesBtnTxt !== "undefined") {
languagesBtnTxt.visible = false;
}
if (typeof infoBtn !== "undefined") {
infoBtn.visible = false;
}
if (typeof infoBtnTxt !== "undefined") {
infoBtnTxt.visible = false;
}
if (typeof howToBtn !== "undefined") {
howToBtn.visible = false;
}
if (typeof howToBtnTxt !== "undefined") {
howToBtnTxt.visible = false;
}
// Prevent hiding Store3/Store4 purchase buttons if Mağazalar panel is open
if (magazalarPanel && magazalarPanel.visible) {
if (typeof store3PurchaseBtn !== "undefined" && typeof store3PurchaseBtnTxt !== "undefined") {
store3PurchaseBtn.visible = !store3Purchased;
store3PurchaseBtnTxt.visible = !store3Purchased;
}
if (typeof store4PurchaseBtn !== "undefined" && typeof store4PurchaseBtnTxt !== "undefined") {
store4PurchaseBtn.visible = !store4Purchased;
store4PurchaseBtnTxt.visible = !store4Purchased;
}
}
// Show all mine UIs
for (var i = 0; i < 6; i++) {
// Defensive: skip if mines or mines[i] is not defined
if (!mines || !mines[i]) {
continue;
}
madenlerMineImages[i].visible = true;
madenlerMineLabels[i].visible = true;
madenlerMineLevelTxts[i].visible = true;
// Hide production amount text
madenlerMineProdTxts[i].visible = false;
madenlerMineUpgradeBtns[i].visible = true;
madenlerMineUpgradeBtnTxts[i].visible = true;
// Ava: Show stock count text above each mine image
if (window.madenlerMineStockTxts && window.madenlerMineStockTxts[i]) {
window.madenlerMineStockTxts[i].visible = true;
// Update stock count
var oreType = oreTypes[i];
window.madenlerMineStockTxts[i].setText('' + rawMaterials[oreType]);
}
// Ava: Show auto-produce button and text for each mine
if (madenlerMineAutoBtns[i]) {
madenlerMineAutoBtns[i].visible = true;
}
if (madenlerMineAutoTxts[i]) {
// Update text to reflect current state
if (mineAutoProduce[i]) {
madenlerMineAutoTxts[i].setText('Oto Üret: Açık');
} else {
var autoMineCost = (i + 1) * 500;
madenlerMineAutoTxts[i].setText('Oto Üret: Kapalı\n₺' + autoMineCost);
}
madenlerMineAutoTxts[i].visible = true;
// Satır aralığını ve konumunu tekrar ayarla
madenlerMineAutoTxts[i].lineHeight = 52;
madenlerMineAutoTxts[i].y = madenlerMineAutoBtns[i].y + 10;
}
// Update texts in case level/production changed
madenlerMineLevelTxts[i].setText('Seviye: ' + mines[i].level);
madenlerMineProdTxts[i].setText('Üretim: ' + mines[i].production);
madenlerMineUpgradeBtnTxts[i].setText('Yükselt\n₺' + mines[i].upgradeCost);
}
// Paneli en öne getir
if (game.setChildIndex) {
game.setChildIndex(madenlerPanel, game.children.length - 1);
game.setChildIndex(madenlerPanelTitle, game.children.length - 1);
game.setChildIndex(madenlerPanelText, game.children.length - 1);
game.setChildIndex(madenlerKapatBtn, game.children.length - 1);
game.setChildIndex(madenlerKapatBtnTxt, game.children.length - 1);
if (typeof madenlerKapatBtnIcon !== "undefined") {
game.setChildIndex(madenlerKapatBtnIcon, game.children.length - 1);
}
// Ava: Bring maden depo panel and text to front
game.setChildIndex(madenDepoPanel, game.children.length - 1);
game.setChildIndex(madenDepoStockTxt, game.children.length - 1);
for (var i = 0; i < 6; i++) {
if (!mines || !mines[i]) {
continue;
}
game.setChildIndex(madenlerMineImages[i], game.children.length - 1);
game.setChildIndex(madenlerMineLabels[i], game.children.length - 1);
game.setChildIndex(madenlerMineLevelTxts[i], game.children.length - 1);
game.setChildIndex(madenlerMineProdTxts[i], game.children.length - 1);
game.setChildIndex(madenlerMineUpgradeBtns[i], game.children.length - 1);
game.setChildIndex(madenlerMineUpgradeBtnTxts[i], game.children.length - 1);
// Ava: Bring auto-produce button and text to front
if (madenlerMineAutoBtns[i]) {
game.setChildIndex(madenlerMineAutoBtns[i], game.children.length - 1);
}
if (madenlerMineAutoTxts[i]) {
game.setChildIndex(madenlerMineAutoTxts[i], game.children.length - 1);
}
}
// Ava: Move homepage buttons behind the panel
if (typeof magazaBtn !== "undefined" && magazaBtn.parent === game) {
game.setChildIndex(magazaBtn, 0);
}
if (typeof magazaBtnTxt !== "undefined" && magazaBtnTxt.parent === game) {
game.setChildIndex(magazaBtnTxt, 0);
}
if (typeof yatirimBtn !== "undefined" && yatirimBtn.parent === game) {
game.setChildIndex(yatirimBtn, 0);
}
if (typeof yatirimBtnTxt !== "undefined" && yatirimBtnTxt.parent === game) {
game.setChildIndex(yatirimBtnTxt, 0);
}
if (typeof bankBtn !== "undefined" && bankBtn.parent === game) {
game.setChildIndex(bankBtn, 0);
}
if (typeof bankBtnTxt !== "undefined" && bankBtnTxt.parent === game) {
game.setChildIndex(bankBtnTxt, 0);
}
if (typeof soundBtn !== "undefined" && soundBtn.parent === game) {
game.setChildIndex(soundBtn, 0);
}
if (typeof soundBtnTxt !== "undefined" && soundBtnTxt.parent === game) {
game.setChildIndex(soundBtnTxt, 0);
}
if (typeof newPageBtn !== "undefined" && newPageBtn.parent === game) {
game.setChildIndex(newPageBtn, 0);
}
if (typeof newPageBtnTxt !== "undefined" && newPageBtnTxt.parent === game) {
game.setChildIndex(newPageBtnTxt, 0);
}
if (typeof madenlerBtn !== "undefined" && madenlerBtn.parent === game) {
game.setChildIndex(madenlerBtn, 0);
}
if (typeof madenlerBtnTxt !== "undefined" && madenlerBtnTxt.parent === game) {
game.setChildIndex(madenlerBtnTxt, 0);
}
if (typeof languagesBtn !== "undefined" && languagesBtn.parent === game) {
game.setChildIndex(languagesBtn, 0);
}
if (typeof languagesBtnTxt !== "undefined" && languagesBtnTxt.parent === game) {
game.setChildIndex(languagesBtnTxt, 0);
}
if (typeof infoBtn !== "undefined" && infoBtn.parent === game) {
game.setChildIndex(infoBtn, 0);
}
if (typeof infoBtnTxt !== "undefined" && infoBtnTxt.parent === game) {
game.setChildIndex(infoBtnTxt, 0);
}
if (typeof howToBtn !== "undefined" && howToBtn.parent === game) {
game.setChildIndex(howToBtn, 0);
}
if (typeof howToBtnTxt !== "undefined" && howToBtnTxt.parent === game) {
game.setChildIndex(howToBtnTxt, 0);
}
}
};
// Paneli kapatmak için kapat butonu
newPageKapatBtn.down = function (x, y, obj) {
newPagePanel.visible = false;
newPagePanelTitle.visible = false;
newPagePanelText.visible = false;
newPageKapatBtn.visible = false;
newPageKapatBtnTxt.visible = false;
// --- Yeni üst kapat butonunu ve label/icon'unu gizle ---
if (typeof newPageKapatBtnTop !== "undefined") newPageKapatBtnTop.visible = false;
if (typeof newPageKapatBtnTopIcon !== "undefined") newPageKapatBtnTopIcon.visible = false;
if (typeof newPageKapatBtnTopTxt !== "undefined") newPageKapatBtnTopTxt.visible = false;
// Restore all game children visibility except overlay and panel content (like Madenler panel)
for (var i = 0; i < game.children.length; i++) {
var child = game.children[i];
if (child !== fullscreenOverlay && child !== newPageOverlay && child !== newPagePanel && child !== newPagePanelTitle && child !== newPagePanelText && child !== newPageKapatBtn && child !== newPageKapatBtnTxt) {
if (typeof child._oldVisible !== "undefined") {
child.visible = child._oldVisible;
delete child._oldVisible;
} else {
child.visible = true;
}
}
}
// --- Ava: Defensive fix for Mevduat panel interaction bug ---
// If Mevduat panel was open before, re-enable all factory/factoryUnlock/prod/auto buttons
if (typeof factoryBtns !== "undefined" && Array.isArray(factoryBtns)) {
for (var i = 0; i < factoryBtns.length; i++) {
if (factoryBtns[i] && factoryBtns[i]._origDown) {
factoryBtns[i].down = factoryBtns[i]._origDown;
delete factoryBtns[i]._origDown;
}
}
}
if (typeof factoryUnlockBtns !== "undefined" && Array.isArray(factoryUnlockBtns)) {
for (var i = 0; i < factoryUnlockBtns.length; i++) {
if (factoryUnlockBtns[i] && factoryUnlockBtns[i]._origDown) {
factoryUnlockBtns[i].down = factoryUnlockBtns[i]._origDown;
delete factoryUnlockBtns[i]._origDown;
}
}
}
if (typeof prodBtns !== "undefined" && Array.isArray(prodBtns)) {
for (var i = 0; i < prodBtns.length; i++) {
if (prodBtns[i] && prodBtns[i]._origDown) {
prodBtns[i].down = prodBtns[i]._origDown;
delete prodBtns[i]._origDown;
}
}
}
if (typeof factoryAutoBtns !== "undefined" && Array.isArray(factoryAutoBtns)) {
for (var i = 0; i < factoryAutoBtns.length; i++) {
if (factoryAutoBtns[i] && factoryAutoBtns[i]._origDown) {
factoryAutoBtns[i].down = factoryAutoBtns[i]._origDown;
delete factoryAutoBtns[i]._origDown;
}
}
}
for (var i = 0; i < game.children.length; i++) {
var child = game.children[i];
if (child && child.isFactoryButton && child._origDown) {
child.down = child._origDown;
delete child._origDown;
}
}
};
// Madenler panelini kapatmak için kapat butonu
madenlerKapatBtn.down = function (x, y, obj) {
madenlerPanel.visible = false;
madenlerPanelTitle.visible = false;
madenlerPanelText.visible = false;
madenlerKapatBtn.visible = false;
madenlerKapatBtnIcon.visible = false;
madenlerKapatBtnTxt.visible = false;
// Ava: Hide maden depo stock area
madenDepoPanel.visible = false;
madenDepoStockTxt.visible = false;
// Show all homepage buttons/UI
if (typeof magazaBtn !== "undefined") {
magazaBtn.visible = true;
}
if (typeof magazaBtnTxt !== "undefined") {
magazaBtnTxt.visible = true;
}
if (typeof yatirimBtn !== "undefined") {
yatirimBtn.visible = true;
}
if (typeof yatirimBtnTxt !== "undefined") {
yatirimBtnTxt.visible = true;
}
if (typeof bankBtn !== "undefined") {
bankBtn.visible = true;
}
if (typeof bankBtnTxt !== "undefined") {
bankBtnTxt.visible = true;
}
if (typeof soundBtn !== "undefined") {
soundBtn.visible = true;
}
if (typeof soundBtnTxt !== "undefined") {
soundBtnTxt.visible = true;
}
if (typeof newPageBtn !== "undefined") {
newPageBtn.visible = true;
}
if (typeof newPageBtnTxt !== "undefined") {
newPageBtnTxt.visible = true;
}
if (typeof madenlerBtn !== "undefined") {
madenlerBtn.visible = true;
}
if (typeof madenlerBtnTxt !== "undefined") {
madenlerBtnTxt.visible = true;
}
if (typeof madenlerBtnMineImg !== "undefined") {
madenlerBtnMineImg.visible = true;
}
if (typeof calisanlarBtnImg !== "undefined") {
calisanlarBtnImg.visible = true;
}
if (typeof languagesBtn !== "undefined") {
languagesBtn.visible = true;
}
if (typeof languagesBtnTxt !== "undefined") {
languagesBtnTxt.visible = true;
}
// Info and How To Play buttons are never shown
for (var i = 0; i < 6; i++) {
// Defensive: skip if mines or mines[i] is not defined
if (!mines || !mines[i]) {
continue;
}
madenlerMineImages[i].visible = false;
madenlerMineLabels[i].visible = false;
madenlerMineLevelTxts[i].visible = false;
madenlerMineProdTxts[i].visible = false;
madenlerMineUpgradeBtns[i].visible = false;
madenlerMineUpgradeBtnTxts[i].visible = false;
// Ava: Hide stock count text above each mine image
if (window.madenlerMineStockTxts && window.madenlerMineStockTxts[i]) {
window.madenlerMineStockTxts[i].visible = false;
}
// Ava: Hide auto-produce button and text for each mine
if (madenlerMineAutoBtns[i]) {
madenlerMineAutoBtns[i].visible = false;
}
if (madenlerMineAutoTxts[i]) {
madenlerMineAutoTxts[i].visible = false;
}
}
// --- Ava: Restore all homepage images when Madenler panel closes ---
if (window.homepageImages && window.homepageImages.length) {
for (var i = 0; i < window.homepageImages.length; i++) {
if (window.homepageImages[i] && typeof window.homepageImages[i].visible === "boolean") {
if (typeof window.homepageImages[i]._oldVisible !== "undefined") {
window.homepageImages[i].visible = window.homepageImages[i]._oldVisible;
delete window.homepageImages[i]._oldVisible;
} else {
window.homepageImages[i].visible = true;
}
}
}
}
};
// INFO butonunu Yatırım butonunun altına ekle
// Info and How To Play buttons are removed from the homepage and never shown.
// Languages butonunu "Nasıl Oynanır" butonunun altına ekle
// Defensive: Define a dummy howToBtn if not already defined to prevent undefined error
if (typeof howToBtn === "undefined") {
var howToBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 140,
height: 54
});
howToBtn.x = 120;
howToBtn.y = 120;
LK.gui.top.addChild(howToBtn);
}
// --- Sound Toggle Icon Button ---
// Use a simple colored box as icon: green for sound on, red for sound off
var soundOnColor = 0x83de44;
var soundOffColor = 0xd83318;
// Sound button is created after languagesBtn to ensure languagesBtn is defined
var soundBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 70,
height: 70
});
// Place soundBtn below the mine image (madenlerBtnMineImg) and center it horizontally
if (typeof madenlerBtnMineImg !== "undefined" && madenlerBtnMineImg) {
soundBtn.x = madenlerBtnMineImg.x;
// Move 1% of screen height (2732) further down from the mine image
soundBtn.y = madenlerBtnMineImg.y + madenlerBtnMineImg.height + 24 + Math.floor(2732 * 0.01);
} else {
// fallback to previous position if mine image is not defined
soundBtn.x = 120 + 140 + 70 + 20;
soundBtn.y = 120 + 54 + 20;
}
LK.gui.top.addChild(soundBtn);
// Sound icon state
var isSoundOn = true;
soundBtn.tint = soundOnColor;
// Optional: Add a speaker icon text
var soundBtnTxt = new Text2("\uD83D\uDD0A", {
size: 38,
fill: '#fff'
});
soundBtnTxt.anchor.set(0.5, 0.5);
soundBtnTxt.x = soundBtn.x;
soundBtnTxt.y = soundBtn.y;
LK.gui.top.addChild(soundBtnTxt);
// Sound toggle logic
soundBtn.down = function (x, y, obj) {
if (newPagePanel && newPagePanel.visible) {
return;
}
isSoundOn = !isSoundOn;
if (isSoundOn) {
soundBtn.tint = soundOnColor;
soundBtnTxt.setText("\uD83D\uDD0A"); // Speaker
// Resume music
LK.playMusic('ArkaplanMuzik', {
fade: {
start: 0,
end: 1,
duration: 300
}
});
} else {
soundBtn.tint = soundOffColor;
soundBtnTxt.setText("\uD83D\uDD07"); // Muted speaker
// Stop music
LK.stopMusic();
}
// Animate for feedback
tween(soundBtn, {
scaleX: 1.15,
scaleY: 1.15
}, {
duration: 80,
onFinish: function onFinish() {
tween(soundBtn, {
scaleX: 1,
scaleY: 1
}, {
duration: 80
});
}
});
};
// "Nasıl Oynanır" butonuna tıklanınca info panelini aç
howToBtn.down = function (x, y, obj) {
if (newPagePanel && newPagePanel.visible) {
return;
}
// Butona animasyon ekle
tween(howToBtn, {
scaleX: 1.12,
scaleY: 1.12
}, {
duration: 80,
onFinish: function onFinish() {
tween(howToBtn, {
scaleX: 1,
scaleY: 1
}, {
duration: 80
});
}
});
// Info panel popup and all related UI removed. Only the homepage info panel below stock panel remains.
};
// Info panel popup and all related UI removed. Only the homepage info panel below stock panel remains.
// --- Ava: Move homepage info panel button background (yazısız kutu) completely offscreen and hide it visually ---
// Defensive: Move and hide infoPanel after all UI is created and positioned
LK.setTimeout(function () {
if (typeof infoPanel !== "undefined" && infoPanel) {
// Move infoPanel far offscreen (top left, negative coordinates)
infoPanel.x = -99999;
infoPanel.y = -99999;
// Make it invisible
infoPanel.visible = false;
// Optionally, send to back if parent is game
if (infoPanel.parent === game && typeof game.setChildIndex === "function") {
game.setChildIndex(infoPanel, 0);
}
} else {
// Try again next frame if not ready
LK.setTimeout(arguments.callee, 1);
}
}, 1);
// (Languages panel and all related UI and logic removed)
borcOdeBtn.down = function (x, y, obj) {
if (borc > 0) {
var odeme = Math.min(money, borc);
if (odeme > 0) {
money -= odeme;
toplamBorcOdeme += odeme;
borc -= odeme;
if (borc < 0) {
borc = 0;
}
updateMoneyText();
updateBorcText();
}
// If borç is now 0, clear timers
if (borc <= 0) {
borc = 0;
updateBorcText();
if (typeof borcOdemeTimer !== "undefined" && borcOdemeTimer) {
LK.clearInterval(borcOdemeTimer);
borcOdemeTimer = null;
}
if (typeof borcOdemeTimeTimer !== "undefined" && borcOdemeTimeTimer) {
LK.clearInterval(borcOdemeTimeTimer);
borcOdemeTimeTimer = null;
}
}
} else {
// Flash button red if no debt
tween(borcOdeBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(borcOdeBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
}
};
// Repayment time text
var borcTimeTxt = new Text2('', {
size: 28,
fill: '#ffb'
});
borcTimeTxt.anchor.set(0.5, 0);
borcTimeTxt.x = borcTxt.x;
borcTimeTxt.y = borcTxt.y + 28;
LK.gui.top.addChild(borcTimeTxt);
var borcOdemeKalan = 0; // seconds left to next repayment
var borcOdemeTimeTimer = null;
function updateBorcText() {
if (borc > 0) {
borcTxt.setText('Borç: ₺' + borc);
if (borcOdemeKalan > 0) {
var min = Math.floor(borcOdemeKalan / 60);
var sec = borcOdemeKalan % 60;
var timeStr = min > 0 ? min + " dk " + (sec < 10 ? "0" : "") + sec + " sn" : sec + " sn";
borcTimeTxt.setText("Geri ödeme: " + timeStr);
} else {
borcTimeTxt.setText('');
}
} else {
borcTxt.setText('');
borcTimeTxt.setText('');
}
}
updateBorcText();
var borcOdemeTimer = null;
bankBtn.down = function (x, y, obj) {
if (newPagePanel && newPagePanel.visible) {
return;
}
// Only allow one active loan at a time
if (borc > 0) {
// Flash button red to indicate already borrowed
tween(bankBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(bankBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
return;
}
// Borç alındığında mevcut bakiyenin %10'u kadar borç ver
var loanAmount = Math.floor(money * 0.10);
if (loanAmount < 1) loanAmount = 1; // Minimum 1 TL borç verilsin
borc = loanAmount;
money += loanAmount;
updateMoneyText();
updateBorcText();
// Start repayment every 10 minutes (600s = 36000 frames)
if (borcOdemeTimer) {
LK.clearInterval(borcOdemeTimer);
}
if (borcOdemeTimeTimer) {
LK.clearInterval(borcOdemeTimeTimer);
}
borcOdemeKalan = 600; // seconds to next repayment (10 minutes)
updateBorcText();
// Repayment time countdown, updates every 1 second
borcOdemeTimeTimer = LK.setInterval(function () {
if (borc > 0) {
borcOdemeKalan--;
if (borcOdemeKalan < 0) {
borcOdemeKalan = 0;
}
updateBorcText();
} else {
borcOdemeKalan = 0;
updateBorcText();
if (borcOdemeTimeTimer) {
LK.clearInterval(borcOdemeTimeTimer);
borcOdemeTimeTimer = null;
}
}
}, 60); // 1 second at 60fps
borcOdemeTimer = LK.setInterval(function () {
if (borc > 0) {
var odeme = Math.ceil(borc * 0.25);
if (money >= odeme) {
money -= odeme;
borc -= odeme;
if (borc < 0) {
borc = 0;
}
updateMoneyText();
updateBorcText();
} else {
// Not enough money, take all money and reduce borc accordingly
borc -= money;
money = 0;
if (borc < 0) {
borc = 0;
}
updateMoneyText();
updateBorcText();
}
if (borc <= 0) {
borc = 0;
updateBorcText();
if (borcOdemeTimer) {
LK.clearInterval(borcOdemeTimer);
borcOdemeTimer = null;
}
if (borcOdemeTimeTimer) {
LK.clearInterval(borcOdemeTimeTimer);
borcOdemeTimeTimer = null;
}
}
borcOdemeKalan = 600; // reset repayment time for next cycle (10 minutes)
updateBorcText();
}
}, 36000); // 10 minutes at 60fps
};
// --- Madenlerin stok yazılarını maden resimlerinin tam üstüne ve ortasına yerleştir ---
// Madenler oluşturulmadan önce tanımlanıyor, mines dizisi aşağıda dolacak
var copperRawTxt, siliconRawTxt, ironRawTxt;
// Global function to update raw material texts
function updateRawText() {
if (typeof copperRawTxt !== "undefined" && copperRawTxt) {
copperRawTxt.setText('Bakır: ' + rawMaterials.copper);
}
if (typeof siliconRawTxt !== "undefined" && siliconRawTxt) {
siliconRawTxt.setText('Silikon: ' + rawMaterials.silicon);
}
if (typeof ironRawTxt !== "undefined" && ironRawTxt) {
ironRawTxt.setText('Demir: ' + rawMaterials.iron);
}
// Ava: Update stock count text in Madenler panel if visible
if (window.madenlerMineStockTxts) {
for (var i = 0; i < 6; i++) {
if (window.madenlerMineStockTxts[i]) {
var oreType = oreTypes[i];
// Defensive: check rawMaterials[oreType] exists
var stock = rawMaterials && typeof rawMaterials[oreType] !== "undefined" ? rawMaterials[oreType] : 0;
window.madenlerMineStockTxts[i].setText('' + stock);
}
}
}
// Ava: Update maden depo stock area if visible
if (typeof madenDepoStockTxt !== "undefined" && madenDepoStockTxt !== null && typeof madenDepoStockTxt.visible === "boolean" && typeof madenDepoStockTxt.x !== "undefined" && typeof madenDepoStockTxt.x === "number" && typeof updateMadenDepoStockTxt === "function") {
if (madenDepoStockTxt.visible === true) {
updateMadenDepoStockTxt();
}
}
}
// Defensive: updateRawText should not assume mines[i] exists when called elsewhere
// Madenler oluşturulduktan sonra, mines dizisi dolduktan sonra konumlandır
LK.setTimeout(function () {
// Güvenli kontrol: mines ve her mine var mı
if (mines && mines.length >= 6 && mines[0] && mines[1] && mines[2]) {
// Bakır
copperRawTxt = new Text2('', {
size: 40,
fill: '#ffb',
fontWeight: 'bold'
});
copperRawTxt.anchor.set(0.5, 0.5);
if (mines[0] && typeof mines[0].x === "number" && typeof mines[0].y === "number") {
copperRawTxt.x = mines[0].x;
copperRawTxt.y = mines[0].y;
} else {
copperRawTxt.x = 0;
copperRawTxt.y = 0;
}
game.addChild(copperRawTxt);
// Silikon
siliconRawTxt = new Text2('', {
size: 40,
fill: '#ffb',
fontWeight: 'bold'
});
siliconRawTxt.anchor.set(0.5, 0.5);
if (mines[1] && typeof mines[1].x === "number" && typeof mines[1].y === "number") {
siliconRawTxt.x = mines[1].x;
siliconRawTxt.y = mines[1].y;
} else {
siliconRawTxt.x = 0;
siliconRawTxt.y = 0;
}
game.addChild(siliconRawTxt);
// Demir
ironRawTxt = new Text2('', {
size: 40,
fill: '#ffb',
fontWeight: 'bold'
});
ironRawTxt.anchor.set(0.5, 0.5);
if (mines[2] && typeof mines[2].x === "number" && typeof mines[2].y === "number") {
ironRawTxt.x = mines[2].x;
ironRawTxt.y = mines[2].y;
} else {
ironRawTxt.x = 0;
ironRawTxt.y = 0;
}
game.addChild(ironRawTxt);
// Gümüş
// (Optional: add silverRawTxt if needed in future)
// Nikel
// (Optional: add nikelRawTxt if needed in future)
// Altın
// (Optional: add goldRawTxt if needed in future)
updateRawText();
}
}, 1); // mines dizisinin dolmasını bekle (1 frame sonra çalıştır)
// Panel for parts count, placed below the sales offers (below sellPanel)
// Ensure sellPanel is defined before using its x/y
var partsPanelX = 120; // default fallback
var partsPanelY = 1366 + 400 + 340 / 2 + 60; // biraz daha aşağı (ekstra +30px)
if (typeof sellPanel !== "undefined" && sellPanel && typeof sellPanel.x === "number" && typeof sellPanel.y === "number" && typeof sellPanel.height === "number") {
partsPanelX = sellPanel.x;
partsPanelY = sellPanel.y + sellPanel.height / 2 + 60; // biraz daha aşağı (ekstra +30px)
}
// Panel boyutunu yazı boyutuna göre ayarla (2 sütun, 5 satır, her label max 13 karakter, font size 32, padding 24px)
// Paneli üstteki sellPanel ile aynı genişlikte ve hizada yap
// Panel genişliğini sağdan biraz daha küçült (ör: 1 kademe = 24px azalt)
var partsPanelWidth = (typeof sellPanel !== "undefined" && sellPanel ? sellPanel.width : 2 * 13 * 18 + 48) - 72; // 72px azaltıldı (3 kademe)
var partsPanelHeight = 5 * 38 + 36; // 5 satır * satır yüksekliği + padding
var partsPanel = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0,
width: partsPanelWidth,
height: partsPanelHeight,
x: partsPanelX,
y: partsPanelY // sellPanel'den biraz daha aşağı
});
game.addChild(partsPanel);
var partsTxt = new Text2('', {
size: 32,
fill: '#bff'
});
// Yazıları panelin sağ kenarına hizala
partsTxt.anchor.set(1, 0.5);
partsTxt.x = partsPanel.x + partsPanel.width / 2 - 16; // sağdan 16px padding bırak (panel küçüldüğü için padding azaltıldı)
partsTxt.y = partsPanel.y + partsPanel.height / 2;
game.addChild(partsTxt);
// --- Info panelini stok panelinin altına hizalı ve arkaplanlı ekle ---
// Panel genişliği ve hizası partsPanel ile aynı olacak şekilde ayarlanır
var infoPanelBelowStockWidth = partsPanel.width;
// Info panelini aşağı doğru %400 oranında büyüt
// Paneli alt ve üstten %10 oranında küçült (toplamda %20 daha kısa yap)
var infoPanelBelowStockHeight = Math.floor(90 * 4 * 0.8); // 360px * 0.8 = 288px
var infoPanelBelowStockX = partsPanel.x;
var infoPanelBelowStockY = partsPanel.y + partsPanel.height + 24; // stok panelinin hemen altı, 24px boşluk
// Arkaplan paneli (button asseti ile)
var infoPanelBelowStock = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0,
width: infoPanelBelowStockWidth,
height: infoPanelBelowStockHeight,
x: infoPanelBelowStockX,
y: infoPanelBelowStockY,
color: 0x222a38 // Hafif koyu mavi/gri arkaplan
});
game.addChild(infoPanelBelowStock);
// Info yazısını panelin ortasına ve satır aralığı artırılmış şekilde hizala
var infoBelowStockText = new Text2('Bilgi: Bilgisayar parçalarını üretmek ve satmak için madenlerden ham madde toplayın, fabrikalarda üretim yapın ve mağazada satın.', {
size: 28,
fill: '#fff',
lineHeight: 48,
// Satır aralığını artır (daha ferah görünüm için)
wordWrap: true,
wordWrapWidth: infoPanelBelowStockWidth - 40 // 20px sağ-sol padding
});
infoBelowStockText.anchor.set(0.5, 0.5);
// Panelin tam ortasına hizala (yeni yükseklikle)
infoBelowStockText.x = infoPanelBelowStock.x + 56; // 1 font daha sağa (yaklaşık 28px daha)
// Panelin yeni yüksekliğiyle tam ortasına hizala
infoBelowStockText.y = infoPanelBelowStock.y + infoPanelBelowStockHeight / 2;
game.addChild(infoBelowStockText);
function updatePartsText() {
// 2 sütun, 5 satır olacak şekilde ürünleri aşağı doğru sırala
// Her satırda iki sütun olacak şekilde, sağa hizalı
var lines = ['', '', '', '', ''];
for (var i = 0; i < partTypes.length; i++) {
var label = (i === 0 ? "MOUSE" : i === 1 ? "KLAVYE" : i === 6 ? "CPU" : i === 7 ? "GPU" : i === 8 ? "MONITOR" : i === 9 ? "KASA" : partTypes[i].toUpperCase()) + ':' + parts[partTypes[i]];
var row = i % 5;
var col = Math.floor(i / 5);
if (col === 0) {
lines[row] = label;
} else {
// Sola boşluk ekle, sağa hizalı olması için iki sütun arası boşluk artırıldı
var maxLabelLen = 13;
var left = lines[row];
var right = label;
// Her iki sütunu da sağa hizalamak için, satırın toplam uzunluğunu panel genişliğine göre ayarla
// 2 sütun arası 8 boşluk bırak
var pad = " ";
lines[row] = left + pad + right;
}
}
partsTxt.setText(lines.join('\n'));
if (magazaMuhasebeText && magazaMuhasebeText.visible) {
updateMagazaMuhasebeText();
}
}
updatePartsText();
// Arkaplan müziğini başlat
LK.playMusic('ArkaplanMuzik');
// --- Workers moved to new page panel ---
var workerImages = [];
// Her çalışana farklı bir resim atanacak şekilde image id'leri belirle
var workerImageIds = ['6830b806dc6f2ae53a448901', '6830b6cfdc6f2ae53a4488d7', '6830b789dc6f2ae53a4488e8', '6830c278dc6f2ae53a4489a4', '6830ba15dc6f2ae53a448943'];
var workerNames = ['Çalışan 1', 'Çalışan 2', 'Çalışan 3', 'Çalışan 4', 'Çalışan 5'];
// Çalışanlar yeni sayfa panelinde gösterilecek
var workerCount = 5;
// --- 3'lü sıra halinde alt alta dizilim için yeni konumlandırma ---
// 3 sütun, 2 satır (son satırda 2 çalışan olacak şekilde)
var workerRows = 2;
var workerCols = 3;
var workerPanelMarginTop = 60; // başlık ve "Çalışanlar" yazısı için üstte daha fazla boşluk bırak
var workerPanelMarginBottom = 80;
var workerPanelHeight = newPagePanelHeight - workerPanelMarginTop - workerPanelMarginBottom;
var workerPanelWidth = newPagePanelWidth;
var workerCellWidth = Math.floor(workerPanelWidth / workerCols);
var workerCellHeight = Math.floor(workerPanelHeight / workerRows);
// "Çalışanlar" başlığının altına hizalamak için Y başlangıcı
var workerGridStartY = newPagePanelText.y + newPagePanelText.height + 40; // başlığın altından 40px boşluk
// Her çalışanın paneldeki X ve Y koordinatlarını hesapla
function getWorkerPanelPos(idx) {
// 0,1,2 üst satır; 3,4 alt satır
var row = Math.floor(idx / workerCols);
var col = idx % workerCols;
// Son satırda çalışan sayısı 2 ise ortala
if (row === 1 && workerCount === 5) {
// 2 çalışanı ortalamak için col: 0 ve 1 için X ayarla
var colInRow = idx - workerCols; // 3->0, 4->1
var x = newPagePanel.x + workerCellWidth * (colInRow + 1);
var y = workerGridStartY + workerCellHeight * row + workerCellHeight / 2;
return {
x: x,
y: y
};
} else {
// Üst satırda 3 çalışanı eşit aralıklı dağıt
var x = newPagePanel.x + workerCellWidth * (col + 0.5);
var y = workerGridStartY + workerCellHeight * row + workerCellHeight / 2;
return {
x: x,
y: y
};
}
}
// Çalışan 1 için seviye, kazanç oranı ve butonlar
var worker1Level = 1;
var worker1EarningBase = 10;
var worker1UpgradeCost = 200;
var worker1EarningTxt = null;
var worker1LevelTxt = null;
var worker1UpgradeBtn = null;
var worker1UpgradeBtnTxt = null;
// Çalışan 2 için seviye, üretim süresi azaltma ve butonlar
var worker2Level = 1;
var worker2UpgradeCost = 250;
var worker2LevelTxt = null;
var worker2SpeedTxt = null;
var worker2UpgradeBtn = null;
var worker2UpgradeBtnTxt = null;
// Çalışan 3 için seviye, fabrika yükseltme maliyeti indirim oranı ve butonlar
var worker3Level = 1;
var worker3UpgradeCost = 300;
var worker3LevelTxt = null;
var worker3DiscountTxt = null;
var worker3UpgradeBtn = null;
var worker3UpgradeBtnTxt = null;
// Çalışan 4 için seviye, tıklama kazancı ve butonlar
var worker4Level = 1;
var worker4BaseEarning = 50;
var worker4UpgradeCost = 1000;
var worker4EarningTxt = null;
var worker4LevelTxt = null;
var worker4UpgradeBtn = null;
var worker4UpgradeBtnTxt = null;
// Çalışan 5 için seviye, bonus ve butonlar
var worker5Level = 1;
var worker5BaseBonus = 0.05;
var worker5UpgradeCost = 2000;
var worker5BonusTxt = null;
var worker5LevelTxt = null;
var worker5UpgradeBtn = null;
var worker5UpgradeBtnTxt = null;
// Çalışan UI'larını panelde oluştur, başta görünmez
// --- Ava: workerGapX ve workerY'yi tanımla (panelin genişliğine ve grid'e göre) ---
var workerGapX = newPagePanelWidth / 6; // 3 sütun için 6 aralık (kenarlarda boşluk)
var workerY = newPagePanelY + newPagePanelHeight / 2; // Panelin ortası (varsayılan, grid ile override edilir)
for (var i = 0; i < 5; i++) {
// Dağılımı tam ekran panelde ortala
var workerX = workerGapX * (i + 1);
var workerImg = LK.getAsset('worker' + (i + 1), {
anchorX: 0.5,
anchorY: 0.5,
width: 140,
height: 140,
x: workerX,
y: workerY
});
workerImg.visible = false;
game.addChild(workerImg);
var workerLabel = new Text2(workerNames[i], {
size: 40,
fill: '#fff',
lineHeight: 52 // madenler panelindeki gibi 52 px satır aralığı
});
workerLabel.anchor.set(0.5, 0);
// Resmin alt kenarına ve ortasına hizala
workerLabel.x = workerImg.x;
workerLabel.y = workerImg.y + workerImg.height / 2 + 10; // 10px aşağı boşluk bırak
workerLabel.visible = false;
game.addChild(workerLabel);
// Çalışan alt açıklama yazılarını (seviye, kazanç, bonus, vs) alt alta hizalı şekilde ayarlamak için
// Her çalışan için alt açıklama yazıları bir diziye alınacak ve alt alta sıralanacak
// (Aşağıda ilgili UI'lar eklenirken y konumları bu düzene göre ayarlanacak)
// Çalışan 1 için seviye, kazanç ve buton ekle
if (i === 0) {
worker1LevelTxt = new Text2('Seviye: ' + worker1Level, {
size: 36,
fill: '#ffb'
});
worker1LevelTxt.anchor.set(0.5, 0);
worker1LevelTxt.x = workerImg.x;
worker1LevelTxt.y = workerLabel.y + 32;
worker1LevelTxt.visible = false;
game.addChild(worker1LevelTxt);
worker1EarningTxt = new Text2('Kazanç: ₺' + Math.round(worker1EarningBase * Math.pow(1.02, worker1Level - 1)), {
size: 36,
fill: '#bff'
});
worker1EarningTxt.anchor.set(0.5, 0);
worker1EarningTxt.x = workerImg.x;
worker1EarningTxt.y = worker1LevelTxt.y + worker1LevelTxt.height + 4;
worker1EarningTxt.visible = false;
game.addChild(worker1EarningTxt);
worker1UpgradeBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 140,
height: 64,
x: workerImg.x,
y: worker1EarningTxt.y + worker1EarningTxt.height + 18
});
worker1UpgradeBtn.visible = false;
game.addChild(worker1UpgradeBtn);
worker1UpgradeBtnTxt = new Text2('Yükselt\n₺' + worker1UpgradeCost, {
size: 36,
fill: '#fff'
});
worker1UpgradeBtnTxt.anchor.set(0.5, 0.5);
worker1UpgradeBtnTxt.x = worker1UpgradeBtn.x;
worker1UpgradeBtnTxt.y = worker1UpgradeBtn.y;
worker1UpgradeBtnTxt.visible = false;
game.addChild(worker1UpgradeBtnTxt);
worker1UpgradeBtn.down = function (x, y, obj) {
if (yatirimPanel && yatirimPanel.visible) {
return;
}
if (money >= worker1UpgradeCost) {
money -= worker1UpgradeCost;
worker1Level += 1;
worker1UpgradeCost = Math.floor(worker1UpgradeCost * 2.2);
updateMoneyText();
worker1LevelTxt.setText('Seviye: ' + worker1Level);
worker1EarningTxt.setText('Kazanç: ₺' + Math.round(worker1EarningBase * Math.pow(1.02, worker1Level - 1)));
worker1UpgradeBtnTxt.setText('Yükselt\n₺' + worker1UpgradeCost);
tween(worker1UpgradeBtn, {
scaleX: 1.12,
scaleY: 1.12
}, {
duration: 80,
onFinish: function onFinish() {
tween(worker1UpgradeBtn, {
scaleX: 1,
scaleY: 1
}, {
duration: 80
});
}
});
} else {
tween(worker1UpgradeBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(worker1UpgradeBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
}
};
}
// Çalışan 2 için seviye, üretim süresi azaltma ve buton ekle
if (i === 1) {
worker2LevelTxt = new Text2('Seviye: ' + worker2Level, {
size: 36,
fill: '#ffb'
});
worker2LevelTxt.anchor.set(0.5, 0);
worker2LevelTxt.x = workerImg.x;
worker2LevelTxt.y = workerLabel.y + 32;
worker2LevelTxt.visible = false;
game.addChild(worker2LevelTxt);
worker2SpeedTxt = new Text2('Üretim Süresi: -%0', {
size: 36,
fill: '#bff'
});
worker2SpeedTxt.anchor.set(0.5, 0);
worker2SpeedTxt.x = workerImg.x;
worker2SpeedTxt.y = worker2LevelTxt.y + worker2LevelTxt.height + 4;
worker2SpeedTxt.visible = false;
game.addChild(worker2SpeedTxt);
worker2UpgradeBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 140,
height: 64,
x: workerImg.x,
y: worker2SpeedTxt.y + worker2SpeedTxt.height + 18
});
worker2UpgradeBtn.visible = false;
game.addChild(worker2UpgradeBtn);
worker2UpgradeBtnTxt = new Text2('Yükselt\n₺' + worker2UpgradeCost, {
size: 36,
fill: '#fff'
});
worker2UpgradeBtnTxt.anchor.set(0.5, 0.5);
worker2UpgradeBtnTxt.x = worker2UpgradeBtn.x;
worker2UpgradeBtnTxt.y = worker2UpgradeBtn.y;
worker2UpgradeBtnTxt.visible = false;
game.addChild(worker2UpgradeBtnTxt);
worker2UpgradeBtn.down = function (x, y, obj) {
if (yatirimPanel && yatirimPanel.visible) {
return;
}
if (money >= worker2UpgradeCost) {
money -= worker2UpgradeCost;
worker2Level += 1;
worker2UpgradeCost = Math.floor(worker2UpgradeCost * 2.2);
updateMoneyText();
worker2LevelTxt.setText('Seviye: ' + worker2Level);
worker2SpeedTxt.setText('Üretim Süresi: -%' + (worker2Level - 1) * 2);
worker2UpgradeBtnTxt.setText('Yükselt\n₺' + worker2UpgradeCost);
tween(worker2UpgradeBtn, {
scaleX: 1.12,
scaleY: 1.12
}, {
duration: 80,
onFinish: function onFinish() {
tween(worker2UpgradeBtn, {
scaleX: 1,
scaleY: 1
}, {
duration: 80
});
}
});
} else {
tween(worker2UpgradeBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(worker2UpgradeBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
}
};
}
// Çalışan 3 için seviye, fabrika yükseltme maliyeti indirim oranı ve buton ekle
if (i === 2) {
worker3LevelTxt = new Text2('Seviye: ' + worker3Level, {
size: 36,
fill: '#ffb'
});
worker3LevelTxt.anchor.set(0.5, 0);
worker3LevelTxt.x = workerImg.x;
worker3LevelTxt.y = workerLabel.y + 32;
worker3LevelTxt.visible = false;
game.addChild(worker3LevelTxt);
worker3DiscountTxt = new Text2('Fabrika Yükseltme İndirimi: -%0', {
size: 36,
fill: '#bff'
});
worker3DiscountTxt.anchor.set(0.5, 0);
worker3DiscountTxt.x = workerImg.x;
worker3DiscountTxt.y = worker3LevelTxt.y + worker3LevelTxt.height + 4;
worker3DiscountTxt.visible = false;
game.addChild(worker3DiscountTxt);
worker3UpgradeBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 140,
height: 64,
x: workerImg.x,
y: worker3DiscountTxt.y + worker3DiscountTxt.height + 18
});
worker3UpgradeBtn.visible = false;
game.addChild(worker3UpgradeBtn);
worker3UpgradeBtnTxt = new Text2('Yükselt\n₺' + worker3UpgradeCost, {
size: 36,
fill: '#fff'
});
worker3UpgradeBtnTxt.anchor.set(0.5, 0.5);
worker3UpgradeBtnTxt.x = worker3UpgradeBtn.x;
worker3UpgradeBtnTxt.y = worker3UpgradeBtn.y;
worker3UpgradeBtnTxt.visible = false;
game.addChild(worker3UpgradeBtnTxt);
worker3UpgradeBtn.down = function (x, y, obj) {
if (yatirimPanel && yatirimPanel.visible) {
return;
}
if (money >= worker3UpgradeCost) {
money -= worker3UpgradeCost;
worker3Level += 1;
worker3UpgradeCost = Math.floor(worker3UpgradeCost * 2.2);
updateMoneyText && updateMoneyText();
worker3LevelTxt.setText('Seviye: ' + worker3Level);
worker3DiscountTxt.setText('Fabrika Yükseltme İndirimi: -%' + (worker3Level - 1) * 2);
worker3UpgradeBtnTxt.setText('Yükselt\n₺' + worker3UpgradeCost);
tween(worker3UpgradeBtn, {
scaleX: 1.12,
scaleY: 1.12
}, {
duration: 80,
onFinish: function onFinish() {
tween(worker3UpgradeBtn, {
scaleX: 1,
scaleY: 1
}, {
duration: 80
});
}
});
} else {
tween(worker3UpgradeBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(worker3UpgradeBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
}
};
}
// Çalışan 4 için seviye, tıklama kazancı ve yükseltme butonu ekle
if (i === 3) {
worker4LevelTxt = new Text2('Seviye: ' + worker4Level, {
size: 36,
fill: '#ffb'
});
worker4LevelTxt.anchor.set(0.5, 0);
worker4LevelTxt.x = workerImg.x;
worker4LevelTxt.y = workerLabel.y + 32;
worker4LevelTxt.visible = false;
game.addChild(worker4LevelTxt);
var earning = Math.round(worker4BaseEarning * Math.pow(1.25, worker4Level - 1));
worker4EarningTxt = new Text2('Resmime Tıkla\nTıkla: ₺' + earning, {
size: 36,
fill: '#bff'
});
worker4EarningTxt.anchor.set(0.5, 0);
worker4EarningTxt.x = workerImg.x;
worker4EarningTxt.y = worker4LevelTxt.y + worker4LevelTxt.height + 4;
worker4EarningTxt.visible = false;
game.addChild(worker4EarningTxt);
worker4UpgradeBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 140,
height: 64,
x: workerImg.x,
y: worker4EarningTxt.y + worker4EarningTxt.height + 18
});
worker4UpgradeBtn.visible = false;
game.addChild(worker4UpgradeBtn);
worker4UpgradeBtnTxt = new Text2('Yükselt\n₺' + worker4UpgradeCost, {
size: 36,
fill: '#fff'
});
worker4UpgradeBtnTxt.anchor.set(0.5, 0.5);
worker4UpgradeBtnTxt.x = worker4UpgradeBtn.x;
worker4UpgradeBtnTxt.y = worker4UpgradeBtn.y;
worker4UpgradeBtnTxt.visible = false;
game.addChild(worker4UpgradeBtnTxt);
workerImg.down = function (x, y, obj) {
if (yatirimPanel && yatirimPanel.visible) {
return;
}
var earning = Math.round(worker4BaseEarning * Math.pow(1.25, worker4Level - 1));
money += earning;
updateMoneyText && updateMoneyText();
tween(workerImg, {
scaleX: 1.12,
scaleY: 1.12
}, {
duration: 80,
onFinish: function onFinish() {
tween(workerImg, {
scaleX: 1,
scaleY: 1
}, {
duration: 80
});
}
});
worker4EarningTxt.setText('Resmime Tıkla\nTıkla: ₺' + earning);
};
worker4UpgradeBtn.down = function (x, y, obj) {
if (yatirimPanel && yatirimPanel.visible) {
return;
}
if (money >= worker4UpgradeCost) {
money -= worker4UpgradeCost;
worker4Level += 1;
worker4UpgradeCost = Math.floor(worker4UpgradeCost * 2.5);
updateMoneyText && updateMoneyText();
worker4LevelTxt.setText('Seviye: ' + worker4Level);
var earning = Math.round(worker4BaseEarning * Math.pow(1.25, worker4Level - 1));
worker4EarningTxt.setText('Resmime Tıkla\nTıkla: ₺' + earning);
worker4UpgradeBtnTxt.setText('Yükselt\n₺' + worker4UpgradeCost);
tween(worker4UpgradeBtn, {
scaleX: 1.12,
scaleY: 1.12
}, {
duration: 80,
onFinish: function onFinish() {
tween(worker4UpgradeBtn, {
scaleX: 1,
scaleY: 1
}, {
duration: 80
});
}
});
} else {
tween(worker4UpgradeBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(worker4UpgradeBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
}
};
}
// Çalışan 5 için seviye, bonus ve yükseltme butonu ekle
if (i === 4) {
worker5LevelTxt = new Text2('Seviye: ' + worker5Level, {
size: 36,
fill: '#ffb'
});
worker5LevelTxt.anchor.set(0.5, 0);
worker5LevelTxt.x = workerImg.x;
worker5LevelTxt.y = workerLabel.y + 32;
worker5LevelTxt.visible = false;
game.addChild(worker5LevelTxt);
var bonusPercent = Math.round(worker5BaseBonus * worker5Level * 100);
worker5BonusTxt = new Text2('Tüm Kazanç: +%' + bonusPercent, {
size: 36,
fill: '#bff'
});
worker5BonusTxt.anchor.set(0.5, 0);
worker5BonusTxt.x = workerImg.x;
worker5BonusTxt.y = worker5LevelTxt.y + worker5LevelTxt.height + 4;
worker5BonusTxt.visible = false;
game.addChild(worker5BonusTxt);
worker5UpgradeBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 140,
height: 64,
x: workerImg.x,
y: worker5BonusTxt.y + worker5BonusTxt.height + 18
});
worker5UpgradeBtn.visible = false;
game.addChild(worker5UpgradeBtn);
worker5UpgradeBtnTxt = new Text2('Yükselt\n₺' + worker5UpgradeCost, {
size: 36,
fill: '#fff'
});
worker5UpgradeBtnTxt.anchor.set(0.5, 0.5);
worker5UpgradeBtnTxt.x = worker5UpgradeBtn.x;
worker5UpgradeBtnTxt.y = worker5UpgradeBtn.y;
worker5UpgradeBtnTxt.visible = false;
game.addChild(worker5UpgradeBtnTxt);
worker5UpgradeBtn.down = function (x, y, obj) {
if (yatirimPanel && yatirimPanel.visible) {
return;
}
if (money >= worker5UpgradeCost) {
money -= worker5UpgradeCost;
worker5Level += 1;
worker5UpgradeCost = Math.floor(worker5UpgradeCost * 2.5);
updateMoneyText && updateMoneyText();
worker5LevelTxt.setText('Seviye: ' + worker5Level);
var bonusPercent = Math.round(worker5BaseBonus * worker5Level * 100);
worker5BonusTxt.setText('Tüm Kazanç: +%' + bonusPercent);
worker5UpgradeBtnTxt.setText('Yükselt\n₺' + worker5UpgradeCost);
tween(worker5UpgradeBtn, {
scaleX: 1.12,
scaleY: 1.12
}, {
duration: 80,
onFinish: function onFinish() {
tween(worker5UpgradeBtn, {
scaleX: 1,
scaleY: 1
}, {
duration: 80
});
}
});
} else {
tween(worker5UpgradeBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(worker5UpgradeBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
}
};
}
workerImages.push({
img: workerImg,
label: workerLabel
});
}
// Çalışan 1 kazancını her 10 saniyede bir ekle
// Defensive: define mevduatTutar as 0 if not already defined, to prevent 'mevduatTutar is not defined' error
if (typeof mevduatTutar === "undefined") {
var mevduatTutar = 0;
}
LK.setInterval(function () {
var earning = Math.round(worker1EarningBase * Math.pow(1.02, worker1Level - 1));
money += earning;
// --- Mevduat faizi: %2 yıllık, 10 saniyede bir işlesin (yıllık faiz, 10 saniyeye bölünür) ---
// Yıllık faiz oranı
var mevduatFaizYillik = 0.02;
// 1 yılda 365*24*60*60/10 = 315360 kez 10 saniyelik periyot var
var faizPeriyotSayisi = 365 * 24 * 60 * 60 / 10;
// Her 10 saniyede işlenecek faiz oranı
var mevduatFaizOrani = Math.pow(1 + mevduatFaizYillik, 1 / faizPeriyotSayisi) - 1;
// Mevduat faizi ekle
if (mevduatTutar > 0) {
var faizKazanc = mevduatTutar * mevduatFaizOrani;
// En az 1 kuruş (0.01) birikirse ekle, küsuratı biriktir
if (typeof mevduatFaizKalan === "undefined") {
window.mevduatFaizKalan = 0;
}
window.mevduatFaizKalan += faizKazanc;
if (window.mevduatFaizKalan >= 0.01) {
var eklenecek = Math.floor(window.mevduatFaizKalan * 100) / 100;
mevduatTutar += eklenecek;
window.mevduatFaizKalan -= eklenecek;
updateMevduatTxt && updateMevduatTxt();
}
}
updateMoneyText && updateMoneyText();
if (typeof worker1EarningTxt !== "undefined" && worker1EarningTxt !== null && typeof worker1EarningTxt.setText === "function" && typeof worker1EarningTxt.x !== "undefined" && typeof worker1EarningTxt.x === "number") {
worker1EarningTxt.setText('Kazanç: ₺' + earning);
}
}, 600); // 10 saniye (60fps * 10)
// Panel açıldığında çalışanları göster
newPageBtn.down = function (x, y, obj) {
newPagePanel.visible = true;
newPagePanelTitle.visible = true;
newPagePanelText.visible = true;
newPageKapatBtn.visible = true;
newPageKapatBtnTxt.visible = true;
// Çalışanları ve altındaki UI'ları göster ve panelde 3'lü sıra halinde alt alta ortala
for (var i = 0; i < workerImages.length; i++) {
var pos = getWorkerPanelPos(i);
workerImages[i].img.x = pos.x;
workerImages[i].img.y = pos.y;
workerImages[i].img.visible = true;
workerImages[i].label.x = pos.x;
workerImages[i].label.y = pos.y + 80;
workerImages[i].label.visible = true;
// Alt açıklama yazılarını alt alta ve hizalı şekilde göster
var baseY = workerImages[i].label.y + workerImages[i].label.height + 8; // label'ın altından 8px boşluk
var lineGap = 8; // satırlar arası boşluk
if (i === 0) {
var y = baseY;
if (worker1LevelTxt) {
worker1LevelTxt.x = pos.x;
worker1LevelTxt.y = y;
worker1LevelTxt.visible = true;
y += worker1LevelTxt.height + lineGap;
}
if (worker1EarningTxt) {
worker1EarningTxt.x = pos.x;
worker1EarningTxt.y = y;
worker1EarningTxt.visible = true;
y += worker1EarningTxt.height + lineGap;
}
if (worker1UpgradeBtn) {
worker1UpgradeBtn.x = pos.x;
worker1UpgradeBtn.y = y + worker1UpgradeBtn.height / 2;
worker1UpgradeBtn.visible = true;
}
if (worker1UpgradeBtnTxt) {
worker1UpgradeBtnTxt.x = pos.x;
worker1UpgradeBtnTxt.y = worker1UpgradeBtn.y;
worker1UpgradeBtnTxt.visible = true;
}
}
if (i === 1) {
var y = baseY;
if (worker2LevelTxt) {
worker2LevelTxt.x = pos.x;
worker2LevelTxt.y = y;
worker2LevelTxt.visible = true;
y += worker2LevelTxt.height + lineGap;
}
if (worker2SpeedTxt) {
worker2SpeedTxt.x = pos.x;
worker2SpeedTxt.y = y;
worker2SpeedTxt.visible = true;
y += worker2SpeedTxt.height + lineGap;
}
if (worker2UpgradeBtn) {
worker2UpgradeBtn.x = pos.x;
worker2UpgradeBtn.y = y + worker2UpgradeBtn.height / 2;
worker2UpgradeBtn.visible = true;
}
if (worker2UpgradeBtnTxt) {
worker2UpgradeBtnTxt.x = pos.x;
worker2UpgradeBtnTxt.y = worker2UpgradeBtn.y;
worker2UpgradeBtnTxt.visible = true;
}
}
if (i === 2) {
var y = baseY;
if (worker3LevelTxt) {
worker3LevelTxt.x = pos.x;
worker3LevelTxt.y = y;
worker3LevelTxt.visible = true;
y += worker3LevelTxt.height + lineGap;
}
if (worker3DiscountTxt) {
worker3DiscountTxt.x = pos.x;
worker3DiscountTxt.y = y;
worker3DiscountTxt.visible = true;
y += worker3DiscountTxt.height + lineGap;
}
if (worker3UpgradeBtn) {
worker3UpgradeBtn.x = pos.x;
worker3UpgradeBtn.y = y + worker3UpgradeBtn.height / 2;
worker3UpgradeBtn.visible = true;
}
if (worker3UpgradeBtnTxt) {
worker3UpgradeBtnTxt.x = pos.x;
worker3UpgradeBtnTxt.y = worker3UpgradeBtn.y;
worker3UpgradeBtnTxt.visible = true;
}
}
if (i === 3) {
var y = baseY;
if (worker4LevelTxt) {
worker4LevelTxt.x = pos.x;
worker4LevelTxt.y = y;
worker4LevelTxt.visible = true;
y += worker4LevelTxt.height + lineGap;
}
if (worker4EarningTxt) {
worker4EarningTxt.x = pos.x;
worker4EarningTxt.y = y;
worker4EarningTxt.visible = true;
y += worker4EarningTxt.height + lineGap;
}
if (worker4UpgradeBtn) {
worker4UpgradeBtn.x = pos.x;
worker4UpgradeBtn.y = y + worker4UpgradeBtn.height / 2;
worker4UpgradeBtn.visible = true;
}
if (worker4UpgradeBtnTxt) {
worker4UpgradeBtnTxt.x = pos.x;
worker4UpgradeBtnTxt.y = worker4UpgradeBtn.y;
worker4UpgradeBtnTxt.visible = true;
}
}
if (i === 4) {
var y = baseY;
if (worker5LevelTxt) {
worker5LevelTxt.x = pos.x;
worker5LevelTxt.y = y;
worker5LevelTxt.visible = true;
y += worker5LevelTxt.height + lineGap;
}
if (worker5BonusTxt) {
worker5BonusTxt.x = pos.x;
worker5BonusTxt.y = y;
worker5BonusTxt.visible = true;
y += worker5BonusTxt.height + lineGap;
}
if (worker5UpgradeBtn) {
worker5UpgradeBtn.x = pos.x;
worker5UpgradeBtn.y = y + worker5UpgradeBtn.height / 2;
worker5UpgradeBtn.visible = true;
}
if (worker5UpgradeBtnTxt) {
worker5UpgradeBtnTxt.x = pos.x;
worker5UpgradeBtnTxt.y = worker5UpgradeBtn.y;
worker5UpgradeBtnTxt.visible = true;
}
}
}
// Paneli en öne getir
if (game.setChildIndex) {
game.setChildIndex(newPagePanel, game.children.length - 1);
game.setChildIndex(newPagePanelTitle, game.children.length - 1);
game.setChildIndex(newPagePanelText, game.children.length - 1);
game.setChildIndex(newPageKapatBtn, game.children.length - 1);
game.setChildIndex(newPageKapatBtnTxt, game.children.length - 1);
// Çalışanları ve altındaki UI'ları en öne getir
for (var i = 0; i < workerImages.length; i++) {
game.setChildIndex(workerImages[i].img, game.children.length - 1);
game.setChildIndex(workerImages[i].label, game.children.length - 1);
}
if (worker1LevelTxt) {
game.setChildIndex(worker1LevelTxt, game.children.length - 1);
}
if (worker1EarningTxt) {
game.setChildIndex(worker1EarningTxt, game.children.length - 1);
}
if (worker1UpgradeBtn) {
game.setChildIndex(worker1UpgradeBtn, game.children.length - 1);
}
if (worker1UpgradeBtnTxt) {
game.setChildIndex(worker1UpgradeBtnTxt, game.children.length - 1);
}
if (worker2LevelTxt) {
game.setChildIndex(worker2LevelTxt, game.children.length - 1);
}
if (worker2SpeedTxt) {
game.setChildIndex(worker2SpeedTxt, game.children.length - 1);
}
if (worker2UpgradeBtn) {
game.setChildIndex(worker2UpgradeBtn, game.children.length - 1);
}
if (worker2UpgradeBtnTxt) {
game.setChildIndex(worker2UpgradeBtnTxt, game.children.length - 1);
}
if (worker3LevelTxt) {
game.setChildIndex(worker3LevelTxt, game.children.length - 1);
}
if (worker3DiscountTxt) {
game.setChildIndex(worker3DiscountTxt, game.children.length - 1);
}
if (worker3UpgradeBtn) {
game.setChildIndex(worker3UpgradeBtn, game.children.length - 1);
}
if (worker3UpgradeBtnTxt) {
game.setChildIndex(worker3UpgradeBtnTxt, game.children.length - 1);
}
if (worker4LevelTxt) {
game.setChildIndex(worker4LevelTxt, game.children.length - 1);
}
if (worker4EarningTxt) {
game.setChildIndex(worker4EarningTxt, game.children.length - 1);
}
if (worker4UpgradeBtn) {
game.setChildIndex(worker4UpgradeBtn, game.children.length - 1);
}
if (worker4UpgradeBtnTxt) {
game.setChildIndex(worker4UpgradeBtnTxt, game.children.length - 1);
}
if (worker5LevelTxt) {
game.setChildIndex(worker5LevelTxt, game.children.length - 1);
}
if (worker5BonusTxt) {
game.setChildIndex(worker5BonusTxt, game.children.length - 1);
}
if (worker5UpgradeBtn) {
game.setChildIndex(worker5UpgradeBtn, game.children.length - 1);
}
if (worker5UpgradeBtnTxt) {
game.setChildIndex(worker5UpgradeBtnTxt, game.children.length - 1);
}
}
};
// Paneli kapatınca çalışanları gizle
newPageKapatBtn.down = function (x, y, obj) {
// Hide Çalışanlar panel and all its UI
newPagePanel.visible = false;
newPagePanelTitle.visible = false;
newPagePanelText.visible = false;
newPageKapatBtn.visible = false;
newPageKapatBtnTxt.visible = false;
// --- Yeni üst kapat butonunu ve label/icon'unu gizle ---
if (typeof newPageKapatBtnTop !== "undefined") newPageKapatBtnTop.visible = false;
if (typeof newPageKapatBtnTopIcon !== "undefined") newPageKapatBtnTopIcon.visible = false;
if (typeof newPageKapatBtnTopTxt !== "undefined") newPageKapatBtnTopTxt.visible = false;
// Hide all worker UI
for (var i = 0; i < workerImages.length; i++) {
workerImages[i].img.visible = false;
workerImages[i].label.visible = false;
}
if (worker1LevelTxt) worker1LevelTxt.visible = false; //{17H}{17I}
if (worker1EarningTxt) worker1EarningTxt.visible = false; //{17K}{17L}
if (worker1UpgradeBtn) worker1UpgradeBtn.visible = false; //{17N}{17O}
if (worker1UpgradeBtnTxt) worker1UpgradeBtnTxt.visible = false; //{17Q}{17R}
if (worker2LevelTxt) worker2LevelTxt.visible = false; //{17T}{17U}
if (worker2SpeedTxt) worker2SpeedTxt.visible = false; //{17W}{17X}
if (worker2UpgradeBtn) worker2UpgradeBtn.visible = false; //{17Z}{180}
if (worker2UpgradeBtnTxt) worker2UpgradeBtnTxt.visible = false; //{182}{183}
if (worker3LevelTxt) worker3LevelTxt.visible = false; //{185}{186}
if (worker3DiscountTxt) worker3DiscountTxt.visible = false; //{188}{189}
if (worker3UpgradeBtn) worker3UpgradeBtn.visible = false; //{18b}{18c}
if (worker3UpgradeBtnTxt) worker3UpgradeBtnTxt.visible = false; //{18e}{18f}
if (worker4LevelTxt) worker4LevelTxt.visible = false; //{18h}{18i}
if (worker4EarningTxt) worker4EarningTxt.visible = false; //{18k}{18l}
if (worker4UpgradeBtn) worker4UpgradeBtn.visible = false; //{18n}{18o}
if (worker4UpgradeBtnTxt) worker4UpgradeBtnTxt.visible = false; //{18q}{18r}
if (worker5LevelTxt) worker5LevelTxt.visible = false; //{18t}{18u}
if (worker5BonusTxt) worker5BonusTxt.visible = false; //{18w}{18x}
if (worker5UpgradeBtn) worker5UpgradeBtn.visible = false; //{18z}{18A}
if (worker5UpgradeBtnTxt) worker5UpgradeBtnTxt.visible = false; //{18C}{18D}
// Restore all homepage/game UI (defensive, in case other panels were open)
if (typeof magazaBtn !== "undefined") magazaBtn.visible = true;
if (typeof magazaBtnTxt !== "undefined") magazaBtnTxt.visible = true;
if (typeof yatirimBtn !== "undefined") yatirimBtn.visible = true;
if (typeof yatirimBtnTxt !== "undefined") yatirimBtnTxt.visible = true;
if (typeof bankBtn !== "undefined") bankBtn.visible = true;
if (typeof bankBtnTxt !== "undefined") bankBtnTxt.visible = true;
if (typeof soundBtn !== "undefined") soundBtn.visible = true;
if (typeof soundBtnTxt !== "undefined") soundBtnTxt.visible = true;
if (typeof newPageBtn !== "undefined") newPageBtn.visible = true;
if (typeof newPageBtnTxt !== "undefined") newPageBtnTxt.visible = true;
if (typeof madenlerBtn !== "undefined") madenlerBtn.visible = true;
if (typeof madenlerBtnTxt !== "undefined") madenlerBtnTxt.visible = true;
if (typeof magazalarBtn !== "undefined") magazalarBtn.visible = true;
if (typeof magazalarBtnTxt !== "undefined") magazalarBtnTxt.visible = true;
if (typeof languagesBtn !== "undefined") languagesBtn.visible = true;
if (typeof languagesBtnTxt !== "undefined") languagesBtnTxt.visible = true;
if (typeof calisanlarBtnImg !== "undefined") calisanlarBtnImg.visible = true;
if (typeof madenlerBtnMineImg !== "undefined") madenlerBtnMineImg.visible = true;
// Info and How To Play buttons are never shown
if (typeof borcOdeBtn !== "undefined") borcOdeBtn.visible = true;
if (typeof borcOdeBtnTxt !== "undefined") borcOdeBtnTxt.visible = true;
if (typeof mevduatBtn !== "undefined") mevduatBtn.visible = true;
if (typeof mevduatBtnTxt !== "undefined") mevduatBtnTxt.visible = true;
// --- Ava: Restore all homepage images when Çalışanlar panel closes ---
if (window.homepageImages && window.homepageImages.length) {
for (var i = 0; i < window.homepageImages.length; i++) {
if (window.homepageImages[i] && typeof window.homepageImages[i].visible === "boolean") {
if (typeof window.homepageImages[i]._oldVisible !== "undefined") {
window.homepageImages[i].visible = window.homepageImages[i]._oldVisible;
delete window.homepageImages[i]._oldVisible;
} else {
window.homepageImages[i].visible = true;
}
}
}
}
// Defensive: re-enable all factory/factoryUnlock/prod/auto buttons if they were disabled by other panels
if (typeof factoryBtns !== "undefined" && Array.isArray(factoryBtns)) {
for (var i = 0; i < factoryBtns.length; i++) {
if (factoryBtns[i] && factoryBtns[i]._origDown) {
factoryBtns[i].down = factoryBtns[i]._origDown;
delete factoryBtns[i]._origDown;
}
}
}
if (typeof factoryUnlockBtns !== "undefined" && Array.isArray(factoryUnlockBtns)) {
for (var i = 0; i < factoryUnlockBtns.length; i++) {
if (factoryUnlockBtns[i] && factoryUnlockBtns[i]._origDown) {
factoryUnlockBtns[i].down = factoryUnlockBtns[i]._origDown;
delete factoryUnlockBtns[i]._origDown;
}
}
}
if (typeof prodBtns !== "undefined" && Array.isArray(prodBtns)) {
for (var i = 0; i < prodBtns.length; i++) {
if (prodBtns[i] && prodBtns[i]._origDown) {
prodBtns[i].down = prodBtns[i]._origDown;
delete prodBtns[i]._origDown;
}
}
}
if (typeof factoryAutoBtns !== "undefined" && Array.isArray(factoryAutoBtns)) {
for (var i = 0; i < factoryAutoBtns.length; i++) {
if (factoryAutoBtns[i] && factoryAutoBtns[i]._origDown) {
factoryAutoBtns[i].down = factoryAutoBtns[i]._origDown;
delete factoryAutoBtns[i]._origDown;
}
}
}
for (var i = 0; i < game.children.length; i++) {
var child = game.children[i];
if (child && child.isFactoryButton && child._origDown) {
child.down = child._origDown;
delete child._origDown;
}
}
// Hide overlays if visible
if (typeof fullscreenOverlay !== "undefined") fullscreenOverlay.visible = false;
};
// --- Mines ---
// Anasayfada madenler, stok sayısı ve butonları gösterilmeyecek
var mines = [];
var mineAutoProduce = [false, false, false, false, false, false]; // Track auto-produce state for each mine
var mineAutoBtns = [];
var mineAutoTxts = [];
// Defensive: Always initialize mines array with 6 Mine objects, one for each ore type
if (!Array.isArray(mines) || mines.length !== 6) {
mines = [];
for (var i = 0; i < 6; i++) {
var m = new Mine();
m.setType(oreTypes[i]);
// Arrange mines offscreen by default (UI panels will reposition them)
m.x = -1000;
m.y = -1000;
mines.push(m);
game.addChild(m);
}
}
// --- Factories for each part ---
var factories = [];
var factoryUnlocks = [];
var factoryUnlockCosts = [0, 350, 525, 700, 875, 1050, 1225, 1400, 1575, 1750];
// Apply 50% price increase to all except the first (CPU)
for (var i = 1; i < factoryUnlockCosts.length; i++) {
factoryUnlockCosts[i] = Math.floor(factoryUnlockCosts[i] * 1.5);
}
var factoryAutoProduce = [];
var factoryAutoBtns = [];
var factoryAutoTxts = [];
for (var i = 0; i < partTypes.length; i++) {
var FactoryClass = FactoryClasses[partTypes[i]];
var f = new FactoryClass();
// Arrange factories in two rows of 5, with extra vertical spacing between rows
var col = i % 5;
var row = Math.floor(i / 5);
// Add vertical spacing (gap) between factory panels
var factoryPanelGap = 24;
f.x = 500 + col * 300 + col * factoryPanelGap;
// Move MB, CASE, FAN, HDD, COOLER (indices 5,6,7,8,9) further down
// Move the whole factories panel lower by +200px
if (i >= 5) {
// Increase the offset for the second row and move these factories further down
f.y = 1300 + row * 420 + 320;
} else {
f.y = 1300 + row * 420;
}
game.addChild(f);
factories.push(f);
// Add production time text under the part icon
var prodTime = f.getProductionTime ? f.getProductionTime() : 30;
var prodTimeSec = (prodTime / 60).toFixed(2);
// Add a panel image behind the production time text
var prodTimePanel = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0,
width: 220,
height: 54,
x: f.x,
y: f.y - 60 + 60 * 0.7 + 28,
// 10px higher to allow for text padding
scaleX: 0.8,
scaleY: 0.7
});
// Add horizontal gap to prodTimePanel to match factory panel gap
prodTimePanel.x = f.x;
game.addChild(prodTimePanel);
var prodTimeTxt = new Text2("Üretim: " + prodTimeSec + " sn", {
size: 32,
fill: "#fff"
});
prodTimeTxt.anchor.set(0.5, 0);
// Place under the part icon (which is at y: -60, scale 0.7, so about -60+60*0.7+10)
prodTimeTxt.x = f.x;
prodTimeTxt.y = f.y - 60 + 60 * 0.7 + 38;
game.addChild(prodTimeTxt);
// Store reference for later update on upgrade
f._prodTimeTxt = prodTimeTxt;
// Unlock state: CPU (i==0) is always unlocked, others locked
factoryUnlocks.push(i === 0 ? true : false);
// Add auto-produce toggle button for each factory
factoryAutoProduce.push(false);
var autoBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
autoBtn.x = f.x;
// Move auto-produce button further down
// Add horizontal gap to autoBtn to match factory panel gap
autoBtn.x = f.x;
if (i >= 5) {
autoBtn.y = f.y + 530 + 80;
} else {
autoBtn.y = f.y + 530;
}
game.addChild(autoBtn);
var autoTxt = new Text2('Oto Üret: Kapalı', {
size: 36,
fill: '#fff'
});
autoTxt.anchor.set(0.5, 0.5);
autoTxt.x = autoBtn.x;
autoTxt.y = autoBtn.y;
game.addChild(autoTxt);
autoBtn.factoryIndex = i;
autoBtn.down = function (x, y, obj) {
// Disable if investment panel is open or Çalışanlar paneli is open
if (yatirimPanel && yatirimPanel.visible || newPagePanel && newPagePanel.visible) {
return;
}
var idx = this.factoryIndex;
if (!factoryAutoProduce[idx]) {
// Cost to enable auto-produce for factory: 1000
var autoFactoryCost = (idx + 1) * 1000;
if (money >= autoFactoryCost) {
money -= autoFactoryCost;
updateMoneyText();
factoryAutoProduce[idx] = true;
factoryAutoTxts[idx].setText('Oto Üret: Açık');
} else {
// Not enough money, flash button red
tween(this, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(autoBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
}
} else {
// Oto Üret kapatılmasın: Satın alındıktan sonra kapatmaya izin verme
// Artık kapatma işlemi yapılmıyor, buton işlevsiz.
}
};
factoryAutoBtns.push(autoBtn);
factoryAutoTxts.push(autoTxt);
// Set initial text
var autoFactoryCost = (i + 1) * 1000;
autoTxt.setText('Oto Üret: Kapalı\n₺' + autoFactoryCost);
}
// --- Store ---
var store = new Store();
// --- Ava: Arrange all stores and their purchase/upgrade buttons horizontally above factories ---
// Calculate horizontal layout for stores above factories
// Move all stores and their buttons 0.75 row higher (row height = 420, so move up by 315px)
var storeAboveFactoryY = 980 - 315; // 0.75 satır yukarı taşı
var storeAboveFactoryGapX = 320;
var storeAboveFactoryStartX = 650; // Ekranın solundan biraz içeride başlat
// Store 1
store.x = storeAboveFactoryStartX;
store.y = storeAboveFactoryY;
store.scaleX = 0.82;
store.scaleY = 0.82;
game.addChild(store);
// Store 2
var store2Purchased = false;
var store2PurchaseCost = 2000;
var store2 = new Store();
store2.x = store.x + storeAboveFactoryGapX * 1;
store2.y = storeAboveFactoryY;
store2.scaleX = 0.82;
store2.scaleY = 0.82;
game.addChild(store2);
store2.visible = true;
// Store 3
var store3Purchased = false;
var store3PurchaseCost = 5000;
var store3 = new Store();
store3.x = store.x + storeAboveFactoryGapX * 2;
store3.y = storeAboveFactoryY;
store3.scaleX = 0.82;
store3.scaleY = 0.82;
game.addChild(store3);
store3.visible = true;
// Store 4
var store4Purchased = false;
var store4PurchaseCost = 10000;
var store4 = new Store();
store4.x = store.x + storeAboveFactoryGapX * 3;
store4.y = storeAboveFactoryY;
store4.scaleX = 0.82;
store4.scaleY = 0.82;
game.addChild(store4);
store4.visible = true;
// --- Store 2 Purchase Button (fabrikaların üstündeki mağazaların altına hizala) ---
var store2PurchaseBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 260,
height: 80
});
store2PurchaseBtn.x = store2.x;
store2PurchaseBtn.y = store2.y + 160;
store2PurchaseBtn.visible = !store2Purchased;
game.addChild(store2PurchaseBtn);
var store2PurchaseBtnTxt = new Text2('Mağaza 2 Satın Al\n₺' + store2PurchaseCost, {
size: 38,
fill: '#fff'
});
store2PurchaseBtnTxt.anchor.set(0.5, 0.5);
store2PurchaseBtnTxt.x = store2PurchaseBtn.x;
store2PurchaseBtnTxt.y = store2PurchaseBtn.y + 10;
store2PurchaseBtnTxt.visible = !store2Purchased;
game.addChild(store2PurchaseBtnTxt);
// Store2 purchase logic as a function for reuse
function handleStore2Purchase() {
if (store2Purchased) {
return;
}
if (money >= store2PurchaseCost) {
money -= store2PurchaseCost;
store2Purchased = true;
updateMoneyText && updateMoneyText();
store2PurchaseBtn.visible = false;
store2PurchaseBtnTxt.visible = false;
// Show upgrade button after purchase
if (typeof store2Btn !== "undefined") {
store2Btn.visible = true;
}
if (typeof store2BtnTxt !== "undefined") {
store2BtnTxt.visible = true;
}
// Show store2 in Mağazalar panel after purchase
if (typeof store2 !== "undefined") {
store2.visible = true;
}
// Hide purchase button after purchase on homepage
store2PurchaseBtn.visible = false;
store2PurchaseBtnTxt.visible = false;
// Also hide on homepage duplicate if exists
if (typeof store2PurchaseBtn !== "undefined") {
store2PurchaseBtn.visible = false;
}
if (typeof store2PurchaseBtnTxt !== "undefined") {
store2PurchaseBtnTxt.visible = false;
}
} else {
// Not enough money, flash button red
tween(store2PurchaseBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(store2PurchaseBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
}
// Hide purchase button if purchased (defensive, in case of duplicate UI)
if (store2Purchased) {
store2PurchaseBtn.visible = false;
store2PurchaseBtnTxt.visible = false;
}
}
// Button logic
store2PurchaseBtn.down = function (x, y, obj) {
handleStore2Purchase();
};
// --- Store 2 Upgrade Button (fabrikaların üstündeki mağazaların altına hizala) ---
if (typeof store2Btn !== "undefined") {
store2Btn.x = store2.x;
store2Btn.y = store2.y + 160;
}
if (typeof store2BtnTxt !== "undefined") {
store2BtnTxt.x = store2.x;
store2BtnTxt.y = store2.y + 180;
}
// --- Store 3 Purchase Button (fabrikaların üstündeki mağazaların altına hizala) ---
// --- Store 3 Purchase Button (store2'ye benzer şekilde) ---
var store3PurchaseBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 260,
height: 80
});
store3PurchaseBtn.x = store3.x;
store3PurchaseBtn.y = store3.y + 160;
store3PurchaseBtn.visible = !store3Purchased;
game.addChild(store3PurchaseBtn);
var store3PurchaseBtnTxt = new Text2('Mağaza 3 Satın Al\n₺' + store3PurchaseCost, {
size: 38,
fill: '#fff'
});
store3PurchaseBtnTxt.anchor.set(0.5, 0.5);
store3PurchaseBtnTxt.x = store3PurchaseBtn.x;
store3PurchaseBtnTxt.y = store3PurchaseBtn.y + 10;
store3PurchaseBtnTxt.visible = !store3Purchased;
game.addChild(store3PurchaseBtnTxt);
function handleStore3Purchase() {
if (store3Purchased) {
return;
}
if (money >= store3PurchaseCost) {
money -= store3PurchaseCost;
store3Purchased = true;
updateMoneyText && updateMoneyText();
store3PurchaseBtn.visible = false;
store3PurchaseBtnTxt.visible = false;
store3PurchaseBtnImg.visible = false;
if (typeof store3Btn !== "undefined") {
store3Btn.visible = true;
}
if (typeof store3BtnTxt !== "undefined") {
store3BtnTxt.visible = true;
}
if (typeof store3 !== "undefined") {
store3.visible = true;
}
// Hide purchase button after purchase on homepage
if (typeof store3PurchaseBtn !== "undefined") {
store3PurchaseBtn.visible = false;
}
if (typeof store3PurchaseBtnTxt !== "undefined") {
store3PurchaseBtnTxt.visible = false;
}
if (typeof store3PurchaseBtnImg !== "undefined") {
store3PurchaseBtnImg.visible = false;
}
} else {
// Not enough money, flash button red
tween(store3PurchaseBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(store3PurchaseBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
tween(store3PurchaseBtnImg, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(store3PurchaseBtnImg, {
tint: 0x3fa9f5
}, {
duration: 120
});
}
});
}
if (store3Purchased) {
store3PurchaseBtn.visible = false;
store3PurchaseBtnTxt.visible = false;
store3PurchaseBtnImg.visible = false;
}
}
store3PurchaseBtn.down = function (x, y, obj) {
handleStore3Purchase();
};
store3PurchaseBtnTxt.down = function (x, y, obj) {
handleStore3Purchase();
};
if (typeof store3Btn !== "undefined") {
store3Btn.x = store3.x;
store3Btn.y = store3.y + 160;
store3Btn.visible = !!store3Purchased;
}
if (typeof store3BtnTxt !== "undefined") {
store3BtnTxt.x = store3.x;
store3BtnTxt.y = store3.y + 180;
store3BtnTxt.visible = !!store3Purchased;
}
// --- Store 4 Purchase Button (store2'ye benzer şekilde) ---
var store4PurchaseBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 260,
height: 80
});
store4PurchaseBtn.x = store4.x;
store4PurchaseBtn.y = store4.y + 160;
store4PurchaseBtn.visible = !store4Purchased;
game.addChild(store4PurchaseBtn);
var store4PurchaseBtnTxt = new Text2('Mağaza 4 Satın Al\n₺' + store4PurchaseCost, {
size: 38,
fill: '#fff'
});
store4PurchaseBtnTxt.anchor.set(0.5, 0.5);
store4PurchaseBtnTxt.x = store4PurchaseBtn.x;
store4PurchaseBtnTxt.y = store4PurchaseBtn.y + 10;
store4PurchaseBtnTxt.visible = !store4Purchased;
game.addChild(store4PurchaseBtnTxt);
function handleStore4Purchase() {
if (store4Purchased) {
return;
}
if (money >= store4PurchaseCost) {
money -= store4PurchaseCost;
store4Purchased = true;
updateMoneyText && updateMoneyText();
store4PurchaseBtn.visible = false;
store4PurchaseBtnTxt.visible = false;
store4PurchaseBtnImg.visible = false;
if (typeof store4Btn !== "undefined") {
store4Btn.visible = true;
}
if (typeof store4BtnTxt !== "undefined") {
store4BtnTxt.visible = true;
}
if (typeof store4 !== "undefined") {
store4.visible = true;
}
// Hide purchase button after purchase on homepage
if (typeof store4PurchaseBtn !== "undefined") {
store4PurchaseBtn.visible = false;
}
if (typeof store4PurchaseBtnTxt !== "undefined") {
store4PurchaseBtnTxt.visible = false;
}
if (typeof store4PurchaseBtnImg !== "undefined") {
store4PurchaseBtnImg.visible = false;
}
} else {
// Not enough money, flash button red
tween(store4PurchaseBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(store4PurchaseBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
tween(store4PurchaseBtnImg, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(store4PurchaseBtnImg, {
tint: 0xf97f62
}, {
duration: 120
});
}
});
}
if (store4Purchased) {
store4PurchaseBtn.visible = false;
store4PurchaseBtnTxt.visible = false;
store4PurchaseBtnImg.visible = false;
}
}
store4PurchaseBtn.down = function (x, y, obj) {
handleStore4Purchase();
};
store4PurchaseBtnTxt.down = function (x, y, obj) {
handleStore4Purchase();
};
if (typeof store4Btn !== "undefined") {
store4Btn.x = store4.x;
store4Btn.y = store4.y + 160;
store4Btn.visible = !!store4Purchased;
}
if (typeof store4BtnTxt !== "undefined") {
store4BtnTxt.x = store4.x;
store4BtnTxt.y = store4.y + 180;
store4BtnTxt.visible = !!store4Purchased;
}
// --- Ava: Always show all stores and their purchase buttons on homepage until purchased ---
store.visible = true;
store2.visible = true;
store3.visible = true;
store4.visible = true;
if (typeof store2PurchaseBtn !== "undefined" && store2PurchaseBtn) {
store2PurchaseBtn.visible = !store2Purchased;
if (store2Purchased) {
store2PurchaseBtn.visible = false;
store2PurchaseBtnTxt.visible = false;
}
}
store2PurchaseBtnTxt.visible = !store2Purchased;
store3PurchaseBtn.visible = false;
store3PurchaseBtnTxt.visible = false;
if (typeof store3PurchaseBtnIcon !== "undefined") {
store3PurchaseBtnIcon.visible = false;
}
if (store3Purchased) {
store3PurchaseBtn.visible = false;
store3PurchaseBtnTxt.visible = false;
if (typeof store3PurchaseBtnIcon !== "undefined") {
store3PurchaseBtnIcon.visible = false;
}
}
store4PurchaseBtn.visible = false;
store4PurchaseBtnTxt.visible = false;
if (typeof store4PurchaseBtnIcon !== "undefined") {
store4PurchaseBtnIcon.visible = false;
}
if (store4Purchased) {
store4PurchaseBtn.visible = false;
store4PurchaseBtnTxt.visible = false;
if (typeof store4PurchaseBtnIcon !== "undefined") {
store4PurchaseBtnIcon.visible = false;
}
}
// --- Show all customers on homepage ---
if (typeof customers === "undefined" || !Array.isArray(customers)) {
customers = [];
}
for (var i = 0; i < customers.length; i++) {
customers[i].visible = true;
}
// --- Store 2 Purchase Button (Mağazalar panelinde, upgrade üstünde) ---
var store2PurchaseBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 260,
height: 80
});
// Show on homepage (anasayfa)
store2PurchaseBtn.x = store2.x;
store2PurchaseBtn.y = store2.y + 160;
store2PurchaseBtn.visible = !store2Purchased;
game.addChild(store2PurchaseBtn);
var store2PurchaseBtnTxt = new Text2('Mağaza 2 Satın Al\n₺' + store2PurchaseCost, {
size: 38,
fill: '#fff'
});
store2PurchaseBtnTxt.anchor.set(0.5, 0.5);
store2PurchaseBtnTxt.x = store2PurchaseBtn.x;
store2PurchaseBtnTxt.y = store2PurchaseBtn.y + 10;
store2PurchaseBtnTxt.visible = !store2Purchased;
game.addChild(store2PurchaseBtnTxt);
store2PurchaseBtn.down = function (x, y, obj) {
if (store2Purchased) {
return;
}
if (money >= store2PurchaseCost) {
money -= store2PurchaseCost;
store2Purchased = true;
updateMoneyText && updateMoneyText();
store2PurchaseBtn.visible = false;
store2PurchaseBtnTxt.visible = false;
// Show upgrade button after purchase
if (typeof store2Btn !== "undefined") {
store2Btn.visible = true;
}
if (typeof store2BtnTxt !== "undefined") {
store2BtnTxt.visible = true;
}
// Show store2 in Mağazalar panel after purchase
if (typeof store2 !== "undefined") {
store2.visible = true;
}
} else {
// Not enough money, flash button red
tween(store2PurchaseBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(store2PurchaseBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
}
};
// --- Store 3 Purchase Button (Mağazalar panelinde, upgrade üstünde) ---
var store3PurchaseBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 260,
height: 80
});
// Show on homepage (anasayfa)
store3PurchaseBtn.x = store3.x;
store3PurchaseBtn.y = store3.y + 160;
store3PurchaseBtn.visible = !store3Purchased;
game.addChild(store3PurchaseBtn);
// (icon removed for Store3 purchase button - duplicate)
var store3PurchaseBtnTxt = new Text2('Mağaza 3 Satın Al\n₺' + store3PurchaseCost, {
size: 36,
fill: '#fff'
});
store3PurchaseBtnTxt.anchor.set(0.5, 0.5);
store3PurchaseBtnTxt.x = store3PurchaseBtn.x;
store3PurchaseBtnTxt.y = store3PurchaseBtn.y + 10;
store3PurchaseBtnTxt.visible = !store3Purchased;
store3PurchaseBtnTxt.style = store3PurchaseBtnTxt.style || {};
store3PurchaseBtnTxt.style.fill = '#fff';
game.addChild(store3PurchaseBtnTxt);
// Store3 purchase button logic
store3PurchaseBtn.down = function (x, y, obj) {
if (store3Purchased) {
return;
}
if (money >= store3PurchaseCost) {
money -= store3PurchaseCost;
store3Purchased = true;
updateMoneyText && updateMoneyText();
store3PurchaseBtn.visible = false;
store3PurchaseBtnTxt.visible = false;
// Show upgrade button after purchase
if (typeof store3Btn !== "undefined") {
store3Btn.visible = true;
}
if (typeof store3BtnTxt !== "undefined") {
store3BtnTxt.visible = true;
}
// Show store3 in Mağazalar panel after purchase
if (typeof store3 !== "undefined") {
store3.visible = true;
}
} else {
// Not enough money, flash button red
tween(store3PurchaseBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(store3PurchaseBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
}
};
store3PurchaseBtnTxt.down = function (x, y, obj) {
store3PurchaseBtn.down(x, y, obj);
};
// --- Store 4 Purchase Button (Mağazalar panelinde, upgrade üstünde) ---
var store4PurchaseBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 260,
height: 80
});
// Show on homepage (anasayfa)
store4PurchaseBtn.x = store4.x;
store4PurchaseBtn.y = store4.y + 160;
store4PurchaseBtn.visible = !store4Purchased;
game.addChild(store4PurchaseBtn);
// (icon removed for Store4 purchase button - duplicate)
var store4PurchaseBtnTxt = new Text2('Mağaza 4 Satın Al\n₺' + store4PurchaseCost, {
size: 36,
fill: '#fff'
});
store4PurchaseBtnTxt.anchor.set(0.5, 0.5);
store4PurchaseBtnTxt.x = store4PurchaseBtn.x;
store4PurchaseBtnTxt.y = store4PurchaseBtn.y + 10;
store4PurchaseBtnTxt.visible = !store4Purchased;
store4PurchaseBtnTxt.style = store4PurchaseBtnTxt.style || {};
store4PurchaseBtnTxt.style.fill = '#fff';
game.addChild(store4PurchaseBtnTxt);
// Store4 purchase button logic
store4PurchaseBtn.down = function (x, y, obj) {
if (store4Purchased) {
return;
}
if (money >= store4PurchaseCost) {
money -= store4PurchaseCost;
store4Purchased = true;
updateMoneyText && updateMoneyText();
store4PurchaseBtn.visible = false;
store4PurchaseBtnTxt.visible = false;
// Show upgrade button after purchase
if (typeof store4Btn !== "undefined") {
store4Btn.visible = true;
}
if (typeof store4BtnTxt !== "undefined") {
store4BtnTxt.visible = true;
}
// Show store4 in Mağazalar panel after purchase
if (typeof store4 !== "undefined") {
store4.visible = true;
}
} else {
// Not enough money, flash button red
tween(store4PurchaseBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(store4PurchaseBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
}
};
store4PurchaseBtnTxt.down = function (x, y, obj) {
store4PurchaseBtn.down(x, y, obj);
};
// --- Upgrade Buttons ---
var mineBtns = [];
for (var i = 0; i < 3; i++) {
// Defensive: skip if mines or mines[i] is not defined
if (!mines || !mines[i]) {
continue;
}
var btn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
btn.x = mines[i].x - 80; // Move left to make space for produce button
btn.y = mines[i].y + 200;
game.addChild(btn);
var txt = new Text2('Maden Yükselt\n₺' + mines[i].upgradeCost, {
size: 44,
fill: '#fff'
});
txt.anchor.set(0.5, 0.5);
txt.y = btn.y + 20;
txt.x = btn.x;
game.addChild(txt);
btn.mineIndex = i;
btn.txt = txt;
btn.down = function (x, y, obj) {
// Disable if investment panel is open
if (yatirimPanel && yatirimPanel.visible) {
return;
}
var idx = this.mineIndex;
if (!mines || !mines[idx]) {
return;
}
var m = mines[idx];
if (money >= m.upgradeCost) {
toplamMadenYukseltme += m.upgradeCost;
m.upgrade();
this.txt.setText('Maden Yükselt\n₺' + m.upgradeCost);
}
};
mineBtns.push(btn);
// Add ÜRET (Produce) button next to upgrade
var prodBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 180,
height: 80
});
// ÜRET butonunu madenin altına yerleştir
prodBtn.x = mines[i].x - 170;
prodBtn.y = mines[i].y + 320;
game.addChild(prodBtn);
var prodTxt = new Text2('ÜRET', {
size: 36,
fill: '#fff'
});
prodTxt.anchor.set(0.5, 0.5);
// ÜRET yazısını butonun tam ortasına yerleştir
prodTxt.x = prodBtn.x;
prodTxt.y = prodBtn.y;
game.addChild(prodTxt);
prodBtn.mineIndex = i;
prodBtn.down = function (x, y, obj) {
// Disable if investment panel is open
if (yatirimPanel && yatirimPanel.visible) {
return;
}
var idx = this.mineIndex;
if (!mines || !mines[idx]) {
return;
}
var m = mines[idx];
// Instantly produce one batch of raw material for this mine
rawMaterials[m.type] += m.production;
updateRawText();
// Animate mine for feedback
tween(m, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 120,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(m, {
scaleX: 1,
scaleY: 1
}, {
duration: 120
});
}
});
};
}
// Factory upgrade buttons for each part
var factoryBtns = [];
var factoryUnlockBtns = [];
for (var i = 0; i < factories.length; i++) {
var f = factories[i];
// If factory is locked (except CPU), show unlock button instead of upgrade
if (!factoryUnlocks[i]) {
var unlockBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
unlockBtn.x = f.x;
// Add horizontal gap to unlock buttons to match factory panel gap
unlockBtn.x = f.x;
if (i >= 5) {
unlockBtn.y = f.y + 200 + 80;
} else {
unlockBtn.y = f.y + 200;
}
game.addChild(unlockBtn);
var unlockTxt = new Text2((i === 0 ? "MOUSE" : i === 1 ? "KLAVYE" : i === 6 ? "CPU" : i === 7 ? "GPU" : i === 8 ? "MONITOR" : i === 9 ? "KASA" : partTypes[i].toUpperCase()) + " Aç\n₺" + factoryUnlockCosts[i], {
size: 44,
fill: '#fff'
});
unlockTxt.anchor.set(0.5, 0.5);
unlockTxt.x = unlockBtn.x;
unlockTxt.y = unlockBtn.y + 20;
game.addChild(unlockTxt);
unlockBtn.factoryIndex = i;
unlockBtn.txt = unlockTxt;
unlockBtn.down = function (x, y, obj) {
// Disable if investment panel is open or Çalışanlar paneli is open
if (yatirimPanel && yatirimPanel.visible || newPagePanel && newPagePanel.visible) {
return;
}
var idx = this.factoryIndex;
if (!factoryUnlocks[idx] && money >= factoryUnlockCosts[idx]) {
money -= factoryUnlockCosts[idx];
updateMoneyText();
factoryUnlocks[idx] = true;
// Remove unlock button and text
this.destroy();
this.txt.destroy();
// Show upgrade button for this factory
showFactoryUpgradeButton(idx);
}
};
factoryUnlockBtns.push(unlockBtn);
// Don't show upgrade button for locked factories
continue;
}
// Show upgrade button for unlocked factories
var btn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
btn.x = f.x;
// Add horizontal gap to upgrade/unlock/production buttons to match factory panel gap
btn.x = f.x;
// Move MB, CASE, FAN, HDD, COOLER (indices 5,6,7,8,9) buttons further down
if (i >= 5) {
btn.y = f.y + 200 + 80;
} else {
btn.y = f.y + 200;
}
game.addChild(btn);
var txt = new Text2((i === 0 ? "MOUSE" : i === 1 ? "KLAVYE" : i === 6 ? "CPU" : i === 7 ? "GPU" : i === 8 ? "MONITOR" : partTypes[i].toUpperCase()) + " Yükselt\n₺" + f.upgradeCost, {
size: 44,
fill: '#fff'
});
txt.anchor.set(0.5, 0.5);
txt.x = btn.x;
txt.y = btn.y + 20;
game.addChild(txt);
btn.factoryIndex = i;
btn.txt = txt;
btn.down = function (x, y, obj) {
// Disable if investment panel is open or Çalışanlar paneli is open
if (yatirimPanel && yatirimPanel.visible || newPagePanel && newPagePanel.visible) {
return;
}
var idx = this.factoryIndex;
var f = factories[idx];
// Çalışan 3 indirimini uygula
var discount = 1 - (worker3Level - 1) * 0.02;
if (discount < 0.1) {
discount = 0.1;
} // Maksimum %90 indirim
var discountedCost = Math.floor(f.upgradeCost * discount);
if (money >= discountedCost) {
toplamFabrikaYukseltme += discountedCost;
money -= discountedCost;
f.upgrade();
updateMoneyText && updateMoneyText();
this.txt.setText((idx === 0 ? "MOUSE" : idx === 1 ? "KLAVYE" : idx === 6 ? "CPU" : idx === 7 ? "GPU" : idx === 8 ? "MONITOR" : idx === 9 ? "KASA" : partTypes[idx].toUpperCase()) + " Yükselt\n₺" + f.upgradeCost);
}
};
factoryBtns.push(btn);
}
// Helper to show upgrade button after unlock
function showFactoryUpgradeButton(idx) {
var f = factories[idx];
var btn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
btn.x = f.x;
// Add horizontal gap to upgrade button after unlock to match factory panel gap
btn.x = f.x;
if (idx >= 5) {
btn.y = f.y + 200 + 80;
} else {
btn.y = f.y + 200;
}
game.addChild(btn);
var txt = new Text2((idx === 0 ? "MOUSE" : idx === 1 ? "KLAVYE" : idx === 6 ? "CPU" : idx === 7 ? "GPU" : idx === 8 ? "MONITOR" : idx === 9 ? "KASA" : partTypes[idx].toUpperCase()) + " Yükselt\n₺" + f.upgradeCost, {
size: 44,
fill: '#fff'
});
txt.anchor.set(0.5, 0.5);
txt.x = btn.x;
txt.y = btn.y + 20;
game.addChild(txt);
btn.factoryIndex = idx;
btn.txt = txt;
btn.down = function (x, y, obj) {
// Disable if investment panel is open or Çalışanlar paneli is open
if (yatirimPanel && yatirimPanel.visible || newPagePanel && newPagePanel.visible) {
return;
}
var idx = this.factoryIndex;
var f = factories[idx];
// Çalışan 3 indirimini uygula
var discount = 1 - (worker3Level - 1) * 0.02;
if (discount < 0.1) {
discount = 0.1;
} // Maksimum %90 indirim
var discountedCost = Math.floor(f.upgradeCost * discount);
if (money >= discountedCost) {
money -= discountedCost;
f.upgrade();
updateMoneyText && updateMoneyText();
this.txt.setText((idx === 0 ? "MOUSE" : idx === 1 ? "KLAVYE" : idx === 6 ? "CPU" : idx === 7 ? "GPU" : idx === 8 ? "MONITOR" : partTypes[idx].toUpperCase()) + " Yükselt\n₺" + f.upgradeCost);
}
};
factoryBtns[idx] = btn;
}
// Store upgrade button (moved to Mağazalar panel overlay)
var storeBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
// Move Store1 upgrade button below the store image on the homepage
storeBtn.x = store.x;
storeBtn.y = store.y + 160;
storeBtn.visible = true;
game.addChild(storeBtn);
var storeBtnTxt = new Text2('Mağaza Yükselt\n₺' + store.upgradeCost, {
size: 44,
fill: '#fff'
});
storeBtnTxt.anchor.set(0.5, 0.5);
storeBtnTxt.x = storeBtn.x;
storeBtnTxt.y = storeBtn.y + 20;
storeBtnTxt.visible = true;
game.addChild(storeBtnTxt);
storeBtn.down = function (x, y, obj) {
if (money >= store.upgradeCost) {
toplamStoreYukseltme += store.upgradeCost;
store.upgrade();
storeBtnTxt.setText('Mağaza Yükselt\n₺' + store.upgradeCost);
}
};
// --- Store 2 Upgrade Button (moved to Mağazalar panel overlay) ---
var store2Btn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
// Move Store2 upgrade button below the store2 image on the homepage
store2Btn.x = store2.x;
store2Btn.y = store2.y + 160;
store2Btn.visible = false;
game.addChild(store2Btn);
var store2BtnTxt = new Text2('Mağaza 2 Yükselt\n₺' + store2.upgradeCost, {
size: 44,
fill: '#fff'
});
store2BtnTxt.anchor.set(0.5, 0.5);
store2BtnTxt.x = store2.x;
store2BtnTxt.y = store2.y + 180;
store2BtnTxt.visible = false;
game.addChild(store2BtnTxt);
store2Btn.down = function (x, y, obj) {
if (money >= store2.upgradeCost) {
toplamStoreYukseltme += store2.upgradeCost;
store2.upgrade();
store2BtnTxt.setText('Mağaza 2 Yükselt\n₺' + store2.upgradeCost);
}
};
// --- Store 3 Upgrade Button (Mağazalar panelinde) ---
var store3Btn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
// Move Store3 upgrade button below the store3 image on the homepage
store3Btn.x = store3.x;
store3Btn.y = store3.y + 260;
store3Btn.visible = false;
game.addChild(store3Btn);
var store3BtnTxt = new Text2('Mağaza 3 Yükselt\n₺' + store3.upgradeCost, {
size: 44,
fill: '#fff'
});
store3BtnTxt.anchor.set(0.5, 0.5);
store3BtnTxt.x = store3.x;
store3BtnTxt.y = store3.y + 280;
store3BtnTxt.visible = false;
game.addChild(store3BtnTxt);
store3Btn.down = function (x, y, obj) {
if (money >= store3.upgradeCost) {
toplamStoreYukseltme += store3.upgradeCost;
store3.upgrade();
store3BtnTxt.setText('Mağaza 3 Yükselt\n₺' + store3.upgradeCost);
}
};
// --- Store 4 Upgrade Button (Mağazalar panelinde) ---
var store4Btn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
// Move Store4 upgrade button below the store4 image on the homepage
store4Btn.x = store4.x;
store4Btn.y = store4.y + 260;
store4Btn.visible = false;
game.addChild(store4Btn);
var store4BtnTxt = new Text2('Mağaza 4 Yükselt\n₺' + store4.upgradeCost, {
size: 44,
fill: '#fff'
});
store4BtnTxt.anchor.set(0.5, 0.5);
store4BtnTxt.x = store4.x;
store4BtnTxt.y = store4.y + 280;
store4BtnTxt.visible = false;
game.addChild(store4BtnTxt);
store4Btn.down = function (x, y, obj) {
if (money >= store4.upgradeCost) {
toplamStoreYukseltme += store4.upgradeCost;
store4.upgrade();
store4BtnTxt.setText('Mağaza 4 Yükselt\n₺' + store4.upgradeCost);
}
};
// --- Show/hide store upgrade buttons with Mağazalar panel ---
// Show panel on button press
// Kapat butonu logic
magazalarKapatBtn.down = function (x, y, obj) {
magazalarPanel.visible = false;
magazalarPanelTitle.visible = false;
magazalarPanelText.visible = false;
magazalarKapatBtn.visible = false;
magazalarKapatBtnIcon.visible = false;
magazalarKapatBtnTxt.visible = false;
// Hide store upgrade buttons
if (typeof storeBtn !== "undefined") {
storeBtn.visible = false;
}
if (typeof storeBtnTxt !== "undefined") {
storeBtnTxt.visible = false;
}
if (typeof store2Btn !== "undefined") {
store2Btn.visible = false;
}
if (typeof store2BtnTxt !== "undefined") {
store2BtnTxt.visible = false;
}
if (typeof store2PurchaseBtn !== "undefined") {
store2PurchaseBtn.visible = false;
}
if (typeof store2PurchaseBtnTxt !== "undefined") {
store2PurchaseBtnTxt.visible = false;
}
if (typeof store3Btn !== "undefined") {
store3Btn.visible = false;
}
if (typeof store3BtnTxt !== "undefined") {
store3BtnTxt.visible = false;
}
if (typeof store4Btn !== "undefined") {
store4Btn.visible = false;
}
if (typeof store4BtnTxt !== "undefined") {
store4BtnTxt.visible = false;
}
// Restore all homepage buttons/UI
if (typeof store2PurchaseBtn !== "undefined") {
store2PurchaseBtn.visible = !store2Purchased;
}
if (typeof store2PurchaseBtnTxt !== "undefined") {
store2PurchaseBtnTxt.visible = !store2Purchased;
}
if (typeof store3PurchaseBtn !== "undefined") {
store3PurchaseBtn.visible = !store3Purchased;
}
if (typeof store3PurchaseBtnTxt !== "undefined") {
store3PurchaseBtnTxt.visible = !store3Purchased;
}
if (typeof store3PurchaseBtnIcon !== "undefined") {
store3PurchaseBtnIcon.visible = !store3Purchased;
}
if (typeof store4PurchaseBtn !== "undefined") {
store4PurchaseBtn.visible = !store4Purchased;
}
if (typeof store4PurchaseBtnTxt !== "undefined") {
store4PurchaseBtnTxt.visible = !store4Purchased;
}
if (typeof store4PurchaseBtnIcon !== "undefined") {
store4PurchaseBtnIcon.visible = !store4Purchased;
}
// Defensive: ensure other panels do not re-show these buttons after Mağazalar panel is closed
if (typeof magazaBtn !== "undefined") {
magazaBtn.visible = true;
}
if (typeof magazaBtnTxt !== "undefined") {
magazaBtnTxt.visible = true;
}
if (typeof yatirimBtn !== "undefined") {
yatirimBtn.visible = true;
}
if (typeof yatirimBtnTxt !== "undefined") {
yatirimBtnTxt.visible = true;
}
if (typeof bankBtn !== "undefined") {
bankBtn.visible = true;
}
if (typeof bankBtnTxt !== "undefined") {
bankBtnTxt.visible = true;
}
if (typeof soundBtn !== "undefined") {
soundBtn.visible = true;
}
if (typeof soundBtnTxt !== "undefined") {
soundBtnTxt.visible = true;
}
if (typeof newPageBtn !== "undefined") {
newPageBtn.visible = true;
}
if (typeof newPageBtnTxt !== "undefined") {
newPageBtnTxt.visible = true;
}
if (typeof madenlerBtn !== "undefined") {
madenlerBtn.visible = true;
}
if (typeof madenlerBtnTxt !== "undefined") {
madenlerBtnTxt.visible = true;
}
// Removed magazalarBtn and magazalarBtnTxt show logic (button was deleted)
if (typeof languagesBtn !== "undefined") {
languagesBtn.visible = true;
}
if (typeof languagesBtnTxt !== "undefined") {
languagesBtnTxt.visible = true;
}
// Info and How To Play buttons are never shown
if (typeof borcOdeBtn !== "undefined") {
borcOdeBtn.visible = true;
}
if (typeof borcOdeBtnTxt !== "undefined") {
borcOdeBtnTxt.visible = true;
}
if (typeof mevduatBtn !== "undefined") {
mevduatBtn.visible = true;
}
if (typeof mevduatBtnTxt !== "undefined") {
mevduatBtnTxt.visible = true;
}
// Move stores and customers back to their original positions
if (typeof store !== "undefined") {
store.x = 1850;
store.y = 600;
store.visible = true; // Anasayfa'da mağazaları göster
}
if (typeof store2 !== "undefined") {
store2.x = 1850;
store2.y = 950;
store2.visible = true; // Anasayfa'da mağazaları göster
}
if (typeof store3 !== "undefined") {
store3.x = 1850;
store3.y = 1300;
store3.visible = true; // Anasayfa'da mağazaları göster
}
if (typeof store4 !== "undefined") {
store4.x = 1850;
store4.y = 1650;
store4.visible = true; // Anasayfa'da mağazaları göster
}
// Customer logic removed: no customers to reposition on Mağazalar panel close.
};
// --- Production Buttons and Logic for each factory ---
var prodBtns = [];
for (var i = 0; i < factories.length; i++) {
(function (idx) {
var f = factories[idx];
var btn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
btn.x = f.x;
// Add horizontal gap to production buttons to match factory panel gap
btn.x = f.x;
// Move MB, CASE, FAN, HDD, COOLER (indices 5,6,7,8,9) production buttons further down
if (idx >= 5) {
btn.y = f.y + 350 + 80;
} else {
btn.y = f.y + 350;
}
game.addChild(btn);
var txt = new Text2('ÜRET', {
size: 36,
fill: '#fff'
});
txt.anchor.set(0.5, 0.5);
txt.x = btn.x;
txt.y = btn.y;
game.addChild(txt);
btn.factoryIndex = idx;
btn.down = function (x, y, obj) {
// Disable if investment panel is open or Çalışanlar paneli is open
if (yatirimPanel && yatirimPanel.visible || newPagePanel && newPagePanel.visible) {
return;
}
var idx = this.factoryIndex;
// Only allow production if factory is unlocked
if (!factoryUnlocks[idx]) {
// Optionally, flash or shake to indicate locked
tween(factories[idx], {
scaleX: 1.15,
scaleY: 1.15
}, {
duration: 80,
onFinish: function onFinish() {
tween(factories[idx], {
scaleX: 1,
scaleY: 1
}, {
duration: 80
});
}
});
return;
}
var f = factories[idx];
var part = partTypes[idx];
var produced = 0;
var hadMaterial = false;
for (var j = 0; j < f.production; j++) {
// Each part needs: copper:2, silicon:1, iron:1, silver:1, nikel:1, gold:1
// Calculate production cost as 50% of the sale price (which is 30~49, so use 40 as avg, or use 30 + Math.floor(Math.random()*20)/2 for dynamic)
var salePrice = 30 + Math.floor(Math.random() * 20);
var productionCost = Math.floor(salePrice * 0.5);
if (rawMaterials.copper >= 2 && rawMaterials.silicon >= 1 && rawMaterials.iron >= 1 && rawMaterials.silver >= 1 && rawMaterials.nikel >= 1 && rawMaterials.gold >= 1 && money >= productionCost) {
hadMaterial = true;
rawMaterials.copper -= 2;
rawMaterials.silicon -= 1;
rawMaterials.iron -= 1;
rawMaterials.silver -= 1;
rawMaterials.nikel -= 1;
rawMaterials.gold -= 1;
money -= productionCost;
updateMoneyText();
parts[part] += 1;
produced++;
}
}
if (produced > 0) {
updateRawText();
updatePartsText();
// Animate factory
tween(f, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 120,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(f, {
scaleX: 1,
scaleY: 1
}, {
duration: 120
});
}
});
} else if (!hadMaterial) {
// Show "Maden Kalmadı" warning for 1 minute (60 seconds = 3600 frames)
var oldText = txt.getText ? txt.getText() : '';
txt.setText('Maden Kalmadı');
tween(txt, {
tint: 0xff2222
}, {
duration: 120
});
LK.setTimeout(function () {
if (txt && txt.setText) {
txt.setText('ÜRET');
}
tween(txt, {
tint: 0xffffff
}, {
duration: 120
});
}, 3600); // 1 minute (60s * 60fps)
}
};
prodBtns.push(btn);
})(i);
}
// --- Customer/Store Logic ---
// Customer logic removed: customers are no longer used in the game.
// --- Game Update ---
game.update = function () {
// Auto-produce for mines
for (var i = 0; i < mines.length; i++) {
mines[i].update();
// Auto-produce for mine if enabled
if (mineAutoProduce[i]) {
// Çalışan 2'nin seviyesiyle üretim süresini azalt: her seviye %2 daha hızlı
var baseInterval = 30; // 0.5s
var speedBonus = 1 - (worker2Level - 1) * 0.02;
if (speedBonus < 0.1) {
speedBonus = 0.1;
} // min %90 azaltma (maks %900 hız)
var interval = Math.max(2, Math.floor(baseInterval * speedBonus));
if (!mines[i].autoTick) {
mines[i].autoTick = 0;
}
mines[i].autoTick++;
if (mines[i].autoTick >= interval) {
rawMaterials[mines[i].type] += mines[i].production;
updateRawText();
// Animate mine for feedback
tween(mines[i], {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 120,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(this.target, {
scaleX: 1,
scaleY: 1
}, {
duration: 120
});
}.bind({
target: mines[i]
})
});
mines[i].autoTick = 0;
}
}
}
// Auto-produce for factories
for (var i = 0; i < factories.length; i++) {
if (factoryAutoProduce[i] && factoryUnlocks[i]) {
if (!factories[i].autoTick) {
factories[i].autoTick = 0;
}
factories[i].autoTick++;
// Use per-factory production time (speed up with level)
// Çalışan 2'nin seviyesiyle üretim süresi indirimi uygula
var prodTime = factories[i].getProductionTime ? factories[i].getProductionTime() : 30;
// Çalışan 2'nin seviyesiyle fabrika üretim süresi indirimi uygula
var worker2FactoryBonus = 1 - (worker2Level - 1) * 0.02;
if (worker2FactoryBonus < 0.1) {
worker2FactoryBonus = 0.1;
} // min %90 azaltma (maks %900 hız)
prodTime = Math.max(2, Math.floor(prodTime * worker2FactoryBonus));
// Çalışan 2'nin seviyesiyle ek olarak üretim hızını %2 düşür (yani prodTime'ı tekrar %2 azalt)
var worker2ExtraSpeedBonus = 1 - (worker2Level - 1) * 0.02;
if (worker2ExtraSpeedBonus < 0.1) {
worker2ExtraSpeedBonus = 0.1;
}
prodTime = Math.max(2, Math.floor(prodTime * worker2ExtraSpeedBonus));
if (factories[i].autoTick >= prodTime) {
var f = factories[i];
var part = partTypes[i];
var produced = 0;
// Çalışan 2'nin seviyesiyle üretim miktarını artır: her seviye %2 daha fazla üretim
var worker2ProductionBonus = 1 + (worker2Level - 1) * 0.02;
var totalProduction = Math.floor(f.production * worker2ProductionBonus);
if (totalProduction < 1) {
totalProduction = 1;
}
for (var j = 0; j < totalProduction; j++) {
// Each part needs: copper:2, silicon:1, iron:1, silver:1, nikel:1, gold:1
// Calculate production cost as 50% of the sale price (which is 30~49, so use 40 as avg, or use 30 + Math.floor(Math.random()*20)/2 for dynamic)
var salePrice = 30 + Math.floor(Math.random() * 20);
var productionCost = Math.floor(salePrice * 0.5);
if (rawMaterials.copper >= 2 && rawMaterials.silicon >= 1 && rawMaterials.iron >= 1 && rawMaterials.silver >= 1 && rawMaterials.nikel >= 1 && rawMaterials.gold >= 1 && money >= productionCost) {
rawMaterials.copper -= 2;
rawMaterials.silicon -= 1;
rawMaterials.iron -= 1;
rawMaterials.silver -= 1;
rawMaterials.nikel -= 1;
rawMaterials.gold -= 1;
money -= productionCost;
updateMoneyText();
parts[part] += 1;
produced++;
}
}
if (produced > 0) {
updateRawText();
updatePartsText();
// Animate factory
tween(f, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 120,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(this.target, {
scaleX: 1,
scaleY: 1
}, {
duration: 120
});
}.bind({
target: f
})
});
}
factories[i].autoTick = 0;
}
}
}
// Customer logic removed: no customer spawning or processing.
// --- Ava: Mağazalar stokta olan ürünleri otomatik satar ---
// Her mağaza için otomatik satış (her biri kendi hızında)
// Satış, mağaza görünür olmasa da devam etmeli
if (store && typeof store.tryAutoSell === "function") {
store.tryAutoSell();
}
if (store2 && store2Purchased && typeof store2.tryAutoSell === "function") {
store2.tryAutoSell();
}
if (store3 && store3Purchased && typeof store3.tryAutoSell === "function") {
store3.tryAutoSell();
}
if (store4 && store4Purchased && typeof store4.tryAutoSell === "function") {
store4.tryAutoSell();
}
};
// --- Dragging (for fun, not required) ---
var dragNode = null;
game.down = function (x, y, obj) {
// No drag for now
};
game.move = function (x, y, obj) {
// No drag for now
};
game.up = function (x, y, obj) {
// No drag for now
};
// --- Internet Offer Panel ---
// Panel variables
var offerPanel = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 420,
height: 340,
x: 120,
y: 1366 // center of 2732
});
game.addChild(offerPanel);
var offerTitle = new Text2('İNTERNET TEKLİFİ', {
size: 32,
fill: '#fff'
});
// Move to right edge of panel
offerTitle.anchor.set(1, 0);
offerTitle.x = offerPanel.x + offerPanel.width / 2 - 20;
offerTitle.y = offerPanel.y - 140;
game.addChild(offerTitle);
var offerPartTxt = new Text2('', {
size: 28,
fill: '#bff'
});
offerPartTxt.anchor.set(0.5, 0);
offerPartTxt.x = offerPanel.x;
offerPartTxt.y = offerPanel.y - 60;
game.addChild(offerPartTxt);
var offerAmountTxt = new Text2('', {
size: 28,
fill: '#fff'
});
offerAmountTxt.anchor.set(0.5, 0);
offerAmountTxt.x = offerPanel.x;
offerAmountTxt.y = offerPanel.y - 10;
game.addChild(offerAmountTxt);
var offerPriceTxt = new Text2('', {
size: 28,
fill: '#ffb'
});
offerPriceTxt.anchor.set(0.5, 0);
offerPriceTxt.x = offerPanel.x;
offerPriceTxt.y = offerPanel.y + 40;
game.addChild(offerPriceTxt);
var offerBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 220,
height: 70,
x: offerPanel.x,
y: offerPanel.y + 180 // moved 30px lower (was 150), now 180
});
game.addChild(offerBtn);
var offerBtnTxt = new Text2('Satın Al', {
size: 36,
fill: '#fff'
});
offerBtnTxt.anchor.set(0.5, 0.5);
offerBtnTxt.x = offerBtn.x;
offerBtnTxt.y = offerBtn.y;
game.addChild(offerBtnTxt);
// Offer state
var currentOffer = {
part: null,
amount: 0,
price: 0,
active: false // yeni teklif aktif mi
};
// Helper to generate a new offer
var offerTimeLeft = 0;
var offerTimerInterval = null;
var offerTimeTxt = new Text2('', {
size: 32,
fill: '#ffb'
});
offerTimeTxt.anchor.set(0.5, 0);
offerTimeTxt.x = offerPanel.x;
offerTimeTxt.y = offerPanel.y + 90;
game.addChild(offerTimeTxt);
function updateOfferTimeTxt() {
if (offerTimeLeft > 0) {
var min = Math.floor(offerTimeLeft / 60);
var sec = offerTimeLeft % 60;
var timeStr = min > 0 ? min + " dk " + (sec < 10 ? "0" : "") + sec + " sn" : sec + " sn";
offerTimeTxt.setText("Süre: " + timeStr);
} else {
offerTimeTxt.setText('');
}
}
function generateInternetOffer() {
// Pick a random part type
var idx = Math.floor(Math.random() * partTypes.length);
var part = partTypes[idx];
// Random amount: 2-8
var amount = 2 + Math.floor(Math.random() * 7);
// Random price per item: 18-32
var pricePer = 18 + Math.floor(Math.random() * 15);
var totalPrice = pricePer * amount;
currentOffer.part = part;
currentOffer.amount = amount;
currentOffer.price = totalPrice;
currentOffer.active = true;
// Update UI
offerPartTxt.setText(idx === 0 ? "MOUSE" : idx === 1 ? "KLAVYE" : idx === 6 ? "CPU" : idx === 7 ? "GPU" : idx === 8 ? "MONITOR" : idx === 9 ? "KASA" : part.toUpperCase());
offerAmountTxt.setText("Adet: " + amount);
offerPriceTxt.setText("Toplam: ₺" + totalPrice);
offerBtn.visible = true;
offerBtnTxt.visible = true;
// Rastgele 1-2 dakika (60-120 saniye) arası süre belirle
offerTimeLeft = (60 + Math.floor(Math.random() * 61)) * 60;
updateOfferTimeTxt();
// Start timer for next offer
if (offerTimerInterval) {
LK.clearInterval(offerTimerInterval);
offerTimerInterval = null;
}
offerTimerInterval = LK.setInterval(function () {
if (!currentOffer.active) {
LK.clearInterval(offerTimerInterval);
offerTimerInterval = null;
return;
}
offerTimeLeft--;
updateOfferTimeTxt();
if (offerTimeLeft <= 0) {
// Süre doldu, yeni teklif gelsin
currentOffer.active = false;
offerBtn.visible = false;
offerBtnTxt.visible = false;
offerPartTxt.setText("Süre doldu!");
offerAmountTxt.setText("");
offerPriceTxt.setText("");
updateOfferTimeTxt();
LK.clearInterval(offerTimerInterval);
offerTimerInterval = null;
LK.setTimeout(function () {
generateInternetOffer();
}, 60); // 1 frame sonra yeni teklif gelsin
}
}, 60); // 1 saniye
}
generateInternetOffer();
// Button logic
offerBtn.down = function (x, y, obj) {
if (!currentOffer.active) {
return;
}
if (money >= currentOffer.price) {
money -= currentOffer.price;
toplamInternetTeklifHarcamasi += currentOffer.price;
parts[currentOffer.part] += currentOffer.amount;
updateMoneyText();
updatePartsText();
// Animate panel for feedback
tween(offerPanel, {
scaleX: 1.08,
scaleY: 1.08
}, {
duration: 120,
onFinish: function onFinish() {
tween(offerPanel, {
scaleX: 1,
scaleY: 1
}, {
duration: 120
});
}
});
// Teklif tamamlandı, yeni teklif gelene kadar butonu kapat
currentOffer.active = false;
offerBtn.visible = false;
offerBtnTxt.visible = false;
offerPartTxt.setText("Teklif tamamlandı!");
offerAmountTxt.setText("");
offerPriceTxt.setText("");
offerTimeLeft = 1200;
updateOfferTimeTxt();
if (offerTimerInterval) {
LK.clearInterval(offerTimerInterval);
offerTimerInterval = null;
}
// Yeni teklif rastgele 1-2 dakika sonra gelsin
var nextOfferDelay = (60 + Math.floor(Math.random() * 61)) * 60;
LK.setTimeout(function () {
generateInternetOffer();
}, nextOfferDelay);
} else {
// Not enough money, flash button red
tween(offerBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(offerBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
}
};
// --- Toplu Satış Paneli ---
var sellPanel = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 420,
height: 340,
x: 120,
y: 1366 + 400 // offerPanel.y + 400 px altına
});
game.addChild(sellPanel);
var sellTitle = new Text2('TOPLU SATIŞ TEKLİFİ', {
size: 32,
fill: '#fff'
});
// Move to right edge of panel
sellTitle.anchor.set(1, 0);
sellTitle.x = sellPanel.x + sellPanel.width / 2 - 20;
sellTitle.y = sellPanel.y - 140;
game.addChild(sellTitle);
var sellPartTxt = new Text2('', {
size: 28,
fill: '#bff'
});
sellPartTxt.anchor.set(0.5, 0);
sellPartTxt.x = sellPanel.x;
sellPartTxt.y = sellPanel.y - 60;
game.addChild(sellPartTxt);
var sellAmountTxt = new Text2('', {
size: 28,
fill: '#fff'
});
sellAmountTxt.anchor.set(0.5, 0);
sellAmountTxt.x = sellPanel.x;
sellAmountTxt.y = sellPanel.y - 10;
game.addChild(sellAmountTxt);
var sellPriceTxt = new Text2('', {
size: 28,
fill: '#ffb'
});
sellPriceTxt.anchor.set(0.5, 0);
sellPriceTxt.x = sellPanel.x;
sellPriceTxt.y = sellPanel.y + 40;
game.addChild(sellPriceTxt);
var sellBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 220,
height: 70,
x: sellPanel.x,
y: sellPanel.y + 180 // moved 30px lower (was 150), now 180
});
game.addChild(sellBtn);
var sellBtnTxt = new Text2('Sat', {
size: 36,
fill: '#fff'
});
sellBtnTxt.anchor.set(0.5, 0.5);
sellBtnTxt.x = sellBtn.x;
sellBtnTxt.y = sellBtn.y;
game.addChild(sellBtnTxt);
// Satış teklifi state
var currentSellOffer = {
part: null,
amount: 0,
price: 0,
active: false
};
// Helper to generate a new sell offer
var sellOfferTimeLeft = 0;
var sellOfferTimerInterval = null;
var sellOfferTimeTxt = new Text2('', {
size: 32,
fill: '#ffb'
});
sellOfferTimeTxt.anchor.set(0.5, 0);
sellOfferTimeTxt.x = sellPanel.x;
sellOfferTimeTxt.y = sellPanel.y + 90;
game.addChild(sellOfferTimeTxt);
function updateSellOfferTimeTxt() {
if (sellOfferTimeLeft > 0) {
var min = Math.floor(sellOfferTimeLeft / 60);
var sec = sellOfferTimeLeft % 60;
var timeStr = min > 0 ? min + " dk " + (sec < 10 ? "0" : "") + sec + " sn" : sec + " sn";
sellOfferTimeTxt.setText("Süre: " + timeStr);
} else {
sellOfferTimeTxt.setText('');
}
}
// Helper to generate a new sell offer
function generateSellOffer() {
// Sadece stoğunda en az 2 olanlardan rastgele seç
var available = [];
for (var i = 0; i < partTypes.length; i++) {
if (parts[partTypes[i]] >= 2) {
available.push(partTypes[i]);
}
}
// Eğer hiç stoğu olan ürün yoksa, teklif oluşturma
if (available.length === 0) {
currentSellOffer.part = null;
currentSellOffer.amount = 0;
currentSellOffer.price = 0;
currentSellOffer.active = false;
sellPartTxt.setText("Stokta ürün yok");
sellAmountTxt.setText("");
sellPriceTxt.setText("");
sellBtn.visible = false;
sellBtnTxt.visible = false;
return;
}
var idx = Math.floor(Math.random() * available.length);
var part = available[idx];
// Satış miktarı: mevcut stoğun %50-%75 aralığında, en az 2, en fazla 8 ve stoğun kendisinden fazla olamaz
var stock = parts[part];
var minAmount = Math.max(2, Math.floor(stock * 0.5));
var maxAmount = Math.max(minAmount, Math.min(Math.floor(stock * 0.75), 8));
var amount = minAmount;
if (maxAmount > minAmount) {
amount = minAmount + Math.floor(Math.random() * (maxAmount - minAmount + 1));
}
// Satış fiyatı: 28-45 arası birim fiyat
var pricePer = 28 + Math.floor(Math.random() * 18);
var totalPrice = pricePer * amount;
currentSellOffer.part = part;
currentSellOffer.amount = amount;
currentSellOffer.price = totalPrice;
currentSellOffer.active = true;
sellPartTxt.setText(idx === 0 ? "MOUSE" : idx === 1 ? "KLAVYE" : idx === 6 ? "CPU" : idx === 7 ? "GPU" : idx === 8 ? "MONITOR" : idx === 9 ? "KASA" : part.toUpperCase());
sellAmountTxt.setText("Adet: " + amount);
sellPriceTxt.setText("Toplam: ₺" + totalPrice);
sellBtn.visible = true;
sellBtnTxt.visible = true;
// Süreyi rastgele 1-2 dakika (60-120 saniye) arası belirle
sellOfferTimeLeft = (60 + Math.floor(Math.random() * 61)) * 60;
updateSellOfferTimeTxt();
// Timer varsa temizle
if (sellOfferTimerInterval) {
LK.clearInterval(sellOfferTimerInterval);
sellOfferTimerInterval = null;
}
sellOfferTimerInterval = LK.setInterval(function () {
if (!currentSellOffer.active) {
LK.clearInterval(sellOfferTimerInterval);
sellOfferTimerInterval = null;
return;
}
sellOfferTimeLeft--;
updateSellOfferTimeTxt();
if (sellOfferTimeLeft <= 0) {
// Süre doldu, yeni teklif gelsin
currentSellOffer.active = false;
sellBtn.visible = false;
sellBtnTxt.visible = false;
sellPartTxt.setText("Süre doldu!");
sellAmountTxt.setText("");
sellPriceTxt.setText("");
updateSellOfferTimeTxt();
LK.clearInterval(sellOfferTimerInterval);
sellOfferTimerInterval = null;
LK.setTimeout(function () {
generateSellOffer();
}, 60); // 1 frame sonra yeni teklif gelsin
}
}, 60); // 1 saniye
}
generateSellOffer();
// Satış butonu logic
sellBtn.down = function (x, y, obj) {
// If not active or not enough stock, do nothing (button is visually disabled)
if (!currentSellOffer.active || parts[currentSellOffer.part] < currentSellOffer.amount) {
// Optionally, flash button red and show warning if user tries to press when not enough stock
tween(sellBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(sellBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
// 'Stok yetersiz' uyarısı göster
sellBtnTxt.setText('Stok yetersiz');
LK.setTimeout(function () {
// Eğer buton hala görünürse eski haline döndür
if (sellBtn.visible) {
sellBtnTxt.setText('Sat');
}
// Teklifi yenileme, teklif tamamlanmasın!
}, 300); // 5 saniye = 300 frame
return;
}
// Satış işlemi
parts[currentSellOffer.part] -= currentSellOffer.amount;
money += currentSellOffer.price;
toplamTopluSatisGeliri += currentSellOffer.price;
updateMoneyText();
updatePartsText();
// Panel animasyonu
tween(sellPanel, {
scaleX: 1.08,
scaleY: 1.08
}, {
duration: 120,
onFinish: function onFinish() {
tween(sellPanel, {
scaleX: 1,
scaleY: 1
}, {
duration: 120
});
}
});
// Teklif tamamlandı, yeni teklif gelene kadar butonu kapat
currentSellOffer.active = false;
sellBtn.visible = false;
sellBtnTxt.visible = false;
sellPartTxt.setText("Teklif tamamlandı!");
sellAmountTxt.setText("");
sellPriceTxt.setText("");
// Yeni teklif rastgele 1-2 dakika sonra gelsin
var nextSellOfferDelay = (60 + Math.floor(Math.random() * 61)) * 60;
LK.setTimeout(function () {
generateSellOffer();
}, nextSellOfferDelay);
};
// Satış teklifi her rastgele 1-5 dakikada bir yenilensin (eğer aktif değilse)
function scheduleNextSellOfferInterval() {
var interval = (60 + Math.floor(Math.random() * 61)) * 60;
LK.setTimeout(function () {
if (!currentSellOffer.active) {
generateSellOffer();
}
scheduleNextSellOfferInterval();
}, interval);
}
scheduleNextSellOfferInterval();
// Image file for CPU product (part_cpu) is now registered with id '6842c1a1c660c325a06c2abc' /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Factory class: base for all part factories
var BaseFactory = Container.expand(function () {
var self = Container.call(this);
self.level = 1;
self.production = 1; // per click
self.upgradeCost = 100;
self.partType = null;
// Production time in frames (default 30, halves every 5 levels, min 5)
self.getProductionTime = function () {
// Each 5 levels halves the time, min 5 frames
var base = 30;
var speedup = Math.floor((self.level - 1) / 5);
var prodTime = Math.floor(base / Math.pow(2, speedup));
if (prodTime < 5) {
prodTime = 5;
}
return prodTime;
};
// Use unique factory image for each partType if available
var factoryImageId = 'factory';
if (self.partType) {
if (LK.hasAsset && LK.hasAsset('factory_' + self.partType)) {
factoryImageId = 'factory_' + self.partType;
} else if (LK.getAsset && LK.getAsset('factory_' + self.partType, {
anchorX: 0.5,
anchorY: 0.5
})) {
factoryImageId = 'factory_' + self.partType;
}
}
self.attachAsset(factoryImageId, {
anchorX: 0.5,
anchorY: 0.5
});
// Part icon
var partIcon = null;
if (self.partType) {
partIcon = self.attachAsset('part_' + self.partType, {
anchorX: 0.5,
anchorY: 0.5,
y: -60,
scaleX: 0.7,
scaleY: 0.7
});
}
// Level text
var levelTxt = new Text2('Lv.' + self.level, {
size: 40,
fill: '#fff'
});
levelTxt.anchor.set(0.5, 0);
levelTxt.y = 90;
self.addChild(levelTxt);
self.upgrade = function () {
if (money >= self.upgradeCost) {
money -= self.upgradeCost;
self.level += 1;
self.production += 1;
self.upgradeCost = Math.floor(self.upgradeCost * 3.5);
levelTxt.setText('Lv.' + self.level);
updateMoneyText();
// Reset autoTick so production interval is not skipped after upgrade
self.autoTick = 0;
// --- Reduce production time by 10% after each upgrade, if customProductionTime is present ---
if (typeof self.customProductionTime === "number") {
self.customProductionTime = Math.max(Math.floor(self.customProductionTime * 0.9), 60); // min 1s (60 frames)
}
// Update production time text if present
if (self._prodTimeTxt) {
var prodTime = self.getProductionTime ? self.getProductionTime() : 30;
var prodTimeSec = (prodTime / 60).toFixed(2);
self._prodTimeTxt.setText("Üretim: " + prodTimeSec + " sn");
}
}
};
self.setPartType = function (type) {
self.partType = type;
if (partIcon) {
partIcon.destroy();
}
partIcon = self.attachAsset('part_' + type, {
anchorX: 0.5,
anchorY: 0.5,
y: -60,
scaleX: 0.7,
scaleY: 0.7
});
};
return self;
});
// Create a factory class for each part type
// Mine class: produces raw materials over time
var Mine = Container.expand(function () {
var self = Container.call(this);
self.level = 1;
self.type = 'copper'; // 'copper', 'silicon', 'iron'
self.production = 1; // per tick
self.timer = 0;
self.upgradeCost = 50;
self.attachAsset('mine', {
anchorX: 0.5,
anchorY: 0.5
});
// Ore icon
var oreIcon = self.attachAsset('ore_' + self.type, {
anchorX: 0.5,
anchorY: 0.5,
y: 60,
scaleX: 0.7,
scaleY: 0.7
});
// Level text
var levelTxt = new Text2('Lv.' + self.level, {
size: 40,
fill: '#fff'
});
levelTxt.anchor.set(0.5, 0);
levelTxt.y = 90;
self.addChild(levelTxt);
self.setType = function (type) {
self.type = type;
oreIcon.destroy();
var newOre = self.attachAsset('ore_' + type, {
anchorX: 0.5,
anchorY: 0.5,
y: 60,
scaleX: 0.7,
scaleY: 0.7
});
};
self.upgrade = function () {
if (money >= self.upgradeCost) {
money -= self.upgradeCost;
self.level += 1;
self.production += 1;
self.upgradeCost = Math.floor(self.upgradeCost * 2.975);
levelTxt.setText('Lv.' + self.level);
updateMoneyText();
}
};
self.update = function () {
self.timer++;
// No automatic production
};
return self;
});
// Store class: sells computer parts to customers
var Store = Container.expand(function () {
var self = Container.call(this);
self.level = 1;
self.sellSpeed = 1; // customers per 2s
self.upgradeCost = 120;
self.attachAsset('store', {
anchorX: 0.5,
anchorY: 0.5
});
// Level text
var levelTxt = new Text2('Lv.' + self.level, {
size: 48,
//{1Y} // 40'tan 48'e büyütüldü
fill: '#fff'
});
levelTxt.anchor.set(0.5, 0);
levelTxt.y = 90;
self.addChild(levelTxt);
self.upgrade = function () {
if (money >= self.upgradeCost) {
money -= self.upgradeCost;
self.level += 1;
self.sellSpeed += 1;
self.upgradeCost = Math.floor(self.upgradeCost * 3.85);
levelTxt.setText('Lv.' + self.level);
updateMoneyText();
}
};
// Add auto-sell tick for automatic sales
self.autoSellTick = 0;
self.autoSellInterval = function () {
// Satış aralığı: 120 frame / sellSpeed (daha yüksek seviye daha hızlı)
return Math.max(30, Math.floor(120 / self.sellSpeed));
};
self.tryAutoSell = function () {
self.autoSellTick++;
if (self.autoSellTick >= self.autoSellInterval()) {
// Satılacak ürün bul (stokta olanlardan rastgele seç)
var availableParts = [];
for (var i = 0; i < partTypes.length; i++) {
if (parts[partTypes[i]] > 0) {
availableParts.push(i);
}
}
if (availableParts.length > 0) {
var randIdx = availableParts[Math.floor(Math.random() * availableParts.length)];
var salePrice = 30 + Math.floor(Math.random() * 20);
parts[partTypes[randIdx]] -= 1;
money += salePrice;
if (typeof updateMoneyText === "function") {
updateMoneyText();
}
if (typeof updatePartsText === "function") {
updatePartsText();
}
// Satış animasyonu (mağaza hafif büyüsün)
tween(self, {
scaleX: 1.08,
scaleY: 1.08
}, {
duration: 80,
onFinish: function onFinish() {
tween(self, {
scaleX: 0.82,
scaleY: 0.82
}, {
duration: 80
});
}
});
// --- Ava: Show sold product image above store for 5 seconds ---
// Panel açıkken satılan ürün resmi gösterilmesin
if (!(typeof magazaPanel !== "undefined" && magazaPanel.visible) && !(typeof yatirimPanel !== "undefined" && yatirimPanel.visible) && !(typeof magazalarPanel !== "undefined" && magazalarPanel.visible) && !(typeof madenlerPanel !== "undefined" && madenlerPanel.visible) && !(typeof newPagePanel !== "undefined" && newPagePanel.visible) && !(typeof mevduatPopupPanel !== "undefined" && mevduatPopupPanel.visible) && !(typeof languagesPanel !== "undefined" && languagesPanel.visible) && !(typeof infoPanel !== "undefined" && infoPanel.visible)) {
if (typeof self.soldImage !== "undefined" && self.soldImage) {
self.soldImage.destroy();
self.soldImage = undefined;
}
var soldImgId = 'part_' + partTypes[randIdx];
var soldImg = LK.getAsset(soldImgId, {
anchorX: 0.5,
anchorY: 1,
x: self.x,
y: self.y - 120,
scaleX: 0.6,
// 1.2 * 0.5 = 0.6, %50 oranında küçültüldü
scaleY: 0.6
});
soldImg.visible = true;
if (typeof game !== "undefined" && game.addChild) {
game.addChild(soldImg);
}
self.soldImage = soldImg;
if (typeof game !== "undefined" && game.setChildIndex) {
game.setChildIndex(soldImg, game.children.length - 1);
}
LK.setTimeout(function () {
if (soldImg && soldImg.destroy) {
soldImg.destroy();
}
if (self) {
self.soldImage = undefined;
}
}, 300); // 5 seconds = 300 frames at 60fps
}
}
self.autoSellTick = 0;
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x181818
});
/****
* Game Code
****/
// Defensive: Only use offerPanel's width/height/x/y if offerPanel is defined and has those properties
// --- Mevduat (Deposit) Panel: Internet Teklif panelinin üstüne hizalanacak şekilde ekle ---
// Panel içeriğine göre genişlik/uzunluk ayarla ve ortala
var mevduatPanelTitleText = 'Mevduat';
var mevduatPanelFaizText = '2 dakikada %10 faiz';
var mevduatPanelTitleObj = new Text2(mevduatPanelTitleText, {
size: 32,
fill: '#fff'
});
var mevduatPanelFaizObj = new Text2(mevduatPanelFaizText, {
size: 28,
fill: '#bff'
});
var mevduatPanelContentWidth = Math.max(mevduatPanelTitleObj.width, mevduatPanelFaizObj.width, 340) + 80;
var mevduatPanelContentHeight = 40 + mevduatPanelTitleObj.height + 10 + mevduatPanelFaizObj.height + 10 + 40 + 60 + 80;
var mevduatPanelWidth = mevduatPanelContentWidth;
var mevduatPanelHeight = mevduatPanelContentHeight;
var mevduatPanelX = typeof offerPanel !== "undefined" && offerPanel && typeof offerPanel.x === "number" ? offerPanel.x : 120;
var mevduatPanelY = typeof offerPanel !== "undefined" && offerPanel && typeof offerPanel.y === "number" && typeof offerPanel.height === "number" ? offerPanel.y - offerPanel.height / 2 - mevduatPanelHeight / 2 - 40 : 1366 - 340 / 2 - mevduatPanelHeight / 2 - 40;
var mevduatPanel = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: mevduatPanelWidth,
height: mevduatPanelHeight,
x: mevduatPanelX,
y: mevduatPanelY
});
game.addChild(mevduatPanel);
// Panel başlığı
var mevduatPanelTitle = new Text2(mevduatPanelTitleText, {
size: 32,
fill: '#fff'
});
mevduatPanelTitle.anchor.set(0.5, 0);
mevduatPanelTitle.x = mevduatPanel.x + 32;
mevduatPanelTitle.y = mevduatPanel.y - mevduatPanel.height / 2 + 20;
game.addChild(mevduatPanelTitle);
// Faiz ibaresi
var mevduatPanelFaiz = new Text2(mevduatPanelFaizText, {
size: 28,
fill: '#bff'
});
mevduatPanelFaiz.anchor.set(0.5, 0);
mevduatPanelFaiz.x = mevduatPanel.x + 32;
mevduatPanelFaiz.y = mevduatPanelTitle.y + mevduatPanelTitle.height + 10;
game.addChild(mevduatPanelFaiz);
// Mevduat tutarı
var mevduatTutar = typeof mevduatTutar !== "undefined" ? mevduatTutar : 0;
var mevduatTxt = new Text2('Mevduat: ₺' + mevduatTutar, {
size: 28,
fill: '#ffb'
});
mevduatTxt.anchor.set(0.5, 0.5);
mevduatTxt.x = mevduatPanel.x + 32;
mevduatTxt.y = mevduatPanelFaiz.y + mevduatPanelFaiz.height + 30;
game.addChild(mevduatTxt);
function updateMevduatTxt() {
mevduatTxt.setText('Mevduat: ₺' + Math.floor(mevduatTutar * 100) / 100);
}
// Mevduat yatır ve çek butonları
var mevduatYatirBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 120,
height: 60,
x: mevduatPanel.x - 80 + 32,
y: mevduatTxt.y + 60
});
game.addChild(mevduatYatirBtn);
var mevduatYatirBtnTxt = new Text2('Yatır', {
size: 28,
fill: '#fff'
});
mevduatYatirBtnTxt.anchor.set(0.5, 0.5);
mevduatYatirBtnTxt.x = mevduatYatirBtn.x;
mevduatYatirBtnTxt.y = mevduatYatirBtn.y;
game.addChild(mevduatYatirBtnTxt);
var mevduatCekBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 120,
height: 60,
x: mevduatPanel.x + 80 + 32,
y: mevduatTxt.y + 60
});
game.addChild(mevduatCekBtn);
var mevduatCekBtnTxt = new Text2('Çek', {
size: 28,
fill: '#fff'
});
mevduatCekBtnTxt.anchor.set(0.5, 0.5);
mevduatCekBtnTxt.x = mevduatCekBtn.x;
mevduatCekBtnTxt.y = mevduatCekBtn.y;
game.addChild(mevduatCekBtnTxt);
// Mevduat yatırma: 1000 TL ve katları
mevduatYatirBtn.down = function (x, y, obj) {
if (money >= 1000) {
money -= 1000;
mevduatTutar += 1000;
updateMoneyText && updateMoneyText();
updateMevduatTxt && updateMevduatTxt();
tween(mevduatYatirBtn, {
scaleX: 1.12,
scaleY: 1.12
}, {
duration: 80,
onFinish: function onFinish() {
tween(mevduatYatirBtn, {
scaleX: 1,
scaleY: 1
}, {
duration: 80
});
}
});
} else {
tween(mevduatYatirBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(mevduatYatirBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
}
};
// Mevduat çekme: 1000 TL ve katları
mevduatCekBtn.down = function (x, y, obj) {
if (mevduatTutar >= 1000) {
mevduatTutar -= 1000;
money += 1000;
updateMoneyText && updateMoneyText();
updateMevduatTxt && updateMevduatTxt();
tween(mevduatCekBtn, {
scaleX: 1.12,
scaleY: 1.12
}, {
duration: 80,
onFinish: function onFinish() {
tween(mevduatCekBtn, {
scaleX: 1,
scaleY: 1
}, {
duration: 80
});
}
});
} else {
tween(mevduatCekBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(mevduatCekBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
}
};
// Mevduat faizi: 7200 saniyede %10 faiz (her 7200 saniyede bir %10 artış)
LK.setInterval(function () {
// 7200 saniye = 2 saat = 432000 frame (60fps)
// Her 7200 saniyede bir %10 faiz ekle
if (mevduatTutar > 0) {
var faizOran = 0.10;
var faizKazanc = mevduatTutar * faizOran;
if (typeof mevduatFaizKalan === "undefined") {
window.mevduatFaizKalan = 0;
}
window.mevduatFaizKalan += faizKazanc;
if (window.mevduatFaizKalan >= 0.01) {
var eklenecek = Math.floor(window.mevduatFaizKalan * 100) / 100;
mevduatTutar += eklenecek;
window.mevduatFaizKalan -= eklenecek;
updateMevduatTxt && updateMevduatTxt();
}
}
}, 432000); // 7200 saniye (60fps * 7200s = 432000)
// mor
// turuncu
// yeşil
// mavi
// kırmızımsı
// Her çalışana farklı renkli box tanımla
// Create a factory class for each part type
// Button
// Customer
// Factory, Store, Mine icons
// Raw materials (3 types)
// Computer parts (10 types)
// Unique mine images for each ore type
// Example: Use existing factory image for mouse
// Example: Use GPU part image as factory image
// Example: Use RAM part image as factory image
// Example: Use SSD part image as factory image
// Example: Use PSU part image as factory image
// Example: Use MB part image as factory image
// Example: Use CASE part image as factory image
// Example: Use FAN part image as factory image
// Example: Use HDD part image as factory image
// Example: Use COOLER part image as factory image
function _typeof(o) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
return typeof o;
} : function (o) {
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
}, _typeof(o);
}
function _defineProperty(e, r, t) {
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
value: t,
enumerable: !0,
configurable: !0,
writable: !0
}) : e[r] = t, e;
}
function _toPropertyKey(t) {
var i = _toPrimitive(t, "string");
return "symbol" == _typeof(i) ? i : i + "";
}
function _toPrimitive(t, r) {
if ("object" != _typeof(t) || !t) {
return t;
}
var e = t[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t, r || "default");
if ("object" != _typeof(i)) {
return i;
}
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return ("string" === r ? String : Number)(t);
}
var partTypes = ['mouse', 'klavye', 'ram', 'ssd', 'psu', 'mb', 'cpu', 'gpu', 'monitor', 'case'];
var oreTypes = ['copper', 'silicon', 'iron', 'silver', 'nikel', 'gold'];
var FactoryClasses = {};
var partProductionTimes = [];
for (var i = 0; i < partTypes.length; i++) {
partProductionTimes[i] = (i + 1) * 2 * 60; // 2,4,6,...,20 saniye (frame cinsinden)
}
for (var i = 0; i < partTypes.length; i++) {
(function (type, idx) {
FactoryClasses[type] = Container.expand(function () {
var self = BaseFactory.call(this);
self.setPartType(type);
self.customProductionTime = partProductionTimes[idx];
self.getProductionTime = function () {
// Use the customProductionTime, which is reduced by 10% on each upgrade
var prodTime = self.customProductionTime;
// Each 5 levels halves the time, min 1s (60 frames)
var speedup = Math.floor((self.level - 1) / 5);
prodTime = Math.floor(prodTime / Math.pow(2, speedup));
if (prodTime < 60) {
prodTime = 60;
}
return prodTime;
};
return self;
});
})(partTypes[i], i);
}
// Inventory
var rawMaterials = {
copper: 10,
silicon: 10,
iron: 10,
silver: 10,
nikel: 10,
gold: 10
};
var parts = {};
for (var i = 0; i < partTypes.length; i++) {
parts[partTypes[i]] = 0;
}
// Money
var money = 5000;
// UI Texts
var moneyTxt = new Text2('₺' + money, {
size: 50,
fill: '#fff'
});
moneyTxt.anchor.set(0.5, 0);
moneyTxt.y = 10;
LK.gui.top.addChild(moneyTxt);
// --- Mağaza Button ---
// Mağaza butonunu Patron butonundan önce tanımla ki, Patron butonu konumunu doğru alsın
var magazaBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 180,
height: 70
});
magazaBtn.x = moneyTxt.x - 220;
magazaBtn.y = 40;
LK.gui.top.addChild(magazaBtn);
var magazaBtnTxt = new Text2('Mağaza', {
size: 36,
fill: '#fff'
});
magazaBtnTxt.anchor.set(0.5, 0.5);
magazaBtnTxt.x = magazaBtn.x;
magazaBtnTxt.y = magazaBtn.y;
LK.gui.top.addChild(magazaBtnTxt);
// --- PATRON Button and Panel ---
// Place PATRON button below Mağaza button (with 20px gap)
// Defensive: Ensure magazaBtn is defined before using its x/y, otherwise use fallback values
var patronBtnX = typeof magazaBtn !== "undefined" && typeof magazaBtn.x === "number" ? magazaBtn.x : 120;
var patronBtnY = typeof magazaBtn !== "undefined" && typeof magazaBtn.y === "number" && typeof magazaBtn.height === "number" ? magazaBtn.y + magazaBtn.height / 2 + 20 + 70 / 2 : 120 + 70 + 20 + 70 / 2;
var patronBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 180,
height: 70,
x: patronBtnX,
y: patronBtnY
});
LK.gui.top.addChild(patronBtn);
var patronBtnTxt = new Text2('PATRON', {
size: 36,
fill: '#fff'
});
patronBtnTxt.anchor.set(0.5, 0.5);
patronBtnTxt.x = patronBtn.x;
patronBtnTxt.y = patronBtn.y;
LK.gui.top.addChild(patronBtnTxt);
// Patron panelini Madenler paneli ile aynı boyut, arkaplan ve kapat butonu düzenine getir
// Madenler paneli ile aynı panel boyutları ve konumlandırma
var patronPanelWidth = Math.floor(2048 * 0.9);
var patronPanelHeight = Math.floor(2732 * 0.9);
var patronPanelX = Math.floor((2048 - patronPanelWidth) / 2);
var patronPanelY = Math.floor((2732 - patronPanelHeight) / 2);
var patronPanel = LK.getAsset('button', {
anchorX: 0,
anchorY: 0,
width: patronPanelWidth,
height: patronPanelHeight,
x: patronPanelX,
y: patronPanelY
});
patronPanel.visible = false;
game.addChild(patronPanel);
// Panel başlığı üstte ortalı, madenlerPanelTitle ile aynı font ve konumda
var patronPanelTitle = new Text2('PATRON', {
size: 44,
fill: '#fff'
});
patronPanelTitle.anchor.set(0.5, 0);
patronPanelTitle.x = 2048 / 2;
patronPanelTitle.y = patronPanelY + 40;
patronPanelTitle.visible = false;
game.addChild(patronPanelTitle);
// Panel merkez X'i güncelle
var patronPanelCenterX = 2048 / 2;
// --- Patron Panel: Toplu Sipariş Sistemi (Kurumsal Müşteri) ---
// 20 farklı elektronik şirket ismi
var patronSirketler = ["TeknoMarket", "DijitalA.Ş.", "MegaElektronik", "BilişimX", "Elektronix", "TeknolojiPark", "BilgiNet", "SmartTech", "Elektronika", "DijitalDepo", "TeknoPlus", "ElektronikEv", "BilişimDünyası", "TeknoStar", "DijitalOfis", "ElektronikAda", "TeknoZone", "BilişimExpress", "ElektronikMarket", "DijitalTek"];
// Sipariş state
var patronSiparis = {
sirket: null,
urunler: [],
// [{part, adet}]
toplamAdet: 0,
bonus: 0,
aktif: false,
tamamlandi: false
};
// Panelde gösterilecek sipariş metni
var patronSiparisTxt = new Text2('', {
size: 45,
fill: '#fff',
lineHeight: 60,
wordWrap: true,
wordWrapWidth: patronPanelWidth - 120 // Panel kenarlarından daha fazla boşluk bırak
});
patronSiparisTxt.anchor.set(0.5, 0);
patronSiparisTxt.x = patronPanelCenterX;
patronSiparisTxt.y = patronPanelTitle.y + patronPanelTitle.height + 36;
patronSiparisTxt.visible = false;
game.addChild(patronSiparisTxt);
// Bilgilendirici yazı (panelin altına, satır aralığı ve hizası iyileştirildi)
var patronInfoTxt = new Text2("Kurumsal müşterilerden toplu siparişler alırsınız.\n" + "Siparişi tamamladığınızda %2-%10 arası ek kazanç elde edersiniz.\n" + "Sipariş tamamlanmadan başka teklif gelmez.\n" + "Redderseniz %5 ceza ödersiniz.\n" + "Sipariş tamamlanmadan kazanç verilmez.", {
size: 45,
fill: '#bff',
lineHeight: 60,
wordWrap: true,
wordWrapWidth: patronPanelWidth - 120 // Panel kenarlarından daha fazla boşluk bırak
});
patronInfoTxt.anchor.set(0.5, 0);
patronInfoTxt.x = patronPanelCenterX;
// Bilgi yazısı ile butonlar arasında en fazla 5 satır boşluk olacak şekilde hizala
// 5 satır * 60px = 300px boşluk bırakıyoruz
patronInfoTxt.y = patronPanelY + patronPanelHeight - 160 - 300 - 90 - 60 - 3 * 60; // 3 satır yukarı (3*60px)
patronInfoTxt.visible = false;
game.addChild(patronInfoTxt);
// Siparişi tamamla butonu
var patronSiparisTamamlaBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 260,
height: 90,
x: patronPanelCenterX - 180,
// 2 satır yukarı: 2 * 60px = 120px
y: patronPanelY + patronPanelHeight - 160 - 90 - 120,
color: 0x83de44,
borderColor: 0x222222,
borderWidth: 6
});
patronSiparisTamamlaBtn.visible = false;
game.addChild(patronSiparisTamamlaBtn);
var patronSiparisTamamlaBtnTxt = new Text2('Siparişi Tamamla', {
size: 45,
fill: '#fff'
});
patronSiparisTamamlaBtnTxt.anchor.set(0.5, 0.5);
patronSiparisTamamlaBtnTxt.x = patronSiparisTamamlaBtn.x;
// 2 satır yukarı: 2 * 60px = 120px
patronSiparisTamamlaBtnTxt.y = patronSiparisTamamlaBtn.y;
patronSiparisTamamlaBtnTxt.visible = false;
game.addChild(patronSiparisTamamlaBtnTxt);
// --- Tamamlanınca Toplam Kazanç Yazısı ---
var patronSiparisKazancTxt = new Text2('', {
size: 45,
fill: '#ffb',
lineHeight: 60,
wordWrap: true,
wordWrapWidth: patronPanelWidth - 120
});
patronSiparisKazancTxt.anchor.set(0.5, 0.5);
patronSiparisKazancTxt.x = patronPanelCenterX;
// 2 satır yukarı: 2 * 60px = 120px
patronSiparisKazancTxt.y = patronSiparisTamamlaBtn.y - 80;
patronSiparisKazancTxt.visible = false;
game.addChild(patronSiparisKazancTxt);
// Siparişi reddet butonu
var patronSiparisReddetBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 260,
height: 90,
x: patronPanelCenterX + 180,
// 2 satır yukarı: 2 * 60px = 120px
y: patronPanelY + patronPanelHeight - 160 - 90 - 120,
color: 0xd83318,
borderColor: 0x222222,
borderWidth: 6
});
patronSiparisReddetBtn.visible = false;
game.addChild(patronSiparisReddetBtn);
var patronSiparisReddetBtnTxt = new Text2('Reddet (%5 Ceza)', {
size: 45,
fill: '#fff'
});
patronSiparisReddetBtnTxt.anchor.set(0.5, 0.5);
patronSiparisReddetBtnTxt.x = patronSiparisReddetBtn.x;
// 2 satır yukarı: 2 * 60px = 120px
patronSiparisReddetBtnTxt.y = patronSiparisReddetBtn.y;
patronSiparisReddetBtnTxt.visible = false;
game.addChild(patronSiparisReddetBtnTxt);
// Paneldeki eski metni kaldır
// patronPanelText artık kullanılmıyor, referans kaldırıldı
// Sipariş oluşturucu
function generatePatronSiparis() {
if (patronSiparis.aktif) return; // Sipariş varken yenisi gelmez
// Şirket seç
var sirket = patronSirketler[Math.floor(Math.random() * patronSirketler.length)];
// 2-10 farklı ürün, her biri 20-300 adet
var urunSayisi = 2 + Math.floor(Math.random() * 9); // 2-10
var secilenler = [];
var secilenIndexler = [];
while (secilenler.length < urunSayisi) {
var idx = Math.floor(Math.random() * partTypes.length);
if (secilenIndexler.indexOf(idx) === -1) {
secilenIndexler.push(idx);
var adet = 20 + Math.floor(Math.random() * 281); // 20-300
secilenler.push({
part: partTypes[idx],
adet: adet
});
}
}
// Bonus: %2-%10 arası
var bonus = 2 + Math.floor(Math.random() * 9); // 2-10
patronSiparis.sirket = sirket;
patronSiparis.urunler = secilenler;
patronSiparis.toplamAdet = 0;
for (var i = 0; i < secilenler.length; i++) {
patronSiparis.toplamAdet += secilenler[i].adet;
}
patronSiparis.bonus = bonus;
patronSiparis.aktif = true;
patronSiparis.tamamlandi = false;
updatePatronSiparisPanel();
}
// Panelde siparişi güncelle
function updatePatronSiparisPanel() {
if (!patronPanel.visible) return;
if (!patronSiparis.aktif) {
patronSiparisTxt.setText("Şu anda aktif bir kurumsal sipariş yok.\nYeni sipariş için bekleyin.");
patronSiparisTamamlaBtn.visible = false;
patronSiparisTamamlaBtnTxt.visible = false;
patronSiparisReddetBtn.visible = false;
patronSiparisReddetBtnTxt.visible = false;
patronInfoTxt.visible = true;
return;
}
// Sipariş metni
var txt = "[Kurumsal Müşteri: " + patronSiparis.sirket + "]\n";
txt += "Toplu ürün siparişi:\n";
for (var i = 0; i < patronSiparis.urunler.length; i++) {
var p = patronSiparis.urunler[i];
var label = p.part === "mouse" ? "MOUSE" : p.part === "klavye" ? "KLAVYE" : p.part === "cpu" ? "CPU" : p.part === "gpu" ? "GPU" : p.part === "monitor" ? "MONITOR" : p.part === "case" ? "KASA" : p.part.toUpperCase();
txt += "- " + label + ": " + p.adet + " adet (Stok: " + (parts[p.part] || 0) + ")\n";
}
txt += "\nSipariş tamamlandığında: %" + patronSiparis.bonus + " ek kazanç!";
patronSiparisTxt.setText(txt);
patronSiparisTamamlaBtn.visible = true;
patronSiparisTamamlaBtnTxt.visible = true;
patronSiparisReddetBtn.visible = true;
patronSiparisReddetBtnTxt.visible = true;
patronInfoTxt.visible = true;
// Butonları aktif/pasif yap
var tamamlanabilir = true;
for (var i = 0; i < patronSiparis.urunler.length; i++) {
var p = patronSiparis.urunler[i];
if ((parts[p.part] || 0) < p.adet) {
tamamlanabilir = false;
break;
}
}
patronSiparisTamamlaBtn.alpha = tamamlanabilir ? 1 : 0.5;
patronSiparisTamamlaBtnTxt.setText(tamamlanabilir ? "Siparişi Tamamla" : "Stok Yetersiz");
patronSiparisTamamlaBtn.downEnabled = tamamlanabilir;
// --- Tamamlanınca Toplam Kazanç Yazısı ---
// Sipariş tamamlanabilir ise toplam kazancı ve bonusu göster
if (typeof patronSiparisKazancTxt !== "undefined") {
if (patronSiparis.aktif && tamamlanabilir) {
var toplamKazanc = 0;
for (var i = 0; i < patronSiparis.urunler.length; i++) {
toplamKazanc += patronSiparis.urunler[i].adet * 45;
}
var bonusKazanc = Math.floor(toplamKazanc * patronSiparis.bonus / 100);
patronSiparisKazancTxt.setText("Tamamlanınca Toplam Kazanç: ₺" + (toplamKazanc + bonusKazanc) + "\n(Bonus: ₺" + bonusKazanc + ")");
patronSiparisKazancTxt.visible = true;
} else {
patronSiparisKazancTxt.visible = false;
}
}
}
// Siparişi tamamla butonu
patronSiparisTamamlaBtn.down = function (x, y, obj) {
if (!patronSiparis.aktif) return;
// Tüm ürünler stokta mı?
var tamamlanabilir = true;
for (var i = 0; i < patronSiparis.urunler.length; i++) {
var p = patronSiparis.urunler[i];
if ((parts[p.part] || 0) < p.adet) {
tamamlanabilir = false;
break;
}
}
if (!tamamlanabilir) {
tween(patronSiparisTamamlaBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(patronSiparisTamamlaBtn, {
tint: 0x83de44
}, {
duration: 120
});
}
});
return;
}
// Ürünleri düş
for (var i = 0; i < patronSiparis.urunler.length; i++) {
var p = patronSiparis.urunler[i];
parts[p.part] -= p.adet;
}
updatePartsText && updatePartsText();
// Kazanç: toplam ürün adedi * 45 TL (ortalama satış fiyatı) * bonus/100
var toplamKazanc = 0;
for (var i = 0; i < patronSiparis.urunler.length; i++) {
toplamKazanc += patronSiparis.urunler[i].adet * 45;
}
var bonusKazanc = Math.floor(toplamKazanc * patronSiparis.bonus / 100);
money += toplamKazanc + bonusKazanc;
updateMoneyText && updateMoneyText();
patronSiparis.aktif = false;
patronSiparis.tamamlandi = true;
patronSiparisTxt.setText("Sipariş başarıyla tamamlandı!\nKazanç: ₺" + (toplamKazanc + bonusKazanc) + " (Bonus: ₺" + bonusKazanc + ")");
// Toplam kazanç yazısını göster
if (typeof patronSiparisKazancTxt !== "undefined") {
patronSiparisKazancTxt.setText("Toplam Kazanç: ₺" + (toplamKazanc + bonusKazanc));
patronSiparisKazancTxt.visible = true;
}
// Butonları gizle
patronSiparisTamamlaBtn.visible = false;
patronSiparisTamamlaBtnTxt.visible = false;
patronSiparisReddetBtn.visible = false;
patronSiparisReddetBtnTxt.visible = false;
// Yeni sipariş gelene kadar toplam kazanç yazısı 3 saniye görünsün, sonra gizle
if (typeof patronSiparisKazancTxt !== "undefined") {
LK.setTimeout(function () {
patronSiparisKazancTxt.visible = false;
}, 180); // 3 saniye (60fps * 3)
}
// Yeni sipariş 1-2 dakika sonra gelsin
LK.setTimeout(function () {
generatePatronSiparis();
updatePatronSiparisPanel();
}, (60 + Math.floor(Math.random() * 61)) * 60);
};
// Siparişi reddet butonu
patronSiparisReddetBtn.down = function (x, y, obj) {
if (!patronSiparis.aktif) return;
// Ceza: tüm ürünlerin toplam bedelinin %5'i kadar para düş
var toplamBedel = 0;
for (var i = 0; i < patronSiparis.urunler.length; i++) {
toplamBedel += patronSiparis.urunler[i].adet * 45;
}
var ceza = Math.floor(toplamBedel * 0.05);
money -= ceza;
if (money < 0) money = 0;
updateMoneyText && updateMoneyText();
patronSiparis.aktif = false;
patronSiparis.tamamlandi = false;
patronSiparisTxt.setText("Sipariş reddedildi.\nCeza: ₺" + ceza + " ödendi.");
patronSiparisTamamlaBtn.visible = false;
patronSiparisTamamlaBtnTxt.visible = false;
patronSiparisReddetBtn.visible = false;
patronSiparisReddetBtnTxt.visible = false;
// Yeni sipariş 1-2 dakika sonra gelsin
LK.setTimeout(function () {
generatePatronSiparis();
updatePatronSiparisPanel();
}, (60 + Math.floor(Math.random() * 61)) * 60);
};
// Panel açıldığında siparişi göster
patronBtn.down = function (x, y, obj) {
patronPanel.visible = true;
patronPanelTitle.visible = true;
patronSiparisTxt.visible = true;
patronInfoTxt.visible = true;
patronKapatBtn.visible = true;
patronKapatBtnTxt.visible = true;
patronSiparisTamamlaBtn.visible = patronSiparis.aktif;
patronSiparisTamamlaBtnTxt.visible = patronSiparis.aktif;
patronSiparisReddetBtn.visible = patronSiparis.aktif;
patronSiparisReddetBtnTxt.visible = patronSiparis.aktif;
updatePatronSiparisPanel();
// Hide homepage UI (including PATRON button)
if (typeof patronBtn !== "undefined") patronBtn.visible = false;
if (typeof patronBtnTxt !== "undefined") patronBtnTxt.visible = false;
// Disable all factory buttons while patron panel is open
if (typeof factoryBtns !== "undefined" && Array.isArray(factoryBtns)) {
for (var i = 0; i < factoryBtns.length; i++) {
if (factoryBtns[i]) {
if (factoryBtns[i]._origDown === undefined && factoryBtns[i].down) {
factoryBtns[i]._origDown = factoryBtns[i].down;
}
factoryBtns[i].down = function () {
return true;
};
}
}
}
if (typeof factoryUnlockBtns !== "undefined" && Array.isArray(factoryUnlockBtns)) {
for (var i = 0; i < factoryUnlockBtns.length; i++) {
if (factoryUnlockBtns[i]) {
if (factoryUnlockBtns[i]._origDown === undefined && factoryUnlockBtns[i].down) {
factoryUnlockBtns[i]._origDown = factoryUnlockBtns[i].down;
}
factoryUnlockBtns[i].down = function () {
return true;
};
}
}
}
if (typeof prodBtns !== "undefined" && Array.isArray(prodBtns)) {
for (var i = 0; i < prodBtns.length; i++) {
if (prodBtns[i]) {
if (prodBtns[i]._origDown === undefined && prodBtns[i].down) {
prodBtns[i]._origDown = prodBtns[i].down;
}
prodBtns[i].down = function () {
return true;
};
}
}
}
if (typeof factoryAutoBtns !== "undefined" && Array.isArray(factoryAutoBtns)) {
for (var i = 0; i < factoryAutoBtns.length; i++) {
if (factoryAutoBtns[i]) {
if (factoryAutoBtns[i]._origDown === undefined && factoryAutoBtns[i].down) {
factoryAutoBtns[i]._origDown = factoryAutoBtns[i].down;
}
factoryAutoBtns[i].down = function () {
return true;
};
}
}
}
// Defensive: bring panel to front
if (game.setChildIndex) {
game.setChildIndex(patronPanel, game.children.length - 1);
game.setChildIndex(patronPanelTitle, game.children.length - 1);
game.setChildIndex(patronSiparisTxt, game.children.length - 1);
game.setChildIndex(patronInfoTxt, game.children.length - 1);
game.setChildIndex(patronKapatBtn, game.children.length - 1);
game.setChildIndex(patronKapatBtnTxt, game.children.length - 1);
game.setChildIndex(patronSiparisTamamlaBtn, game.children.length - 1);
game.setChildIndex(patronSiparisTamamlaBtnTxt, game.children.length - 1);
game.setChildIndex(patronSiparisReddetBtn, game.children.length - 1);
game.setChildIndex(patronSiparisReddetBtnTxt, game.children.length - 1);
}
};
// Panel kapatınca butonları gizle
if (typeof patronKapatBtn !== "undefined" && patronKapatBtn) {
patronKapatBtn.down = function (x, y, obj) {
patronPanel.visible = false;
patronPanelTitle.visible = false;
patronSiparisTxt.visible = false;
patronInfoTxt.visible = false;
patronKapatBtn.visible = false;
patronKapatBtnTxt.visible = false;
patronSiparisTamamlaBtn.visible = false;
patronSiparisTamamlaBtnTxt.visible = false;
patronSiparisReddetBtn.visible = false;
patronSiparisReddetBtnTxt.visible = false;
if (typeof patronBtn !== "undefined") patronBtn.visible = true;
if (typeof patronBtnTxt !== "undefined") patronBtnTxt.visible = true;
// Re-enable all factory buttons when patron panel closes
if (typeof factoryBtns !== "undefined" && Array.isArray(factoryBtns)) {
for (var i = 0; i < factoryBtns.length; i++) {
if (factoryBtns[i] && factoryBtns[i]._origDown) {
factoryBtns[i].down = factoryBtns[i]._origDown;
delete factoryBtns[i]._origDown;
}
}
}
if (typeof factoryUnlockBtns !== "undefined" && Array.isArray(factoryUnlockBtns)) {
for (var i = 0; i < factoryUnlockBtns.length; i++) {
if (factoryUnlockBtns[i] && factoryUnlockBtns[i]._origDown) {
factoryUnlockBtns[i].down = factoryUnlockBtns[i]._origDown;
delete factoryUnlockBtns[i]._origDown;
}
}
}
if (typeof prodBtns !== "undefined" && Array.isArray(prodBtns)) {
for (var i = 0; i < prodBtns.length; i++) {
if (prodBtns[i] && prodBtns[i]._origDown) {
prodBtns[i].down = prodBtns[i]._origDown;
delete prodBtns[i]._origDown;
}
}
}
if (typeof factoryAutoBtns !== "undefined" && Array.isArray(factoryAutoBtns)) {
for (var i = 0; i < factoryAutoBtns.length; i++) {
if (factoryAutoBtns[i] && factoryAutoBtns[i]._origDown) {
factoryAutoBtns[i].down = factoryAutoBtns[i]._origDown;
delete factoryAutoBtns[i]._origDown;
}
}
}
};
}
// Oyun başında ilk siparişi oluştur
LK.setTimeout(function () {
if (!patronSiparis.aktif) {
generatePatronSiparis();
}
}, 120);
// Paneldeki eski metni kaldır
// (patronPanelText artık kullanılmıyor)
// Patron panel close button (bottom center) - Madenler paneli ile aynı şekilde, büyük ve kırmızı çerçeveli
var patronKapatBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 360,
height: 180,
x: patronPanel.x + patronPanel.width / 2,
y: patronPanel.y + patronPanel.height - 60,
color: 0xffffff,
borderColor: 0xff2222,
borderWidth: 8
});
patronKapatBtn.visible = false;
game.addChild(patronKapatBtn);
// Kapat butonu için X simgesi (Unicode heavy multiplication X)
var patronKapatBtnIcon = new Text2("\u2716", {
size: 81,
fill: '#ff2222'
});
patronKapatBtnIcon.anchor.set(1, 0.5);
patronKapatBtnIcon.x = patronKapatBtn.x - 60;
patronKapatBtnIcon.y = patronKapatBtn.y;
patronKapatBtnIcon.visible = false;
game.addChild(patronKapatBtnIcon);
var patronKapatBtnTxt = new Text2('Kapat', {
size: 96,
fill: '#ff2222'
});
patronKapatBtnTxt.anchor.set(0.5, 0.5);
patronKapatBtnTxt.x = patronKapatBtn.x;
patronKapatBtnTxt.y = patronKapatBtn.y;
patronKapatBtnTxt.visible = false;
game.addChild(patronKapatBtnTxt);
// Patron button opens panel
patronBtn.down = function (x, y, obj) {
// Patron Paneli arkaplan ve içeriğini sıfırla
// Paneli ve tüm içeriğini görünmez yap, sonra sadece gerekli olanları aç
patronPanel.visible = false;
patronPanelTitle.visible = false;
patronSiparisTxt.visible = false;
patronInfoTxt.visible = false;
patronKapatBtn.visible = false;
patronKapatBtnTxt.visible = false;
if (typeof patronKapatBtnIcon !== "undefined") patronKapatBtnIcon.visible = false;
patronSiparisTamamlaBtn.visible = false;
patronSiparisTamamlaBtnTxt.visible = false;
patronSiparisReddetBtn.visible = false;
patronSiparisReddetBtnTxt.visible = false;
if (typeof patronSiparisKazancTxt !== "undefined") patronSiparisKazancTxt.visible = false;
// Paneli ve başlığı tekrar aç
patronPanel.visible = true;
patronPanelTitle.visible = true;
patronSiparisTxt.visible = true;
patronInfoTxt.visible = true;
patronKapatBtn.visible = true;
patronKapatBtnTxt.visible = true;
if (typeof patronKapatBtnIcon !== "undefined") patronKapatBtnIcon.visible = true;
patronSiparisTamamlaBtn.visible = patronSiparis.aktif;
patronSiparisTamamlaBtnTxt.visible = patronSiparis.aktif;
patronSiparisReddetBtn.visible = patronSiparis.aktif;
patronSiparisReddetBtnTxt.visible = patronSiparis.aktif;
updatePatronSiparisPanel();
// Hide homepage UI (including PATRON button)
if (typeof patronBtn !== "undefined") patronBtn.visible = false;
if (typeof patronBtnTxt !== "undefined") patronBtnTxt.visible = false;
// Defensive: bring panel to front
if (game.setChildIndex) {
game.setChildIndex(patronPanel, game.children.length - 1);
game.setChildIndex(patronPanelTitle, game.children.length - 1);
game.setChildIndex(patronSiparisTxt, game.children.length - 1);
game.setChildIndex(patronInfoTxt, game.children.length - 1);
game.setChildIndex(patronKapatBtn, game.children.length - 1);
game.setChildIndex(patronKapatBtnTxt, game.children.length - 1);
if (typeof patronKapatBtnIcon !== "undefined") game.setChildIndex(patronKapatBtnIcon, game.children.length - 1);
game.setChildIndex(patronSiparisTamamlaBtn, game.children.length - 1);
game.setChildIndex(patronSiparisTamamlaBtnTxt, game.children.length - 1);
game.setChildIndex(patronSiparisReddetBtn, game.children.length - 1);
game.setChildIndex(patronSiparisReddetBtnTxt, game.children.length - 1);
}
};
// Patron panel close button
patronKapatBtn.down = function (x, y, obj) {
patronPanel.visible = false;
patronPanelTitle.visible = false;
patronSiparisTxt.visible = false;
patronInfoTxt.visible = false;
patronKapatBtn.visible = false;
patronKapatBtnTxt.visible = false;
if (typeof patronKapatBtnIcon !== "undefined") patronKapatBtnIcon.visible = false;
patronSiparisTamamlaBtn.visible = false;
patronSiparisTamamlaBtnTxt.visible = false;
patronSiparisReddetBtn.visible = false;
patronSiparisReddetBtnTxt.visible = false;
// Restore homepage UI (including PATRON button)
if (typeof patronBtn !== "undefined") patronBtn.visible = true;
if (typeof patronBtnTxt !== "undefined") patronBtnTxt.visible = true;
};
// --- Hide PATRON button when any panel is open ---
// Helper: list of all panels that should hide PATRON button when open
function updatePatronBtnVisibility() {
// Patron butonunun görünürlüğünü kontrol et: Sadece patronPanel açıkken gizle, diğer panelleri hariç tut
var anyPanelOpen = patronPanel.visible;
if (typeof patronBtn !== "undefined") patronBtn.visible = !anyPanelOpen;
if (typeof patronBtnTxt !== "undefined") patronBtnTxt.visible = !anyPanelOpen;
}
// Patch all panel open/close logic to call updatePatronBtnVisibility
// (Do this with a timer for robustness)
LK.setInterval(updatePatronBtnVisibility, 10);
// overlays and overlay logic removed
function showPanelOverlay(panelObj) {}
function hidePanelOverlay() {}
// --- Ava: Helper to hide all homepage/anasayfa UI and disable all their input when any panel is open ---
// Also disables all factory buttons (upgrade, unlock, prod, auto) and disables factory panel clicks when any panel is open
function setHomepageUIEnabled(enabled) {
// (fullscreen overlay logic removed)
// List all homepage/anasayfa UI elements including all game elements
var homepageUI = [magazaBtn, magazaBtnTxt, yatirimBtn, yatirimBtnTxt, bankBtn, bankBtnTxt, soundBtn, soundBtnTxt, newPageBtn, newPageBtnTxt, madenlerBtn, madenlerBtnTxt, madenlerBtnMineImg, calisanlarBtnImg, /* infoBtn, infoBtnTxt, howToBtn, howToBtnTxt, */borcOdeBtn, borcOdeBtnTxt, moneyTxt, borcTxt, borcTimeTxt, partsTxt, partsPanel, offerPanel, offerTitle, offerPartTxt, offerAmountTxt, offerPriceTxt, offerBtn, offerBtnTxt, offerTimeTxt, sellPanel, sellTitle, sellPartTxt, sellAmountTxt, sellPriceTxt, sellBtn, sellBtnTxt, sellOfferTimeTxt];
// Hide all factories, mines, stores and their UI elements
if (typeof factories !== "undefined") {
for (var i = 0; i < factories.length; i++) {
if (factories[i]) homepageUI.push(factories[i]);
}
}
if (typeof mines !== "undefined") {
for (var i = 0; i < mines.length; i++) {
if (mines[i]) homepageUI.push(mines[i]);
}
}
if (typeof store !== "undefined") homepageUI.push(store);
if (typeof store2 !== "undefined") homepageUI.push(store2);
if (typeof store3 !== "undefined") homepageUI.push(store3);
if (typeof store4 !== "undefined") homepageUI.push(store4);
// Add raw material texts
if (typeof copperRawTxt !== "undefined") homepageUI.push(copperRawTxt);
if (typeof siliconRawTxt !== "undefined") homepageUI.push(siliconRawTxt);
if (typeof ironRawTxt !== "undefined") homepageUI.push(ironRawTxt);
for (var i = 0; i < homepageUI.length; i++) {
if (typeof homepageUI[i] !== "undefined" && homepageUI[i] && typeof homepageUI[i].visible === "boolean") {
homepageUI[i].visible = !!enabled;
}
// Defensive: also disable input by removing .down/.move/.up handlers if disabled
if (typeof homepageUI[i] !== "undefined" && homepageUI[i]) {
if (!enabled) {
if (homepageUI[i]._origDown === undefined && homepageUI[i].down) {
homepageUI[i]._origDown = homepageUI[i].down;
}
if (homepageUI[i]._origMove === undefined && homepageUI[i].move) {
homepageUI[i]._origMove = homepageUI[i].move;
}
if (homepageUI[i]._origUp === undefined && homepageUI[i].up) {
homepageUI[i]._origUp = homepageUI[i].up;
}
homepageUI[i].down = function () {
return true;
};
homepageUI[i].move = function () {
return true;
};
homepageUI[i].up = function () {
return true;
};
} else {
if (homepageUI[i]._origDown) {
homepageUI[i].down = homepageUI[i]._origDown;
}
if (homepageUI[i]._origMove) {
homepageUI[i].move = homepageUI[i]._origMove;
}
if (homepageUI[i]._origUp) {
homepageUI[i].up = homepageUI[i]._origUp;
}
}
}
}
// --- Ava: Disable all factory buttons and factory panel clicks when any panel is open ---
if (typeof factoryBtns !== "undefined" && Array.isArray(factoryBtns)) {
for (var i = 0; i < factoryBtns.length; i++) {
if (factoryBtns[i]) {
if (!enabled) {
if (factoryBtns[i]._origDown === undefined && factoryBtns[i].down) {
factoryBtns[i]._origDown = factoryBtns[i].down;
}
factoryBtns[i].down = function () {
return true;
};
} else {
if (factoryBtns[i]._origDown) {
factoryBtns[i].down = factoryBtns[i]._origDown;
delete factoryBtns[i]._origDown;
}
}
}
}
}
if (typeof factoryUnlockBtns !== "undefined" && Array.isArray(factoryUnlockBtns)) {
for (var i = 0; i < factoryUnlockBtns.length; i++) {
if (factoryUnlockBtns[i]) {
if (!enabled) {
if (factoryUnlockBtns[i]._origDown === undefined && factoryUnlockBtns[i].down) {
factoryUnlockBtns[i]._origDown = factoryUnlockBtns[i].down;
}
factoryUnlockBtns[i].down = function () {
return true;
};
} else {
if (factoryUnlockBtns[i]._origDown) {
factoryUnlockBtns[i].down = factoryUnlockBtns[i]._origDown;
delete factoryUnlockBtns[i]._origDown;
}
}
}
}
}
if (typeof prodBtns !== "undefined" && Array.isArray(prodBtns)) {
for (var i = 0; i < prodBtns.length; i++) {
if (prodBtns[i]) {
if (!enabled) {
if (prodBtns[i]._origDown === undefined && prodBtns[i].down) {
prodBtns[i]._origDown = prodBtns[i].down;
}
prodBtns[i].down = function () {
return true;
};
} else {
if (prodBtns[i]._origDown) {
prodBtns[i].down = prodBtns[i]._origDown;
delete prodBtns[i]._origDown;
}
}
}
}
}
if (typeof factoryAutoBtns !== "undefined" && Array.isArray(factoryAutoBtns)) {
for (var i = 0; i < factoryAutoBtns.length; i++) {
if (factoryAutoBtns[i]) {
if (!enabled) {
if (factoryAutoBtns[i]._origDown === undefined && factoryAutoBtns[i].down) {
factoryAutoBtns[i]._origDown = factoryAutoBtns[i].down;
}
factoryAutoBtns[i].down = function () {
return true;
};
} else {
if (factoryAutoBtns[i]._origDown) {
factoryAutoBtns[i].down = factoryAutoBtns[i]._origDown;
delete factoryAutoBtns[i]._origDown;
}
}
}
}
}
// Defensive: also disable click on the factory panel itself (the big image)
if (typeof factories !== "undefined" && Array.isArray(factories)) {
for (var i = 0; i < factories.length; i++) {
if (factories[i]) {
if (!enabled) {
if (factories[i]._origDown === undefined && factories[i].down) {
factories[i]._origDown = factories[i].down;
}
factories[i].down = function () {
return true;
};
} else {
if (factories[i]._origDown) {
factories[i].down = factories[i]._origDown;
delete factories[i]._origDown;
}
}
}
}
}
// --- Ava: Show Mevduat button and text again when all panels except Mevduat are closed ---
if (enabled) {
if (typeof mevduatBtn !== "undefined") mevduatBtn.visible = true;
if (typeof mevduatBtnTxt !== "undefined") mevduatBtnTxt.visible = true;
// Info and How To Play buttons are never shown
}
}
// --- Mağaza Button ---
var magazaBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 180,
height: 70
});
magazaBtn.x = moneyTxt.x - 220;
magazaBtn.y = 40;
LK.gui.top.addChild(magazaBtn);
var magazaBtnTxt = new Text2('Mağaza', {
size: 36,
fill: '#fff'
});
magazaBtnTxt.anchor.set(0.5, 0.5);
magazaBtnTxt.x = magazaBtn.x;
magazaBtnTxt.y = magazaBtn.y;
LK.gui.top.addChild(magazaBtnTxt);
// Mağaza butonuna tıklanınca açılır pencereyi göster
// --- Ava: Resize and center all popup/panel windows to 90% of screen and center them ---
var panelWidth = Math.floor(2048 * 0.9);
var panelHeight = Math.floor(2732 * 0.9);
var panelX = Math.floor(2048 / 2);
var panelY = Math.floor(2732 / 2);
var magazaPanel = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: panelWidth,
height: panelHeight,
x: panelX,
y: panelY
});
magazaPanel.visible = false;
game.addChild(magazaPanel);
var magazaPanelTitle = new Text2('Mağaza', {
size: 36,
fill: '#fff'
});
magazaPanelTitle.anchor.set(0.5, 0);
magazaPanelTitle.x = magazaPanel.x;
magazaPanelTitle.y = magazaPanel.y - magazaPanel.height / 2 + 30;
magazaPanelTitle.visible = false;
game.addChild(magazaPanelTitle);
var magazaPanelText = new Text2('Burada mağaza ile ilgili içerik veya açıklama eklenebilir.', {
size: 36,
fill: '#fff'
});
magazaPanelText.anchor.set(0.5, 0.5);
magazaPanelText.x = magazaPanel.x;
magazaPanelText.y = magazaPanel.y - 120;
magazaPanelText.visible = false;
game.addChild(magazaPanelText);
// Muhasebe bilgileri başlığı
var magazaMuhasebeTitle = new Text2('Muhasebe Bilgileri', {
size: 36,
fill: '#ffb'
});
magazaMuhasebeTitle.anchor.set(0.5, 0);
magazaMuhasebeTitle.x = magazaPanel.x;
magazaMuhasebeTitle.y = magazaPanel.y - 30;
magazaMuhasebeTitle.visible = false;
game.addChild(magazaMuhasebeTitle);
// Muhasebe detayları
var magazaMuhasebeText = new Text2('', {
size: 36,
fill: '#fff'
});
magazaMuhasebeText.anchor.set(0.5, 0);
magazaMuhasebeText.x = magazaPanel.x;
magazaMuhasebeText.y = magazaPanel.y + 20;
magazaMuhasebeText.visible = false;
game.addChild(magazaMuhasebeText);
// Muhasebe bilgilerini güncelleyen fonksiyon
function updateMagazaMuhasebeText() {
// Toplam satış adedi ve toplam gelir hesapla
var toplamSatis = 0;
var toplamGelir = 0;
for (var i = 0; i < partTypes.length; i++) {
// Her part için satılan miktarı ve gelirini hesapla
// Satışlar, parts dizisinden değil, toplam üretilen - elde kalan ile bulunabilir
// Basit bir örnek: toplam üretilen ve satılanı takip etmiyorsak, sadece mevcut stoğu göster
// Gelişmiş: Satışları takip etmek için global değişkenler eklenebilir
// Burada örnek olarak sadece mevcut stok ve para gösterelim
// Gelişmiş takip için satılan miktarları ayrıca bir dizi ile tutmak gerekir
// Şimdilik sadece mevcut stok ve para gösterelim
toplamSatis += parts[partTypes[i]];
}
// Toplam gelir olarak mevcut parayı gösterelim (örnek)
toplamGelir = money;
magazaMuhasebeText.setText("Mevcut Stok (adet): " + toplamSatis + "\nKasadaki Para: ₺" + toplamGelir + (typeof borc !== "undefined" && borc > 0 ? "\nBorç: ₺" + borc : ""));
}
// Paneli aç/kapat fonksiyonları
magazaBtn.down = function (x, y, obj) {
if (newPagePanel && newPagePanel.visible) {
return;
}
if (isSoundOn && LK.getSound) {
var clickSound = LK.getSound('ClickSesi');
if (clickSound) {
clickSound.play();
}
}
magazaPanel.visible = true;
magazaPanelTitle.visible = true;
magazaPanelText.visible = true;
magazaKapatBtn.visible = true;
magazaKapatBtnTxt.visible = true;
magazaMuhasebeTitle.visible = true;
magazaMuhasebeText.visible = true;
updateMagazaMuhasebeText();
// --- Ava: Hide only the background elements under the panel area, keep other elements visible ---
// Save which elements are hidden for this panel
if (!magazaPanel._hiddenBackgrounds) magazaPanel._hiddenBackgrounds = [];
for (var i = 0; i < game.children.length; i++) {
var child = game.children[i];
// Hide only if: visible, not the panel or its content, not a Text2, not a button, and is under the panel area
if (child && typeof child.visible === "boolean" && child.visible && child !== magazaPanel && child !== magazaPanelTitle && child !== magazaPanelText && child !== magazaKapatBtn && child !== magazaKapatBtnTxt && child !== magazaKapatBtnIcon && child !== magazaMuhasebeTitle && child !== magazaMuhasebeText && !(child instanceof Text2) && !(child.assetId && child.assetId.indexOf("button") === 0) &&
// Check if child is under the panel area
typeof child.x === "number" && typeof child.y === "number" && child.x + (child.width || 0) > magazaPanel.x - magazaPanel.width / 2 && child.x < magazaPanel.x + magazaPanel.width / 2 && child.y + (child.height || 0) > magazaPanel.y - magazaPanel.height / 2 && child.y < magazaPanel.y + magazaPanel.height / 2) {
child._oldVisible = child.visible;
child.visible = false;
magazaPanel._hiddenBackgrounds.push(child);
}
}
// Paneli ve tüm içeriğini en öne getir (butonlar dahil)
if (game.setChildIndex) {
game.setChildIndex(magazaPanel, game.children.length - 1);
game.setChildIndex(magazaPanelTitle, game.children.length - 1);
game.setChildIndex(magazaPanelText, game.children.length - 1);
game.setChildIndex(magazaMuhasebeTitle, game.children.length - 1);
game.setChildIndex(magazaMuhasebeText, game.children.length - 1);
// Kapat butonu ve X simgesi ve yazısı en önde
game.setChildIndex(magazaKapatBtn, game.children.length - 1);
game.setChildIndex(magazaKapatBtnTxt, game.children.length - 1);
if (typeof magazaKapatBtnIcon !== "undefined") {
game.setChildIndex(magazaKapatBtnIcon, game.children.length - 1);
}
}
};
// Paneli kapatmak için bir kapat butonu ekle
// --- Kapat butonu: sağ üstte, %100 büyüklükte, kırmızı çerçeveli ---
// Panelin sağ üst köşesine hizala, %100 büyüklükte (240x120)
var magazaKapatBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 360,
//{4g} // %50 artırıldı
height: 180,
//{4h} // %50 artırıldı
// Alt orta: panelin alt kenarının ortası, 60px yukarıda
x: magazaPanel.x,
y: magazaPanel.y + magazaPanel.height / 2 - 60,
color: 0xffffff,
borderColor: 0xff2222,
borderWidth: 8
});
magazaKapatBtn.visible = false;
game.addChild(magazaKapatBtn);
// Kapat butonu için X simgesi (Unicode heavy multiplication X)
var magazaKapatBtnIcon = new Text2("\u2716", {
size: 81,
//{4o} // %50 artırıldı
fill: '#ff2222'
});
magazaKapatBtnIcon.anchor.set(1, 0.5);
magazaKapatBtnIcon.x = magazaKapatBtn.x - 60;
magazaKapatBtnIcon.y = magazaKapatBtn.y;
magazaKapatBtnIcon.visible = false;
game.addChild(magazaKapatBtnIcon);
var magazaKapatBtnTxt = new Text2('Kapat', {
size: 96,
//{4r} // %50 artırıldı
fill: '#ff2222'
});
magazaKapatBtnTxt.anchor.set(0.5, 0.5);
magazaKapatBtnTxt.x = magazaKapatBtn.x;
magazaKapatBtnTxt.y = magazaKapatBtn.y;
magazaKapatBtnTxt.visible = false;
game.addChild(magazaKapatBtnTxt);
magazaKapatBtn.down = function (x, y, obj) {
if (isSoundOn && LK.getSound) {
var clickSound = LK.getSound('ClickSesi');
if (clickSound) {
clickSound.play();
}
}
magazaPanel.visible = false;
magazaPanelTitle.visible = false;
magazaPanelText.visible = false;
magazaKapatBtn.visible = false;
magazaKapatBtnTxt.visible = false;
magazaMuhasebeTitle.visible = false;
magazaMuhasebeText.visible = false;
// --- Ava: Restore background elements hidden under the panel area ---
if (magazaPanel._hiddenBackgrounds && magazaPanel._hiddenBackgrounds.length) {
for (var i = 0; i < magazaPanel._hiddenBackgrounds.length; i++) {
var child = magazaPanel._hiddenBackgrounds[i];
if (child && typeof child.visible === "boolean") {
if (typeof child._oldVisible !== "undefined") {
child.visible = child._oldVisible;
delete child._oldVisible;
} else {
child.visible = true;
}
}
}
magazaPanel._hiddenBackgrounds = [];
}
// Restore all homepage elements
setHomepageUIEnabled(true);
};
// --- Yatırım Button ve Açılır Pencere ---
// Yatırım butonunu mağaza butonunun soluna ekle
var yatirimBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 180,
height: 70
});
yatirimBtn.x = magazaBtn.x - 220;
yatirimBtn.y = magazaBtn.y;
LK.gui.top.addChild(yatirimBtn);
var yatirimBtnTxt = new Text2('Yatırım', {
size: 36,
fill: '#fff'
});
yatirimBtnTxt.anchor.set(0.5, 0.5);
yatirimBtnTxt.x = yatirimBtn.x;
yatirimBtnTxt.y = yatirimBtn.y;
LK.gui.top.addChild(yatirimBtnTxt);
// Açılır pencereyi oluştur (başta görünmez) - EKRANIN EN ÜSTÜNDE
// Yatırım panelini tam ekranın ortasına ve %90 genişlikte/ekran yüksekliğinin %70'i kadar yap
var yatirimPanelWidth = Math.floor(2048 * 0.9);
var yatirimPanelHeight = Math.floor(2732 * 0.7);
var yatirimPanelX = Math.floor(2048 / 2);
var yatirimPanelY = Math.floor(2732 / 2);
var yatirimPanel = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: yatirimPanelWidth,
height: yatirimPanelHeight,
x: yatirimPanelX,
y: yatirimPanelY
});
yatirimPanel.visible = false;
// Yatırım panelini ve başlığını en önde göstermek için game üstünde en sona ekle
game.addChild(yatirimPanel);
game.setChildIndex(yatirimPanel, game.children.length - 1);
var yatirimTitle = new Text2('Yatırım - Popüler Coinler', {
size: 40,
fill: '#fff'
});
yatirimTitle.anchor.set(0.5, 0);
// Panelin üst kenarına ortalı hizala
yatirimTitle.x = yatirimPanel.x;
yatirimTitle.y = yatirimPanel.y - yatirimPanel.height / 2 + 20;
yatirimTitle.visible = false;
game.addChild(yatirimTitle);
game.setChildIndex(yatirimTitle, game.children.length - 1);
// 12 popüler coin listesi
var coinList = [{
name: "Bitcoin",
symbol: "BTC"
}, {
name: "Ethereum",
symbol: "ETH"
}, {
name: "Tether",
symbol: "USDT"
}, {
name: "BNB",
symbol: "BNB"
}, {
name: "Solana",
symbol: "SOL"
}, {
name: "XRP",
symbol: "XRP"
}, {
name: "Dogecoin",
symbol: "DOGE"
}, {
name: "Cardano",
symbol: "ADA"
}, {
name: "Toncoin",
symbol: "TON"
}, {
name: "Shiba Inu",
symbol: "SHIB"
}, {
name: "Avalanche",
symbol: "AVAX"
}, {
name: "Polkadot",
symbol: "DOT"
}];
// Coin fiyatları ve kullanıcı bakiyesi
var coinPrices = [];
var coinHoldings = [];
for (var i = 0; i < coinList.length; i++) {
// Başlangıç fiyatları: BTC 1.000.000, ETH 50.000, diğerleri 10.000-1.000 arası
var base = 1000000;
if (i === 1) {
base = 50000;
} else if (i > 1) {
base = 10000 - i * 900;
}
coinPrices[i] = base;
coinHoldings[i] = 0;
}
// Coin ortalama maliyetlerini ve toplam harcanan tutarı tutan diziler
var coinTotalCost = [];
var coinAvgCost = [];
for (var i = 0; i < coinList.length; i++) {
coinTotalCost[i] = 0;
coinAvgCost[i] = 0;
}
// Coin fiyatlarını gösterecek ve al/sat butonları
var coinTxts = [];
var coinPriceTxts = [];
var coinHoldingTxts = [];
var coinBuyBtns = [];
var coinSellBtns = [];
var coinBuyBtnTxts = [];
var coinSellBtnTxts = [];
var coinBuyInputTxts = [];
var coinSellInputTxts = [];
var coinBuyAmounts = [];
var coinSellAmounts = [];
for (var i = 0; i < coinList.length; i++) {
// Coin adı (sadece parantez içindekiler, yani symbol)
var coinTxt = new Text2(i + 1 + ". " + coinList[i].symbol, {
size: 40,
fill: '#bff'
});
coinTxt.anchor.set(0, 0);
// Panelin soluna daha yakın hizala (daha sola çek)
coinTxt.x = yatirimPanel.x - yatirimPanel.width / 2 + 30;
coinTxt.y = yatirimPanel.y + 80 + i * 75;
coinTxt.visible = false;
game.addChild(coinTxt);
coinTxts.push(coinTxt);
// Fiyat
var coinPriceTxt = new Text2("₺" + coinPrices[i], {
size: 40,
fill: '#fff'
});
coinPriceTxt.anchor.set(0, 0);
// Panelin soluna daha yakın hizala
coinPriceTxt.x = yatirimPanel.x - yatirimPanel.width / 2 + 210;
coinPriceTxt.y = coinTxt.y;
coinPriceTxt.visible = false;
game.addChild(coinPriceTxt);
coinPriceTxts.push(coinPriceTxt);
// Kullanıcı bakiyesi
var coinHoldingTxt = new Text2("Adet: 0", {
size: 40,
fill: '#ffb'
});
coinHoldingTxt.anchor.set(0, 0);
// Panelin soluna daha yakın hizala
coinHoldingTxt.x = yatirimPanel.x - yatirimPanel.width / 2 + 370;
coinHoldingTxt.y = coinTxt.y;
coinHoldingTxt.visible = false;
game.addChild(coinHoldingTxt);
coinHoldingTxts.push(coinHoldingTxt);
// Al butonu
var buyBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 100,
height: 60,
// Panelin SAĞ kenarına hizala (yeni genişlik: 950)
x: yatirimPanel.x + yatirimPanel.width / 2 - 150,
y: coinTxt.y + 18
});
buyBtn.visible = false;
game.addChild(buyBtn);
coinBuyBtns.push(buyBtn);
var buyBtnTxt = new Text2('Al', {
size: 40,
fill: '#fff'
});
buyBtnTxt.anchor.set(0.5, 0.5);
buyBtnTxt.x = buyBtn.x;
buyBtnTxt.y = buyBtn.y;
buyBtnTxt.visible = false;
game.addChild(buyBtnTxt);
coinBuyBtnTxts.push(buyBtnTxt);
// Sat butonu
var sellBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 100,
height: 60,
// Panelin SAĞ kenarına hizala, buyBtn'in sağında 130px boşluk bırak (yeni genişlik: 950)
x: yatirimPanel.x + yatirimPanel.width / 2 - 50,
y: coinTxt.y + 18
});
sellBtn.visible = false;
game.addChild(sellBtn);
coinSellBtns.push(sellBtn);
var sellBtnTxt = new Text2('Sat', {
size: 40,
fill: '#fff'
});
sellBtnTxt.anchor.set(0.5, 0.5);
sellBtnTxt.x = sellBtn.x;
sellBtnTxt.y = sellBtn.y;
sellBtnTxt.visible = false;
game.addChild(sellBtnTxt);
coinSellBtnTxts.push(sellBtnTxt);
// Alım miktarı (sabit 1, artırmak için input yok, mobilde kolaylık için)
// Aradaki süre/label kaldırıldı
coinBuyAmounts[i] = 1;
coinSellAmounts[i] = 1;
}
// --- Mevduat (Deposit) Section removed from Yatırım panel ---
// Paneli kapatmak için bir kapat butonu ekle
// --- Kapat butonu: sağ üstte, %100 büyüklükte, kırmızı çerçeveli ---
var yatirimKapatBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 360,
//{6e} // %50 artırıldı
height: 180,
//{6f} // %50 artırıldı
// Alt orta: panelin alt kenarının ortası, 60px yukarıda
x: yatirimPanel.x,
y: yatirimPanel.y + yatirimPanel.height / 2 - 60,
color: 0xffffff,
borderColor: 0xff2222,
borderWidth: 8
});
yatirimKapatBtn.visible = false;
game.addChild(yatirimKapatBtn);
// Kapat butonu için X simgesi
var yatirimKapatBtnIcon = new Text2("\u2716", {
size: 81,
//{6n} // %50 artırıldı
fill: '#ff2222'
});
yatirimKapatBtnIcon.anchor.set(1, 0.5);
yatirimKapatBtnIcon.x = yatirimKapatBtn.x - 60;
yatirimKapatBtnIcon.y = yatirimKapatBtn.y;
yatirimKapatBtnIcon.visible = false;
game.addChild(yatirimKapatBtnIcon);
var yatirimKapatBtnTxt = new Text2('Kapat', {
size: 96,
//{6q} // %50 artırıldı
fill: '#ff2222'
});
yatirimKapatBtnTxt.anchor.set(0.5, 0.5);
yatirimKapatBtnTxt.x = yatirimKapatBtn.x;
yatirimKapatBtnTxt.y = yatirimKapatBtn.y;
yatirimKapatBtnTxt.visible = false;
game.addChild(yatirimKapatBtnTxt);
// Panel açma
yatirimBtn.down = function (x, y, obj) {
if (newPagePanel && newPagePanel.visible) {
return;
}
if (isSoundOn && LK.getSound) {
var clickSound = LK.getSound('ClickSesi');
if (clickSound) {
clickSound.play();
}
}
yatirimPanel.visible = true;
yatirimTitle.visible = true;
yatirimKapatBtn.visible = true;
yatirimKapatBtnTxt.visible = true;
// --- Ava: Hide only the background elements under the panel area, keep other elements visible ---
if (!yatirimPanel._hiddenBackgrounds) yatirimPanel._hiddenBackgrounds = [];
for (var i = 0; i < game.children.length; i++) {
var child = game.children[i];
if (child && typeof child.visible === "boolean" && child.visible && child !== yatirimPanel && child !== yatirimTitle && child !== yatirimKapatBtn && child !== yatirimKapatBtnTxt && !(child instanceof Text2) && !(child.assetId && child.assetId.indexOf("button") === 0) && typeof child.x === "number" && typeof child.y === "number" && child.x + (child.width || 0) > yatirimPanel.x - yatirimPanel.width / 2 && child.x < yatirimPanel.x + yatirimPanel.width / 2 && child.y + (child.height || 0) > yatirimPanel.y - yatirimPanel.height / 2 && child.y < yatirimPanel.y + yatirimPanel.height / 2) {
child._oldVisible = child.visible;
child.visible = false;
yatirimPanel._hiddenBackgrounds.push(child);
}
}
// Panelin merkezine göre coin paneli elemanlarını hizala
for (var i = 0; i < coinTxts.length; i++) {
// Panelin soluna hizala
coinTxts[i].x = yatirimPanel.x - yatirimPanel.width / 2 + 30;
coinTxts[i].y = yatirimPanel.y - yatirimPanel.height / 2 + 80 + i * 75;
coinPriceTxts[i].x = yatirimPanel.x - yatirimPanel.width / 2 + 210;
coinPriceTxts[i].y = coinTxts[i].y;
coinHoldingTxts[i].x = yatirimPanel.x - yatirimPanel.width / 2 + 370;
coinHoldingTxts[i].y = coinTxts[i].y;
// Al ve Sat butonlarını panelin sağ kenarına hizala (panelin sağ kenarından 180px ve 50px içeride)
coinBuyBtns[i].x = yatirimPanel.x + yatirimPanel.width / 2 - 180;
coinBuyBtns[i].y = coinTxts[i].y + 18;
coinSellBtns[i].x = yatirimPanel.x + yatirimPanel.width / 2 - 50;
coinSellBtns[i].y = coinTxts[i].y + 18;
coinBuyBtnTxts[i].x = coinBuyBtns[i].x;
coinBuyBtnTxts[i].y = coinBuyBtns[i].y;
coinSellBtnTxts[i].x = coinSellBtns[i].x;
coinSellBtnTxts[i].y = coinSellBtns[i].y;
coinTxts[i].visible = true;
coinPriceTxts[i].visible = true;
coinHoldingTxts[i].visible = true;
coinBuyBtns[i].visible = true;
coinSellBtns[i].visible = true;
coinBuyBtnTxts[i].visible = true;
coinSellBtnTxts[i].visible = true;
}
// Kapat butonunu panelin alt kenarının ortasına hizala
yatirimKapatBtn.x = yatirimPanel.x;
yatirimKapatBtn.y = yatirimPanel.y + yatirimPanel.height / 2 - 60;
yatirimKapatBtnTxt.x = yatirimKapatBtn.x;
yatirimKapatBtnTxt.y = yatirimKapatBtn.y;
yatirimTitle.x = yatirimPanel.x;
yatirimTitle.y = yatirimPanel.y - yatirimPanel.height / 2 + 20;
updateCoinPanel();
// Panel ve içeriğini en öne getir
if (game.setChildIndex) {
// Panel ve tüm içeriğini en öne getir (butonlar dahil)
game.setChildIndex(yatirimPanel, game.children.length - 1);
game.setChildIndex(yatirimTitle, game.children.length - 1);
// Kapat butonu ve X simgesi ve yazısı en önde
game.setChildIndex(yatirimKapatBtn, game.children.length - 1);
game.setChildIndex(yatirimKapatBtnTxt, game.children.length - 1);
if (typeof yatirimKapatBtnIcon !== "undefined") {
game.setChildIndex(yatirimKapatBtnIcon, game.children.length - 1);
}
for (var i = 0; i < coinTxts.length; i++) {
game.setChildIndex(coinTxts[i], game.children.length - 1);
game.setChildIndex(coinPriceTxts[i], game.children.length - 1);
game.setChildIndex(coinHoldingTxts[i], game.children.length - 1);
game.setChildIndex(coinBuyBtns[i], game.children.length - 1);
game.setChildIndex(coinSellBtns[i], game.children.length - 1);
game.setChildIndex(coinBuyBtnTxts[i], game.children.length - 1);
game.setChildIndex(coinSellBtnTxts[i], game.children.length - 1);
}
}
};
// Panel kapama
yatirimKapatBtn.down = function (x, y, obj) {
yatirimPanel.visible = false;
yatirimTitle.visible = false;
yatirimKapatBtn.visible = false;
yatirimKapatBtnTxt.visible = false;
// --- Ava: Restore background elements hidden under the panel area ---
if (yatirimPanel._hiddenBackgrounds && yatirimPanel._hiddenBackgrounds.length) {
for (var i = 0; i < yatirimPanel._hiddenBackgrounds.length; i++) {
var child = yatirimPanel._hiddenBackgrounds[i];
if (child && typeof child.visible === "boolean") {
if (typeof child._oldVisible !== "undefined") {
child.visible = child._oldVisible;
delete child._oldVisible;
} else {
child.visible = true;
}
}
}
yatirimPanel._hiddenBackgrounds = [];
}
// Show all homepage buttons/UI
if (typeof magazaBtn !== "undefined") {
magazaBtn.visible = true;
}
if (typeof magazaBtnTxt !== "undefined") {
magazaBtnTxt.visible = true;
}
if (typeof yatirimBtn !== "undefined") {
yatirimBtn.visible = true;
}
if (typeof yatirimBtnTxt !== "undefined") {
yatirimBtnTxt.visible = true;
}
if (typeof bankBtn !== "undefined") {
bankBtn.visible = true;
}
if (typeof bankBtnTxt !== "undefined") {
bankBtnTxt.visible = true;
}
if (typeof soundBtn !== "undefined") {
soundBtn.visible = true;
}
if (typeof soundBtnTxt !== "undefined") {
soundBtnTxt.visible = true;
}
// Restore Çalışanlar and Madenler buttons and images when Yatırım panel closes
if (typeof madenlerBtn !== "undefined") {
madenlerBtn.visible = true;
}
if (typeof madenlerBtnTxt !== "undefined") {
madenlerBtnTxt.visible = true;
}
if (typeof madenlerBtnMineImg !== "undefined") {
madenlerBtnMineImg.visible = true;
}
if (typeof newPageBtn !== "undefined") {
newPageBtn.visible = true;
}
if (typeof newPageBtnTxt !== "undefined") {
newPageBtnTxt.visible = true;
}
if (typeof calisanlarBtnImg !== "undefined") {
calisanlarBtnImg.visible = true;
}
if (typeof newPageBtn !== "undefined") {
newPageBtn.visible = true;
}
if (typeof newPageBtnTxt !== "undefined") {
newPageBtnTxt.visible = true;
}
if (typeof madenlerBtn !== "undefined") {
madenlerBtn.visible = true;
}
if (typeof madenlerBtnTxt !== "undefined") {
madenlerBtnTxt.visible = true;
}
if (typeof languagesBtn !== "undefined") {
languagesBtn.visible = true;
}
if (typeof languagesBtnTxt !== "undefined") {
languagesBtnTxt.visible = true;
}
// Info and How To Play buttons are never shown
// Show Borç Öde button again when Yatırım panel is closed
if (typeof borcOdeBtn !== "undefined") {
borcOdeBtn.visible = true;
}
if (typeof borcOdeBtnTxt !== "undefined") {
borcOdeBtnTxt.visible = true;
}
for (var i = 0; i < coinTxts.length; i++) {
coinTxts[i].visible = false;
coinPriceTxts[i].visible = false;
coinHoldingTxts[i].visible = false;
coinBuyBtns[i].visible = false;
coinSellBtns[i].visible = false;
coinBuyBtnTxts[i].visible = false;
coinSellBtnTxts[i].visible = false;
}
};
// Coin panelini güncelle
function updateCoinPanel() {
for (var i = 0; i < coinList.length; i++) {
coinPriceTxts[i].setText("₺" + coinPrices[i]);
// Ortalama maliyet gösterimi
if (coinHoldings[i] > 0) {
coinHoldingTxts[i].setText("Adet: " + coinHoldings[i] + "\nMaliyet: ₺" + Math.round(coinAvgCost[i]));
} else {
coinHoldingTxts[i].setText("Adet: 0");
}
}
}
// Bakiye detayları için global değişkenler
var toplamCoinAlim = 0;
var toplamCoinSatisGeliri = 0;
var toplamBorcOdeme = 0;
var toplamYatirimHarcamasi = 0;
var toplamFabrikaYukseltme = 0;
var toplamMadenYukseltme = 0;
var toplamStoreYukseltme = 0;
var toplamInternetTeklifHarcamasi = 0;
var toplamTopluSatisGeliri = 0;
var toplamMusteriSatisGeliri = 0;
// Coin alım-satım butonları
for (var i = 0; i < coinList.length; i++) {
// Al
coinBuyBtns[i].down = function (idx) {
return function (x, y, obj) {
var adet = coinBuyAmounts[idx];
var tutar = coinPrices[idx] * adet;
if (money >= tutar) {
money -= tutar;
toplamCoinAlim += tutar;
// Ortalama maliyet ve toplam maliyet güncelle
coinTotalCost[idx] += tutar;
coinHoldings[idx] += adet;
coinAvgCost[idx] = coinHoldings[idx] > 0 ? coinTotalCost[idx] / coinHoldings[idx] : 0;
updateMoneyText();
updateCoinPanel();
// Buton animasyonu
if (isSoundOn && LK.getSound) {
var clickSound = LK.getSound('ClickSesi');
if (clickSound) {
clickSound.play();
}
}
tween(coinBuyBtns[idx], {
scaleX: 1.15,
scaleY: 1.15
}, {
duration: 80,
onFinish: function onFinish() {
tween(coinBuyBtns[idx], {
scaleX: 1,
scaleY: 1
}, {
duration: 80
});
}
});
} else {
// Yetersiz bakiye animasyonu
if (isSoundOn && LK.getSound) {
var clickSound = LK.getSound('ClickSesi');
if (clickSound) {
clickSound.play();
}
}
tween(coinBuyBtns[idx], {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(coinBuyBtns[idx], {
tint: 0x222222
}, {
duration: 120
});
}
});
}
};
}(i);
// Sat
coinSellBtns[i].down = function (idx) {
return function (x, y, obj) {
var adet = coinSellAmounts[idx];
// Zararına satış aktif: coinHoldings >= adet ise, maliyet bakılmaksızın satış yapılır
if (coinHoldings[idx] >= adet) {
var tutar = coinPrices[idx] * adet;
toplamCoinSatisGeliri += tutar;
// Satışta ortalama maliyeti azalt (FIFO: en basit haliyle, toplam maliyetten orantılı azalt)
if (coinHoldings[idx] > 0) {
var costPer = coinAvgCost[idx];
coinTotalCost[idx] -= costPer * adet;
if (coinTotalCost[idx] < 0) {
coinTotalCost[idx] = 0;
}
}
coinHoldings[idx] -= adet;
if (coinHoldings[idx] > 0) {
coinAvgCost[idx] = coinTotalCost[idx] / coinHoldings[idx];
} else {
coinAvgCost[idx] = 0;
coinTotalCost[idx] = 0;
}
money += tutar;
updateMoneyText();
updateCoinPanel();
// Buton animasyonu
if (isSoundOn && LK.getSound) {
var clickSound = LK.getSound('ClickSesi');
if (clickSound) {
clickSound.play();
}
}
tween(coinSellBtns[idx], {
scaleX: 1.15,
scaleY: 1.15
}, {
duration: 80,
onFinish: function onFinish() {
tween(coinSellBtns[idx], {
scaleX: 1,
scaleY: 1
}, {
duration: 80
});
}
});
// Satış işlemi anında gerçekleşir, bekleme süresi yok.
} else {
// Yetersiz coin animasyonu
if (isSoundOn && LK.getSound) {
var clickSound = LK.getSound('ClickSesi');
if (clickSound) {
clickSound.play();
}
}
tween(coinSellBtns[idx], {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(coinSellBtns[idx], {
tint: 0x222222
}, {
duration: 120
});
}
});
}
};
}(i);
}
// Coin fiyatları başlangıç fiyatından maksimum %10 yükselip düşebilir, rastgele değişim uygula (her 2 saniyede bir)
var coinBasePrices = [];
for (var i = 0; i < coinList.length; i++) {
// Başlangıç fiyatlarını coinPrices oluşturulurkenki ile aynı şekilde ata
var base = 1000000;
if (i === 1) {
base = 50000;
} else if (i > 1) {
base = 10000 - i * 900;
}
coinBasePrices[i] = base;
}
// Her 40 saniyede bir coin fiyatlarını güncelle (2 saniyeden 40 saniyeye çıkarıldı, %95 yavaşlatıldı)
LK.setInterval(function () {
for (var i = 0; i < coinPrices.length; i++) {
// Rastgele -%2.5 ile +%2.5 arası değişim uygula
var degisim = 1 + (Math.random() * 0.05 - 0.025);
var yeniFiyat = coinPrices[i] * degisim;
// Sınırları uygula: min %10 düşüş, max %10 artış
var minFiyat = Math.floor(coinBasePrices[i] * 0.9);
var maxFiyat = Math.ceil(coinBasePrices[i] * 1.1);
if (yeniFiyat < minFiyat) {
yeniFiyat = minFiyat;
}
if (yeniFiyat > maxFiyat) {
yeniFiyat = maxFiyat;
}
coinPrices[i] = Math.floor(yeniFiyat);
}
updateCoinPanel();
}, 2400); // 40 saniye (60fps * 40)
function updateMoneyText() {
moneyTxt.setText('₺' + money);
updateBorcText && updateBorcText();
if (magazaMuhasebeText && magazaMuhasebeText.visible) {
updateMagazaMuhasebeText();
}
// Bakiye detaylarını güncelleme kodu kaldırıldı.
}
// --- Banka Button & Borç Logic ---
var bankBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 180,
height: 70
});
bankBtn.x = moneyTxt.x + 220;
bankBtn.y = 40;
LK.gui.top.addChild(bankBtn);
// --- Sound Toggle Icon Button ---
// Use a simple colored box as icon: green for sound on, red for sound off
var soundOnColor = 0x83de44;
var soundOffColor = 0xd83318;
// Sound button is created after languagesBtn to ensure languagesBtn is defined
// Ava: Move soundBtn and soundBtnTxt creation after languagesBtn to fix undefined errors and ensure correct button order
// (Moved below languagesBtn and languagesBtnTxt creation)
var bankBtnTxt = new Text2('%10 Borç Al', {
size: 36,
fill: '#fff'
});
bankBtnTxt.anchor.set(0.5, 0.5);
bankBtnTxt.x = bankBtn.x;
bankBtnTxt.y = bankBtn.y;
LK.gui.top.addChild(bankBtnTxt);
var borc = 0;
var borcTxt = new Text2('', {
size: 32,
fill: '#ffb'
});
borcTxt.anchor.set(0.5, 0);
borcTxt.x = moneyTxt.x + 420;
borcTxt.y = 10;
LK.gui.top.addChild(borcTxt);
// Borç Öde button
var borcOdeBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 140,
height: 54
});
borcOdeBtn.x = borcTxt.x + 180;
borcOdeBtn.y = borcTxt.y + 28;
LK.gui.top.addChild(borcOdeBtn);
var borcOdeBtnTxt = new Text2('Borç Öde', {
size: 28,
fill: '#fff'
});
borcOdeBtnTxt.anchor.set(0.5, 0.5);
borcOdeBtnTxt.x = borcOdeBtn.x;
borcOdeBtnTxt.y = borcOdeBtn.y;
LK.gui.top.addChild(borcOdeBtnTxt);
// --- Mağazalar Button below Borç Öde button ---
// Mevduat butonu ve paneli tamamen kaldırıldı
// --- Mağazalar Panel (initially hidden) ---
var magazalarPanelWidth = Math.floor(panelWidth * 0.9);
var magazalarPanelHeight = Math.floor(panelHeight * 0.9);
var magazalarPanelX = Math.floor((2048 - magazalarPanelWidth) / 2);
var magazalarPanelY = Math.floor((2732 - magazalarPanelHeight) / 2);
var magazalarPanel = LK.getAsset('button', {
anchorX: 0,
anchorY: 0,
width: magazalarPanelWidth,
height: magazalarPanelHeight,
x: magazalarPanelX,
y: magazalarPanelY
});
magazalarPanel.visible = false;
game.addChild(magazalarPanel);
var magazalarPanelTitle = new Text2('Mağazalar', {
size: 36,
fill: '#fff'
});
magazalarPanelTitle.anchor.set(0.5, 0);
magazalarPanelTitle.x = 2048 / 2;
magazalarPanelTitle.y = magazalarPanelY + 40;
magazalarPanelTitle.visible = false;
game.addChild(magazalarPanelTitle);
var magazalarPanelText = new Text2('Tüm mağazalar ve müşteriler burada görüntülenir.', {
size: 36,
fill: '#bff',
lineHeight: 44
});
magazalarPanelText.anchor.set(0.5, 0);
magazalarPanelText.x = 2048 / 2;
magazalarPanelText.y = magazalarPanelTitle.y + magazalarPanelTitle.height + 10;
magazalarPanelText.visible = false;
game.addChild(magazalarPanelText);
// Kapat butonu
var magazalarKapatBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 360,
//{aG} // %50 artırıldı
height: 180,
//{aH} // %50 artırıldı
// Alt orta: panelin alt kenarının ortası, 60px yukarıda
x: magazalarPanel.x + magazalarPanel.width / 2,
y: magazalarPanel.y + magazalarPanel.height - 60,
color: 0xffffff,
borderColor: 0xff2222,
borderWidth: 8
});
magazalarKapatBtn.visible = false;
game.addChild(magazalarKapatBtn);
var magazalarKapatBtnIcon = new Text2("\u2716", {
size: 81,
//{aO} // %50 artırıldı
fill: '#ff2222'
});
magazalarKapatBtnIcon.anchor.set(1, 0.5);
magazalarKapatBtnIcon.x = magazalarKapatBtn.x - 60;
magazalarKapatBtnIcon.y = magazalarKapatBtn.y;
magazalarKapatBtnIcon.visible = false;
game.addChild(magazalarKapatBtnIcon);
var magazalarKapatBtnTxt = new Text2('Kapat', {
size: 96,
//{aS} // %50 artırıldı
fill: '#ff2222'
});
magazalarKapatBtnTxt.anchor.set(0.5, 0.5);
magazalarKapatBtnTxt.x = magazalarKapatBtn.x;
magazalarKapatBtnTxt.y = magazalarKapatBtn.y;
magazalarKapatBtnTxt.visible = false;
game.addChild(magazalarKapatBtnTxt);
// --- Move both stores and their customers to the Mağazalar panel ---
function showMagazalarPanel() {
magazalarPanel.visible = true;
magazalarPanelTitle.visible = true;
magazalarPanelText.visible = true;
magazalarKapatBtn.visible = true;
magazalarKapatBtnIcon.visible = true;
magazalarKapatBtnTxt.visible = true;
// Hide all homepage buttons/UI
if (typeof magazaBtn !== "undefined") {
magazaBtn.visible = false;
}
if (typeof magazaBtnTxt !== "undefined") {
magazaBtnTxt.visible = false;
}
if (typeof yatirimBtn !== "undefined") {
yatirimBtn.visible = false;
}
if (typeof yatirimBtnTxt !== "undefined") {
yatirimBtnTxt.visible = false;
}
if (typeof bankBtn !== "undefined") {
bankBtn.visible = false;
}
if (typeof bankBtnTxt !== "undefined") {
bankBtnTxt.visible = false;
}
if (typeof soundBtn !== "undefined") {
soundBtn.visible = false;
}
if (typeof soundBtnTxt !== "undefined") {
soundBtnTxt.visible = false;
}
if (typeof newPageBtn !== "undefined") {
newPageBtn.visible = false;
}
if (typeof newPageBtnTxt !== "undefined") {
newPageBtnTxt.visible = false;
}
if (typeof madenlerBtn !== "undefined") {
madenlerBtn.visible = false;
}
if (typeof madenlerBtnTxt !== "undefined") {
madenlerBtnTxt.visible = false;
}
if (typeof magazalarBtn !== "undefined") {
magazalarBtn.visible = false;
}
if (typeof magazalarBtnTxt !== "undefined") {
magazalarBtnTxt.visible = false;
}
if (typeof languagesBtn !== "undefined") {
languagesBtn.visible = false;
}
if (typeof languagesBtnTxt !== "undefined") {
languagesBtnTxt.visible = false;
}
if (typeof infoBtn !== "undefined") {
infoBtn.visible = false;
}
if (typeof infoBtnTxt !== "undefined") {
infoBtnTxt.visible = false;
}
if (typeof howToBtn !== "undefined") {
howToBtn.visible = false;
}
if (typeof howToBtnTxt !== "undefined") {
howToBtnTxt.visible = false;
}
if (typeof borcOdeBtn !== "undefined") {
borcOdeBtn.visible = false;
}
if (typeof borcOdeBtnTxt !== "undefined") {
borcOdeBtnTxt.visible = false;
}
if (typeof mevduatBtn !== "undefined") {
mevduatBtn.visible = false;
}
if (typeof mevduatBtnTxt !== "undefined") {
mevduatBtnTxt.visible = false;
}
// Prevent hiding store purchase buttons on homepage when Mağazalar panel opens
if (typeof store2PurchaseBtn !== "undefined") {
store2PurchaseBtn.visible = !store2Purchased;
}
if (typeof store2PurchaseBtnTxt !== "undefined" && store2PurchaseBtnTxt && typeof store2PurchaseBtnTxt.visible === "boolean") {
store2PurchaseBtnTxt.visible = !store2Purchased;
}
if (typeof store3PurchaseBtn !== "undefined") {
store3PurchaseBtn.visible = !store3Purchased;
}
if (typeof store3PurchaseBtnTxt !== "undefined") {
store3PurchaseBtnTxt.visible = !store3Purchased;
}
if (typeof store3PurchaseBtnIcon !== "undefined") {
store3PurchaseBtnIcon.visible = !store3Purchased;
}
if (typeof store4PurchaseBtn !== "undefined") {
store4PurchaseBtn.visible = !store4Purchased;
}
if (typeof store4PurchaseBtnTxt !== "undefined") {
store4PurchaseBtnTxt.visible = !store4Purchased;
}
if (typeof store4PurchaseBtnIcon !== "undefined") {
store4PurchaseBtnIcon.visible = !store4Purchased;
}
// Show all store purchase buttons (store2, store3, store4) and bring them to front when Mağazalar panel opens
if (typeof store2PurchaseBtn !== "undefined" && typeof store2PurchaseBtnTxt !== "undefined") {
if (typeof store2PurchaseBtn !== "undefined" && store2PurchaseBtn) {
store2PurchaseBtn.visible = !store2Purchased;
}
if (typeof store2PurchaseBtnTxt !== "undefined" && store2PurchaseBtnTxt) {
store2PurchaseBtnTxt.visible = !store2Purchased;
}
if (game.setChildIndex) {
game.setChildIndex(store2PurchaseBtn, game.children.length - 1);
game.setChildIndex(store2PurchaseBtnTxt, game.children.length - 1);
}
}
if (typeof store3PurchaseBtn !== "undefined" && typeof store3PurchaseBtnTxt !== "undefined") {
store3PurchaseBtn.visible = !store3Purchased;
store3PurchaseBtnTxt.visible = !store3Purchased;
if (typeof store3PurchaseBtnIcon !== "undefined") {
store3PurchaseBtnIcon.visible = !store3Purchased;
}
// Ensure button and text are brought to front
if (game.setChildIndex) {
game.setChildIndex(store3PurchaseBtn, game.children.length - 1);
game.setChildIndex(store3PurchaseBtnTxt, game.children.length - 1);
if (typeof store3PurchaseBtnIcon !== "undefined") {
game.setChildIndex(store3PurchaseBtnIcon, game.children.length - 1);
}
}
}
if (typeof store4PurchaseBtn !== "undefined" && typeof store4PurchaseBtnTxt !== "undefined") {
store4PurchaseBtn.visible = !store4Purchased;
store4PurchaseBtnTxt.visible = !store4Purchased;
if (typeof store4PurchaseBtnIcon !== "undefined") {
store4PurchaseBtnIcon.visible = !store4Purchased;
}
// Ensure button and text are brought to front
if (game.setChildIndex) {
game.setChildIndex(store4PurchaseBtn, game.children.length - 1);
game.setChildIndex(store4PurchaseBtnTxt, game.children.length - 1);
if (typeof store4PurchaseBtnIcon !== "undefined") {
game.setChildIndex(store4PurchaseBtnIcon, game.children.length - 1);
}
}
}
// --- Mağazalar panelinde 2'li sıra halinde alt alta ve ortalı hizalama ---
// Grid ayarları
var storeCols = 2;
var storeRows = 2;
var storeCellWidth = magazalarPanel.width / storeCols;
var storeCellHeight = magazalarPanel.height / 3.5; // 3.5 ile daha sıkışık, 4 ile daha geniş
var storeStartX = magazalarPanel.x + storeCellWidth / 2;
var storeStartY = magazalarPanelText.y + magazalarPanelText.height + 60 + storeCellHeight; // Başlık ve açıklama altı, 1 satır aşağı kaydırıldı
// Mağazaları ve butonları gridde sırala
var storeList = [store, store2, store3, store4];
var storeBtnList = [storeBtn, store2Btn, store3Btn, store4Btn];
var storeBtnTxtList = [storeBtnTxt, store2BtnTxt, store3BtnTxt, store4BtnTxt];
var storePurchaseBtnList = [null, store2PurchaseBtn, store3PurchaseBtn, store4PurchaseBtn];
var storePurchaseBtnTxtList = [null, store2PurchaseBtnTxt, store3PurchaseBtnTxt, store4PurchaseBtnTxt];
var storePurchasedList = [true, store2Purchased, store3Purchased, store4Purchased];
for (var i = 0; i < 4; i++) {
var row = Math.floor(i / storeCols);
var col = i % storeCols;
var cx = storeStartX + col * storeCellWidth;
var cy = storeStartY + row * storeCellHeight;
// Mağaza görseli
if (typeof storeList[i] !== "undefined") {
storeList[i].x = cx;
storeList[i].y = cy;
storeList[i].visible = true;
game.setChildIndex(storeList[i], game.children.length - 1);
}
// Seviye yazısı (her mağaza için)
var levelTxt = null;
if (typeof storeList[i] !== "undefined" && typeof storeList[i].children !== "undefined") {
for (var ch = 0; ch < storeList[i].children.length; ch++) {
if (storeList[i].children[ch] && typeof storeList[i].children[ch].setText === "function" && storeList[i].children[ch].getText && (storeList[i].children[ch].getText() + "").indexOf("Lv.") === 0) {
levelTxt = storeList[i].children[ch];
break;
}
}
}
var levelY = cy + 90;
if (levelTxt) {
levelTxt.x = cx;
levelTxt.y = levelY;
}
// Yükseltme butonu (her mağaza için) -- seviye yazısının altına hizala
if (typeof storeBtnList[i] !== "undefined") {
storeBtnList[i].x = cx;
storeBtnList[i].y = levelY + 60;
// Sadece satın alındıysa göster
storeBtnList[i].visible = i === 0 ? true : !!storePurchasedList[i];
if (game.setChildIndex) {
game.setChildIndex(storeBtnList[i], game.children.length - 1);
}
}
if (typeof storeBtnTxtList[i] !== "undefined") {
storeBtnTxtList[i].x = cx;
storeBtnTxtList[i].y = levelY + 80;
storeBtnTxtList[i].visible = i === 0 ? true : !!storePurchasedList[i];
if (game.setChildIndex) {
game.setChildIndex(storeBtnTxtList[i], game.children.length - 1);
}
}
// Satın al butonu (store2, store3, store4) -- seviye yazısının altına hizala
if (i > 0 && typeof storePurchaseBtnList[i] !== "undefined" && typeof storePurchaseBtnTxtList[i] !== "undefined") {
storePurchaseBtnList[i].x = cx;
storePurchaseBtnList[i].y = levelY + 120;
storePurchaseBtnTxtList[i].x = cx;
storePurchaseBtnTxtList[i].y = levelY + 140;
// Defensive: always set visible based on purchase state
if (i === 2) {
// Store3
storePurchaseBtnList[i].visible = !store3Purchased;
storePurchaseBtnTxtList[i].visible = !store3Purchased;
if (typeof store3PurchaseBtnIcon !== "undefined") {
store3PurchaseBtnIcon.visible = !store3Purchased;
}
} else if (i === 3) {
// Store4
storePurchaseBtnList[i].visible = !store4Purchased;
storePurchaseBtnTxtList[i].visible = !store4Purchased;
if (typeof store4PurchaseBtnIcon !== "undefined") {
store4PurchaseBtnIcon.visible = !store4Purchased;
}
} else {
storePurchaseBtnList[i].visible = !storePurchasedList[i];
storePurchaseBtnTxtList[i].visible = !storePurchasedList[i];
}
if (game.setChildIndex) {
game.setChildIndex(storePurchaseBtnList[i], game.children.length - 1);
game.setChildIndex(storePurchaseBtnTxtList[i], game.children.length - 1);
}
}
}
// --- Ava: Bring Store3 and Store4 purchase buttons and icons to the very front above overlay and panel when Mağazalar panel opens ---
if (game.setChildIndex) {
// First, bring panel to front
game.setChildIndex(magazalarPanel, game.children.length - 1);
// Then, bring Store3 and Store4 purchase buttons, their texts, and icons to the very front
if (typeof store3PurchaseBtn !== "undefined") {
game.setChildIndex(store3PurchaseBtn, game.children.length - 1);
}
if (typeof store3PurchaseBtnIcon !== "undefined") {
game.setChildIndex(store3PurchaseBtnIcon, game.children.length - 1);
}
if (typeof store3PurchaseBtnTxt !== "undefined") {
game.setChildIndex(store3PurchaseBtnTxt, game.children.length - 1);
}
if (typeof store4PurchaseBtn !== "undefined") {
game.setChildIndex(store4PurchaseBtn, game.children.length - 1);
}
if (typeof store4PurchaseBtnIcon !== "undefined") {
game.setChildIndex(store4PurchaseBtnIcon, game.children.length - 1);
}
if (typeof store4PurchaseBtnTxt !== "undefined") {
game.setChildIndex(store4PurchaseBtnTxt, game.children.length - 1);
}
}
// Bring panel and its content to front
if (game.setChildIndex) {
game.setChildIndex(magazalarPanel, game.children.length - 1);
game.setChildIndex(magazalarPanelTitle, game.children.length - 1);
game.setChildIndex(magazalarPanelText, game.children.length - 1);
// Kapat butonu ve X simgesi ve yazısı en önde
game.setChildIndex(magazalarKapatBtn, game.children.length - 1);
game.setChildIndex(magazalarKapatBtnIcon, game.children.length - 1);
game.setChildIndex(magazalarKapatBtnTxt, game.children.length - 1);
if (typeof store !== "undefined") {
game.setChildIndex(store, game.children.length - 1);
}
if (typeof store2 !== "undefined") {
game.setChildIndex(store2, game.children.length - 1);
}
if (typeof store3 !== "undefined") {
game.setChildIndex(store3, game.children.length - 1);
}
if (typeof store4 !== "undefined") {
game.setChildIndex(store4, game.children.length - 1);
}
if (typeof storeBtn !== "undefined") {
game.setChildIndex(storeBtn, game.children.length - 1);
}
if (typeof storeBtnTxt !== "undefined") {
game.setChildIndex(storeBtnTxt, game.children.length - 1);
}
if (typeof store2Btn !== "undefined") {
game.setChildIndex(store2Btn, game.children.length - 1);
}
if (typeof store2BtnTxt !== "undefined") {
game.setChildIndex(store2BtnTxt, game.children.length - 1);
}
if (typeof store2PurchaseBtn !== "undefined") {
game.setChildIndex(store2PurchaseBtn, game.children.length - 1);
}
if (typeof store2PurchaseBtnTxt !== "undefined") {
game.setChildIndex(store2PurchaseBtnTxt, game.children.length - 1);
}
if (typeof store3Btn !== "undefined") {
game.setChildIndex(store3Btn, game.children.length - 1);
}
if (typeof store3BtnTxt !== "undefined") {
game.setChildIndex(store3BtnTxt, game.children.length - 1);
}
if (typeof store4Btn !== "undefined") {
game.setChildIndex(store4Btn, game.children.length - 1);
}
if (typeof store4BtnTxt !== "undefined") {
game.setChildIndex(store4BtnTxt, game.children.length - 1);
}
// Customer logic removed: no customers to bring to front.
}
}
// Show panel on button press
// Mağazalar butonu event handler'ları kaldırıldı
// Kapat butonu logic
magazalarKapatBtn.down = function (x, y, obj) {
magazalarPanel.visible = false;
magazalarPanelTitle.visible = false;
magazalarPanelText.visible = false;
magazalarKapatBtn.visible = false;
magazalarKapatBtnIcon.visible = false;
magazalarKapatBtnTxt.visible = false;
// Restore all homepage buttons/UI
if (typeof magazaBtn !== "undefined") {
magazaBtn.visible = true;
}
if (typeof magazaBtnTxt !== "undefined") {
magazaBtnTxt.visible = true;
}
if (typeof yatirimBtn !== "undefined") {
yatirimBtn.visible = true;
}
if (typeof yatirimBtnTxt !== "undefined") {
yatirimBtnTxt.visible = true;
}
if (typeof bankBtn !== "undefined") {
bankBtn.visible = true;
}
if (typeof bankBtnTxt !== "undefined") {
bankBtnTxt.visible = true;
}
if (typeof soundBtn !== "undefined") {
soundBtn.visible = true;
}
if (typeof soundBtnTxt !== "undefined") {
soundBtnTxt.visible = true;
}
if (typeof newPageBtn !== "undefined") {
newPageBtn.visible = true;
}
if (typeof newPageBtnTxt !== "undefined") {
newPageBtnTxt.visible = true;
}
if (typeof madenlerBtn !== "undefined") {
madenlerBtn.visible = true;
}
if (typeof madenlerBtnTxt !== "undefined") {
madenlerBtnTxt.visible = true;
}
if (typeof magazalarBtn !== "undefined") {
magazalarBtn.visible = true;
}
if (typeof magazalarBtnTxt !== "undefined") {
magazalarBtnTxt.visible = true;
}
if (typeof languagesBtn !== "undefined") {
languagesBtn.visible = true;
}
if (typeof languagesBtnTxt !== "undefined") {
languagesBtnTxt.visible = true;
}
// Info and How To Play buttons are never shown
if (typeof borcOdeBtn !== "undefined") {
borcOdeBtn.visible = true;
}
if (typeof borcOdeBtnTxt !== "undefined") {
borcOdeBtnTxt.visible = true;
}
if (typeof mevduatBtn !== "undefined") {
mevduatBtn.visible = true;
}
if (typeof mevduatBtnTxt !== "undefined") {
mevduatBtnTxt.visible = true;
}
// Move stores and customers back to their original positions
if (typeof store !== "undefined") {
store.x = 1850;
store.y = 600;
store.visible = true; // Anasayfa'da mağazaları göster
store2.visible = true; // Anasayfa'da mağazaları göster
store3.visible = true; // Anasayfa'da mağazaları göster
store4.visible = true; // Anasayfa'da mağazaları göster
store2.visible = true;
store3.visible = true;
if (typeof store4 !== "undefined") {
store4.visible = true;
}
}
if (typeof store2 !== "undefined") {
store2.x = 1850;
store2.y = 950;
store2.visible = true;
}
if (typeof store !== "undefined") {
store.x = 1850;
store.y = 600;
store.visible = true;
}
if (typeof store3 !== "undefined") {
store3.x = 1850;
store3.y = 1300;
store3.visible = true;
}
if (typeof store4 !== "undefined") {
store4.x = 1850;
store4.y = 1650;
store4.visible = true;
}
// Customer logic removed: no customers to reposition on Mağazalar panel close.
};
// --- Mevduat paneli ve tüm ilgili UI/logic tamamen kaldırıldı ---
// --- New Page Button below Banka button ---
var newPageBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 140,
height: 54
});
// --- Madenler butonunu bağımsız olarak konumlandır (Çalışanlar ile bağlantı yok) ---
if (typeof madenlerBtn !== "undefined" && madenlerBtn) {
// Borç öde butonunun altına, kendi sabit bir konuma yerleştir
var madenlerBtnGapY = 20;
madenlerBtn.x = borcOdeBtn.x;
madenlerBtn.y = borcOdeBtn.y + borcOdeBtn.height / 2 + madenlerBtnGapY + madenlerBtn.height / 2;
if (typeof madenlerBtnTxt !== "undefined") {
madenlerBtnTxt.x = madenlerBtn.x;
madenlerBtnTxt.y = madenlerBtn.y;
}
if (typeof madenlerBtnMineImg !== "undefined") {
madenlerBtnMineImg.x = madenlerBtn.x;
madenlerBtnMineImg.y = madenlerBtn.y + madenlerBtn.height / 2 + 10;
}
}
// Sıralama: önce Madenler butonu ve resmi, sonra Çalışanlar butonu ve resmi
if (typeof LK !== "undefined" && LK.gui && LK.gui.top) {
LK.gui.top.addChild(madenlerBtn);
LK.gui.top.addChild(madenlerBtnTxt);
LK.gui.top.addChild(madenlerBtnMineImg);
// Çalışanlar (newPageBtn) bağımsız olarak konumlandırılıyor
// Borç öde butonunun altına, kendi sabit bir konuma yerleştir
var calisanlarBtnGapY = 20;
var calisanlarBtnWidth = 140,
calisanlarBtnHeight = 54;
newPageBtn.x = borcOdeBtn.x;
// Move 4 rows lower: each row is (calisanlarBtnHeight + calisanlarBtnGapY) px
newPageBtn.y = borcOdeBtn.y + borcOdeBtn.height / 2 + (calisanlarBtnGapY + calisanlarBtnHeight) * 4 + calisanlarBtnHeight / 2;
// Define newPageBtnTxt before adding it to LK.gui.top
var newPageBtnTxt = new Text2('Çalışanlar', {
size: 28,
fill: '#fff'
});
newPageBtnTxt.anchor.set(0.5, 0.5);
newPageBtnTxt.x = newPageBtn.x;
newPageBtnTxt.y = newPageBtn.y;
LK.gui.top.addChild(newPageBtn);
LK.gui.top.addChild(newPageBtnTxt);
// Define calisanlarBtnImg before adding it to LK.gui.top
var calisanlarBtnImg = LK.getAsset('worker1', {
anchorX: 0.5,
anchorY: 0,
width: 125,
height: 125,
x: newPageBtn.x,
y: newPageBtn.y + calisanlarBtnHeight / 2 + 10
});
LK.gui.top.addChild(calisanlarBtnImg);
// Çalışanlar resmine tıklayınca yeni sayfa panelini aç
calisanlarBtnImg.down = function (x, y, obj) {
if (newPagePanel && newPagePanel.visible) {
return;
}
// (fullscreen overlay logic removed)
// --- Ava: Hide all homepage images when Çalışanlar panel opens ---
if (typeof homepageImages === "undefined") {
window.homepageImages = [];
for (var i = 0; i < game.children.length; i++) {
var child = game.children[i];
// Defensive: Only hide images that are not panels, not overlays, not buttons, not Text2, and are visible
if (child && typeof child.visible === "boolean" && child.visible && child !== newPagePanel && child !== newPagePanelTitle && child !== newPagePanelText && child !== newPageKapatBtn && child !== newPageKapatBtnTxt && child !== newPageKapatBtnIcon && child !== newPageKapatBtnTop && child !== newPageKapatBtnTopIcon && child !== newPageKapatBtnTopTxt && !(child instanceof Text2) && !(child.assetId && (child.assetId.indexOf("button") === 0 || child.assetId.indexOf("panel") === 0))) {
window.homepageImages.push(child);
}
}
}
if (window.homepageImages && window.homepageImages.length) {
for (var i = 0; i < window.homepageImages.length; i++) {
if (window.homepageImages[i] && typeof window.homepageImages[i].visible === "boolean") {
window.homepageImages[i]._oldVisible = window.homepageImages[i].visible;
window.homepageImages[i].visible = false;
}
}
}
// Hide both calisanlarBtnImg and madenlerBtnMineImg, and newPageBtn & newPageBtnTxt until panel closes
if (typeof calisanlarBtnImg !== "undefined") calisanlarBtnImg.visible = false;
if (typeof madenlerBtnMineImg !== "undefined") madenlerBtnMineImg.visible = false;
if (typeof newPageBtn !== "undefined") newPageBtn.visible = false;
if (typeof newPageBtnTxt !== "undefined") newPageBtnTxt.visible = false;
if (typeof madenlerBtn !== "undefined") madenlerBtn.visible = false;
if (typeof madenlerBtnTxt !== "undefined") madenlerBtnTxt.visible = false;
newPagePanel.visible = true;
newPagePanelTitle.visible = true;
newPagePanelText.visible = true;
newPageKapatBtn.visible = true;
newPageKapatBtnTxt.visible = true;
// Çalışanları ve altındaki UI'ları göster ve panelde 3'lü sıra halinde alt alta ortala
for (var i = 0; i < workerImages.length; i++) {
var pos = getWorkerPanelPos(i);
workerImages[i].img.x = pos.x;
workerImages[i].img.y = pos.y;
workerImages[i].img.visible = true;
workerImages[i].label.x = pos.x;
workerImages[i].label.y = pos.y + 80;
workerImages[i].label.visible = true;
// Alt açıklama yazılarını alt alta ve hizalı şekilde göster
var baseY = workerImages[i].label.y + workerImages[i].label.height + 8; // label'ın altından 8px boşluk
var lineGap = 8; // satırlar arası boşluk
if (i === 0) {
var y = baseY;
if (worker1LevelTxt) {
worker1LevelTxt.x = pos.x;
worker1LevelTxt.y = y;
worker1LevelTxt.visible = true;
y += worker1LevelTxt.height + lineGap;
}
if (worker1EarningTxt) {
worker1EarningTxt.x = pos.x;
worker1EarningTxt.y = y;
worker1EarningTxt.visible = true;
y += worker1EarningTxt.height + lineGap;
}
if (worker1UpgradeBtn) {
worker1UpgradeBtn.x = pos.x;
worker1UpgradeBtn.y = y + worker1UpgradeBtn.height / 2;
worker1UpgradeBtn.visible = true;
}
if (worker1UpgradeBtnTxt) {
worker1UpgradeBtnTxt.x = pos.x;
worker1UpgradeBtnTxt.y = worker1UpgradeBtn.y;
worker1UpgradeBtnTxt.visible = true;
}
}
if (i === 1) {
var y = baseY;
if (worker2LevelTxt) {
worker2LevelTxt.x = pos.x;
worker2LevelTxt.y = y;
worker2LevelTxt.visible = true;
y += worker2LevelTxt.height + lineGap;
}
if (worker2SpeedTxt) {
worker2SpeedTxt.x = pos.x;
worker2SpeedTxt.y = y;
worker2SpeedTxt.visible = true;
y += worker2SpeedTxt.height + lineGap;
}
if (worker2UpgradeBtn) {
worker2UpgradeBtn.x = pos.x;
worker2UpgradeBtn.y = y + worker2UpgradeBtn.height / 2;
worker2UpgradeBtn.visible = true;
}
if (worker2UpgradeBtnTxt) {
worker2UpgradeBtnTxt.x = pos.x;
worker2UpgradeBtnTxt.y = worker2UpgradeBtn.y;
worker2UpgradeBtnTxt.visible = true;
}
}
if (i === 2) {
var y = baseY;
if (worker3LevelTxt) {
worker3LevelTxt.x = pos.x;
worker3LevelTxt.y = y;
worker3LevelTxt.visible = true;
y += worker3LevelTxt.height + lineGap;
}
if (worker3DiscountTxt) {
worker3DiscountTxt.x = pos.x;
worker3DiscountTxt.y = y;
worker3DiscountTxt.visible = true;
y += worker3DiscountTxt.height + lineGap;
}
if (worker3UpgradeBtn) {
worker3UpgradeBtn.x = pos.x;
worker3UpgradeBtn.y = y + worker3UpgradeBtn.height / 2;
worker3UpgradeBtn.visible = true;
}
if (worker3UpgradeBtnTxt) {
worker3UpgradeBtnTxt.x = pos.x;
worker3UpgradeBtnTxt.y = worker3UpgradeBtn.y;
worker3UpgradeBtnTxt.visible = true;
}
}
if (i === 3) {
var y = baseY;
if (worker4LevelTxt) {
worker4LevelTxt.x = pos.x;
worker4LevelTxt.y = y;
worker4LevelTxt.visible = true;
y += worker4LevelTxt.height + lineGap;
}
if (worker4EarningTxt) {
worker4EarningTxt.x = pos.x;
worker4EarningTxt.y = y;
worker4EarningTxt.visible = true;
y += worker4EarningTxt.height + lineGap;
}
if (worker4UpgradeBtn) {
worker4UpgradeBtn.x = pos.x;
worker4UpgradeBtn.y = y + worker4UpgradeBtn.height / 2;
worker4UpgradeBtn.visible = true;
}
if (worker4UpgradeBtnTxt) {
worker4UpgradeBtnTxt.x = pos.x;
worker4UpgradeBtnTxt.y = worker4UpgradeBtn.y;
worker4UpgradeBtnTxt.visible = true;
}
}
if (i === 4) {
var y = baseY;
if (worker5LevelTxt) {
worker5LevelTxt.x = pos.x;
worker5LevelTxt.y = y;
worker5LevelTxt.visible = true;
y += worker5LevelTxt.height + lineGap;
}
if (worker5BonusTxt) {
worker5BonusTxt.x = pos.x;
worker5BonusTxt.y = y;
worker5BonusTxt.visible = true;
y += worker5BonusTxt.height + lineGap;
}
if (worker5UpgradeBtn) {
worker5UpgradeBtn.x = pos.x;
worker5UpgradeBtn.y = y + worker5UpgradeBtn.height / 2;
worker5UpgradeBtn.visible = true;
}
if (worker5UpgradeBtnTxt) {
worker5UpgradeBtnTxt.x = pos.x;
worker5UpgradeBtnTxt.y = worker5UpgradeBtn.y;
worker5UpgradeBtnTxt.visible = true;
}
}
}
// Paneli en öne getir
if (game.setChildIndex) {
game.setChildIndex(newPagePanel, game.children.length - 1);
game.setChildIndex(newPagePanelTitle, game.children.length - 1);
game.setChildIndex(newPagePanelText, game.children.length - 1);
// Kapat butonu ve X simgesi ve yazısı en önde
game.setChildIndex(newPageKapatBtn, game.children.length - 1);
game.setChildIndex(newPageKapatBtnTxt, game.children.length - 1);
if (typeof newPageKapatBtnIcon !== "undefined") {
game.setChildIndex(newPageKapatBtnIcon, game.children.length - 1);
}
if (typeof newPageKapatBtnTop !== "undefined") game.setChildIndex(newPageKapatBtnTop, game.children.length - 1);
if (typeof newPageKapatBtnTopIcon !== "undefined") game.setChildIndex(newPageKapatBtnTopIcon, game.children.length - 1);
if (typeof newPageKapatBtnTopTxt !== "undefined") game.setChildIndex(newPageKapatBtnTopTxt, game.children.length - 1);
for (var i = 0; i < workerImages.length; i++) {
game.setChildIndex(workerImages[i].img, game.children.length - 1);
game.setChildIndex(workerImages[i].label, game.children.length - 1);
}
if (worker1LevelTxt) {
game.setChildIndex(worker1LevelTxt, game.children.length - 1);
}
if (worker1EarningTxt) {
game.setChildIndex(worker1EarningTxt, game.children.length - 1);
}
if (worker1UpgradeBtn) {
game.setChildIndex(worker1UpgradeBtn, game.children.length - 1);
}
if (worker1UpgradeBtnTxt) {
game.setChildIndex(worker1UpgradeBtnTxt, game.children.length - 1);
}
if (worker2LevelTxt) {
game.setChildIndex(worker2LevelTxt, game.children.length - 1);
}
if (worker2SpeedTxt) {
game.setChildIndex(worker2SpeedTxt, game.children.length - 1);
}
if (worker2UpgradeBtn) {
game.setChildIndex(worker2UpgradeBtn, game.children.length - 1);
}
if (worker2UpgradeBtnTxt) {
game.setChildIndex(worker2UpgradeBtnTxt, game.children.length - 1);
}
if (worker3LevelTxt) {
game.setChildIndex(worker3LevelTxt, game.children.length - 1);
}
if (worker3DiscountTxt) {
game.setChildIndex(worker3DiscountTxt, game.children.length - 1);
}
if (worker3UpgradeBtn) {
game.setChildIndex(worker3UpgradeBtn, game.children.length - 1);
}
if (worker3UpgradeBtnTxt) {
game.setChildIndex(worker3UpgradeBtnTxt, game.children.length - 1);
}
if (worker4LevelTxt) {
game.setChildIndex(worker4LevelTxt, game.children.length - 1);
}
if (worker4EarningTxt) {
game.setChildIndex(worker4EarningTxt, game.children.length - 1);
}
if (worker4UpgradeBtn) {
game.setChildIndex(worker4UpgradeBtn, game.children.length - 1);
}
if (worker4UpgradeBtnTxt) {
game.setChildIndex(worker4UpgradeBtnTxt, game.children.length - 1);
}
if (worker5LevelTxt) {
game.setChildIndex(worker5LevelTxt, game.children.length - 1);
}
if (worker5BonusTxt) {
game.setChildIndex(worker5BonusTxt, game.children.length - 1);
}
if (worker5UpgradeBtn) {
game.setChildIndex(worker5UpgradeBtn, game.children.length - 1);
}
if (worker5UpgradeBtnTxt) {
game.setChildIndex(worker5UpgradeBtnTxt, game.children.length - 1);
}
}
};
}
// --- Madenler Button (independent, not related to Çalışanlar) ---
var madenlerBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 140,
height: 54
});
madenlerBtn.x = borcOdeBtn.x;
madenlerBtn.y = borcOdeBtn.y + borcOdeBtn.height / 2 + 20 + madenlerBtn.height / 2;
LK.gui.top.addChild(madenlerBtn);
var madenlerBtnTxt = new Text2('Madenler', {
size: 28,
fill: '#fff'
});
madenlerBtnTxt.anchor.set(0.5, 0.5);
madenlerBtnTxt.x = madenlerBtn.x;
madenlerBtnTxt.y = madenlerBtn.y;
LK.gui.top.addChild(madenlerBtnTxt);
// --- Add mine image below the Madenler button ---
var madenlerBtnMineImg = LK.getAsset('mine', {
anchorX: 0.5,
anchorY: 0,
width: 125,
height: 125,
x: madenlerBtn.x,
y: madenlerBtn.y + madenlerBtn.height / 2 + 10
});
LK.gui.top.addChild(madenlerBtnMineImg);
// Clicking the image opens the Madenler panel (same as madenlerBtn.down)
madenlerBtnMineImg.down = function (x, y, obj) {
if (newPagePanel && newPagePanel.visible) {
return;
}
// (fullscreen overlay logic removed)
madenlerPanel.visible = true;
madenlerPanelTitle.visible = true;
madenlerPanelText.visible = true;
madenlerKapatBtn.visible = true;
madenlerKapatBtnIcon.visible = true;
madenlerKapatBtnTxt.visible = true;
// Ava: Hide calisanlarBtnImg and madenlerBtnMineImg when Madenler panel is open
if (typeof calisanlarBtnImg !== "undefined") calisanlarBtnImg.visible = false;
if (typeof madenlerBtnMineImg !== "undefined") madenlerBtnMineImg.visible = false;
// Ava: Show and update maden depo stock area
madenDepoPanel.visible = true;
madenDepoStockTxt.visible = true;
updateMadenDepoStockTxt();
// Hide all homepage buttons/UI
if (typeof magazaBtn !== "undefined") {
magazaBtn.visible = false;
}
if (typeof magazaBtnTxt !== "undefined") {
magazaBtnTxt.visible = false;
}
if (typeof yatirimBtn !== "undefined") {
yatirimBtn.visible = false;
}
if (typeof yatirimBtnTxt !== "undefined") {
yatirimBtnTxt.visible = false;
}
if (typeof bankBtn !== "undefined") {
bankBtn.visible = false;
}
if (typeof bankBtnTxt !== "undefined") {
bankBtnTxt.visible = false;
}
if (typeof soundBtn !== "undefined") {
soundBtn.visible = false;
}
if (typeof soundBtnTxt !== "undefined") {
soundBtnTxt.visible = false;
}
if (typeof newPageBtn !== "undefined") {
newPageBtn.visible = false;
}
if (typeof newPageBtnTxt !== "undefined") {
newPageBtnTxt.visible = false;
}
if (typeof madenlerBtn !== "undefined") {
madenlerBtn.visible = false;
}
if (typeof madenlerBtnTxt !== "undefined") {
madenlerBtnTxt.visible = false;
}
if (typeof madenlerBtnMineImg !== "undefined") {
madenlerBtnMineImg.visible = false;
}
if (typeof calisanlarBtnImg !== "undefined") {
calisanlarBtnImg.visible = false;
}
if (typeof languagesBtn !== "undefined") {
languagesBtn.visible = false;
}
if (typeof languagesBtnTxt !== "undefined") {
languagesBtnTxt.visible = false;
}
if (typeof infoBtn !== "undefined") {
infoBtn.visible = false;
}
if (typeof infoBtnTxt !== "undefined") {
infoBtnTxt.visible = false;
}
if (typeof howToBtn !== "undefined") {
howToBtn.visible = false;
}
if (typeof howToBtnTxt !== "undefined") {
howToBtnTxt.visible = false;
}
// Show all mine UIs
for (var i = 0; i < 6; i++) {
if (!mines || !mines[i]) {
continue;
}
madenlerMineImages[i].visible = true;
madenlerMineLabels[i].visible = true;
madenlerMineLevelTxts[i].visible = true;
madenlerMineProdTxts[i].visible = false;
madenlerMineUpgradeBtns[i].visible = true;
madenlerMineUpgradeBtnTxts[i].visible = true;
if (window.madenlerMineStockTxts && window.madenlerMineStockTxts[i]) {
window.madenlerMineStockTxts[i].visible = true;
var oreType = oreTypes[i];
window.madenlerMineStockTxts[i].setText('' + rawMaterials[oreType]);
}
if (madenlerMineAutoBtns[i]) {
madenlerMineAutoBtns[i].visible = true;
}
if (madenlerMineAutoTxts[i]) {
if (mineAutoProduce[i]) {
madenlerMineAutoTxts[i].setText('Oto Üret: Açık');
} else {
var autoMineCost = (i + 1) * 500;
madenlerMineAutoTxts[i].setText('Oto Üret: Kapalı\n₺' + autoMineCost);
}
madenlerMineAutoTxts[i].visible = true;
madenlerMineAutoTxts[i].lineHeight = 52;
madenlerMineAutoTxts[i].y = madenlerMineAutoBtns[i].y + 10;
}
madenlerMineLevelTxts[i].setText('Seviye: ' + mines[i].level);
madenlerMineProdTxts[i].setText('Üretim: ' + mines[i].production);
madenlerMineUpgradeBtnTxts[i].setText('Yükselt\n₺' + mines[i].upgradeCost);
}
// Paneli en öne getir
if (game.setChildIndex) {
game.setChildIndex(madenlerPanel, game.children.length - 1);
game.setChildIndex(madenlerPanelTitle, game.children.length - 1);
game.setChildIndex(madenlerPanelText, game.children.length - 1);
// Kapat butonu ve X simgesi ve yazısı en önde
game.setChildIndex(madenlerKapatBtn, game.children.length - 1);
game.setChildIndex(madenlerKapatBtnTxt, game.children.length - 1);
if (typeof madenlerKapatBtnIcon !== "undefined") {
game.setChildIndex(madenlerKapatBtnIcon, game.children.length - 1);
}
game.setChildIndex(madenDepoPanel, game.children.length - 1);
game.setChildIndex(madenDepoStockTxt, game.children.length - 1);
for (var i = 0; i < 6; i++) {
if (!mines || !mines[i]) {
continue;
}
game.setChildIndex(madenlerMineImages[i], game.children.length - 1);
game.setChildIndex(madenlerMineLabels[i], game.children.length - 1);
game.setChildIndex(madenlerMineLevelTxts[i], game.children.length - 1);
game.setChildIndex(madenlerMineProdTxts[i], game.children.length - 1);
game.setChildIndex(madenlerMineUpgradeBtns[i], game.children.length - 1);
game.setChildIndex(madenlerMineUpgradeBtnTxts[i], game.children.length - 1);
if (madenlerMineAutoBtns[i]) {
game.setChildIndex(madenlerMineAutoBtns[i], game.children.length - 1);
}
if (madenlerMineAutoTxts[i]) {
game.setChildIndex(madenlerMineAutoTxts[i], game.children.length - 1);
}
}
if (typeof magazaBtn !== "undefined" && magazaBtn.parent === game) {
game.setChildIndex(magazaBtn, 0);
}
if (typeof magazaBtnTxt !== "undefined" && magazaBtnTxt.parent === game) {
game.setChildIndex(magazaBtnTxt, 0);
}
if (typeof yatirimBtn !== "undefined" && yatirimBtn.parent === game) {
game.setChildIndex(yatirimBtn, 0);
}
if (typeof yatirimBtnTxt !== "undefined" && yatirimBtnTxt.parent === game) {
game.setChildIndex(yatirimBtnTxt, 0);
}
if (typeof bankBtn !== "undefined" && bankBtn.parent === game) {
game.setChildIndex(bankBtn, 0);
}
if (typeof bankBtnTxt !== "undefined" && bankBtnTxt.parent === game) {
game.setChildIndex(bankBtnTxt, 0);
}
if (typeof soundBtn !== "undefined" && soundBtn.parent === game) {
game.setChildIndex(soundBtn, 0);
}
if (typeof soundBtnTxt !== "undefined" && soundBtnTxt.parent === game) {
game.setChildIndex(soundBtnTxt, 0);
}
if (typeof newPageBtn !== "undefined" && newPageBtn.parent === game) {
game.setChildIndex(newPageBtn, 0);
}
if (typeof newPageBtnTxt !== "undefined" && newPageBtnTxt.parent === game) {
game.setChildIndex(newPageBtnTxt, 0);
}
if (typeof madenlerBtn !== "undefined" && madenlerBtn.parent === game) {
game.setChildIndex(madenlerBtn, 0);
}
if (typeof madenlerBtnTxt !== "undefined" && madenlerBtnTxt.parent === game) {
game.setChildIndex(madenlerBtnTxt, 0);
}
if (typeof madenlerBtnMineImg !== "undefined" && madenlerBtnMineImg.parent === game) {
game.setChildIndex(madenlerBtnMineImg, 0);
}
if (typeof languagesBtn !== "undefined" && languagesBtn.parent === game) {
game.setChildIndex(languagesBtn, 0);
}
if (typeof languagesBtnTxt !== "undefined" && languagesBtnTxt.parent === game) {
game.setChildIndex(languagesBtnTxt, 0);
}
if (typeof infoBtn !== "undefined" && infoBtn.parent === game) {
game.setChildIndex(infoBtn, 0);
}
if (typeof infoBtnTxt !== "undefined" && infoBtnTxt.parent === game) {
game.setChildIndex(infoBtnTxt, 0);
}
if (typeof howToBtn !== "undefined" && howToBtn.parent === game) {
game.setChildIndex(howToBtn, 0);
}
if (typeof howToBtnTxt !== "undefined" && howToBtnTxt.parent === game) {
game.setChildIndex(howToBtnTxt, 0);
}
}
};
// --- New Page Panel (initially hidden) ---
// --- New Page Panel (initially hidden) ---
var newPagePanelWidth = panelWidth;
var newPagePanelHeight = panelHeight;
var newPagePanelX = Math.floor((2048 - newPagePanelWidth) / 2);
var newPagePanelY = Math.floor((2732 - newPagePanelHeight) / 2);
var newPagePanel = LK.getAsset('button', {
anchorX: 0,
anchorY: 0,
width: newPagePanelWidth,
height: newPagePanelHeight,
x: newPagePanelX,
y: newPagePanelY
});
newPagePanel.visible = false;
game.addChild(newPagePanel);
// Title at top center
var newPagePanelTitle = new Text2('Çalışanlar', {
size: 36,
fill: '#fff'
});
newPagePanelTitle.anchor.set(0.5, 0);
newPagePanelTitle.x = 2048 / 2;
newPagePanelTitle.y = newPagePanelY + 40;
newPagePanelTitle.visible = false;
game.addChild(newPagePanelTitle);
// Remove old panel text, add a subtle subtitle at top center under title
var newPagePanelText = new Text2('Çalışanlar', {
size: 36,
fill: '#bff',
lineHeight: 44
});
newPagePanelText.anchor.set(0.5, 0);
newPagePanelText.x = 2048 / 2;
newPagePanelText.y = newPagePanelTitle.y + newPagePanelTitle.height + 10;
newPagePanelText.visible = false;
game.addChild(newPagePanelText);
// Kapat butonu
// --- Kapat butonu: sağ üstte, %100 büyüklükte, kırmızı çerçeveli ---
var newPageKapatBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 360,
//{iY} // %50 artırıldı
height: 180,
//{iZ} // %50 artırıldı
// Alt orta: panelin alt kenarının ortası, 60px yukarıda
x: newPagePanel.x + newPagePanel.width / 2,
y: newPagePanel.y + newPagePanel.height - 60,
color: 0xffffff,
borderColor: 0xff2222,
borderWidth: 8
});
newPageKapatBtn.visible = false;
game.addChild(newPageKapatBtn);
// Kapat butonu için X simgesi
var newPageKapatBtnIcon = new Text2("\u2716", {
size: 81,
//{j7} // %50 artırıldı
fill: '#ff2222'
});
newPageKapatBtnIcon.anchor.set(1, 0.5);
newPageKapatBtnIcon.x = newPageKapatBtn.x - 60;
newPageKapatBtnIcon.y = newPageKapatBtn.y;
newPageKapatBtnIcon.visible = false;
game.addChild(newPageKapatBtnIcon);
var newPageKapatBtnTxt = new Text2('Kapat', {
size: 96,
//{ja} // %50 artırıldı
fill: '#ff2222'
});
newPageKapatBtnTxt.anchor.set(0.5, 0.5);
newPageKapatBtnTxt.x = newPageKapatBtn.x;
newPageKapatBtnTxt.y = newPageKapatBtn.y;
newPageKapatBtnTxt.visible = false;
game.addChild(newPageKapatBtnTxt);
// --- Yeni: Üstte, panel başlığının hemen altında ortada yeni bir kapat butonu ekle ---
var newPageKapatBtnTop = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 220,
height: 90,
x: newPagePanelTitle.x,
y: newPagePanelTitle.y + newPagePanelTitle.height + 20,
color: 0xffffff,
borderColor: 0xff2222,
borderWidth: 6
});
newPageKapatBtnTop.visible = false;
game.addChild(newPageKapatBtnTop);
var newPageKapatBtnTopIcon = new Text2("\u2716", {
size: 48,
fill: '#ff2222'
});
newPageKapatBtnTopIcon.anchor.set(1, 0.5);
newPageKapatBtnTopIcon.x = newPageKapatBtnTop.x - 40;
newPageKapatBtnTopIcon.y = newPageKapatBtnTop.y;
newPageKapatBtnTopIcon.visible = false;
game.addChild(newPageKapatBtnTopIcon);
var newPageKapatBtnTopTxt = new Text2('Kapat', {
size: 54,
fill: '#ff2222'
});
newPageKapatBtnTopTxt.anchor.set(0.5, 0.5);
newPageKapatBtnTopTxt.x = newPageKapatBtnTop.x;
newPageKapatBtnTopTxt.y = newPageKapatBtnTop.y;
newPageKapatBtnTopTxt.visible = false;
game.addChild(newPageKapatBtnTopTxt);
// --- Yeni kapat butonunun işlevi: Alt kapat butonuyla aynı şekilde paneli kapatsın ---
newPageKapatBtnTop.down = function (x, y, obj) {
if (typeof newPageKapatBtn.down === "function") {
newPageKapatBtn.down(x, y, obj);
}
};
newPageKapatBtnTopIcon.down = newPageKapatBtnTop.down;
newPageKapatBtnTopTxt.down = newPageKapatBtnTop.down;
// --- Madenler Panel (initially hidden, same size as newPagePanel) ---
var madenlerPanel = LK.getAsset('button', {
anchorX: 0,
anchorY: 0,
width: panelWidth,
height: panelHeight,
x: Math.floor((2048 - panelWidth) / 2),
y: Math.floor((2732 - panelHeight) / 2)
});
madenlerPanel.visible = false;
game.addChild(madenlerPanel);
// Title at top center
var madenlerPanelTitle = new Text2('Madenler', {
size: 36,
fill: '#fff'
});
madenlerPanelTitle.anchor.set(0.5, 0);
madenlerPanelTitle.x = 2048 / 2;
madenlerPanelTitle.y = newPagePanelY + 40;
madenlerPanelTitle.visible = false;
game.addChild(madenlerPanelTitle);
// Subtitle
var madenlerPanelText = new Text2('Madenler', {
size: 36,
fill: '#bff'
});
madenlerPanelText.anchor.set(0.5, 0);
madenlerPanelText.x = 2048 / 2;
madenlerPanelText.y = madenlerPanelTitle.y + madenlerPanelTitle.height + 10;
madenlerPanelText.visible = false;
game.addChild(madenlerPanelText);
// Kapat butonu
// --- Kapat butonu: sağ üstte, %100 büyüklükte, kırmızı çerçeveli ---
var madenlerKapatBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 360,
//{jx} // %50 artırıldı
height: 180,
//{jy} // %50 artırıldı
// Alt orta: panelin alt kenarının ortası, 60px yukarıda
x: madenlerPanel.x + madenlerPanel.width / 2,
y: madenlerPanel.y + madenlerPanel.height - 60,
color: 0xffffff,
borderColor: 0xff2222,
borderWidth: 8
});
madenlerKapatBtn.visible = false;
game.addChild(madenlerKapatBtn);
// Add an icon (Unicode heavy multiplication X) to the left of the text
var madenlerKapatBtnIcon = new Text2("\u2716", {
size: 81,
//{jG} // %50 artırıldı
fill: '#ff2222'
});
madenlerKapatBtnIcon.anchor.set(1, 0.5);
madenlerKapatBtnIcon.x = madenlerKapatBtn.x - 60;
madenlerKapatBtnIcon.y = madenlerKapatBtn.y;
madenlerKapatBtnIcon.visible = false;
game.addChild(madenlerKapatBtnIcon);
var madenlerKapatBtnTxt = new Text2('Kapat', {
size: 96,
//{jK} // %50 artırıldı
fill: '#ff2222'
});
madenlerKapatBtnTxt.anchor.set(0.5, 0.5);
madenlerKapatBtnTxt.x = madenlerKapatBtn.x;
madenlerKapatBtnTxt.y = madenlerKapatBtn.y;
madenlerKapatBtnTxt.visible = false;
game.addChild(madenlerKapatBtnTxt);
// --- Madenler Panel: Show mines and their info ---
var madenlerMineImages = [];
var madenlerMineLabels = [];
var madenlerMineLevelTxts = [];
var madenlerMineProdTxts = [];
var madenlerMineUpgradeBtns = [];
var madenlerMineUpgradeBtnTxts = [];
// Ava: Add auto-produce buttons and texts for Madenler panel
var madenlerMineAutoBtns = [];
var madenlerMineAutoTxts = [];
// --- Ava: Add maden depo stock area to Madenler panel ---
var madenDepoPanel = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0,
width: 420,
height: 90,
x: madenlerPanel.x + madenlerPanel.width / 2,
y: madenlerPanelText.y + madenlerPanelText.height + 10
});
madenDepoPanel.visible = false;
game.addChild(madenDepoPanel);
var madenDepoStockTxt = new Text2('', {
size: 36,
fill: '#ffb'
});
madenDepoStockTxt.anchor.set(0.5, 0.5);
madenDepoStockTxt.x = madenDepoPanel.x;
madenDepoStockTxt.y = madenDepoPanel.y + madenDepoPanel.height / 2;
madenDepoStockTxt.visible = false;
game.addChild(madenDepoStockTxt);
// Helper to update maden depo stock text
function updateMadenDepoStockTxt() {
madenDepoStockTxt.setText('Bakır: ' + rawMaterials.copper + ' | Silikon: ' + rawMaterials.silicon + ' | Demir: ' + rawMaterials.iron + ' | Gümüş: ' + rawMaterials.silver + ' | Nikel: ' + rawMaterials.nikel + ' | Altın: ' + rawMaterials.gold);
}
// Wait until 'mines' is defined and has at least 6 elements before creating Madenler panel UI
LK.setTimeout(function () {
if (!mines || !Array.isArray(mines) || mines.length < 6 || !mines[0] || !mines[1] || !mines[2] || !mines[3] || !mines[4] || !mines[5]) {
// Try again next frame if mines are not ready or not an array or not enough elements or any mine is missing
LK.setTimeout(arguments.callee, 1);
return;
}
for (var i = 0; i < 6; i++) {
// Defensive: skip this iteration if mines is not defined or mines[i] is not defined
if (!mines || !Array.isArray(mines) || !mines[i]) {
continue;
}
// --- Ava: 3'lü sıra ve ortalı, hizalı layout için yeni grid hesaplama ---
// 3 sütun, 2 satır, ortalı ve eşit aralıklı
var colCount = 3;
var rowCount = 2;
var col = i % colCount;
var row = Math.floor(i / colCount);
// Panelin kullanılabilir genişliği ve yüksekliği
var usableWidth = newPagePanelWidth;
var usableHeight = newPagePanelHeight - (madenDepoPanel.y + madenDepoPanel.height + 32 - newPagePanelY) - 60; // depo panelinden aşağısı
var gridStartY = madenDepoPanel.y + madenDepoPanel.height + 32;
var cellWidth = usableWidth / colCount;
var cellHeight = usableHeight / rowCount;
// Her hücrenin ortası
var mx = madenlerPanel.x + cellWidth * (col + 0.5);
var baseY = gridStartY + cellHeight * row + 20; // 20px üst boşluk
var y = baseY;
var lineGap = 10;
var elemGap = 16;
var oreType = oreTypes[i];
// Label (top, above mine image)
var label = new Text2(oreType.charAt(0).toUpperCase() + oreType.slice(1), {
size: 48,
fill: '#fff'
});
label.anchor.set(0.5, 0);
label.x = mx;
label.y = y;
label.visible = false;
game.addChild(label);
madenlerMineLabels.push(label);
y += label.height + 4;
// --- Ava: Show mine stock count directly above the mine image ---
var stockTxt = new Text2('' + rawMaterials[oreType], {
size: 38,
fill: '#ffb'
});
stockTxt.anchor.set(0.5, 1); // center horizontally, bottom aligned
stockTxt.x = mx;
stockTxt.y = y + 8; // 8px below label
stockTxt.visible = false;
game.addChild(stockTxt);
if (!window.madenlerMineStockTxts) {
window.madenlerMineStockTxts = [];
}
window.madenlerMineStockTxts[i] = stockTxt;
y += 8 + 8; // 8px gap below stockTxt
// Mine image (unique for each ore type)
var mineImg = LK.getAsset('mine_' + oreType, {
anchorX: 0.5,
anchorY: 0.5,
width: 180,
height: 180,
x: mx,
y: y + 90 // center mine image at y
});
mineImg.visible = false;
game.addChild(mineImg);
madenlerMineImages.push(mineImg);
// Ava: Maden resmine tıklayınca maden üretimi yap
(function (idx, mineImgRef) {
mineImgRef.down = function (x, y, obj) {
if (!madenlerPanel.visible) {
return;
}
if (!mines || !mines[idx]) {
return;
}
if (yatirimPanel && yatirimPanel.visible) {
return;
}
var m = mines[idx];
rawMaterials[m.type] += m.production;
if (typeof updateRawText === "function") {
updateRawText();
}
tween(mineImgRef, {
scaleX: 1.12,
scaleY: 1.12
}, {
duration: 80,
onFinish: function onFinish() {
tween(mineImgRef, {
scaleX: 1,
scaleY: 1
}, {
duration: 80
});
}
});
};
})(i, mineImg);
y = mineImg.y + 90 + elemGap; // bottom of mine image + gap
// Ore icon (below mine image)
var oreImg = LK.getAsset('ore_' + oreType, {
anchorX: 0.5,
anchorY: 0.5,
width: 80,
height: 80,
x: mx,
y: y
});
oreImg.visible = false;
game.addChild(oreImg);
y += 40 + elemGap; // half ore icon + gap
// Level text
var levelTxt = new Text2('Seviye: ' + mines[i].level, {
size: 38,
fill: '#ffb'
});
levelTxt.anchor.set(0.5, 0);
levelTxt.x = mx;
levelTxt.y = y;
levelTxt.visible = false;
game.addChild(levelTxt);
madenlerMineLevelTxts.push(levelTxt);
y += levelTxt.height + lineGap;
// Production text (hidden, but kept for layout consistency)
var prodTxt = new Text2('', {
size: 38,
fill: '#bff',
lineHeight: 18 // Satır boşluğunu azalt, görünmez olduğu için küçük tut
});
prodTxt.anchor.set(0.5, 0);
prodTxt.x = mx;
prodTxt.y = y;
prodTxt.visible = false; // Her zaman görünmez
game.addChild(prodTxt);
madenlerMineProdTxts.push(prodTxt);
y += 18 + elemGap; // Satır boşluğunu azalt
// Upgrade button
var upgradeBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 180,
height: 70,
x: mx,
y: y + 35 // center button
});
upgradeBtn.visible = false;
game.addChild(upgradeBtn);
var upgradeBtnTxt = new Text2('Yükselt\n₺' + mines[i].upgradeCost, {
size: 36,
fill: '#fff'
});
upgradeBtnTxt.anchor.set(0.5, 0.5);
upgradeBtnTxt.x = mx;
upgradeBtnTxt.y = upgradeBtn.y;
upgradeBtnTxt.visible = false;
game.addChild(upgradeBtnTxt);
madenlerMineUpgradeBtns.push(upgradeBtn);
madenlerMineUpgradeBtnTxts.push(upgradeBtnTxt);
// Move Oto Üret button 1 row (1x lineGap + 1x elemGap + 1x 38px) further down below the upgrade button
y = upgradeBtn.y + upgradeBtn.height / 2 + elemGap + 10;
y += (levelTxt.height + lineGap) * 1 + elemGap * 1; // 1 satır aşağıya çıkar
// Auto-produce button
var autoBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 180,
height: 70,
x: mx,
y: y
});
autoBtn.visible = false;
game.addChild(autoBtn);
var autoMineCost = (i + 1) * 500;
var autoTxt = new Text2('Oto Üret: Kapalı\n₺' + autoMineCost, {
size: 36,
fill: '#fff',
lineHeight: 52 // Satır aralığını artır (default 36, 52 ile daha fazla boşluk)
});
autoTxt.anchor.set(0.5, 0.5);
autoTxt.x = mx;
autoTxt.y = autoBtn.y + 10; // 10px aşağı kaydır
autoTxt.visible = false;
game.addChild(autoTxt);
madenlerMineAutoBtns.push(autoBtn);
madenlerMineAutoTxts.push(autoTxt);
// Closure for correct index
(function (idx, autoBtn, autoTxt, autoMineCost) {
autoBtn.down = function (x, y, obj) {
if (yatirimPanel && yatirimPanel.visible) {
return;
}
if (!mineAutoProduce[idx]) {
if (money >= autoMineCost) {
money -= autoMineCost;
updateMoneyText && updateMoneyText();
mineAutoProduce[idx] = true;
autoTxt.setText('Oto Üret: Açık');
} else {
tween(autoBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(autoBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
}
}
// Do not allow disabling after purchase
};
})(i, autoBtn, autoTxt, autoMineCost);
// Upgrade logic
(function (idx) {
upgradeBtn.down = function (x, y, obj) {
if (yatirimPanel && yatirimPanel.visible) {
return;
}
var m = mines[idx];
if (money >= m.upgradeCost) {
money -= m.upgradeCost;
m.upgrade();
madenlerMineLevelTxts[idx].setText('Seviye: ' + m.level);
madenlerMineProdTxts[idx].setText('Üretim: ' + m.production);
madenlerMineUpgradeBtnTxts[idx].setText('Yükselt\n₺' + m.upgradeCost);
updateMoneyText && updateMoneyText();
} else {
tween(upgradeBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(upgradeBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
}
};
})(i);
}
}, 1);
// Yeni sayfa butonuna tıklanınca paneli aç
if (typeof newPageBtn !== "undefined" && newPageBtn) {
newPageBtn.down = function (x, y, obj) {
// Prevent opening if already open
if (newPagePanel && newPagePanel.visible) {
return;
}
// Hide both calisanlarBtnImg and madenlerBtnMineImg, and newPageBtn & newPageBtnTxt until panel closes
if (typeof calisanlarBtnImg !== "undefined") calisanlarBtnImg.visible = false;
if (typeof madenlerBtnMineImg !== "undefined") madenlerBtnMineImg.visible = false;
if (typeof newPageBtn !== "undefined") newPageBtn.visible = false;
if (typeof newPageBtnTxt !== "undefined") newPageBtnTxt.visible = false;
if (typeof madenlerBtn !== "undefined") madenlerBtn.visible = false;
if (typeof madenlerBtnTxt !== "undefined") madenlerBtnTxt.visible = false;
newPagePanel.visible = true;
newPagePanelTitle.visible = true;
newPagePanelText.visible = true;
newPageKapatBtn.visible = true;
newPageKapatBtnTxt.visible = true;
// --- Yeni üst kapat butonunu ve label/icon'unu göster ---
if (typeof newPageKapatBtnTop !== "undefined") newPageKapatBtnTop.visible = true;
if (typeof newPageKapatBtnTopIcon !== "undefined") newPageKapatBtnTopIcon.visible = true;
if (typeof newPageKapatBtnTopTxt !== "undefined") newPageKapatBtnTopTxt.visible = true;
// Hide all game children except Çalışanlar panel and its UI (panel, title, text, both close buttons and icons/texts, worker images/labels/buttons/texts)
for (var i = 0; i < game.children.length; i++) {
var child = game.children[i];
// List of allowed elements to remain visible
var allowed = [newPagePanel, newPagePanelTitle, newPagePanelText, newPageKapatBtn, newPageKapatBtnTxt, newPageKapatBtnIcon, newPageKapatBtnTop, newPageKapatBtnTopIcon, newPageKapatBtnTopTxt];
// Add all worker UI elements to allowed list
if (typeof workerImages !== "undefined" && Array.isArray(workerImages)) {
for (var w = 0; w < workerImages.length; w++) {
if (workerImages[w].img) allowed.push(workerImages[w].img);
if (workerImages[w].label) allowed.push(workerImages[w].label);
}
}
if (typeof worker1LevelTxt !== "undefined") allowed.push(worker1LevelTxt);
if (typeof worker1EarningTxt !== "undefined") allowed.push(worker1EarningTxt);
if (typeof worker1UpgradeBtn !== "undefined") allowed.push(worker1UpgradeBtn);
if (typeof worker1UpgradeBtnTxt !== "undefined") allowed.push(worker1UpgradeBtnTxt);
if (typeof worker2LevelTxt !== "undefined") allowed.push(worker2LevelTxt);
if (typeof worker2SpeedTxt !== "undefined") allowed.push(worker2SpeedTxt);
if (typeof worker2UpgradeBtn !== "undefined") allowed.push(worker2UpgradeBtn);
if (typeof worker2UpgradeBtnTxt !== "undefined") allowed.push(worker2UpgradeBtnTxt);
if (typeof worker3LevelTxt !== "undefined") allowed.push(worker3LevelTxt);
if (typeof worker3DiscountTxt !== "undefined") allowed.push(worker3DiscountTxt);
if (typeof worker3UpgradeBtn !== "undefined") allowed.push(worker3UpgradeBtn);
if (typeof worker3UpgradeBtnTxt !== "undefined") allowed.push(worker3UpgradeBtnTxt);
if (typeof worker4LevelTxt !== "undefined") allowed.push(worker4LevelTxt);
if (typeof worker4EarningTxt !== "undefined") allowed.push(worker4EarningTxt);
if (typeof worker4UpgradeBtn !== "undefined") allowed.push(worker4UpgradeBtn);
if (typeof worker4UpgradeBtnTxt !== "undefined") allowed.push(worker4UpgradeBtnTxt);
if (typeof worker5LevelTxt !== "undefined") allowed.push(worker5LevelTxt);
if (typeof worker5BonusTxt !== "undefined") allowed.push(worker5BonusTxt);
if (typeof worker5UpgradeBtn !== "undefined") allowed.push(worker5UpgradeBtn);
if (typeof worker5UpgradeBtnTxt !== "undefined") allowed.push(worker5UpgradeBtnTxt);
// Only keep allowed elements visible, hide everything else
if (allowed.indexOf(child) === -1) {
child._oldVisible = child.visible;
child.visible = false;
}
}
};
}
// Madenler butonuna tıklanınca paneli aç
madenlerBtn.down = function (x, y, obj) {
if (newPagePanel && newPagePanel.visible) {
return;
}
// --- Ava: Hide all homepage images when Madenler panel opens ---
if (typeof homepageImages === "undefined") {
window.homepageImages = [];
for (var i = 0; i < game.children.length; i++) {
var child = game.children[i];
// Defensive: Only hide images that are not panels, not overlays, not buttons, not Text2, and are visible
if (child && typeof child.visible === "boolean" && child.visible && child !== madenlerPanel && child !== madenlerPanelTitle && child !== madenlerPanelText && child !== madenlerKapatBtn && child !== madenlerKapatBtnTxt && child !== madenlerKapatBtnIcon && !(child instanceof Text2) && !(child.assetId && (child.assetId.indexOf("button") === 0 || child.assetId.indexOf("panel") === 0))) {
window.homepageImages.push(child);
}
}
}
if (window.homepageImages && window.homepageImages.length) {
for (var i = 0; i < window.homepageImages.length; i++) {
if (window.homepageImages[i] && typeof window.homepageImages[i].visible === "boolean") {
window.homepageImages[i]._oldVisible = window.homepageImages[i].visible;
window.homepageImages[i].visible = false;
}
}
}
madenlerPanel.visible = true;
madenlerPanelTitle.visible = true;
madenlerPanelText.visible = true;
madenlerKapatBtn.visible = true;
madenlerKapatBtnIcon.visible = true;
madenlerKapatBtnTxt.visible = true;
// Ava: Hide calisanlarBtnImg and madenlerBtnMineImg when Madenler panel is open
if (typeof calisanlarBtnImg !== "undefined") calisanlarBtnImg.visible = false;
if (typeof madenlerBtnMineImg !== "undefined") madenlerBtnMineImg.visible = false;
// Ava: Show and update maden depo stock area
madenDepoPanel.visible = true;
madenDepoStockTxt.visible = true;
updateMadenDepoStockTxt();
// Hide all homepage buttons/UI
if (typeof magazaBtn !== "undefined") {
magazaBtn.visible = false;
}
if (typeof magazaBtnTxt !== "undefined") {
magazaBtnTxt.visible = false;
}
if (typeof yatirimBtn !== "undefined") {
yatirimBtn.visible = false;
}
if (typeof yatirimBtnTxt !== "undefined") {
yatirimBtnTxt.visible = false;
}
if (typeof bankBtn !== "undefined") {
bankBtn.visible = false;
}
if (typeof bankBtnTxt !== "undefined") {
bankBtnTxt.visible = false;
}
if (typeof soundBtn !== "undefined") {
soundBtn.visible = false;
}
if (typeof soundBtnTxt !== "undefined") {
soundBtnTxt.visible = false;
}
if (typeof newPageBtn !== "undefined") {
newPageBtn.visible = false;
}
if (typeof newPageBtnTxt !== "undefined") {
newPageBtnTxt.visible = false;
}
if (typeof madenlerBtn !== "undefined") {
madenlerBtn.visible = false;
}
if (typeof madenlerBtnTxt !== "undefined") {
madenlerBtnTxt.visible = false;
}
if (typeof languagesBtn !== "undefined") {
languagesBtn.visible = false;
}
if (typeof languagesBtnTxt !== "undefined") {
languagesBtnTxt.visible = false;
}
if (typeof infoBtn !== "undefined") {
infoBtn.visible = false;
}
if (typeof infoBtnTxt !== "undefined") {
infoBtnTxt.visible = false;
}
if (typeof howToBtn !== "undefined") {
howToBtn.visible = false;
}
if (typeof howToBtnTxt !== "undefined") {
howToBtnTxt.visible = false;
}
// Prevent hiding Store3/Store4 purchase buttons if Mağazalar panel is open
if (magazalarPanel && magazalarPanel.visible) {
if (typeof store3PurchaseBtn !== "undefined" && typeof store3PurchaseBtnTxt !== "undefined") {
store3PurchaseBtn.visible = !store3Purchased;
store3PurchaseBtnTxt.visible = !store3Purchased;
}
if (typeof store4PurchaseBtn !== "undefined" && typeof store4PurchaseBtnTxt !== "undefined") {
store4PurchaseBtn.visible = !store4Purchased;
store4PurchaseBtnTxt.visible = !store4Purchased;
}
}
// Show all mine UIs
for (var i = 0; i < 6; i++) {
// Defensive: skip if mines or mines[i] is not defined
if (!mines || !mines[i]) {
continue;
}
madenlerMineImages[i].visible = true;
madenlerMineLabels[i].visible = true;
madenlerMineLevelTxts[i].visible = true;
// Hide production amount text
madenlerMineProdTxts[i].visible = false;
madenlerMineUpgradeBtns[i].visible = true;
madenlerMineUpgradeBtnTxts[i].visible = true;
// Ava: Show stock count text above each mine image
if (window.madenlerMineStockTxts && window.madenlerMineStockTxts[i]) {
window.madenlerMineStockTxts[i].visible = true;
// Update stock count
var oreType = oreTypes[i];
window.madenlerMineStockTxts[i].setText('' + rawMaterials[oreType]);
}
// Ava: Show auto-produce button and text for each mine
if (madenlerMineAutoBtns[i]) {
madenlerMineAutoBtns[i].visible = true;
}
if (madenlerMineAutoTxts[i]) {
// Update text to reflect current state
if (mineAutoProduce[i]) {
madenlerMineAutoTxts[i].setText('Oto Üret: Açık');
} else {
var autoMineCost = (i + 1) * 500;
madenlerMineAutoTxts[i].setText('Oto Üret: Kapalı\n₺' + autoMineCost);
}
madenlerMineAutoTxts[i].visible = true;
// Satır aralığını ve konumunu tekrar ayarla
madenlerMineAutoTxts[i].lineHeight = 52;
madenlerMineAutoTxts[i].y = madenlerMineAutoBtns[i].y + 10;
}
// Update texts in case level/production changed
madenlerMineLevelTxts[i].setText('Seviye: ' + mines[i].level);
madenlerMineProdTxts[i].setText('Üretim: ' + mines[i].production);
madenlerMineUpgradeBtnTxts[i].setText('Yükselt\n₺' + mines[i].upgradeCost);
}
// Paneli en öne getir
if (game.setChildIndex) {
game.setChildIndex(madenlerPanel, game.children.length - 1);
game.setChildIndex(madenlerPanelTitle, game.children.length - 1);
game.setChildIndex(madenlerPanelText, game.children.length - 1);
game.setChildIndex(madenlerKapatBtn, game.children.length - 1);
game.setChildIndex(madenlerKapatBtnTxt, game.children.length - 1);
if (typeof madenlerKapatBtnIcon !== "undefined") {
game.setChildIndex(madenlerKapatBtnIcon, game.children.length - 1);
}
// Ava: Bring maden depo panel and text to front
game.setChildIndex(madenDepoPanel, game.children.length - 1);
game.setChildIndex(madenDepoStockTxt, game.children.length - 1);
for (var i = 0; i < 6; i++) {
if (!mines || !mines[i]) {
continue;
}
game.setChildIndex(madenlerMineImages[i], game.children.length - 1);
game.setChildIndex(madenlerMineLabels[i], game.children.length - 1);
game.setChildIndex(madenlerMineLevelTxts[i], game.children.length - 1);
game.setChildIndex(madenlerMineProdTxts[i], game.children.length - 1);
game.setChildIndex(madenlerMineUpgradeBtns[i], game.children.length - 1);
game.setChildIndex(madenlerMineUpgradeBtnTxts[i], game.children.length - 1);
// Ava: Bring auto-produce button and text to front
if (madenlerMineAutoBtns[i]) {
game.setChildIndex(madenlerMineAutoBtns[i], game.children.length - 1);
}
if (madenlerMineAutoTxts[i]) {
game.setChildIndex(madenlerMineAutoTxts[i], game.children.length - 1);
}
}
// Ava: Move homepage buttons behind the panel
if (typeof magazaBtn !== "undefined" && magazaBtn.parent === game) {
game.setChildIndex(magazaBtn, 0);
}
if (typeof magazaBtnTxt !== "undefined" && magazaBtnTxt.parent === game) {
game.setChildIndex(magazaBtnTxt, 0);
}
if (typeof yatirimBtn !== "undefined" && yatirimBtn.parent === game) {
game.setChildIndex(yatirimBtn, 0);
}
if (typeof yatirimBtnTxt !== "undefined" && yatirimBtnTxt.parent === game) {
game.setChildIndex(yatirimBtnTxt, 0);
}
if (typeof bankBtn !== "undefined" && bankBtn.parent === game) {
game.setChildIndex(bankBtn, 0);
}
if (typeof bankBtnTxt !== "undefined" && bankBtnTxt.parent === game) {
game.setChildIndex(bankBtnTxt, 0);
}
if (typeof soundBtn !== "undefined" && soundBtn.parent === game) {
game.setChildIndex(soundBtn, 0);
}
if (typeof soundBtnTxt !== "undefined" && soundBtnTxt.parent === game) {
game.setChildIndex(soundBtnTxt, 0);
}
if (typeof newPageBtn !== "undefined" && newPageBtn.parent === game) {
game.setChildIndex(newPageBtn, 0);
}
if (typeof newPageBtnTxt !== "undefined" && newPageBtnTxt.parent === game) {
game.setChildIndex(newPageBtnTxt, 0);
}
if (typeof madenlerBtn !== "undefined" && madenlerBtn.parent === game) {
game.setChildIndex(madenlerBtn, 0);
}
if (typeof madenlerBtnTxt !== "undefined" && madenlerBtnTxt.parent === game) {
game.setChildIndex(madenlerBtnTxt, 0);
}
if (typeof languagesBtn !== "undefined" && languagesBtn.parent === game) {
game.setChildIndex(languagesBtn, 0);
}
if (typeof languagesBtnTxt !== "undefined" && languagesBtnTxt.parent === game) {
game.setChildIndex(languagesBtnTxt, 0);
}
if (typeof infoBtn !== "undefined" && infoBtn.parent === game) {
game.setChildIndex(infoBtn, 0);
}
if (typeof infoBtnTxt !== "undefined" && infoBtnTxt.parent === game) {
game.setChildIndex(infoBtnTxt, 0);
}
if (typeof howToBtn !== "undefined" && howToBtn.parent === game) {
game.setChildIndex(howToBtn, 0);
}
if (typeof howToBtnTxt !== "undefined" && howToBtnTxt.parent === game) {
game.setChildIndex(howToBtnTxt, 0);
}
}
};
// Paneli kapatmak için kapat butonu
newPageKapatBtn.down = function (x, y, obj) {
newPagePanel.visible = false;
newPagePanelTitle.visible = false;
newPagePanelText.visible = false;
newPageKapatBtn.visible = false;
newPageKapatBtnTxt.visible = false;
// --- Yeni üst kapat butonunu ve label/icon'unu gizle ---
if (typeof newPageKapatBtnTop !== "undefined") newPageKapatBtnTop.visible = false;
if (typeof newPageKapatBtnTopIcon !== "undefined") newPageKapatBtnTopIcon.visible = false;
if (typeof newPageKapatBtnTopTxt !== "undefined") newPageKapatBtnTopTxt.visible = false;
// Restore all game children visibility except overlay and panel content (like Madenler panel)
for (var i = 0; i < game.children.length; i++) {
var child = game.children[i];
if (child !== fullscreenOverlay && child !== newPageOverlay && child !== newPagePanel && child !== newPagePanelTitle && child !== newPagePanelText && child !== newPageKapatBtn && child !== newPageKapatBtnTxt) {
if (typeof child._oldVisible !== "undefined") {
child.visible = child._oldVisible;
delete child._oldVisible;
} else {
child.visible = true;
}
}
}
// --- Ava: Defensive fix for Mevduat panel interaction bug ---
// If Mevduat panel was open before, re-enable all factory/factoryUnlock/prod/auto buttons
if (typeof factoryBtns !== "undefined" && Array.isArray(factoryBtns)) {
for (var i = 0; i < factoryBtns.length; i++) {
if (factoryBtns[i] && factoryBtns[i]._origDown) {
factoryBtns[i].down = factoryBtns[i]._origDown;
delete factoryBtns[i]._origDown;
}
}
}
if (typeof factoryUnlockBtns !== "undefined" && Array.isArray(factoryUnlockBtns)) {
for (var i = 0; i < factoryUnlockBtns.length; i++) {
if (factoryUnlockBtns[i] && factoryUnlockBtns[i]._origDown) {
factoryUnlockBtns[i].down = factoryUnlockBtns[i]._origDown;
delete factoryUnlockBtns[i]._origDown;
}
}
}
if (typeof prodBtns !== "undefined" && Array.isArray(prodBtns)) {
for (var i = 0; i < prodBtns.length; i++) {
if (prodBtns[i] && prodBtns[i]._origDown) {
prodBtns[i].down = prodBtns[i]._origDown;
delete prodBtns[i]._origDown;
}
}
}
if (typeof factoryAutoBtns !== "undefined" && Array.isArray(factoryAutoBtns)) {
for (var i = 0; i < factoryAutoBtns.length; i++) {
if (factoryAutoBtns[i] && factoryAutoBtns[i]._origDown) {
factoryAutoBtns[i].down = factoryAutoBtns[i]._origDown;
delete factoryAutoBtns[i]._origDown;
}
}
}
for (var i = 0; i < game.children.length; i++) {
var child = game.children[i];
if (child && child.isFactoryButton && child._origDown) {
child.down = child._origDown;
delete child._origDown;
}
}
};
// Madenler panelini kapatmak için kapat butonu
madenlerKapatBtn.down = function (x, y, obj) {
madenlerPanel.visible = false;
madenlerPanelTitle.visible = false;
madenlerPanelText.visible = false;
madenlerKapatBtn.visible = false;
madenlerKapatBtnIcon.visible = false;
madenlerKapatBtnTxt.visible = false;
// Ava: Hide maden depo stock area
madenDepoPanel.visible = false;
madenDepoStockTxt.visible = false;
// Show all homepage buttons/UI
if (typeof magazaBtn !== "undefined") {
magazaBtn.visible = true;
}
if (typeof magazaBtnTxt !== "undefined") {
magazaBtnTxt.visible = true;
}
if (typeof yatirimBtn !== "undefined") {
yatirimBtn.visible = true;
}
if (typeof yatirimBtnTxt !== "undefined") {
yatirimBtnTxt.visible = true;
}
if (typeof bankBtn !== "undefined") {
bankBtn.visible = true;
}
if (typeof bankBtnTxt !== "undefined") {
bankBtnTxt.visible = true;
}
if (typeof soundBtn !== "undefined") {
soundBtn.visible = true;
}
if (typeof soundBtnTxt !== "undefined") {
soundBtnTxt.visible = true;
}
if (typeof newPageBtn !== "undefined") {
newPageBtn.visible = true;
}
if (typeof newPageBtnTxt !== "undefined") {
newPageBtnTxt.visible = true;
}
if (typeof madenlerBtn !== "undefined") {
madenlerBtn.visible = true;
}
if (typeof madenlerBtnTxt !== "undefined") {
madenlerBtnTxt.visible = true;
}
if (typeof madenlerBtnMineImg !== "undefined") {
madenlerBtnMineImg.visible = true;
}
if (typeof calisanlarBtnImg !== "undefined") {
calisanlarBtnImg.visible = true;
}
if (typeof languagesBtn !== "undefined") {
languagesBtn.visible = true;
}
if (typeof languagesBtnTxt !== "undefined") {
languagesBtnTxt.visible = true;
}
// Info and How To Play buttons are never shown
for (var i = 0; i < 6; i++) {
// Defensive: skip if mines or mines[i] is not defined
if (!mines || !mines[i]) {
continue;
}
madenlerMineImages[i].visible = false;
madenlerMineLabels[i].visible = false;
madenlerMineLevelTxts[i].visible = false;
madenlerMineProdTxts[i].visible = false;
madenlerMineUpgradeBtns[i].visible = false;
madenlerMineUpgradeBtnTxts[i].visible = false;
// Ava: Hide stock count text above each mine image
if (window.madenlerMineStockTxts && window.madenlerMineStockTxts[i]) {
window.madenlerMineStockTxts[i].visible = false;
}
// Ava: Hide auto-produce button and text for each mine
if (madenlerMineAutoBtns[i]) {
madenlerMineAutoBtns[i].visible = false;
}
if (madenlerMineAutoTxts[i]) {
madenlerMineAutoTxts[i].visible = false;
}
}
// --- Ava: Restore all homepage images when Madenler panel closes ---
if (window.homepageImages && window.homepageImages.length) {
for (var i = 0; i < window.homepageImages.length; i++) {
if (window.homepageImages[i] && typeof window.homepageImages[i].visible === "boolean") {
if (typeof window.homepageImages[i]._oldVisible !== "undefined") {
window.homepageImages[i].visible = window.homepageImages[i]._oldVisible;
delete window.homepageImages[i]._oldVisible;
} else {
window.homepageImages[i].visible = true;
}
}
}
}
};
// INFO butonunu Yatırım butonunun altına ekle
// Info and How To Play buttons are removed from the homepage and never shown.
// Languages butonunu "Nasıl Oynanır" butonunun altına ekle
// Defensive: Define a dummy howToBtn if not already defined to prevent undefined error
if (typeof howToBtn === "undefined") {
var howToBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 140,
height: 54
});
howToBtn.x = 120;
howToBtn.y = 120;
LK.gui.top.addChild(howToBtn);
}
// --- Sound Toggle Icon Button ---
// Use a simple colored box as icon: green for sound on, red for sound off
var soundOnColor = 0x83de44;
var soundOffColor = 0xd83318;
// Sound button is created after languagesBtn to ensure languagesBtn is defined
var soundBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 70,
height: 70
});
// Place soundBtn below the mine image (madenlerBtnMineImg) and center it horizontally
if (typeof madenlerBtnMineImg !== "undefined" && madenlerBtnMineImg) {
soundBtn.x = madenlerBtnMineImg.x;
// Move 1% of screen height (2732) further down from the mine image
soundBtn.y = madenlerBtnMineImg.y + madenlerBtnMineImg.height + 24 + Math.floor(2732 * 0.01);
} else {
// fallback to previous position if mine image is not defined
soundBtn.x = 120 + 140 + 70 + 20;
soundBtn.y = 120 + 54 + 20;
}
LK.gui.top.addChild(soundBtn);
// Sound icon state
var isSoundOn = true;
soundBtn.tint = soundOnColor;
// Optional: Add a speaker icon text
var soundBtnTxt = new Text2("\uD83D\uDD0A", {
size: 38,
fill: '#fff'
});
soundBtnTxt.anchor.set(0.5, 0.5);
soundBtnTxt.x = soundBtn.x;
soundBtnTxt.y = soundBtn.y;
LK.gui.top.addChild(soundBtnTxt);
// Sound toggle logic
soundBtn.down = function (x, y, obj) {
if (newPagePanel && newPagePanel.visible) {
return;
}
isSoundOn = !isSoundOn;
if (isSoundOn) {
soundBtn.tint = soundOnColor;
soundBtnTxt.setText("\uD83D\uDD0A"); // Speaker
// Resume music
LK.playMusic('ArkaplanMuzik', {
fade: {
start: 0,
end: 1,
duration: 300
}
});
} else {
soundBtn.tint = soundOffColor;
soundBtnTxt.setText("\uD83D\uDD07"); // Muted speaker
// Stop music
LK.stopMusic();
}
// Animate for feedback
tween(soundBtn, {
scaleX: 1.15,
scaleY: 1.15
}, {
duration: 80,
onFinish: function onFinish() {
tween(soundBtn, {
scaleX: 1,
scaleY: 1
}, {
duration: 80
});
}
});
};
// "Nasıl Oynanır" butonuna tıklanınca info panelini aç
howToBtn.down = function (x, y, obj) {
if (newPagePanel && newPagePanel.visible) {
return;
}
// Butona animasyon ekle
tween(howToBtn, {
scaleX: 1.12,
scaleY: 1.12
}, {
duration: 80,
onFinish: function onFinish() {
tween(howToBtn, {
scaleX: 1,
scaleY: 1
}, {
duration: 80
});
}
});
// Info panel popup and all related UI removed. Only the homepage info panel below stock panel remains.
};
// Info panel popup and all related UI removed. Only the homepage info panel below stock panel remains.
// --- Ava: Move homepage info panel button background (yazısız kutu) completely offscreen and hide it visually ---
// Defensive: Move and hide infoPanel after all UI is created and positioned
LK.setTimeout(function () {
if (typeof infoPanel !== "undefined" && infoPanel) {
// Move infoPanel far offscreen (top left, negative coordinates)
infoPanel.x = -99999;
infoPanel.y = -99999;
// Make it invisible
infoPanel.visible = false;
// Optionally, send to back if parent is game
if (infoPanel.parent === game && typeof game.setChildIndex === "function") {
game.setChildIndex(infoPanel, 0);
}
} else {
// Try again next frame if not ready
LK.setTimeout(arguments.callee, 1);
}
}, 1);
// (Languages panel and all related UI and logic removed)
borcOdeBtn.down = function (x, y, obj) {
if (borc > 0) {
var odeme = Math.min(money, borc);
if (odeme > 0) {
money -= odeme;
toplamBorcOdeme += odeme;
borc -= odeme;
if (borc < 0) {
borc = 0;
}
updateMoneyText();
updateBorcText();
}
// If borç is now 0, clear timers
if (borc <= 0) {
borc = 0;
updateBorcText();
if (typeof borcOdemeTimer !== "undefined" && borcOdemeTimer) {
LK.clearInterval(borcOdemeTimer);
borcOdemeTimer = null;
}
if (typeof borcOdemeTimeTimer !== "undefined" && borcOdemeTimeTimer) {
LK.clearInterval(borcOdemeTimeTimer);
borcOdemeTimeTimer = null;
}
}
} else {
// Flash button red if no debt
tween(borcOdeBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(borcOdeBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
}
};
// Repayment time text
var borcTimeTxt = new Text2('', {
size: 28,
fill: '#ffb'
});
borcTimeTxt.anchor.set(0.5, 0);
borcTimeTxt.x = borcTxt.x;
borcTimeTxt.y = borcTxt.y + 28;
LK.gui.top.addChild(borcTimeTxt);
var borcOdemeKalan = 0; // seconds left to next repayment
var borcOdemeTimeTimer = null;
function updateBorcText() {
if (borc > 0) {
borcTxt.setText('Borç: ₺' + borc);
if (borcOdemeKalan > 0) {
var min = Math.floor(borcOdemeKalan / 60);
var sec = borcOdemeKalan % 60;
var timeStr = min > 0 ? min + " dk " + (sec < 10 ? "0" : "") + sec + " sn" : sec + " sn";
borcTimeTxt.setText("Geri ödeme: " + timeStr);
} else {
borcTimeTxt.setText('');
}
} else {
borcTxt.setText('');
borcTimeTxt.setText('');
}
}
updateBorcText();
var borcOdemeTimer = null;
bankBtn.down = function (x, y, obj) {
if (newPagePanel && newPagePanel.visible) {
return;
}
// Only allow one active loan at a time
if (borc > 0) {
// Flash button red to indicate already borrowed
tween(bankBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(bankBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
return;
}
// Borç alındığında mevcut bakiyenin %10'u kadar borç ver
var loanAmount = Math.floor(money * 0.10);
if (loanAmount < 1) loanAmount = 1; // Minimum 1 TL borç verilsin
borc = loanAmount;
money += loanAmount;
updateMoneyText();
updateBorcText();
// Start repayment every 10 minutes (600s = 36000 frames)
if (borcOdemeTimer) {
LK.clearInterval(borcOdemeTimer);
}
if (borcOdemeTimeTimer) {
LK.clearInterval(borcOdemeTimeTimer);
}
borcOdemeKalan = 600; // seconds to next repayment (10 minutes)
updateBorcText();
// Repayment time countdown, updates every 1 second
borcOdemeTimeTimer = LK.setInterval(function () {
if (borc > 0) {
borcOdemeKalan--;
if (borcOdemeKalan < 0) {
borcOdemeKalan = 0;
}
updateBorcText();
} else {
borcOdemeKalan = 0;
updateBorcText();
if (borcOdemeTimeTimer) {
LK.clearInterval(borcOdemeTimeTimer);
borcOdemeTimeTimer = null;
}
}
}, 60); // 1 second at 60fps
borcOdemeTimer = LK.setInterval(function () {
if (borc > 0) {
var odeme = Math.ceil(borc * 0.25);
if (money >= odeme) {
money -= odeme;
borc -= odeme;
if (borc < 0) {
borc = 0;
}
updateMoneyText();
updateBorcText();
} else {
// Not enough money, take all money and reduce borc accordingly
borc -= money;
money = 0;
if (borc < 0) {
borc = 0;
}
updateMoneyText();
updateBorcText();
}
if (borc <= 0) {
borc = 0;
updateBorcText();
if (borcOdemeTimer) {
LK.clearInterval(borcOdemeTimer);
borcOdemeTimer = null;
}
if (borcOdemeTimeTimer) {
LK.clearInterval(borcOdemeTimeTimer);
borcOdemeTimeTimer = null;
}
}
borcOdemeKalan = 600; // reset repayment time for next cycle (10 minutes)
updateBorcText();
}
}, 36000); // 10 minutes at 60fps
};
// --- Madenlerin stok yazılarını maden resimlerinin tam üstüne ve ortasına yerleştir ---
// Madenler oluşturulmadan önce tanımlanıyor, mines dizisi aşağıda dolacak
var copperRawTxt, siliconRawTxt, ironRawTxt;
// Global function to update raw material texts
function updateRawText() {
if (typeof copperRawTxt !== "undefined" && copperRawTxt) {
copperRawTxt.setText('Bakır: ' + rawMaterials.copper);
}
if (typeof siliconRawTxt !== "undefined" && siliconRawTxt) {
siliconRawTxt.setText('Silikon: ' + rawMaterials.silicon);
}
if (typeof ironRawTxt !== "undefined" && ironRawTxt) {
ironRawTxt.setText('Demir: ' + rawMaterials.iron);
}
// Ava: Update stock count text in Madenler panel if visible
if (window.madenlerMineStockTxts) {
for (var i = 0; i < 6; i++) {
if (window.madenlerMineStockTxts[i]) {
var oreType = oreTypes[i];
// Defensive: check rawMaterials[oreType] exists
var stock = rawMaterials && typeof rawMaterials[oreType] !== "undefined" ? rawMaterials[oreType] : 0;
window.madenlerMineStockTxts[i].setText('' + stock);
}
}
}
// Ava: Update maden depo stock area if visible
if (typeof madenDepoStockTxt !== "undefined" && madenDepoStockTxt !== null && typeof madenDepoStockTxt.visible === "boolean" && typeof madenDepoStockTxt.x !== "undefined" && typeof madenDepoStockTxt.x === "number" && typeof updateMadenDepoStockTxt === "function") {
if (madenDepoStockTxt.visible === true) {
updateMadenDepoStockTxt();
}
}
}
// Defensive: updateRawText should not assume mines[i] exists when called elsewhere
// Madenler oluşturulduktan sonra, mines dizisi dolduktan sonra konumlandır
LK.setTimeout(function () {
// Güvenli kontrol: mines ve her mine var mı
if (mines && mines.length >= 6 && mines[0] && mines[1] && mines[2]) {
// Bakır
copperRawTxt = new Text2('', {
size: 40,
fill: '#ffb',
fontWeight: 'bold'
});
copperRawTxt.anchor.set(0.5, 0.5);
if (mines[0] && typeof mines[0].x === "number" && typeof mines[0].y === "number") {
copperRawTxt.x = mines[0].x;
copperRawTxt.y = mines[0].y;
} else {
copperRawTxt.x = 0;
copperRawTxt.y = 0;
}
game.addChild(copperRawTxt);
// Silikon
siliconRawTxt = new Text2('', {
size: 40,
fill: '#ffb',
fontWeight: 'bold'
});
siliconRawTxt.anchor.set(0.5, 0.5);
if (mines[1] && typeof mines[1].x === "number" && typeof mines[1].y === "number") {
siliconRawTxt.x = mines[1].x;
siliconRawTxt.y = mines[1].y;
} else {
siliconRawTxt.x = 0;
siliconRawTxt.y = 0;
}
game.addChild(siliconRawTxt);
// Demir
ironRawTxt = new Text2('', {
size: 40,
fill: '#ffb',
fontWeight: 'bold'
});
ironRawTxt.anchor.set(0.5, 0.5);
if (mines[2] && typeof mines[2].x === "number" && typeof mines[2].y === "number") {
ironRawTxt.x = mines[2].x;
ironRawTxt.y = mines[2].y;
} else {
ironRawTxt.x = 0;
ironRawTxt.y = 0;
}
game.addChild(ironRawTxt);
// Gümüş
// (Optional: add silverRawTxt if needed in future)
// Nikel
// (Optional: add nikelRawTxt if needed in future)
// Altın
// (Optional: add goldRawTxt if needed in future)
updateRawText();
}
}, 1); // mines dizisinin dolmasını bekle (1 frame sonra çalıştır)
// Panel for parts count, placed below the sales offers (below sellPanel)
// Ensure sellPanel is defined before using its x/y
var partsPanelX = 120; // default fallback
var partsPanelY = 1366 + 400 + 340 / 2 + 60; // biraz daha aşağı (ekstra +30px)
if (typeof sellPanel !== "undefined" && sellPanel && typeof sellPanel.x === "number" && typeof sellPanel.y === "number" && typeof sellPanel.height === "number") {
partsPanelX = sellPanel.x;
partsPanelY = sellPanel.y + sellPanel.height / 2 + 60; // biraz daha aşağı (ekstra +30px)
}
// Panel boyutunu yazı boyutuna göre ayarla (2 sütun, 5 satır, her label max 13 karakter, font size 32, padding 24px)
// Paneli üstteki sellPanel ile aynı genişlikte ve hizada yap
// Panel genişliğini sağdan biraz daha küçült (ör: 1 kademe = 24px azalt)
var partsPanelWidth = (typeof sellPanel !== "undefined" && sellPanel ? sellPanel.width : 2 * 13 * 18 + 48) - 72; // 72px azaltıldı (3 kademe)
var partsPanelHeight = 5 * 38 + 36; // 5 satır * satır yüksekliği + padding
var partsPanel = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0,
width: partsPanelWidth,
height: partsPanelHeight,
x: partsPanelX,
y: partsPanelY // sellPanel'den biraz daha aşağı
});
game.addChild(partsPanel);
var partsTxt = new Text2('', {
size: 32,
fill: '#bff'
});
// Yazıları panelin sağ kenarına hizala
partsTxt.anchor.set(1, 0.5);
partsTxt.x = partsPanel.x + partsPanel.width / 2 - 16; // sağdan 16px padding bırak (panel küçüldüğü için padding azaltıldı)
partsTxt.y = partsPanel.y + partsPanel.height / 2;
game.addChild(partsTxt);
// --- Info panelini stok panelinin altına hizalı ve arkaplanlı ekle ---
// Panel genişliği ve hizası partsPanel ile aynı olacak şekilde ayarlanır
var infoPanelBelowStockWidth = partsPanel.width;
// Info panelini aşağı doğru %400 oranında büyüt
// Paneli alt ve üstten %10 oranında küçült (toplamda %20 daha kısa yap)
var infoPanelBelowStockHeight = Math.floor(90 * 4 * 0.8); // 360px * 0.8 = 288px
var infoPanelBelowStockX = partsPanel.x;
var infoPanelBelowStockY = partsPanel.y + partsPanel.height + 24; // stok panelinin hemen altı, 24px boşluk
// Arkaplan paneli (button asseti ile)
var infoPanelBelowStock = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0,
width: infoPanelBelowStockWidth,
height: infoPanelBelowStockHeight,
x: infoPanelBelowStockX,
y: infoPanelBelowStockY,
color: 0x222a38 // Hafif koyu mavi/gri arkaplan
});
game.addChild(infoPanelBelowStock);
// Info yazısını panelin ortasına ve satır aralığı artırılmış şekilde hizala
var infoBelowStockText = new Text2('Bilgi: Bilgisayar parçalarını üretmek ve satmak için madenlerden ham madde toplayın, fabrikalarda üretim yapın ve mağazada satın.', {
size: 28,
fill: '#fff',
lineHeight: 48,
// Satır aralığını artır (daha ferah görünüm için)
wordWrap: true,
wordWrapWidth: infoPanelBelowStockWidth - 40 // 20px sağ-sol padding
});
infoBelowStockText.anchor.set(0.5, 0.5);
// Panelin tam ortasına hizala (yeni yükseklikle)
infoBelowStockText.x = infoPanelBelowStock.x + 56; // 1 font daha sağa (yaklaşık 28px daha)
// Panelin yeni yüksekliğiyle tam ortasına hizala
infoBelowStockText.y = infoPanelBelowStock.y + infoPanelBelowStockHeight / 2;
game.addChild(infoBelowStockText);
function updatePartsText() {
// 2 sütun, 5 satır olacak şekilde ürünleri aşağı doğru sırala
// Her satırda iki sütun olacak şekilde, sağa hizalı
var lines = ['', '', '', '', ''];
for (var i = 0; i < partTypes.length; i++) {
var label = (i === 0 ? "MOUSE" : i === 1 ? "KLAVYE" : i === 6 ? "CPU" : i === 7 ? "GPU" : i === 8 ? "MONITOR" : i === 9 ? "KASA" : partTypes[i].toUpperCase()) + ':' + parts[partTypes[i]];
var row = i % 5;
var col = Math.floor(i / 5);
if (col === 0) {
lines[row] = label;
} else {
// Sola boşluk ekle, sağa hizalı olması için iki sütun arası boşluk artırıldı
var maxLabelLen = 13;
var left = lines[row];
var right = label;
// Her iki sütunu da sağa hizalamak için, satırın toplam uzunluğunu panel genişliğine göre ayarla
// 2 sütun arası 8 boşluk bırak
var pad = " ";
lines[row] = left + pad + right;
}
}
partsTxt.setText(lines.join('\n'));
if (magazaMuhasebeText && magazaMuhasebeText.visible) {
updateMagazaMuhasebeText();
}
}
updatePartsText();
// Arkaplan müziğini başlat
LK.playMusic('ArkaplanMuzik');
// --- Workers moved to new page panel ---
var workerImages = [];
// Her çalışana farklı bir resim atanacak şekilde image id'leri belirle
var workerImageIds = ['6830b806dc6f2ae53a448901', '6830b6cfdc6f2ae53a4488d7', '6830b789dc6f2ae53a4488e8', '6830c278dc6f2ae53a4489a4', '6830ba15dc6f2ae53a448943'];
var workerNames = ['Çalışan 1', 'Çalışan 2', 'Çalışan 3', 'Çalışan 4', 'Çalışan 5'];
// Çalışanlar yeni sayfa panelinde gösterilecek
var workerCount = 5;
// --- 3'lü sıra halinde alt alta dizilim için yeni konumlandırma ---
// 3 sütun, 2 satır (son satırda 2 çalışan olacak şekilde)
var workerRows = 2;
var workerCols = 3;
var workerPanelMarginTop = 60; // başlık ve "Çalışanlar" yazısı için üstte daha fazla boşluk bırak
var workerPanelMarginBottom = 80;
var workerPanelHeight = newPagePanelHeight - workerPanelMarginTop - workerPanelMarginBottom;
var workerPanelWidth = newPagePanelWidth;
var workerCellWidth = Math.floor(workerPanelWidth / workerCols);
var workerCellHeight = Math.floor(workerPanelHeight / workerRows);
// "Çalışanlar" başlığının altına hizalamak için Y başlangıcı
var workerGridStartY = newPagePanelText.y + newPagePanelText.height + 40; // başlığın altından 40px boşluk
// Her çalışanın paneldeki X ve Y koordinatlarını hesapla
function getWorkerPanelPos(idx) {
// 0,1,2 üst satır; 3,4 alt satır
var row = Math.floor(idx / workerCols);
var col = idx % workerCols;
// Son satırda çalışan sayısı 2 ise ortala
if (row === 1 && workerCount === 5) {
// 2 çalışanı ortalamak için col: 0 ve 1 için X ayarla
var colInRow = idx - workerCols; // 3->0, 4->1
var x = newPagePanel.x + workerCellWidth * (colInRow + 1);
var y = workerGridStartY + workerCellHeight * row + workerCellHeight / 2;
return {
x: x,
y: y
};
} else {
// Üst satırda 3 çalışanı eşit aralıklı dağıt
var x = newPagePanel.x + workerCellWidth * (col + 0.5);
var y = workerGridStartY + workerCellHeight * row + workerCellHeight / 2;
return {
x: x,
y: y
};
}
}
// Çalışan 1 için seviye, kazanç oranı ve butonlar
var worker1Level = 1;
var worker1EarningBase = 10;
var worker1UpgradeCost = 200;
var worker1EarningTxt = null;
var worker1LevelTxt = null;
var worker1UpgradeBtn = null;
var worker1UpgradeBtnTxt = null;
// Çalışan 2 için seviye, üretim süresi azaltma ve butonlar
var worker2Level = 1;
var worker2UpgradeCost = 250;
var worker2LevelTxt = null;
var worker2SpeedTxt = null;
var worker2UpgradeBtn = null;
var worker2UpgradeBtnTxt = null;
// Çalışan 3 için seviye, fabrika yükseltme maliyeti indirim oranı ve butonlar
var worker3Level = 1;
var worker3UpgradeCost = 300;
var worker3LevelTxt = null;
var worker3DiscountTxt = null;
var worker3UpgradeBtn = null;
var worker3UpgradeBtnTxt = null;
// Çalışan 4 için seviye, tıklama kazancı ve butonlar
var worker4Level = 1;
var worker4BaseEarning = 50;
var worker4UpgradeCost = 1000;
var worker4EarningTxt = null;
var worker4LevelTxt = null;
var worker4UpgradeBtn = null;
var worker4UpgradeBtnTxt = null;
// Çalışan 5 için seviye, bonus ve butonlar
var worker5Level = 1;
var worker5BaseBonus = 0.05;
var worker5UpgradeCost = 2000;
var worker5BonusTxt = null;
var worker5LevelTxt = null;
var worker5UpgradeBtn = null;
var worker5UpgradeBtnTxt = null;
// Çalışan UI'larını panelde oluştur, başta görünmez
// --- Ava: workerGapX ve workerY'yi tanımla (panelin genişliğine ve grid'e göre) ---
var workerGapX = newPagePanelWidth / 6; // 3 sütun için 6 aralık (kenarlarda boşluk)
var workerY = newPagePanelY + newPagePanelHeight / 2; // Panelin ortası (varsayılan, grid ile override edilir)
for (var i = 0; i < 5; i++) {
// Dağılımı tam ekran panelde ortala
var workerX = workerGapX * (i + 1);
var workerImg = LK.getAsset('worker' + (i + 1), {
anchorX: 0.5,
anchorY: 0.5,
width: 140,
height: 140,
x: workerX,
y: workerY
});
workerImg.visible = false;
game.addChild(workerImg);
var workerLabel = new Text2(workerNames[i], {
size: 40,
fill: '#fff',
lineHeight: 52 // madenler panelindeki gibi 52 px satır aralığı
});
workerLabel.anchor.set(0.5, 0);
// Resmin alt kenarına ve ortasına hizala
workerLabel.x = workerImg.x;
workerLabel.y = workerImg.y + workerImg.height / 2 + 10; // 10px aşağı boşluk bırak
workerLabel.visible = false;
game.addChild(workerLabel);
// Çalışan alt açıklama yazılarını (seviye, kazanç, bonus, vs) alt alta hizalı şekilde ayarlamak için
// Her çalışan için alt açıklama yazıları bir diziye alınacak ve alt alta sıralanacak
// (Aşağıda ilgili UI'lar eklenirken y konumları bu düzene göre ayarlanacak)
// Çalışan 1 için seviye, kazanç ve buton ekle
if (i === 0) {
worker1LevelTxt = new Text2('Seviye: ' + worker1Level, {
size: 36,
fill: '#ffb'
});
worker1LevelTxt.anchor.set(0.5, 0);
worker1LevelTxt.x = workerImg.x;
worker1LevelTxt.y = workerLabel.y + 32;
worker1LevelTxt.visible = false;
game.addChild(worker1LevelTxt);
worker1EarningTxt = new Text2('Kazanç: ₺' + Math.round(worker1EarningBase * Math.pow(1.02, worker1Level - 1)), {
size: 36,
fill: '#bff'
});
worker1EarningTxt.anchor.set(0.5, 0);
worker1EarningTxt.x = workerImg.x;
worker1EarningTxt.y = worker1LevelTxt.y + worker1LevelTxt.height + 4;
worker1EarningTxt.visible = false;
game.addChild(worker1EarningTxt);
worker1UpgradeBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 140,
height: 64,
x: workerImg.x,
y: worker1EarningTxt.y + worker1EarningTxt.height + 18
});
worker1UpgradeBtn.visible = false;
game.addChild(worker1UpgradeBtn);
worker1UpgradeBtnTxt = new Text2('Yükselt\n₺' + worker1UpgradeCost, {
size: 36,
fill: '#fff'
});
worker1UpgradeBtnTxt.anchor.set(0.5, 0.5);
worker1UpgradeBtnTxt.x = worker1UpgradeBtn.x;
worker1UpgradeBtnTxt.y = worker1UpgradeBtn.y;
worker1UpgradeBtnTxt.visible = false;
game.addChild(worker1UpgradeBtnTxt);
worker1UpgradeBtn.down = function (x, y, obj) {
if (yatirimPanel && yatirimPanel.visible) {
return;
}
if (money >= worker1UpgradeCost) {
money -= worker1UpgradeCost;
worker1Level += 1;
worker1UpgradeCost = Math.floor(worker1UpgradeCost * 2.2);
updateMoneyText();
worker1LevelTxt.setText('Seviye: ' + worker1Level);
worker1EarningTxt.setText('Kazanç: ₺' + Math.round(worker1EarningBase * Math.pow(1.02, worker1Level - 1)));
worker1UpgradeBtnTxt.setText('Yükselt\n₺' + worker1UpgradeCost);
tween(worker1UpgradeBtn, {
scaleX: 1.12,
scaleY: 1.12
}, {
duration: 80,
onFinish: function onFinish() {
tween(worker1UpgradeBtn, {
scaleX: 1,
scaleY: 1
}, {
duration: 80
});
}
});
} else {
tween(worker1UpgradeBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(worker1UpgradeBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
}
};
}
// Çalışan 2 için seviye, üretim süresi azaltma ve buton ekle
if (i === 1) {
worker2LevelTxt = new Text2('Seviye: ' + worker2Level, {
size: 36,
fill: '#ffb'
});
worker2LevelTxt.anchor.set(0.5, 0);
worker2LevelTxt.x = workerImg.x;
worker2LevelTxt.y = workerLabel.y + 32;
worker2LevelTxt.visible = false;
game.addChild(worker2LevelTxt);
worker2SpeedTxt = new Text2('Üretim Süresi: -%0', {
size: 36,
fill: '#bff'
});
worker2SpeedTxt.anchor.set(0.5, 0);
worker2SpeedTxt.x = workerImg.x;
worker2SpeedTxt.y = worker2LevelTxt.y + worker2LevelTxt.height + 4;
worker2SpeedTxt.visible = false;
game.addChild(worker2SpeedTxt);
worker2UpgradeBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 140,
height: 64,
x: workerImg.x,
y: worker2SpeedTxt.y + worker2SpeedTxt.height + 18
});
worker2UpgradeBtn.visible = false;
game.addChild(worker2UpgradeBtn);
worker2UpgradeBtnTxt = new Text2('Yükselt\n₺' + worker2UpgradeCost, {
size: 36,
fill: '#fff'
});
worker2UpgradeBtnTxt.anchor.set(0.5, 0.5);
worker2UpgradeBtnTxt.x = worker2UpgradeBtn.x;
worker2UpgradeBtnTxt.y = worker2UpgradeBtn.y;
worker2UpgradeBtnTxt.visible = false;
game.addChild(worker2UpgradeBtnTxt);
worker2UpgradeBtn.down = function (x, y, obj) {
if (yatirimPanel && yatirimPanel.visible) {
return;
}
if (money >= worker2UpgradeCost) {
money -= worker2UpgradeCost;
worker2Level += 1;
worker2UpgradeCost = Math.floor(worker2UpgradeCost * 2.2);
updateMoneyText();
worker2LevelTxt.setText('Seviye: ' + worker2Level);
worker2SpeedTxt.setText('Üretim Süresi: -%' + (worker2Level - 1) * 2);
worker2UpgradeBtnTxt.setText('Yükselt\n₺' + worker2UpgradeCost);
tween(worker2UpgradeBtn, {
scaleX: 1.12,
scaleY: 1.12
}, {
duration: 80,
onFinish: function onFinish() {
tween(worker2UpgradeBtn, {
scaleX: 1,
scaleY: 1
}, {
duration: 80
});
}
});
} else {
tween(worker2UpgradeBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(worker2UpgradeBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
}
};
}
// Çalışan 3 için seviye, fabrika yükseltme maliyeti indirim oranı ve buton ekle
if (i === 2) {
worker3LevelTxt = new Text2('Seviye: ' + worker3Level, {
size: 36,
fill: '#ffb'
});
worker3LevelTxt.anchor.set(0.5, 0);
worker3LevelTxt.x = workerImg.x;
worker3LevelTxt.y = workerLabel.y + 32;
worker3LevelTxt.visible = false;
game.addChild(worker3LevelTxt);
worker3DiscountTxt = new Text2('Fabrika Yükseltme İndirimi: -%0', {
size: 36,
fill: '#bff'
});
worker3DiscountTxt.anchor.set(0.5, 0);
worker3DiscountTxt.x = workerImg.x;
worker3DiscountTxt.y = worker3LevelTxt.y + worker3LevelTxt.height + 4;
worker3DiscountTxt.visible = false;
game.addChild(worker3DiscountTxt);
worker3UpgradeBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 140,
height: 64,
x: workerImg.x,
y: worker3DiscountTxt.y + worker3DiscountTxt.height + 18
});
worker3UpgradeBtn.visible = false;
game.addChild(worker3UpgradeBtn);
worker3UpgradeBtnTxt = new Text2('Yükselt\n₺' + worker3UpgradeCost, {
size: 36,
fill: '#fff'
});
worker3UpgradeBtnTxt.anchor.set(0.5, 0.5);
worker3UpgradeBtnTxt.x = worker3UpgradeBtn.x;
worker3UpgradeBtnTxt.y = worker3UpgradeBtn.y;
worker3UpgradeBtnTxt.visible = false;
game.addChild(worker3UpgradeBtnTxt);
worker3UpgradeBtn.down = function (x, y, obj) {
if (yatirimPanel && yatirimPanel.visible) {
return;
}
if (money >= worker3UpgradeCost) {
money -= worker3UpgradeCost;
worker3Level += 1;
worker3UpgradeCost = Math.floor(worker3UpgradeCost * 2.2);
updateMoneyText && updateMoneyText();
worker3LevelTxt.setText('Seviye: ' + worker3Level);
worker3DiscountTxt.setText('Fabrika Yükseltme İndirimi: -%' + (worker3Level - 1) * 2);
worker3UpgradeBtnTxt.setText('Yükselt\n₺' + worker3UpgradeCost);
tween(worker3UpgradeBtn, {
scaleX: 1.12,
scaleY: 1.12
}, {
duration: 80,
onFinish: function onFinish() {
tween(worker3UpgradeBtn, {
scaleX: 1,
scaleY: 1
}, {
duration: 80
});
}
});
} else {
tween(worker3UpgradeBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(worker3UpgradeBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
}
};
}
// Çalışan 4 için seviye, tıklama kazancı ve yükseltme butonu ekle
if (i === 3) {
worker4LevelTxt = new Text2('Seviye: ' + worker4Level, {
size: 36,
fill: '#ffb'
});
worker4LevelTxt.anchor.set(0.5, 0);
worker4LevelTxt.x = workerImg.x;
worker4LevelTxt.y = workerLabel.y + 32;
worker4LevelTxt.visible = false;
game.addChild(worker4LevelTxt);
var earning = Math.round(worker4BaseEarning * Math.pow(1.25, worker4Level - 1));
worker4EarningTxt = new Text2('Resmime Tıkla\nTıkla: ₺' + earning, {
size: 36,
fill: '#bff'
});
worker4EarningTxt.anchor.set(0.5, 0);
worker4EarningTxt.x = workerImg.x;
worker4EarningTxt.y = worker4LevelTxt.y + worker4LevelTxt.height + 4;
worker4EarningTxt.visible = false;
game.addChild(worker4EarningTxt);
worker4UpgradeBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 140,
height: 64,
x: workerImg.x,
y: worker4EarningTxt.y + worker4EarningTxt.height + 18
});
worker4UpgradeBtn.visible = false;
game.addChild(worker4UpgradeBtn);
worker4UpgradeBtnTxt = new Text2('Yükselt\n₺' + worker4UpgradeCost, {
size: 36,
fill: '#fff'
});
worker4UpgradeBtnTxt.anchor.set(0.5, 0.5);
worker4UpgradeBtnTxt.x = worker4UpgradeBtn.x;
worker4UpgradeBtnTxt.y = worker4UpgradeBtn.y;
worker4UpgradeBtnTxt.visible = false;
game.addChild(worker4UpgradeBtnTxt);
workerImg.down = function (x, y, obj) {
if (yatirimPanel && yatirimPanel.visible) {
return;
}
var earning = Math.round(worker4BaseEarning * Math.pow(1.25, worker4Level - 1));
money += earning;
updateMoneyText && updateMoneyText();
tween(workerImg, {
scaleX: 1.12,
scaleY: 1.12
}, {
duration: 80,
onFinish: function onFinish() {
tween(workerImg, {
scaleX: 1,
scaleY: 1
}, {
duration: 80
});
}
});
worker4EarningTxt.setText('Resmime Tıkla\nTıkla: ₺' + earning);
};
worker4UpgradeBtn.down = function (x, y, obj) {
if (yatirimPanel && yatirimPanel.visible) {
return;
}
if (money >= worker4UpgradeCost) {
money -= worker4UpgradeCost;
worker4Level += 1;
worker4UpgradeCost = Math.floor(worker4UpgradeCost * 2.5);
updateMoneyText && updateMoneyText();
worker4LevelTxt.setText('Seviye: ' + worker4Level);
var earning = Math.round(worker4BaseEarning * Math.pow(1.25, worker4Level - 1));
worker4EarningTxt.setText('Resmime Tıkla\nTıkla: ₺' + earning);
worker4UpgradeBtnTxt.setText('Yükselt\n₺' + worker4UpgradeCost);
tween(worker4UpgradeBtn, {
scaleX: 1.12,
scaleY: 1.12
}, {
duration: 80,
onFinish: function onFinish() {
tween(worker4UpgradeBtn, {
scaleX: 1,
scaleY: 1
}, {
duration: 80
});
}
});
} else {
tween(worker4UpgradeBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(worker4UpgradeBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
}
};
}
// Çalışan 5 için seviye, bonus ve yükseltme butonu ekle
if (i === 4) {
worker5LevelTxt = new Text2('Seviye: ' + worker5Level, {
size: 36,
fill: '#ffb'
});
worker5LevelTxt.anchor.set(0.5, 0);
worker5LevelTxt.x = workerImg.x;
worker5LevelTxt.y = workerLabel.y + 32;
worker5LevelTxt.visible = false;
game.addChild(worker5LevelTxt);
var bonusPercent = Math.round(worker5BaseBonus * worker5Level * 100);
worker5BonusTxt = new Text2('Tüm Kazanç: +%' + bonusPercent, {
size: 36,
fill: '#bff'
});
worker5BonusTxt.anchor.set(0.5, 0);
worker5BonusTxt.x = workerImg.x;
worker5BonusTxt.y = worker5LevelTxt.y + worker5LevelTxt.height + 4;
worker5BonusTxt.visible = false;
game.addChild(worker5BonusTxt);
worker5UpgradeBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 140,
height: 64,
x: workerImg.x,
y: worker5BonusTxt.y + worker5BonusTxt.height + 18
});
worker5UpgradeBtn.visible = false;
game.addChild(worker5UpgradeBtn);
worker5UpgradeBtnTxt = new Text2('Yükselt\n₺' + worker5UpgradeCost, {
size: 36,
fill: '#fff'
});
worker5UpgradeBtnTxt.anchor.set(0.5, 0.5);
worker5UpgradeBtnTxt.x = worker5UpgradeBtn.x;
worker5UpgradeBtnTxt.y = worker5UpgradeBtn.y;
worker5UpgradeBtnTxt.visible = false;
game.addChild(worker5UpgradeBtnTxt);
worker5UpgradeBtn.down = function (x, y, obj) {
if (yatirimPanel && yatirimPanel.visible) {
return;
}
if (money >= worker5UpgradeCost) {
money -= worker5UpgradeCost;
worker5Level += 1;
worker5UpgradeCost = Math.floor(worker5UpgradeCost * 2.5);
updateMoneyText && updateMoneyText();
worker5LevelTxt.setText('Seviye: ' + worker5Level);
var bonusPercent = Math.round(worker5BaseBonus * worker5Level * 100);
worker5BonusTxt.setText('Tüm Kazanç: +%' + bonusPercent);
worker5UpgradeBtnTxt.setText('Yükselt\n₺' + worker5UpgradeCost);
tween(worker5UpgradeBtn, {
scaleX: 1.12,
scaleY: 1.12
}, {
duration: 80,
onFinish: function onFinish() {
tween(worker5UpgradeBtn, {
scaleX: 1,
scaleY: 1
}, {
duration: 80
});
}
});
} else {
tween(worker5UpgradeBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(worker5UpgradeBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
}
};
}
workerImages.push({
img: workerImg,
label: workerLabel
});
}
// Çalışan 1 kazancını her 10 saniyede bir ekle
// Defensive: define mevduatTutar as 0 if not already defined, to prevent 'mevduatTutar is not defined' error
if (typeof mevduatTutar === "undefined") {
var mevduatTutar = 0;
}
LK.setInterval(function () {
var earning = Math.round(worker1EarningBase * Math.pow(1.02, worker1Level - 1));
money += earning;
// --- Mevduat faizi: %2 yıllık, 10 saniyede bir işlesin (yıllık faiz, 10 saniyeye bölünür) ---
// Yıllık faiz oranı
var mevduatFaizYillik = 0.02;
// 1 yılda 365*24*60*60/10 = 315360 kez 10 saniyelik periyot var
var faizPeriyotSayisi = 365 * 24 * 60 * 60 / 10;
// Her 10 saniyede işlenecek faiz oranı
var mevduatFaizOrani = Math.pow(1 + mevduatFaizYillik, 1 / faizPeriyotSayisi) - 1;
// Mevduat faizi ekle
if (mevduatTutar > 0) {
var faizKazanc = mevduatTutar * mevduatFaizOrani;
// En az 1 kuruş (0.01) birikirse ekle, küsuratı biriktir
if (typeof mevduatFaizKalan === "undefined") {
window.mevduatFaizKalan = 0;
}
window.mevduatFaizKalan += faizKazanc;
if (window.mevduatFaizKalan >= 0.01) {
var eklenecek = Math.floor(window.mevduatFaizKalan * 100) / 100;
mevduatTutar += eklenecek;
window.mevduatFaizKalan -= eklenecek;
updateMevduatTxt && updateMevduatTxt();
}
}
updateMoneyText && updateMoneyText();
if (typeof worker1EarningTxt !== "undefined" && worker1EarningTxt !== null && typeof worker1EarningTxt.setText === "function" && typeof worker1EarningTxt.x !== "undefined" && typeof worker1EarningTxt.x === "number") {
worker1EarningTxt.setText('Kazanç: ₺' + earning);
}
}, 600); // 10 saniye (60fps * 10)
// Panel açıldığında çalışanları göster
newPageBtn.down = function (x, y, obj) {
newPagePanel.visible = true;
newPagePanelTitle.visible = true;
newPagePanelText.visible = true;
newPageKapatBtn.visible = true;
newPageKapatBtnTxt.visible = true;
// Çalışanları ve altındaki UI'ları göster ve panelde 3'lü sıra halinde alt alta ortala
for (var i = 0; i < workerImages.length; i++) {
var pos = getWorkerPanelPos(i);
workerImages[i].img.x = pos.x;
workerImages[i].img.y = pos.y;
workerImages[i].img.visible = true;
workerImages[i].label.x = pos.x;
workerImages[i].label.y = pos.y + 80;
workerImages[i].label.visible = true;
// Alt açıklama yazılarını alt alta ve hizalı şekilde göster
var baseY = workerImages[i].label.y + workerImages[i].label.height + 8; // label'ın altından 8px boşluk
var lineGap = 8; // satırlar arası boşluk
if (i === 0) {
var y = baseY;
if (worker1LevelTxt) {
worker1LevelTxt.x = pos.x;
worker1LevelTxt.y = y;
worker1LevelTxt.visible = true;
y += worker1LevelTxt.height + lineGap;
}
if (worker1EarningTxt) {
worker1EarningTxt.x = pos.x;
worker1EarningTxt.y = y;
worker1EarningTxt.visible = true;
y += worker1EarningTxt.height + lineGap;
}
if (worker1UpgradeBtn) {
worker1UpgradeBtn.x = pos.x;
worker1UpgradeBtn.y = y + worker1UpgradeBtn.height / 2;
worker1UpgradeBtn.visible = true;
}
if (worker1UpgradeBtnTxt) {
worker1UpgradeBtnTxt.x = pos.x;
worker1UpgradeBtnTxt.y = worker1UpgradeBtn.y;
worker1UpgradeBtnTxt.visible = true;
}
}
if (i === 1) {
var y = baseY;
if (worker2LevelTxt) {
worker2LevelTxt.x = pos.x;
worker2LevelTxt.y = y;
worker2LevelTxt.visible = true;
y += worker2LevelTxt.height + lineGap;
}
if (worker2SpeedTxt) {
worker2SpeedTxt.x = pos.x;
worker2SpeedTxt.y = y;
worker2SpeedTxt.visible = true;
y += worker2SpeedTxt.height + lineGap;
}
if (worker2UpgradeBtn) {
worker2UpgradeBtn.x = pos.x;
worker2UpgradeBtn.y = y + worker2UpgradeBtn.height / 2;
worker2UpgradeBtn.visible = true;
}
if (worker2UpgradeBtnTxt) {
worker2UpgradeBtnTxt.x = pos.x;
worker2UpgradeBtnTxt.y = worker2UpgradeBtn.y;
worker2UpgradeBtnTxt.visible = true;
}
}
if (i === 2) {
var y = baseY;
if (worker3LevelTxt) {
worker3LevelTxt.x = pos.x;
worker3LevelTxt.y = y;
worker3LevelTxt.visible = true;
y += worker3LevelTxt.height + lineGap;
}
if (worker3DiscountTxt) {
worker3DiscountTxt.x = pos.x;
worker3DiscountTxt.y = y;
worker3DiscountTxt.visible = true;
y += worker3DiscountTxt.height + lineGap;
}
if (worker3UpgradeBtn) {
worker3UpgradeBtn.x = pos.x;
worker3UpgradeBtn.y = y + worker3UpgradeBtn.height / 2;
worker3UpgradeBtn.visible = true;
}
if (worker3UpgradeBtnTxt) {
worker3UpgradeBtnTxt.x = pos.x;
worker3UpgradeBtnTxt.y = worker3UpgradeBtn.y;
worker3UpgradeBtnTxt.visible = true;
}
}
if (i === 3) {
var y = baseY;
if (worker4LevelTxt) {
worker4LevelTxt.x = pos.x;
worker4LevelTxt.y = y;
worker4LevelTxt.visible = true;
y += worker4LevelTxt.height + lineGap;
}
if (worker4EarningTxt) {
worker4EarningTxt.x = pos.x;
worker4EarningTxt.y = y;
worker4EarningTxt.visible = true;
y += worker4EarningTxt.height + lineGap;
}
if (worker4UpgradeBtn) {
worker4UpgradeBtn.x = pos.x;
worker4UpgradeBtn.y = y + worker4UpgradeBtn.height / 2;
worker4UpgradeBtn.visible = true;
}
if (worker4UpgradeBtnTxt) {
worker4UpgradeBtnTxt.x = pos.x;
worker4UpgradeBtnTxt.y = worker4UpgradeBtn.y;
worker4UpgradeBtnTxt.visible = true;
}
}
if (i === 4) {
var y = baseY;
if (worker5LevelTxt) {
worker5LevelTxt.x = pos.x;
worker5LevelTxt.y = y;
worker5LevelTxt.visible = true;
y += worker5LevelTxt.height + lineGap;
}
if (worker5BonusTxt) {
worker5BonusTxt.x = pos.x;
worker5BonusTxt.y = y;
worker5BonusTxt.visible = true;
y += worker5BonusTxt.height + lineGap;
}
if (worker5UpgradeBtn) {
worker5UpgradeBtn.x = pos.x;
worker5UpgradeBtn.y = y + worker5UpgradeBtn.height / 2;
worker5UpgradeBtn.visible = true;
}
if (worker5UpgradeBtnTxt) {
worker5UpgradeBtnTxt.x = pos.x;
worker5UpgradeBtnTxt.y = worker5UpgradeBtn.y;
worker5UpgradeBtnTxt.visible = true;
}
}
}
// Paneli en öne getir
if (game.setChildIndex) {
game.setChildIndex(newPagePanel, game.children.length - 1);
game.setChildIndex(newPagePanelTitle, game.children.length - 1);
game.setChildIndex(newPagePanelText, game.children.length - 1);
game.setChildIndex(newPageKapatBtn, game.children.length - 1);
game.setChildIndex(newPageKapatBtnTxt, game.children.length - 1);
// Çalışanları ve altındaki UI'ları en öne getir
for (var i = 0; i < workerImages.length; i++) {
game.setChildIndex(workerImages[i].img, game.children.length - 1);
game.setChildIndex(workerImages[i].label, game.children.length - 1);
}
if (worker1LevelTxt) {
game.setChildIndex(worker1LevelTxt, game.children.length - 1);
}
if (worker1EarningTxt) {
game.setChildIndex(worker1EarningTxt, game.children.length - 1);
}
if (worker1UpgradeBtn) {
game.setChildIndex(worker1UpgradeBtn, game.children.length - 1);
}
if (worker1UpgradeBtnTxt) {
game.setChildIndex(worker1UpgradeBtnTxt, game.children.length - 1);
}
if (worker2LevelTxt) {
game.setChildIndex(worker2LevelTxt, game.children.length - 1);
}
if (worker2SpeedTxt) {
game.setChildIndex(worker2SpeedTxt, game.children.length - 1);
}
if (worker2UpgradeBtn) {
game.setChildIndex(worker2UpgradeBtn, game.children.length - 1);
}
if (worker2UpgradeBtnTxt) {
game.setChildIndex(worker2UpgradeBtnTxt, game.children.length - 1);
}
if (worker3LevelTxt) {
game.setChildIndex(worker3LevelTxt, game.children.length - 1);
}
if (worker3DiscountTxt) {
game.setChildIndex(worker3DiscountTxt, game.children.length - 1);
}
if (worker3UpgradeBtn) {
game.setChildIndex(worker3UpgradeBtn, game.children.length - 1);
}
if (worker3UpgradeBtnTxt) {
game.setChildIndex(worker3UpgradeBtnTxt, game.children.length - 1);
}
if (worker4LevelTxt) {
game.setChildIndex(worker4LevelTxt, game.children.length - 1);
}
if (worker4EarningTxt) {
game.setChildIndex(worker4EarningTxt, game.children.length - 1);
}
if (worker4UpgradeBtn) {
game.setChildIndex(worker4UpgradeBtn, game.children.length - 1);
}
if (worker4UpgradeBtnTxt) {
game.setChildIndex(worker4UpgradeBtnTxt, game.children.length - 1);
}
if (worker5LevelTxt) {
game.setChildIndex(worker5LevelTxt, game.children.length - 1);
}
if (worker5BonusTxt) {
game.setChildIndex(worker5BonusTxt, game.children.length - 1);
}
if (worker5UpgradeBtn) {
game.setChildIndex(worker5UpgradeBtn, game.children.length - 1);
}
if (worker5UpgradeBtnTxt) {
game.setChildIndex(worker5UpgradeBtnTxt, game.children.length - 1);
}
}
};
// Paneli kapatınca çalışanları gizle
newPageKapatBtn.down = function (x, y, obj) {
// Hide Çalışanlar panel and all its UI
newPagePanel.visible = false;
newPagePanelTitle.visible = false;
newPagePanelText.visible = false;
newPageKapatBtn.visible = false;
newPageKapatBtnTxt.visible = false;
// --- Yeni üst kapat butonunu ve label/icon'unu gizle ---
if (typeof newPageKapatBtnTop !== "undefined") newPageKapatBtnTop.visible = false;
if (typeof newPageKapatBtnTopIcon !== "undefined") newPageKapatBtnTopIcon.visible = false;
if (typeof newPageKapatBtnTopTxt !== "undefined") newPageKapatBtnTopTxt.visible = false;
// Hide all worker UI
for (var i = 0; i < workerImages.length; i++) {
workerImages[i].img.visible = false;
workerImages[i].label.visible = false;
}
if (worker1LevelTxt) worker1LevelTxt.visible = false; //{17H}{17I}
if (worker1EarningTxt) worker1EarningTxt.visible = false; //{17K}{17L}
if (worker1UpgradeBtn) worker1UpgradeBtn.visible = false; //{17N}{17O}
if (worker1UpgradeBtnTxt) worker1UpgradeBtnTxt.visible = false; //{17Q}{17R}
if (worker2LevelTxt) worker2LevelTxt.visible = false; //{17T}{17U}
if (worker2SpeedTxt) worker2SpeedTxt.visible = false; //{17W}{17X}
if (worker2UpgradeBtn) worker2UpgradeBtn.visible = false; //{17Z}{180}
if (worker2UpgradeBtnTxt) worker2UpgradeBtnTxt.visible = false; //{182}{183}
if (worker3LevelTxt) worker3LevelTxt.visible = false; //{185}{186}
if (worker3DiscountTxt) worker3DiscountTxt.visible = false; //{188}{189}
if (worker3UpgradeBtn) worker3UpgradeBtn.visible = false; //{18b}{18c}
if (worker3UpgradeBtnTxt) worker3UpgradeBtnTxt.visible = false; //{18e}{18f}
if (worker4LevelTxt) worker4LevelTxt.visible = false; //{18h}{18i}
if (worker4EarningTxt) worker4EarningTxt.visible = false; //{18k}{18l}
if (worker4UpgradeBtn) worker4UpgradeBtn.visible = false; //{18n}{18o}
if (worker4UpgradeBtnTxt) worker4UpgradeBtnTxt.visible = false; //{18q}{18r}
if (worker5LevelTxt) worker5LevelTxt.visible = false; //{18t}{18u}
if (worker5BonusTxt) worker5BonusTxt.visible = false; //{18w}{18x}
if (worker5UpgradeBtn) worker5UpgradeBtn.visible = false; //{18z}{18A}
if (worker5UpgradeBtnTxt) worker5UpgradeBtnTxt.visible = false; //{18C}{18D}
// Restore all homepage/game UI (defensive, in case other panels were open)
if (typeof magazaBtn !== "undefined") magazaBtn.visible = true;
if (typeof magazaBtnTxt !== "undefined") magazaBtnTxt.visible = true;
if (typeof yatirimBtn !== "undefined") yatirimBtn.visible = true;
if (typeof yatirimBtnTxt !== "undefined") yatirimBtnTxt.visible = true;
if (typeof bankBtn !== "undefined") bankBtn.visible = true;
if (typeof bankBtnTxt !== "undefined") bankBtnTxt.visible = true;
if (typeof soundBtn !== "undefined") soundBtn.visible = true;
if (typeof soundBtnTxt !== "undefined") soundBtnTxt.visible = true;
if (typeof newPageBtn !== "undefined") newPageBtn.visible = true;
if (typeof newPageBtnTxt !== "undefined") newPageBtnTxt.visible = true;
if (typeof madenlerBtn !== "undefined") madenlerBtn.visible = true;
if (typeof madenlerBtnTxt !== "undefined") madenlerBtnTxt.visible = true;
if (typeof magazalarBtn !== "undefined") magazalarBtn.visible = true;
if (typeof magazalarBtnTxt !== "undefined") magazalarBtnTxt.visible = true;
if (typeof languagesBtn !== "undefined") languagesBtn.visible = true;
if (typeof languagesBtnTxt !== "undefined") languagesBtnTxt.visible = true;
if (typeof calisanlarBtnImg !== "undefined") calisanlarBtnImg.visible = true;
if (typeof madenlerBtnMineImg !== "undefined") madenlerBtnMineImg.visible = true;
// Info and How To Play buttons are never shown
if (typeof borcOdeBtn !== "undefined") borcOdeBtn.visible = true;
if (typeof borcOdeBtnTxt !== "undefined") borcOdeBtnTxt.visible = true;
if (typeof mevduatBtn !== "undefined") mevduatBtn.visible = true;
if (typeof mevduatBtnTxt !== "undefined") mevduatBtnTxt.visible = true;
// --- Ava: Restore all homepage images when Çalışanlar panel closes ---
if (window.homepageImages && window.homepageImages.length) {
for (var i = 0; i < window.homepageImages.length; i++) {
if (window.homepageImages[i] && typeof window.homepageImages[i].visible === "boolean") {
if (typeof window.homepageImages[i]._oldVisible !== "undefined") {
window.homepageImages[i].visible = window.homepageImages[i]._oldVisible;
delete window.homepageImages[i]._oldVisible;
} else {
window.homepageImages[i].visible = true;
}
}
}
}
// Defensive: re-enable all factory/factoryUnlock/prod/auto buttons if they were disabled by other panels
if (typeof factoryBtns !== "undefined" && Array.isArray(factoryBtns)) {
for (var i = 0; i < factoryBtns.length; i++) {
if (factoryBtns[i] && factoryBtns[i]._origDown) {
factoryBtns[i].down = factoryBtns[i]._origDown;
delete factoryBtns[i]._origDown;
}
}
}
if (typeof factoryUnlockBtns !== "undefined" && Array.isArray(factoryUnlockBtns)) {
for (var i = 0; i < factoryUnlockBtns.length; i++) {
if (factoryUnlockBtns[i] && factoryUnlockBtns[i]._origDown) {
factoryUnlockBtns[i].down = factoryUnlockBtns[i]._origDown;
delete factoryUnlockBtns[i]._origDown;
}
}
}
if (typeof prodBtns !== "undefined" && Array.isArray(prodBtns)) {
for (var i = 0; i < prodBtns.length; i++) {
if (prodBtns[i] && prodBtns[i]._origDown) {
prodBtns[i].down = prodBtns[i]._origDown;
delete prodBtns[i]._origDown;
}
}
}
if (typeof factoryAutoBtns !== "undefined" && Array.isArray(factoryAutoBtns)) {
for (var i = 0; i < factoryAutoBtns.length; i++) {
if (factoryAutoBtns[i] && factoryAutoBtns[i]._origDown) {
factoryAutoBtns[i].down = factoryAutoBtns[i]._origDown;
delete factoryAutoBtns[i]._origDown;
}
}
}
for (var i = 0; i < game.children.length; i++) {
var child = game.children[i];
if (child && child.isFactoryButton && child._origDown) {
child.down = child._origDown;
delete child._origDown;
}
}
// Hide overlays if visible
if (typeof fullscreenOverlay !== "undefined") fullscreenOverlay.visible = false;
};
// --- Mines ---
// Anasayfada madenler, stok sayısı ve butonları gösterilmeyecek
var mines = [];
var mineAutoProduce = [false, false, false, false, false, false]; // Track auto-produce state for each mine
var mineAutoBtns = [];
var mineAutoTxts = [];
// Defensive: Always initialize mines array with 6 Mine objects, one for each ore type
if (!Array.isArray(mines) || mines.length !== 6) {
mines = [];
for (var i = 0; i < 6; i++) {
var m = new Mine();
m.setType(oreTypes[i]);
// Arrange mines offscreen by default (UI panels will reposition them)
m.x = -1000;
m.y = -1000;
mines.push(m);
game.addChild(m);
}
}
// --- Factories for each part ---
var factories = [];
var factoryUnlocks = [];
var factoryUnlockCosts = [0, 350, 525, 700, 875, 1050, 1225, 1400, 1575, 1750];
// Apply 50% price increase to all except the first (CPU)
for (var i = 1; i < factoryUnlockCosts.length; i++) {
factoryUnlockCosts[i] = Math.floor(factoryUnlockCosts[i] * 1.5);
}
var factoryAutoProduce = [];
var factoryAutoBtns = [];
var factoryAutoTxts = [];
for (var i = 0; i < partTypes.length; i++) {
var FactoryClass = FactoryClasses[partTypes[i]];
var f = new FactoryClass();
// Arrange factories in two rows of 5, with extra vertical spacing between rows
var col = i % 5;
var row = Math.floor(i / 5);
// Add vertical spacing (gap) between factory panels
var factoryPanelGap = 24;
f.x = 500 + col * 300 + col * factoryPanelGap;
// Move MB, CASE, FAN, HDD, COOLER (indices 5,6,7,8,9) further down
// Move the whole factories panel lower by +200px
if (i >= 5) {
// Increase the offset for the second row and move these factories further down
f.y = 1300 + row * 420 + 320;
} else {
f.y = 1300 + row * 420;
}
game.addChild(f);
factories.push(f);
// Add production time text under the part icon
var prodTime = f.getProductionTime ? f.getProductionTime() : 30;
var prodTimeSec = (prodTime / 60).toFixed(2);
// Add a panel image behind the production time text
var prodTimePanel = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0,
width: 220,
height: 54,
x: f.x,
y: f.y - 60 + 60 * 0.7 + 28,
// 10px higher to allow for text padding
scaleX: 0.8,
scaleY: 0.7
});
// Add horizontal gap to prodTimePanel to match factory panel gap
prodTimePanel.x = f.x;
game.addChild(prodTimePanel);
var prodTimeTxt = new Text2("Üretim: " + prodTimeSec + " sn", {
size: 32,
fill: "#fff"
});
prodTimeTxt.anchor.set(0.5, 0);
// Place under the part icon (which is at y: -60, scale 0.7, so about -60+60*0.7+10)
prodTimeTxt.x = f.x;
prodTimeTxt.y = f.y - 60 + 60 * 0.7 + 38;
game.addChild(prodTimeTxt);
// Store reference for later update on upgrade
f._prodTimeTxt = prodTimeTxt;
// Unlock state: CPU (i==0) is always unlocked, others locked
factoryUnlocks.push(i === 0 ? true : false);
// Add auto-produce toggle button for each factory
factoryAutoProduce.push(false);
var autoBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
autoBtn.x = f.x;
// Move auto-produce button further down
// Add horizontal gap to autoBtn to match factory panel gap
autoBtn.x = f.x;
if (i >= 5) {
autoBtn.y = f.y + 530 + 80;
} else {
autoBtn.y = f.y + 530;
}
game.addChild(autoBtn);
var autoTxt = new Text2('Oto Üret: Kapalı', {
size: 36,
fill: '#fff'
});
autoTxt.anchor.set(0.5, 0.5);
autoTxt.x = autoBtn.x;
autoTxt.y = autoBtn.y;
game.addChild(autoTxt);
autoBtn.factoryIndex = i;
autoBtn.down = function (x, y, obj) {
// Disable if investment panel is open or Çalışanlar paneli is open
if (yatirimPanel && yatirimPanel.visible || newPagePanel && newPagePanel.visible) {
return;
}
var idx = this.factoryIndex;
if (!factoryAutoProduce[idx]) {
// Cost to enable auto-produce for factory: 1000
var autoFactoryCost = (idx + 1) * 1000;
if (money >= autoFactoryCost) {
money -= autoFactoryCost;
updateMoneyText();
factoryAutoProduce[idx] = true;
factoryAutoTxts[idx].setText('Oto Üret: Açık');
} else {
// Not enough money, flash button red
tween(this, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(autoBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
}
} else {
// Oto Üret kapatılmasın: Satın alındıktan sonra kapatmaya izin verme
// Artık kapatma işlemi yapılmıyor, buton işlevsiz.
}
};
factoryAutoBtns.push(autoBtn);
factoryAutoTxts.push(autoTxt);
// Set initial text
var autoFactoryCost = (i + 1) * 1000;
autoTxt.setText('Oto Üret: Kapalı\n₺' + autoFactoryCost);
}
// --- Store ---
var store = new Store();
// --- Ava: Arrange all stores and their purchase/upgrade buttons horizontally above factories ---
// Calculate horizontal layout for stores above factories
// Move all stores and their buttons 0.75 row higher (row height = 420, so move up by 315px)
var storeAboveFactoryY = 980 - 315; // 0.75 satır yukarı taşı
var storeAboveFactoryGapX = 320;
var storeAboveFactoryStartX = 650; // Ekranın solundan biraz içeride başlat
// Store 1
store.x = storeAboveFactoryStartX;
store.y = storeAboveFactoryY;
store.scaleX = 0.82;
store.scaleY = 0.82;
game.addChild(store);
// Store 2
var store2Purchased = false;
var store2PurchaseCost = 2000;
var store2 = new Store();
store2.x = store.x + storeAboveFactoryGapX * 1;
store2.y = storeAboveFactoryY;
store2.scaleX = 0.82;
store2.scaleY = 0.82;
game.addChild(store2);
store2.visible = true;
// Store 3
var store3Purchased = false;
var store3PurchaseCost = 5000;
var store3 = new Store();
store3.x = store.x + storeAboveFactoryGapX * 2;
store3.y = storeAboveFactoryY;
store3.scaleX = 0.82;
store3.scaleY = 0.82;
game.addChild(store3);
store3.visible = true;
// Store 4
var store4Purchased = false;
var store4PurchaseCost = 10000;
var store4 = new Store();
store4.x = store.x + storeAboveFactoryGapX * 3;
store4.y = storeAboveFactoryY;
store4.scaleX = 0.82;
store4.scaleY = 0.82;
game.addChild(store4);
store4.visible = true;
// --- Store 2 Purchase Button (fabrikaların üstündeki mağazaların altına hizala) ---
var store2PurchaseBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 260,
height: 80
});
store2PurchaseBtn.x = store2.x;
store2PurchaseBtn.y = store2.y + 160;
store2PurchaseBtn.visible = !store2Purchased;
game.addChild(store2PurchaseBtn);
var store2PurchaseBtnTxt = new Text2('Mağaza 2 Satın Al\n₺' + store2PurchaseCost, {
size: 38,
fill: '#fff'
});
store2PurchaseBtnTxt.anchor.set(0.5, 0.5);
store2PurchaseBtnTxt.x = store2PurchaseBtn.x;
store2PurchaseBtnTxt.y = store2PurchaseBtn.y + 10;
store2PurchaseBtnTxt.visible = !store2Purchased;
game.addChild(store2PurchaseBtnTxt);
// Store2 purchase logic as a function for reuse
function handleStore2Purchase() {
if (store2Purchased) {
return;
}
if (money >= store2PurchaseCost) {
money -= store2PurchaseCost;
store2Purchased = true;
updateMoneyText && updateMoneyText();
store2PurchaseBtn.visible = false;
store2PurchaseBtnTxt.visible = false;
// Show upgrade button after purchase
if (typeof store2Btn !== "undefined") {
store2Btn.visible = true;
}
if (typeof store2BtnTxt !== "undefined") {
store2BtnTxt.visible = true;
}
// Show store2 in Mağazalar panel after purchase
if (typeof store2 !== "undefined") {
store2.visible = true;
}
// Hide purchase button after purchase on homepage
store2PurchaseBtn.visible = false;
store2PurchaseBtnTxt.visible = false;
// Also hide on homepage duplicate if exists
if (typeof store2PurchaseBtn !== "undefined") {
store2PurchaseBtn.visible = false;
}
if (typeof store2PurchaseBtnTxt !== "undefined") {
store2PurchaseBtnTxt.visible = false;
}
} else {
// Not enough money, flash button red
tween(store2PurchaseBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(store2PurchaseBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
}
// Hide purchase button if purchased (defensive, in case of duplicate UI)
if (store2Purchased) {
store2PurchaseBtn.visible = false;
store2PurchaseBtnTxt.visible = false;
}
}
// Button logic
store2PurchaseBtn.down = function (x, y, obj) {
handleStore2Purchase();
};
// --- Store 2 Upgrade Button (fabrikaların üstündeki mağazaların altına hizala) ---
if (typeof store2Btn !== "undefined") {
store2Btn.x = store2.x;
store2Btn.y = store2.y + 160;
}
if (typeof store2BtnTxt !== "undefined") {
store2BtnTxt.x = store2.x;
store2BtnTxt.y = store2.y + 180;
}
// --- Store 3 Purchase Button (fabrikaların üstündeki mağazaların altına hizala) ---
// --- Store 3 Purchase Button (store2'ye benzer şekilde) ---
var store3PurchaseBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 260,
height: 80
});
store3PurchaseBtn.x = store3.x;
store3PurchaseBtn.y = store3.y + 160;
store3PurchaseBtn.visible = !store3Purchased;
game.addChild(store3PurchaseBtn);
var store3PurchaseBtnTxt = new Text2('Mağaza 3 Satın Al\n₺' + store3PurchaseCost, {
size: 38,
fill: '#fff'
});
store3PurchaseBtnTxt.anchor.set(0.5, 0.5);
store3PurchaseBtnTxt.x = store3PurchaseBtn.x;
store3PurchaseBtnTxt.y = store3PurchaseBtn.y + 10;
store3PurchaseBtnTxt.visible = !store3Purchased;
game.addChild(store3PurchaseBtnTxt);
function handleStore3Purchase() {
if (store3Purchased) {
return;
}
if (money >= store3PurchaseCost) {
money -= store3PurchaseCost;
store3Purchased = true;
updateMoneyText && updateMoneyText();
store3PurchaseBtn.visible = false;
store3PurchaseBtnTxt.visible = false;
store3PurchaseBtnImg.visible = false;
if (typeof store3Btn !== "undefined") {
store3Btn.visible = true;
}
if (typeof store3BtnTxt !== "undefined") {
store3BtnTxt.visible = true;
}
if (typeof store3 !== "undefined") {
store3.visible = true;
}
// Hide purchase button after purchase on homepage
if (typeof store3PurchaseBtn !== "undefined") {
store3PurchaseBtn.visible = false;
}
if (typeof store3PurchaseBtnTxt !== "undefined") {
store3PurchaseBtnTxt.visible = false;
}
if (typeof store3PurchaseBtnImg !== "undefined") {
store3PurchaseBtnImg.visible = false;
}
} else {
// Not enough money, flash button red
tween(store3PurchaseBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(store3PurchaseBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
tween(store3PurchaseBtnImg, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(store3PurchaseBtnImg, {
tint: 0x3fa9f5
}, {
duration: 120
});
}
});
}
if (store3Purchased) {
store3PurchaseBtn.visible = false;
store3PurchaseBtnTxt.visible = false;
store3PurchaseBtnImg.visible = false;
}
}
store3PurchaseBtn.down = function (x, y, obj) {
handleStore3Purchase();
};
store3PurchaseBtnTxt.down = function (x, y, obj) {
handleStore3Purchase();
};
if (typeof store3Btn !== "undefined") {
store3Btn.x = store3.x;
store3Btn.y = store3.y + 160;
store3Btn.visible = !!store3Purchased;
}
if (typeof store3BtnTxt !== "undefined") {
store3BtnTxt.x = store3.x;
store3BtnTxt.y = store3.y + 180;
store3BtnTxt.visible = !!store3Purchased;
}
// --- Store 4 Purchase Button (store2'ye benzer şekilde) ---
var store4PurchaseBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 260,
height: 80
});
store4PurchaseBtn.x = store4.x;
store4PurchaseBtn.y = store4.y + 160;
store4PurchaseBtn.visible = !store4Purchased;
game.addChild(store4PurchaseBtn);
var store4PurchaseBtnTxt = new Text2('Mağaza 4 Satın Al\n₺' + store4PurchaseCost, {
size: 38,
fill: '#fff'
});
store4PurchaseBtnTxt.anchor.set(0.5, 0.5);
store4PurchaseBtnTxt.x = store4PurchaseBtn.x;
store4PurchaseBtnTxt.y = store4PurchaseBtn.y + 10;
store4PurchaseBtnTxt.visible = !store4Purchased;
game.addChild(store4PurchaseBtnTxt);
function handleStore4Purchase() {
if (store4Purchased) {
return;
}
if (money >= store4PurchaseCost) {
money -= store4PurchaseCost;
store4Purchased = true;
updateMoneyText && updateMoneyText();
store4PurchaseBtn.visible = false;
store4PurchaseBtnTxt.visible = false;
store4PurchaseBtnImg.visible = false;
if (typeof store4Btn !== "undefined") {
store4Btn.visible = true;
}
if (typeof store4BtnTxt !== "undefined") {
store4BtnTxt.visible = true;
}
if (typeof store4 !== "undefined") {
store4.visible = true;
}
// Hide purchase button after purchase on homepage
if (typeof store4PurchaseBtn !== "undefined") {
store4PurchaseBtn.visible = false;
}
if (typeof store4PurchaseBtnTxt !== "undefined") {
store4PurchaseBtnTxt.visible = false;
}
if (typeof store4PurchaseBtnImg !== "undefined") {
store4PurchaseBtnImg.visible = false;
}
} else {
// Not enough money, flash button red
tween(store4PurchaseBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(store4PurchaseBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
tween(store4PurchaseBtnImg, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(store4PurchaseBtnImg, {
tint: 0xf97f62
}, {
duration: 120
});
}
});
}
if (store4Purchased) {
store4PurchaseBtn.visible = false;
store4PurchaseBtnTxt.visible = false;
store4PurchaseBtnImg.visible = false;
}
}
store4PurchaseBtn.down = function (x, y, obj) {
handleStore4Purchase();
};
store4PurchaseBtnTxt.down = function (x, y, obj) {
handleStore4Purchase();
};
if (typeof store4Btn !== "undefined") {
store4Btn.x = store4.x;
store4Btn.y = store4.y + 160;
store4Btn.visible = !!store4Purchased;
}
if (typeof store4BtnTxt !== "undefined") {
store4BtnTxt.x = store4.x;
store4BtnTxt.y = store4.y + 180;
store4BtnTxt.visible = !!store4Purchased;
}
// --- Ava: Always show all stores and their purchase buttons on homepage until purchased ---
store.visible = true;
store2.visible = true;
store3.visible = true;
store4.visible = true;
if (typeof store2PurchaseBtn !== "undefined" && store2PurchaseBtn) {
store2PurchaseBtn.visible = !store2Purchased;
if (store2Purchased) {
store2PurchaseBtn.visible = false;
store2PurchaseBtnTxt.visible = false;
}
}
store2PurchaseBtnTxt.visible = !store2Purchased;
store3PurchaseBtn.visible = false;
store3PurchaseBtnTxt.visible = false;
if (typeof store3PurchaseBtnIcon !== "undefined") {
store3PurchaseBtnIcon.visible = false;
}
if (store3Purchased) {
store3PurchaseBtn.visible = false;
store3PurchaseBtnTxt.visible = false;
if (typeof store3PurchaseBtnIcon !== "undefined") {
store3PurchaseBtnIcon.visible = false;
}
}
store4PurchaseBtn.visible = false;
store4PurchaseBtnTxt.visible = false;
if (typeof store4PurchaseBtnIcon !== "undefined") {
store4PurchaseBtnIcon.visible = false;
}
if (store4Purchased) {
store4PurchaseBtn.visible = false;
store4PurchaseBtnTxt.visible = false;
if (typeof store4PurchaseBtnIcon !== "undefined") {
store4PurchaseBtnIcon.visible = false;
}
}
// --- Show all customers on homepage ---
if (typeof customers === "undefined" || !Array.isArray(customers)) {
customers = [];
}
for (var i = 0; i < customers.length; i++) {
customers[i].visible = true;
}
// --- Store 2 Purchase Button (Mağazalar panelinde, upgrade üstünde) ---
var store2PurchaseBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 260,
height: 80
});
// Show on homepage (anasayfa)
store2PurchaseBtn.x = store2.x;
store2PurchaseBtn.y = store2.y + 160;
store2PurchaseBtn.visible = !store2Purchased;
game.addChild(store2PurchaseBtn);
var store2PurchaseBtnTxt = new Text2('Mağaza 2 Satın Al\n₺' + store2PurchaseCost, {
size: 38,
fill: '#fff'
});
store2PurchaseBtnTxt.anchor.set(0.5, 0.5);
store2PurchaseBtnTxt.x = store2PurchaseBtn.x;
store2PurchaseBtnTxt.y = store2PurchaseBtn.y + 10;
store2PurchaseBtnTxt.visible = !store2Purchased;
game.addChild(store2PurchaseBtnTxt);
store2PurchaseBtn.down = function (x, y, obj) {
if (store2Purchased) {
return;
}
if (money >= store2PurchaseCost) {
money -= store2PurchaseCost;
store2Purchased = true;
updateMoneyText && updateMoneyText();
store2PurchaseBtn.visible = false;
store2PurchaseBtnTxt.visible = false;
// Show upgrade button after purchase
if (typeof store2Btn !== "undefined") {
store2Btn.visible = true;
}
if (typeof store2BtnTxt !== "undefined") {
store2BtnTxt.visible = true;
}
// Show store2 in Mağazalar panel after purchase
if (typeof store2 !== "undefined") {
store2.visible = true;
}
} else {
// Not enough money, flash button red
tween(store2PurchaseBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(store2PurchaseBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
}
};
// --- Store 3 Purchase Button (Mağazalar panelinde, upgrade üstünde) ---
var store3PurchaseBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 260,
height: 80
});
// Show on homepage (anasayfa)
store3PurchaseBtn.x = store3.x;
store3PurchaseBtn.y = store3.y + 160;
store3PurchaseBtn.visible = !store3Purchased;
game.addChild(store3PurchaseBtn);
// (icon removed for Store3 purchase button - duplicate)
var store3PurchaseBtnTxt = new Text2('Mağaza 3 Satın Al\n₺' + store3PurchaseCost, {
size: 36,
fill: '#fff'
});
store3PurchaseBtnTxt.anchor.set(0.5, 0.5);
store3PurchaseBtnTxt.x = store3PurchaseBtn.x;
store3PurchaseBtnTxt.y = store3PurchaseBtn.y + 10;
store3PurchaseBtnTxt.visible = !store3Purchased;
store3PurchaseBtnTxt.style = store3PurchaseBtnTxt.style || {};
store3PurchaseBtnTxt.style.fill = '#fff';
game.addChild(store3PurchaseBtnTxt);
// Store3 purchase button logic
store3PurchaseBtn.down = function (x, y, obj) {
if (store3Purchased) {
return;
}
if (money >= store3PurchaseCost) {
money -= store3PurchaseCost;
store3Purchased = true;
updateMoneyText && updateMoneyText();
store3PurchaseBtn.visible = false;
store3PurchaseBtnTxt.visible = false;
// Show upgrade button after purchase
if (typeof store3Btn !== "undefined") {
store3Btn.visible = true;
}
if (typeof store3BtnTxt !== "undefined") {
store3BtnTxt.visible = true;
}
// Show store3 in Mağazalar panel after purchase
if (typeof store3 !== "undefined") {
store3.visible = true;
}
} else {
// Not enough money, flash button red
tween(store3PurchaseBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(store3PurchaseBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
}
};
store3PurchaseBtnTxt.down = function (x, y, obj) {
store3PurchaseBtn.down(x, y, obj);
};
// --- Store 4 Purchase Button (Mağazalar panelinde, upgrade üstünde) ---
var store4PurchaseBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 260,
height: 80
});
// Show on homepage (anasayfa)
store4PurchaseBtn.x = store4.x;
store4PurchaseBtn.y = store4.y + 160;
store4PurchaseBtn.visible = !store4Purchased;
game.addChild(store4PurchaseBtn);
// (icon removed for Store4 purchase button - duplicate)
var store4PurchaseBtnTxt = new Text2('Mağaza 4 Satın Al\n₺' + store4PurchaseCost, {
size: 36,
fill: '#fff'
});
store4PurchaseBtnTxt.anchor.set(0.5, 0.5);
store4PurchaseBtnTxt.x = store4PurchaseBtn.x;
store4PurchaseBtnTxt.y = store4PurchaseBtn.y + 10;
store4PurchaseBtnTxt.visible = !store4Purchased;
store4PurchaseBtnTxt.style = store4PurchaseBtnTxt.style || {};
store4PurchaseBtnTxt.style.fill = '#fff';
game.addChild(store4PurchaseBtnTxt);
// Store4 purchase button logic
store4PurchaseBtn.down = function (x, y, obj) {
if (store4Purchased) {
return;
}
if (money >= store4PurchaseCost) {
money -= store4PurchaseCost;
store4Purchased = true;
updateMoneyText && updateMoneyText();
store4PurchaseBtn.visible = false;
store4PurchaseBtnTxt.visible = false;
// Show upgrade button after purchase
if (typeof store4Btn !== "undefined") {
store4Btn.visible = true;
}
if (typeof store4BtnTxt !== "undefined") {
store4BtnTxt.visible = true;
}
// Show store4 in Mağazalar panel after purchase
if (typeof store4 !== "undefined") {
store4.visible = true;
}
} else {
// Not enough money, flash button red
tween(store4PurchaseBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(store4PurchaseBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
}
};
store4PurchaseBtnTxt.down = function (x, y, obj) {
store4PurchaseBtn.down(x, y, obj);
};
// --- Upgrade Buttons ---
var mineBtns = [];
for (var i = 0; i < 3; i++) {
// Defensive: skip if mines or mines[i] is not defined
if (!mines || !mines[i]) {
continue;
}
var btn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
btn.x = mines[i].x - 80; // Move left to make space for produce button
btn.y = mines[i].y + 200;
game.addChild(btn);
var txt = new Text2('Maden Yükselt\n₺' + mines[i].upgradeCost, {
size: 44,
fill: '#fff'
});
txt.anchor.set(0.5, 0.5);
txt.y = btn.y + 20;
txt.x = btn.x;
game.addChild(txt);
btn.mineIndex = i;
btn.txt = txt;
btn.down = function (x, y, obj) {
// Disable if investment panel is open
if (yatirimPanel && yatirimPanel.visible) {
return;
}
var idx = this.mineIndex;
if (!mines || !mines[idx]) {
return;
}
var m = mines[idx];
if (money >= m.upgradeCost) {
toplamMadenYukseltme += m.upgradeCost;
m.upgrade();
this.txt.setText('Maden Yükselt\n₺' + m.upgradeCost);
}
};
mineBtns.push(btn);
// Add ÜRET (Produce) button next to upgrade
var prodBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 180,
height: 80
});
// ÜRET butonunu madenin altına yerleştir
prodBtn.x = mines[i].x - 170;
prodBtn.y = mines[i].y + 320;
game.addChild(prodBtn);
var prodTxt = new Text2('ÜRET', {
size: 36,
fill: '#fff'
});
prodTxt.anchor.set(0.5, 0.5);
// ÜRET yazısını butonun tam ortasına yerleştir
prodTxt.x = prodBtn.x;
prodTxt.y = prodBtn.y;
game.addChild(prodTxt);
prodBtn.mineIndex = i;
prodBtn.down = function (x, y, obj) {
// Disable if investment panel is open
if (yatirimPanel && yatirimPanel.visible) {
return;
}
var idx = this.mineIndex;
if (!mines || !mines[idx]) {
return;
}
var m = mines[idx];
// Instantly produce one batch of raw material for this mine
rawMaterials[m.type] += m.production;
updateRawText();
// Animate mine for feedback
tween(m, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 120,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(m, {
scaleX: 1,
scaleY: 1
}, {
duration: 120
});
}
});
};
}
// Factory upgrade buttons for each part
var factoryBtns = [];
var factoryUnlockBtns = [];
for (var i = 0; i < factories.length; i++) {
var f = factories[i];
// If factory is locked (except CPU), show unlock button instead of upgrade
if (!factoryUnlocks[i]) {
var unlockBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
unlockBtn.x = f.x;
// Add horizontal gap to unlock buttons to match factory panel gap
unlockBtn.x = f.x;
if (i >= 5) {
unlockBtn.y = f.y + 200 + 80;
} else {
unlockBtn.y = f.y + 200;
}
game.addChild(unlockBtn);
var unlockTxt = new Text2((i === 0 ? "MOUSE" : i === 1 ? "KLAVYE" : i === 6 ? "CPU" : i === 7 ? "GPU" : i === 8 ? "MONITOR" : i === 9 ? "KASA" : partTypes[i].toUpperCase()) + " Aç\n₺" + factoryUnlockCosts[i], {
size: 44,
fill: '#fff'
});
unlockTxt.anchor.set(0.5, 0.5);
unlockTxt.x = unlockBtn.x;
unlockTxt.y = unlockBtn.y + 20;
game.addChild(unlockTxt);
unlockBtn.factoryIndex = i;
unlockBtn.txt = unlockTxt;
unlockBtn.down = function (x, y, obj) {
// Disable if investment panel is open or Çalışanlar paneli is open
if (yatirimPanel && yatirimPanel.visible || newPagePanel && newPagePanel.visible) {
return;
}
var idx = this.factoryIndex;
if (!factoryUnlocks[idx] && money >= factoryUnlockCosts[idx]) {
money -= factoryUnlockCosts[idx];
updateMoneyText();
factoryUnlocks[idx] = true;
// Remove unlock button and text
this.destroy();
this.txt.destroy();
// Show upgrade button for this factory
showFactoryUpgradeButton(idx);
}
};
factoryUnlockBtns.push(unlockBtn);
// Don't show upgrade button for locked factories
continue;
}
// Show upgrade button for unlocked factories
var btn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
btn.x = f.x;
// Add horizontal gap to upgrade/unlock/production buttons to match factory panel gap
btn.x = f.x;
// Move MB, CASE, FAN, HDD, COOLER (indices 5,6,7,8,9) buttons further down
if (i >= 5) {
btn.y = f.y + 200 + 80;
} else {
btn.y = f.y + 200;
}
game.addChild(btn);
var txt = new Text2((i === 0 ? "MOUSE" : i === 1 ? "KLAVYE" : i === 6 ? "CPU" : i === 7 ? "GPU" : i === 8 ? "MONITOR" : partTypes[i].toUpperCase()) + " Yükselt\n₺" + f.upgradeCost, {
size: 44,
fill: '#fff'
});
txt.anchor.set(0.5, 0.5);
txt.x = btn.x;
txt.y = btn.y + 20;
game.addChild(txt);
btn.factoryIndex = i;
btn.txt = txt;
btn.down = function (x, y, obj) {
// Disable if investment panel is open or Çalışanlar paneli is open
if (yatirimPanel && yatirimPanel.visible || newPagePanel && newPagePanel.visible) {
return;
}
var idx = this.factoryIndex;
var f = factories[idx];
// Çalışan 3 indirimini uygula
var discount = 1 - (worker3Level - 1) * 0.02;
if (discount < 0.1) {
discount = 0.1;
} // Maksimum %90 indirim
var discountedCost = Math.floor(f.upgradeCost * discount);
if (money >= discountedCost) {
toplamFabrikaYukseltme += discountedCost;
money -= discountedCost;
f.upgrade();
updateMoneyText && updateMoneyText();
this.txt.setText((idx === 0 ? "MOUSE" : idx === 1 ? "KLAVYE" : idx === 6 ? "CPU" : idx === 7 ? "GPU" : idx === 8 ? "MONITOR" : idx === 9 ? "KASA" : partTypes[idx].toUpperCase()) + " Yükselt\n₺" + f.upgradeCost);
}
};
factoryBtns.push(btn);
}
// Helper to show upgrade button after unlock
function showFactoryUpgradeButton(idx) {
var f = factories[idx];
var btn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
btn.x = f.x;
// Add horizontal gap to upgrade button after unlock to match factory panel gap
btn.x = f.x;
if (idx >= 5) {
btn.y = f.y + 200 + 80;
} else {
btn.y = f.y + 200;
}
game.addChild(btn);
var txt = new Text2((idx === 0 ? "MOUSE" : idx === 1 ? "KLAVYE" : idx === 6 ? "CPU" : idx === 7 ? "GPU" : idx === 8 ? "MONITOR" : idx === 9 ? "KASA" : partTypes[idx].toUpperCase()) + " Yükselt\n₺" + f.upgradeCost, {
size: 44,
fill: '#fff'
});
txt.anchor.set(0.5, 0.5);
txt.x = btn.x;
txt.y = btn.y + 20;
game.addChild(txt);
btn.factoryIndex = idx;
btn.txt = txt;
btn.down = function (x, y, obj) {
// Disable if investment panel is open or Çalışanlar paneli is open
if (yatirimPanel && yatirimPanel.visible || newPagePanel && newPagePanel.visible) {
return;
}
var idx = this.factoryIndex;
var f = factories[idx];
// Çalışan 3 indirimini uygula
var discount = 1 - (worker3Level - 1) * 0.02;
if (discount < 0.1) {
discount = 0.1;
} // Maksimum %90 indirim
var discountedCost = Math.floor(f.upgradeCost * discount);
if (money >= discountedCost) {
money -= discountedCost;
f.upgrade();
updateMoneyText && updateMoneyText();
this.txt.setText((idx === 0 ? "MOUSE" : idx === 1 ? "KLAVYE" : idx === 6 ? "CPU" : idx === 7 ? "GPU" : idx === 8 ? "MONITOR" : partTypes[idx].toUpperCase()) + " Yükselt\n₺" + f.upgradeCost);
}
};
factoryBtns[idx] = btn;
}
// Store upgrade button (moved to Mağazalar panel overlay)
var storeBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
// Move Store1 upgrade button below the store image on the homepage
storeBtn.x = store.x;
storeBtn.y = store.y + 160;
storeBtn.visible = true;
game.addChild(storeBtn);
var storeBtnTxt = new Text2('Mağaza Yükselt\n₺' + store.upgradeCost, {
size: 44,
fill: '#fff'
});
storeBtnTxt.anchor.set(0.5, 0.5);
storeBtnTxt.x = storeBtn.x;
storeBtnTxt.y = storeBtn.y + 20;
storeBtnTxt.visible = true;
game.addChild(storeBtnTxt);
storeBtn.down = function (x, y, obj) {
if (money >= store.upgradeCost) {
toplamStoreYukseltme += store.upgradeCost;
store.upgrade();
storeBtnTxt.setText('Mağaza Yükselt\n₺' + store.upgradeCost);
}
};
// --- Store 2 Upgrade Button (moved to Mağazalar panel overlay) ---
var store2Btn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
// Move Store2 upgrade button below the store2 image on the homepage
store2Btn.x = store2.x;
store2Btn.y = store2.y + 160;
store2Btn.visible = false;
game.addChild(store2Btn);
var store2BtnTxt = new Text2('Mağaza 2 Yükselt\n₺' + store2.upgradeCost, {
size: 44,
fill: '#fff'
});
store2BtnTxt.anchor.set(0.5, 0.5);
store2BtnTxt.x = store2.x;
store2BtnTxt.y = store2.y + 180;
store2BtnTxt.visible = false;
game.addChild(store2BtnTxt);
store2Btn.down = function (x, y, obj) {
if (money >= store2.upgradeCost) {
toplamStoreYukseltme += store2.upgradeCost;
store2.upgrade();
store2BtnTxt.setText('Mağaza 2 Yükselt\n₺' + store2.upgradeCost);
}
};
// --- Store 3 Upgrade Button (Mağazalar panelinde) ---
var store3Btn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
// Move Store3 upgrade button below the store3 image on the homepage
store3Btn.x = store3.x;
store3Btn.y = store3.y + 260;
store3Btn.visible = false;
game.addChild(store3Btn);
var store3BtnTxt = new Text2('Mağaza 3 Yükselt\n₺' + store3.upgradeCost, {
size: 44,
fill: '#fff'
});
store3BtnTxt.anchor.set(0.5, 0.5);
store3BtnTxt.x = store3.x;
store3BtnTxt.y = store3.y + 280;
store3BtnTxt.visible = false;
game.addChild(store3BtnTxt);
store3Btn.down = function (x, y, obj) {
if (money >= store3.upgradeCost) {
toplamStoreYukseltme += store3.upgradeCost;
store3.upgrade();
store3BtnTxt.setText('Mağaza 3 Yükselt\n₺' + store3.upgradeCost);
}
};
// --- Store 4 Upgrade Button (Mağazalar panelinde) ---
var store4Btn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
// Move Store4 upgrade button below the store4 image on the homepage
store4Btn.x = store4.x;
store4Btn.y = store4.y + 260;
store4Btn.visible = false;
game.addChild(store4Btn);
var store4BtnTxt = new Text2('Mağaza 4 Yükselt\n₺' + store4.upgradeCost, {
size: 44,
fill: '#fff'
});
store4BtnTxt.anchor.set(0.5, 0.5);
store4BtnTxt.x = store4.x;
store4BtnTxt.y = store4.y + 280;
store4BtnTxt.visible = false;
game.addChild(store4BtnTxt);
store4Btn.down = function (x, y, obj) {
if (money >= store4.upgradeCost) {
toplamStoreYukseltme += store4.upgradeCost;
store4.upgrade();
store4BtnTxt.setText('Mağaza 4 Yükselt\n₺' + store4.upgradeCost);
}
};
// --- Show/hide store upgrade buttons with Mağazalar panel ---
// Show panel on button press
// Kapat butonu logic
magazalarKapatBtn.down = function (x, y, obj) {
magazalarPanel.visible = false;
magazalarPanelTitle.visible = false;
magazalarPanelText.visible = false;
magazalarKapatBtn.visible = false;
magazalarKapatBtnIcon.visible = false;
magazalarKapatBtnTxt.visible = false;
// Hide store upgrade buttons
if (typeof storeBtn !== "undefined") {
storeBtn.visible = false;
}
if (typeof storeBtnTxt !== "undefined") {
storeBtnTxt.visible = false;
}
if (typeof store2Btn !== "undefined") {
store2Btn.visible = false;
}
if (typeof store2BtnTxt !== "undefined") {
store2BtnTxt.visible = false;
}
if (typeof store2PurchaseBtn !== "undefined") {
store2PurchaseBtn.visible = false;
}
if (typeof store2PurchaseBtnTxt !== "undefined") {
store2PurchaseBtnTxt.visible = false;
}
if (typeof store3Btn !== "undefined") {
store3Btn.visible = false;
}
if (typeof store3BtnTxt !== "undefined") {
store3BtnTxt.visible = false;
}
if (typeof store4Btn !== "undefined") {
store4Btn.visible = false;
}
if (typeof store4BtnTxt !== "undefined") {
store4BtnTxt.visible = false;
}
// Restore all homepage buttons/UI
if (typeof store2PurchaseBtn !== "undefined") {
store2PurchaseBtn.visible = !store2Purchased;
}
if (typeof store2PurchaseBtnTxt !== "undefined") {
store2PurchaseBtnTxt.visible = !store2Purchased;
}
if (typeof store3PurchaseBtn !== "undefined") {
store3PurchaseBtn.visible = !store3Purchased;
}
if (typeof store3PurchaseBtnTxt !== "undefined") {
store3PurchaseBtnTxt.visible = !store3Purchased;
}
if (typeof store3PurchaseBtnIcon !== "undefined") {
store3PurchaseBtnIcon.visible = !store3Purchased;
}
if (typeof store4PurchaseBtn !== "undefined") {
store4PurchaseBtn.visible = !store4Purchased;
}
if (typeof store4PurchaseBtnTxt !== "undefined") {
store4PurchaseBtnTxt.visible = !store4Purchased;
}
if (typeof store4PurchaseBtnIcon !== "undefined") {
store4PurchaseBtnIcon.visible = !store4Purchased;
}
// Defensive: ensure other panels do not re-show these buttons after Mağazalar panel is closed
if (typeof magazaBtn !== "undefined") {
magazaBtn.visible = true;
}
if (typeof magazaBtnTxt !== "undefined") {
magazaBtnTxt.visible = true;
}
if (typeof yatirimBtn !== "undefined") {
yatirimBtn.visible = true;
}
if (typeof yatirimBtnTxt !== "undefined") {
yatirimBtnTxt.visible = true;
}
if (typeof bankBtn !== "undefined") {
bankBtn.visible = true;
}
if (typeof bankBtnTxt !== "undefined") {
bankBtnTxt.visible = true;
}
if (typeof soundBtn !== "undefined") {
soundBtn.visible = true;
}
if (typeof soundBtnTxt !== "undefined") {
soundBtnTxt.visible = true;
}
if (typeof newPageBtn !== "undefined") {
newPageBtn.visible = true;
}
if (typeof newPageBtnTxt !== "undefined") {
newPageBtnTxt.visible = true;
}
if (typeof madenlerBtn !== "undefined") {
madenlerBtn.visible = true;
}
if (typeof madenlerBtnTxt !== "undefined") {
madenlerBtnTxt.visible = true;
}
// Removed magazalarBtn and magazalarBtnTxt show logic (button was deleted)
if (typeof languagesBtn !== "undefined") {
languagesBtn.visible = true;
}
if (typeof languagesBtnTxt !== "undefined") {
languagesBtnTxt.visible = true;
}
// Info and How To Play buttons are never shown
if (typeof borcOdeBtn !== "undefined") {
borcOdeBtn.visible = true;
}
if (typeof borcOdeBtnTxt !== "undefined") {
borcOdeBtnTxt.visible = true;
}
if (typeof mevduatBtn !== "undefined") {
mevduatBtn.visible = true;
}
if (typeof mevduatBtnTxt !== "undefined") {
mevduatBtnTxt.visible = true;
}
// Move stores and customers back to their original positions
if (typeof store !== "undefined") {
store.x = 1850;
store.y = 600;
store.visible = true; // Anasayfa'da mağazaları göster
}
if (typeof store2 !== "undefined") {
store2.x = 1850;
store2.y = 950;
store2.visible = true; // Anasayfa'da mağazaları göster
}
if (typeof store3 !== "undefined") {
store3.x = 1850;
store3.y = 1300;
store3.visible = true; // Anasayfa'da mağazaları göster
}
if (typeof store4 !== "undefined") {
store4.x = 1850;
store4.y = 1650;
store4.visible = true; // Anasayfa'da mağazaları göster
}
// Customer logic removed: no customers to reposition on Mağazalar panel close.
};
// --- Production Buttons and Logic for each factory ---
var prodBtns = [];
for (var i = 0; i < factories.length; i++) {
(function (idx) {
var f = factories[idx];
var btn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5
});
btn.x = f.x;
// Add horizontal gap to production buttons to match factory panel gap
btn.x = f.x;
// Move MB, CASE, FAN, HDD, COOLER (indices 5,6,7,8,9) production buttons further down
if (idx >= 5) {
btn.y = f.y + 350 + 80;
} else {
btn.y = f.y + 350;
}
game.addChild(btn);
var txt = new Text2('ÜRET', {
size: 36,
fill: '#fff'
});
txt.anchor.set(0.5, 0.5);
txt.x = btn.x;
txt.y = btn.y;
game.addChild(txt);
btn.factoryIndex = idx;
btn.down = function (x, y, obj) {
// Disable if investment panel is open or Çalışanlar paneli is open
if (yatirimPanel && yatirimPanel.visible || newPagePanel && newPagePanel.visible) {
return;
}
var idx = this.factoryIndex;
// Only allow production if factory is unlocked
if (!factoryUnlocks[idx]) {
// Optionally, flash or shake to indicate locked
tween(factories[idx], {
scaleX: 1.15,
scaleY: 1.15
}, {
duration: 80,
onFinish: function onFinish() {
tween(factories[idx], {
scaleX: 1,
scaleY: 1
}, {
duration: 80
});
}
});
return;
}
var f = factories[idx];
var part = partTypes[idx];
var produced = 0;
var hadMaterial = false;
for (var j = 0; j < f.production; j++) {
// Each part needs: copper:2, silicon:1, iron:1, silver:1, nikel:1, gold:1
// Calculate production cost as 50% of the sale price (which is 30~49, so use 40 as avg, or use 30 + Math.floor(Math.random()*20)/2 for dynamic)
var salePrice = 30 + Math.floor(Math.random() * 20);
var productionCost = Math.floor(salePrice * 0.5);
if (rawMaterials.copper >= 2 && rawMaterials.silicon >= 1 && rawMaterials.iron >= 1 && rawMaterials.silver >= 1 && rawMaterials.nikel >= 1 && rawMaterials.gold >= 1 && money >= productionCost) {
hadMaterial = true;
rawMaterials.copper -= 2;
rawMaterials.silicon -= 1;
rawMaterials.iron -= 1;
rawMaterials.silver -= 1;
rawMaterials.nikel -= 1;
rawMaterials.gold -= 1;
money -= productionCost;
updateMoneyText();
parts[part] += 1;
produced++;
}
}
if (produced > 0) {
updateRawText();
updatePartsText();
// Animate factory
tween(f, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 120,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(f, {
scaleX: 1,
scaleY: 1
}, {
duration: 120
});
}
});
} else if (!hadMaterial) {
// Show "Maden Kalmadı" warning for 1 minute (60 seconds = 3600 frames)
var oldText = txt.getText ? txt.getText() : '';
txt.setText('Maden Kalmadı');
tween(txt, {
tint: 0xff2222
}, {
duration: 120
});
LK.setTimeout(function () {
if (txt && txt.setText) {
txt.setText('ÜRET');
}
tween(txt, {
tint: 0xffffff
}, {
duration: 120
});
}, 3600); // 1 minute (60s * 60fps)
}
};
prodBtns.push(btn);
})(i);
}
// --- Customer/Store Logic ---
// Customer logic removed: customers are no longer used in the game.
// --- Game Update ---
game.update = function () {
// Auto-produce for mines
for (var i = 0; i < mines.length; i++) {
mines[i].update();
// Auto-produce for mine if enabled
if (mineAutoProduce[i]) {
// Çalışan 2'nin seviyesiyle üretim süresini azalt: her seviye %2 daha hızlı
var baseInterval = 30; // 0.5s
var speedBonus = 1 - (worker2Level - 1) * 0.02;
if (speedBonus < 0.1) {
speedBonus = 0.1;
} // min %90 azaltma (maks %900 hız)
var interval = Math.max(2, Math.floor(baseInterval * speedBonus));
if (!mines[i].autoTick) {
mines[i].autoTick = 0;
}
mines[i].autoTick++;
if (mines[i].autoTick >= interval) {
rawMaterials[mines[i].type] += mines[i].production;
updateRawText();
// Animate mine for feedback
tween(mines[i], {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 120,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(this.target, {
scaleX: 1,
scaleY: 1
}, {
duration: 120
});
}.bind({
target: mines[i]
})
});
mines[i].autoTick = 0;
}
}
}
// Auto-produce for factories
for (var i = 0; i < factories.length; i++) {
if (factoryAutoProduce[i] && factoryUnlocks[i]) {
if (!factories[i].autoTick) {
factories[i].autoTick = 0;
}
factories[i].autoTick++;
// Use per-factory production time (speed up with level)
// Çalışan 2'nin seviyesiyle üretim süresi indirimi uygula
var prodTime = factories[i].getProductionTime ? factories[i].getProductionTime() : 30;
// Çalışan 2'nin seviyesiyle fabrika üretim süresi indirimi uygula
var worker2FactoryBonus = 1 - (worker2Level - 1) * 0.02;
if (worker2FactoryBonus < 0.1) {
worker2FactoryBonus = 0.1;
} // min %90 azaltma (maks %900 hız)
prodTime = Math.max(2, Math.floor(prodTime * worker2FactoryBonus));
// Çalışan 2'nin seviyesiyle ek olarak üretim hızını %2 düşür (yani prodTime'ı tekrar %2 azalt)
var worker2ExtraSpeedBonus = 1 - (worker2Level - 1) * 0.02;
if (worker2ExtraSpeedBonus < 0.1) {
worker2ExtraSpeedBonus = 0.1;
}
prodTime = Math.max(2, Math.floor(prodTime * worker2ExtraSpeedBonus));
if (factories[i].autoTick >= prodTime) {
var f = factories[i];
var part = partTypes[i];
var produced = 0;
// Çalışan 2'nin seviyesiyle üretim miktarını artır: her seviye %2 daha fazla üretim
var worker2ProductionBonus = 1 + (worker2Level - 1) * 0.02;
var totalProduction = Math.floor(f.production * worker2ProductionBonus);
if (totalProduction < 1) {
totalProduction = 1;
}
for (var j = 0; j < totalProduction; j++) {
// Each part needs: copper:2, silicon:1, iron:1, silver:1, nikel:1, gold:1
// Calculate production cost as 50% of the sale price (which is 30~49, so use 40 as avg, or use 30 + Math.floor(Math.random()*20)/2 for dynamic)
var salePrice = 30 + Math.floor(Math.random() * 20);
var productionCost = Math.floor(salePrice * 0.5);
if (rawMaterials.copper >= 2 && rawMaterials.silicon >= 1 && rawMaterials.iron >= 1 && rawMaterials.silver >= 1 && rawMaterials.nikel >= 1 && rawMaterials.gold >= 1 && money >= productionCost) {
rawMaterials.copper -= 2;
rawMaterials.silicon -= 1;
rawMaterials.iron -= 1;
rawMaterials.silver -= 1;
rawMaterials.nikel -= 1;
rawMaterials.gold -= 1;
money -= productionCost;
updateMoneyText();
parts[part] += 1;
produced++;
}
}
if (produced > 0) {
updateRawText();
updatePartsText();
// Animate factory
tween(f, {
scaleX: 1.1,
scaleY: 1.1
}, {
duration: 120,
easing: tween.easeOut,
onFinish: function onFinish() {
tween(this.target, {
scaleX: 1,
scaleY: 1
}, {
duration: 120
});
}.bind({
target: f
})
});
}
factories[i].autoTick = 0;
}
}
}
// Customer logic removed: no customer spawning or processing.
// --- Ava: Mağazalar stokta olan ürünleri otomatik satar ---
// Her mağaza için otomatik satış (her biri kendi hızında)
// Satış, mağaza görünür olmasa da devam etmeli
if (store && typeof store.tryAutoSell === "function") {
store.tryAutoSell();
}
if (store2 && store2Purchased && typeof store2.tryAutoSell === "function") {
store2.tryAutoSell();
}
if (store3 && store3Purchased && typeof store3.tryAutoSell === "function") {
store3.tryAutoSell();
}
if (store4 && store4Purchased && typeof store4.tryAutoSell === "function") {
store4.tryAutoSell();
}
};
// --- Dragging (for fun, not required) ---
var dragNode = null;
game.down = function (x, y, obj) {
// No drag for now
};
game.move = function (x, y, obj) {
// No drag for now
};
game.up = function (x, y, obj) {
// No drag for now
};
// --- Internet Offer Panel ---
// Panel variables
var offerPanel = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 420,
height: 340,
x: 120,
y: 1366 // center of 2732
});
game.addChild(offerPanel);
var offerTitle = new Text2('İNTERNET TEKLİFİ', {
size: 32,
fill: '#fff'
});
// Move to right edge of panel
offerTitle.anchor.set(1, 0);
offerTitle.x = offerPanel.x + offerPanel.width / 2 - 20;
offerTitle.y = offerPanel.y - 140;
game.addChild(offerTitle);
var offerPartTxt = new Text2('', {
size: 28,
fill: '#bff'
});
offerPartTxt.anchor.set(0.5, 0);
offerPartTxt.x = offerPanel.x;
offerPartTxt.y = offerPanel.y - 60;
game.addChild(offerPartTxt);
var offerAmountTxt = new Text2('', {
size: 28,
fill: '#fff'
});
offerAmountTxt.anchor.set(0.5, 0);
offerAmountTxt.x = offerPanel.x;
offerAmountTxt.y = offerPanel.y - 10;
game.addChild(offerAmountTxt);
var offerPriceTxt = new Text2('', {
size: 28,
fill: '#ffb'
});
offerPriceTxt.anchor.set(0.5, 0);
offerPriceTxt.x = offerPanel.x;
offerPriceTxt.y = offerPanel.y + 40;
game.addChild(offerPriceTxt);
var offerBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 220,
height: 70,
x: offerPanel.x,
y: offerPanel.y + 180 // moved 30px lower (was 150), now 180
});
game.addChild(offerBtn);
var offerBtnTxt = new Text2('Satın Al', {
size: 36,
fill: '#fff'
});
offerBtnTxt.anchor.set(0.5, 0.5);
offerBtnTxt.x = offerBtn.x;
offerBtnTxt.y = offerBtn.y;
game.addChild(offerBtnTxt);
// Offer state
var currentOffer = {
part: null,
amount: 0,
price: 0,
active: false // yeni teklif aktif mi
};
// Helper to generate a new offer
var offerTimeLeft = 0;
var offerTimerInterval = null;
var offerTimeTxt = new Text2('', {
size: 32,
fill: '#ffb'
});
offerTimeTxt.anchor.set(0.5, 0);
offerTimeTxt.x = offerPanel.x;
offerTimeTxt.y = offerPanel.y + 90;
game.addChild(offerTimeTxt);
function updateOfferTimeTxt() {
if (offerTimeLeft > 0) {
var min = Math.floor(offerTimeLeft / 60);
var sec = offerTimeLeft % 60;
var timeStr = min > 0 ? min + " dk " + (sec < 10 ? "0" : "") + sec + " sn" : sec + " sn";
offerTimeTxt.setText("Süre: " + timeStr);
} else {
offerTimeTxt.setText('');
}
}
function generateInternetOffer() {
// Pick a random part type
var idx = Math.floor(Math.random() * partTypes.length);
var part = partTypes[idx];
// Random amount: 2-8
var amount = 2 + Math.floor(Math.random() * 7);
// Random price per item: 18-32
var pricePer = 18 + Math.floor(Math.random() * 15);
var totalPrice = pricePer * amount;
currentOffer.part = part;
currentOffer.amount = amount;
currentOffer.price = totalPrice;
currentOffer.active = true;
// Update UI
offerPartTxt.setText(idx === 0 ? "MOUSE" : idx === 1 ? "KLAVYE" : idx === 6 ? "CPU" : idx === 7 ? "GPU" : idx === 8 ? "MONITOR" : idx === 9 ? "KASA" : part.toUpperCase());
offerAmountTxt.setText("Adet: " + amount);
offerPriceTxt.setText("Toplam: ₺" + totalPrice);
offerBtn.visible = true;
offerBtnTxt.visible = true;
// Rastgele 1-2 dakika (60-120 saniye) arası süre belirle
offerTimeLeft = (60 + Math.floor(Math.random() * 61)) * 60;
updateOfferTimeTxt();
// Start timer for next offer
if (offerTimerInterval) {
LK.clearInterval(offerTimerInterval);
offerTimerInterval = null;
}
offerTimerInterval = LK.setInterval(function () {
if (!currentOffer.active) {
LK.clearInterval(offerTimerInterval);
offerTimerInterval = null;
return;
}
offerTimeLeft--;
updateOfferTimeTxt();
if (offerTimeLeft <= 0) {
// Süre doldu, yeni teklif gelsin
currentOffer.active = false;
offerBtn.visible = false;
offerBtnTxt.visible = false;
offerPartTxt.setText("Süre doldu!");
offerAmountTxt.setText("");
offerPriceTxt.setText("");
updateOfferTimeTxt();
LK.clearInterval(offerTimerInterval);
offerTimerInterval = null;
LK.setTimeout(function () {
generateInternetOffer();
}, 60); // 1 frame sonra yeni teklif gelsin
}
}, 60); // 1 saniye
}
generateInternetOffer();
// Button logic
offerBtn.down = function (x, y, obj) {
if (!currentOffer.active) {
return;
}
if (money >= currentOffer.price) {
money -= currentOffer.price;
toplamInternetTeklifHarcamasi += currentOffer.price;
parts[currentOffer.part] += currentOffer.amount;
updateMoneyText();
updatePartsText();
// Animate panel for feedback
tween(offerPanel, {
scaleX: 1.08,
scaleY: 1.08
}, {
duration: 120,
onFinish: function onFinish() {
tween(offerPanel, {
scaleX: 1,
scaleY: 1
}, {
duration: 120
});
}
});
// Teklif tamamlandı, yeni teklif gelene kadar butonu kapat
currentOffer.active = false;
offerBtn.visible = false;
offerBtnTxt.visible = false;
offerPartTxt.setText("Teklif tamamlandı!");
offerAmountTxt.setText("");
offerPriceTxt.setText("");
offerTimeLeft = 1200;
updateOfferTimeTxt();
if (offerTimerInterval) {
LK.clearInterval(offerTimerInterval);
offerTimerInterval = null;
}
// Yeni teklif rastgele 1-2 dakika sonra gelsin
var nextOfferDelay = (60 + Math.floor(Math.random() * 61)) * 60;
LK.setTimeout(function () {
generateInternetOffer();
}, nextOfferDelay);
} else {
// Not enough money, flash button red
tween(offerBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(offerBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
}
};
// --- Toplu Satış Paneli ---
var sellPanel = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 420,
height: 340,
x: 120,
y: 1366 + 400 // offerPanel.y + 400 px altına
});
game.addChild(sellPanel);
var sellTitle = new Text2('TOPLU SATIŞ TEKLİFİ', {
size: 32,
fill: '#fff'
});
// Move to right edge of panel
sellTitle.anchor.set(1, 0);
sellTitle.x = sellPanel.x + sellPanel.width / 2 - 20;
sellTitle.y = sellPanel.y - 140;
game.addChild(sellTitle);
var sellPartTxt = new Text2('', {
size: 28,
fill: '#bff'
});
sellPartTxt.anchor.set(0.5, 0);
sellPartTxt.x = sellPanel.x;
sellPartTxt.y = sellPanel.y - 60;
game.addChild(sellPartTxt);
var sellAmountTxt = new Text2('', {
size: 28,
fill: '#fff'
});
sellAmountTxt.anchor.set(0.5, 0);
sellAmountTxt.x = sellPanel.x;
sellAmountTxt.y = sellPanel.y - 10;
game.addChild(sellAmountTxt);
var sellPriceTxt = new Text2('', {
size: 28,
fill: '#ffb'
});
sellPriceTxt.anchor.set(0.5, 0);
sellPriceTxt.x = sellPanel.x;
sellPriceTxt.y = sellPanel.y + 40;
game.addChild(sellPriceTxt);
var sellBtn = LK.getAsset('button', {
anchorX: 0.5,
anchorY: 0.5,
width: 220,
height: 70,
x: sellPanel.x,
y: sellPanel.y + 180 // moved 30px lower (was 150), now 180
});
game.addChild(sellBtn);
var sellBtnTxt = new Text2('Sat', {
size: 36,
fill: '#fff'
});
sellBtnTxt.anchor.set(0.5, 0.5);
sellBtnTxt.x = sellBtn.x;
sellBtnTxt.y = sellBtn.y;
game.addChild(sellBtnTxt);
// Satış teklifi state
var currentSellOffer = {
part: null,
amount: 0,
price: 0,
active: false
};
// Helper to generate a new sell offer
var sellOfferTimeLeft = 0;
var sellOfferTimerInterval = null;
var sellOfferTimeTxt = new Text2('', {
size: 32,
fill: '#ffb'
});
sellOfferTimeTxt.anchor.set(0.5, 0);
sellOfferTimeTxt.x = sellPanel.x;
sellOfferTimeTxt.y = sellPanel.y + 90;
game.addChild(sellOfferTimeTxt);
function updateSellOfferTimeTxt() {
if (sellOfferTimeLeft > 0) {
var min = Math.floor(sellOfferTimeLeft / 60);
var sec = sellOfferTimeLeft % 60;
var timeStr = min > 0 ? min + " dk " + (sec < 10 ? "0" : "") + sec + " sn" : sec + " sn";
sellOfferTimeTxt.setText("Süre: " + timeStr);
} else {
sellOfferTimeTxt.setText('');
}
}
// Helper to generate a new sell offer
function generateSellOffer() {
// Sadece stoğunda en az 2 olanlardan rastgele seç
var available = [];
for (var i = 0; i < partTypes.length; i++) {
if (parts[partTypes[i]] >= 2) {
available.push(partTypes[i]);
}
}
// Eğer hiç stoğu olan ürün yoksa, teklif oluşturma
if (available.length === 0) {
currentSellOffer.part = null;
currentSellOffer.amount = 0;
currentSellOffer.price = 0;
currentSellOffer.active = false;
sellPartTxt.setText("Stokta ürün yok");
sellAmountTxt.setText("");
sellPriceTxt.setText("");
sellBtn.visible = false;
sellBtnTxt.visible = false;
return;
}
var idx = Math.floor(Math.random() * available.length);
var part = available[idx];
// Satış miktarı: mevcut stoğun %50-%75 aralığında, en az 2, en fazla 8 ve stoğun kendisinden fazla olamaz
var stock = parts[part];
var minAmount = Math.max(2, Math.floor(stock * 0.5));
var maxAmount = Math.max(minAmount, Math.min(Math.floor(stock * 0.75), 8));
var amount = minAmount;
if (maxAmount > minAmount) {
amount = minAmount + Math.floor(Math.random() * (maxAmount - minAmount + 1));
}
// Satış fiyatı: 28-45 arası birim fiyat
var pricePer = 28 + Math.floor(Math.random() * 18);
var totalPrice = pricePer * amount;
currentSellOffer.part = part;
currentSellOffer.amount = amount;
currentSellOffer.price = totalPrice;
currentSellOffer.active = true;
sellPartTxt.setText(idx === 0 ? "MOUSE" : idx === 1 ? "KLAVYE" : idx === 6 ? "CPU" : idx === 7 ? "GPU" : idx === 8 ? "MONITOR" : idx === 9 ? "KASA" : part.toUpperCase());
sellAmountTxt.setText("Adet: " + amount);
sellPriceTxt.setText("Toplam: ₺" + totalPrice);
sellBtn.visible = true;
sellBtnTxt.visible = true;
// Süreyi rastgele 1-2 dakika (60-120 saniye) arası belirle
sellOfferTimeLeft = (60 + Math.floor(Math.random() * 61)) * 60;
updateSellOfferTimeTxt();
// Timer varsa temizle
if (sellOfferTimerInterval) {
LK.clearInterval(sellOfferTimerInterval);
sellOfferTimerInterval = null;
}
sellOfferTimerInterval = LK.setInterval(function () {
if (!currentSellOffer.active) {
LK.clearInterval(sellOfferTimerInterval);
sellOfferTimerInterval = null;
return;
}
sellOfferTimeLeft--;
updateSellOfferTimeTxt();
if (sellOfferTimeLeft <= 0) {
// Süre doldu, yeni teklif gelsin
currentSellOffer.active = false;
sellBtn.visible = false;
sellBtnTxt.visible = false;
sellPartTxt.setText("Süre doldu!");
sellAmountTxt.setText("");
sellPriceTxt.setText("");
updateSellOfferTimeTxt();
LK.clearInterval(sellOfferTimerInterval);
sellOfferTimerInterval = null;
LK.setTimeout(function () {
generateSellOffer();
}, 60); // 1 frame sonra yeni teklif gelsin
}
}, 60); // 1 saniye
}
generateSellOffer();
// Satış butonu logic
sellBtn.down = function (x, y, obj) {
// If not active or not enough stock, do nothing (button is visually disabled)
if (!currentSellOffer.active || parts[currentSellOffer.part] < currentSellOffer.amount) {
// Optionally, flash button red and show warning if user tries to press when not enough stock
tween(sellBtn, {
tint: 0xff2222
}, {
duration: 120,
onFinish: function onFinish() {
tween(sellBtn, {
tint: 0x222222
}, {
duration: 120
});
}
});
// 'Stok yetersiz' uyarısı göster
sellBtnTxt.setText('Stok yetersiz');
LK.setTimeout(function () {
// Eğer buton hala görünürse eski haline döndür
if (sellBtn.visible) {
sellBtnTxt.setText('Sat');
}
// Teklifi yenileme, teklif tamamlanmasın!
}, 300); // 5 saniye = 300 frame
return;
}
// Satış işlemi
parts[currentSellOffer.part] -= currentSellOffer.amount;
money += currentSellOffer.price;
toplamTopluSatisGeliri += currentSellOffer.price;
updateMoneyText();
updatePartsText();
// Panel animasyonu
tween(sellPanel, {
scaleX: 1.08,
scaleY: 1.08
}, {
duration: 120,
onFinish: function onFinish() {
tween(sellPanel, {
scaleX: 1,
scaleY: 1
}, {
duration: 120
});
}
});
// Teklif tamamlandı, yeni teklif gelene kadar butonu kapat
currentSellOffer.active = false;
sellBtn.visible = false;
sellBtnTxt.visible = false;
sellPartTxt.setText("Teklif tamamlandı!");
sellAmountTxt.setText("");
sellPriceTxt.setText("");
// Yeni teklif rastgele 1-2 dakika sonra gelsin
var nextSellOfferDelay = (60 + Math.floor(Math.random() * 61)) * 60;
LK.setTimeout(function () {
generateSellOffer();
}, nextSellOfferDelay);
};
// Satış teklifi her rastgele 1-5 dakikada bir yenilensin (eğer aktif değilse)
function scheduleNextSellOfferInterval() {
var interval = (60 + Math.floor(Math.random() * 61)) * 60;
LK.setTimeout(function () {
if (!currentSellOffer.active) {
generateSellOffer();
}
scheduleNextSellOfferInterval();
}, interval);
}
scheduleNextSellOfferInterval();
// Image file for CPU product (part_cpu) is now registered with id '6842c1a1c660c325a06c2abc'
Factory. In-Game asset. 2d. High contrast. No shadows
Copper. In-Game asset. 2d. High contrast. No shadows
Müşteri. In-Game asset. 2d. High contrast. No shadows
Iron. In-Game asset. 2d. High contrast. No shadows
Silicon. In-Game asset. 2d. High contrast. No shadows
Store. In-Game asset. 2d. High contrast. No shadows
CPU. In-Game asset. 2d. High contrast. No shadows
PC Case. In-Game asset. 2d. High contrast. No shadows
PC GPU. In-Game asset. 2d. High contrast. No shadows
PC RAM. In-Game asset. 2d. High contrast. No shadows
PC Klavye. In-Game asset. 2d. High contrast. No shadows
PC Monitör. In-Game asset. 2d. High contrast. No shadows
City. In-Game asset. 2d. High contrast. No shadows
Bilgisayar teknikeri personel. In-Game asset. 2d. High contrast. No shadows
Mavi gömlekli bilgisayar teknikeri personeli. In-Game asset. 2d. High contrast. No shadows
Silver madeni. In-Game asset. 2d. High contrast. No shadows
Altın cevheri. In-Game asset. 2d. High contrast. No shadows
Nikel cevheri. In-Game asset. 2d. High contrast. No shadows
SSD bilgisayar Parçası. In-Game asset. 2d. High contrast. No shadows
PSU bilgisayar Parçası. In-Game asset. 2d. High contrast. No shadows
ANAKART Bilgisayar Parçası. In-Game asset. 2d. High contrast. No shadows
Maden girişi. In-Game asset. 2d. High contrast. No shadows
2000 sayısı ve Buy butonu. In-Game asset. 2d. High contrast. No shadows