User prompt
Please fix the bug: 'Cannot set properties of undefined (setting 'down')' in or related to this line: 'merchantCornerBtn.down = function (x, y, obj) {' Line Number: 322
User prompt
Please fix the bug: 'Timeout.tick error: Cannot read properties of undefined (reading 'length')' in or related to this line: 'for (var i = 0; i < resourceButtons.length; i++) {' Line Number: 305
User prompt
Please fix the bug: 'Timeout.tick error: Cannot read properties of undefined (reading '0')' in or related to this line: 'if (resourceButtons[idx]) {' Line Number: 308
User prompt
Please fix the bug: 'setTimeout is not a function' in or related to this line: 'setTimeout(function () {' Line Number: 307
User prompt
Don't deactivate sulama or orak buttons until player touchs any other buttons
User prompt
Player should understand if he clicked the orak or sulama buttons. Make an animation for them when clicked. Also move them to a little bit left. ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Now add 2 buttons to the downside of the soils "orak" and "sulama". Activate harvesting only When player taps orak and taps on wheats. Also if player clicks on sulama and then clicks on the soil to activate wheat, make the durations between wheat phases 10 secs instead of 15 secs.
User prompt
Please fix the bug: 'Timeout.tick error: Invalid value. Only literals or 1-level deep objects/arrays containing literals are allowed.' in or related to this line: 'storage.soilStates = trulyFlatSoilStates;' Line Number: 514
User prompt
Please fix the bug: 'Timeout.tick error: Invalid value. Only literals or 1-level deep objects/arrays containing literals are allowed.' in or related to this line: 'storage.soilStates = oneLevelSoilStates;' Line Number: 503
User prompt
Please fix the bug: 'Timeout.tick error: Invalid value. Only literals or 1-level deep objects/arrays containing literals are allowed.' in or related to this line: 'storage.soilStates = finalSoilStates;' Line Number: 492
User prompt
Please fix the bug: 'Timeout.tick error: Invalid value. Only literals or 1-level deep objects/arrays containing literals are allowed.' in or related to this line: 'storage.soilStates = safeSoilStates;' Line Number: 481
User prompt
Please fix the bug: 'Timeout.tick error: Invalid value. Only literals or 1-level deep objects/arrays containing literals are allowed.' in or related to this line: 'storage.soilStates = shallowSoilStates;' Line Number: 470
User prompt
Please fix the bug: 'Timeout.tick error: Invalid value. Only literals or 1-level deep objects/arrays containing literals are allowed.' in or related to this line: 'storage.soilStates = shallowSoilStates;' Line Number: 469
User prompt
Please fix the bug: 'Timeout.tick error: Invalid value. Only literals or 1-level deep objects/arrays containing literals are allowed.' in or related to this line: 'storage.soilStates = soilStates;' Line Number: 459
User prompt
Please fix the bug: 'Timeout.tick error: Invalid value. Only literals or 1-level deep objects/arrays containing literals are allowed.' in or related to this line: 'storage.soilStates = flatSoilStates;' Line Number: 469
User prompt
Please fix the bug: 'Timeout.tick error: Invalid value. Only literals or 1-level deep objects/arrays containing literals are allowed.' in or related to this line: 'storage.soilStates = soilStates;' Line Number: 458
User prompt
Save all the data every 5 secs, so when player opens the game back he will continue from the moment he left ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Save game every 5 secs, so player won't lose progress ↪💡 Consider importing and using the following plugins: @upit/storage.v1
User prompt
Decrease the amount of the wheat for "1" when player plants a wheat
User prompt
Play sound "plant" when player plants seeds
User prompt
Add another phase for wheats 15 later wheatthird phase , add "wheatlast" and make the harvesting after the wheatlast phase
User prompt
When player touch a single soil, make that one "wheatfirst" instantly. And after 15 secs make it "wheatsec", after 15 secs make it "wheatthird". And when player touchs that image after the wheatthird phase, increase the amount of the wheat for 3.
User prompt
But a little gap between 6 soils
User prompt
Put a little gap between soils and put them in the middle of the vertical
User prompt
Add the image "soil" to the left middle of the screen 6 times, 3 from up to down and another 3 next to them.
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); var storage = LK.import("@upit/storage.v1"); /**** * Classes ****/ // (InventoryPopup class removed) // ResourceButton: A button for collecting a resource with cooldown var ResourceButton = Container.expand(function () { var self = Container.call(this); // Properties to be set after creation: // self.resourceType (string) // self.iconId (string) // self.cooldown (ms) // self.onCollect (function) // State self.isCoolingDown = false; self.lastCollectTime = 0; // Button background removed (resourceBtnBg no longer used) // Icon // NOTE: Do not attach icon here, as iconId is not set yet. It will be attached after construction in Game Code. // Attach a placeholder (invisible) so children[1] exists for later replacement. var icon = self.attachAsset('cowIcon', { anchorX: 0.5, anchorY: 0.5, alpha: 0 // invisible placeholder }); icon.y = 0; // Cooldown overlay (semi-transparent) // Attach a placeholder (invisible) so children[2] exists for later replacement. var cooldownOverlay = self.attachAsset('cooldownOverlay', { anchorX: 0.5, anchorY: 0.5, alpha: 0 // invisible placeholder }); // Amount text (shows +1 when collected) var plusText = new Text2("+1", { size: 80, fill: 0xFFFFFF }); plusText.anchor.set(0.5, 0.5); plusText.alpha = 0; self.addChild(plusText); // Cooldown timer text var cdText = new Text2("", { size: 60, fill: 0xFFFFFF }); cdText.anchor.set(0.5, 0); // Place the cooldown text below the icon (icon is at y=0, icon is 2x scaled, so offset by icon height) cdText.y = 140; self.addChild(cdText); // Button press handler self.down = function (x, y, obj) { if (self.isCoolingDown) return; // Mark as pressed, but do not collect yet self._pressed = true; self._pressValid = true; // Optionally, you could store the press position if you want to check for drags/cancels }; // Collect on up event (tap release) self.up = function (x, y, obj) { if (self.isCoolingDown) return; if (!self._pressed) return; self._pressed = false; if (!self._pressValid) return; // Play cow sound if this is the cow button if (self.resourceType === "cow") { LK.getSound('Cow').play(); } // Play wheat sound if this is the wheat button if (self.resourceType === "wheat") { LK.getSound('Wheat').play(); } // Play ore sound if this is the ore button if (self.resourceType === "ore") { LK.getSound('Ore').play(); } // Play wood sound if this is the wood button if (self.resourceType === "wood") { LK.getSound('Wood').play(); } // Play fish sound if this is the fish button if (self.resourceType === "fish") { LK.getSound('Fish').play(); } self.startCooldown(); if (typeof self.onCollect === "function") self.onCollect(); // Animate +1 plusText.alpha = 1; plusText.y = -40; tween(plusText, { y: -120, alpha: 0 }, { duration: 700, easing: tween.easeOut }); }; // Start cooldown self.startCooldown = function () { self.isCoolingDown = true; self.lastCollectTime = Date.now(); cooldownOverlay.alpha = 0.5; cdText.visible = true; }; // End cooldown self.endCooldown = function () { self.isCoolingDown = false; cooldownOverlay.alpha = 0; cdText.visible = false; }; // Update cooldown overlay and timer self.update = function () { if (!self.isCoolingDown) return; var elapsed = Date.now() - self.lastCollectTime; var left = Math.max(0, self.cooldown - elapsed); if (left <= 0) { self.endCooldown(); } else { // Show seconds left cdText.setText(Math.ceil(left / 1000) + "s"); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x2d2d2d }); /**** * Game Code ****/ // Resource definitions var resources = [{ type: "cow", iconId: "cowIcon", cooldown: 30000 // 30s }, { type: "fish", iconId: "fishIcon", cooldown: 30000 }, { type: "wheat", iconId: "wheatIcon", cooldown: 30000 }, { type: "ore", iconId: "oreIcon", cooldown: 30000 }, { type: "wood", iconId: "woodIcon", cooldown: 30000 }]; // --- Add 6 soil images to the left middle of the screen in a 2x3 grid, with a gap and vertically centered --- var soilImages = []; var soilCols = 2; var soilRows = 3; var soilGap = 48; // increased gap between soils // Get soil asset size (scaled) var soilSample = LK.getAsset('Soil', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.2, scaleY: 1.2 }); var soilW = soilSample.width; var soilH = soilSample.height; // Calculate total height of grid var totalSoilHeight = soilRows * soilH + (soilRows - 1) * soilGap; var soilStartY = (2732 - totalSoilHeight) / 2 + soilH / 2; // center grid vertically var soilStartX = 300; // left side, but not too close to the edge var soilSpacingX = soilW + soilGap; var soilSpacingY = soilH + soilGap; for (var row = 0; row < soilRows; row++) { for (var col = 0; col < soilCols; col++) { // Create a container for each soil plot var soilContainer = new Container(); soilContainer.x = soilStartX + col * soilSpacingX; soilContainer.y = soilStartY + row * soilSpacingY; game.addChild(soilContainer); // State: 0 = soil, 1 = wheatfirst, 2 = wheatsec, 3 = wheatthird, 4 = wheatlast soilContainer.growthStage = 0; soilContainer.growthTimeout1 = null; soilContainer.growthTimeout2 = null; soilContainer.growthTimeout3 = null; soilContainer._growthEnd1 = 0; soilContainer._growthEnd2 = 0; soilContainer._growthEnd3 = 0; // Add the soil image (initial) var soilImg = LK.getAsset('Soil', { anchorX: 0.5, anchorY: 0.5, scaleX: 1.2, scaleY: 1.2 }); soilContainer.addChild(soilImg); soilContainer.currentImg = soilImg; // Helper to set the growth stage and update image soilContainer.setGrowthStage = function (stage) { // Remove current image if (this.currentImg && this.currentImg.parent) { this.currentImg.parent.removeChild(this.currentImg); } this.growthStage = stage; var imgId = "Soil"; if (stage === 1) imgId = "Wheatfirst";else if (stage === 2) imgId = "Wheatsec";else if (stage === 3) imgId = "Wheatthird";else if (stage === 4) imgId = "Wheatlast"; var newImg = LK.getAsset(imgId, { anchorX: 0.5, anchorY: 0.5, scaleX: 1.2, scaleY: 1.2 }); this.addChild(newImg); this.currentImg = newImg; }; // Touch logic soilContainer.down = function (x, y, obj) { // Do nothing on down, only act on up }; soilContainer.up = function (x, y, obj) { var self = this; if (self.growthStage === 0) { // Decrease wheat amount by 1 if possible if (resourceAmounts.wheat > 0) { resourceAmounts.wheat -= 1; saveResources(); // Update wheat amount text if present for (var j = 0; j < resourceAmountTexts.length; j++) { if (resourceAmountTexts[j].type === "wheat") { resourceAmountTexts[j].text.setText(resourceAmounts.wheat + ""); break; } } // Play plant sound LK.getSound('Plant').play(); // Instantly become wheatfirst self.setGrowthStage(1); // Start timer to wheatsec after 15s if (self.growthTimeout1) LK.clearTimeout(self.growthTimeout1); if (self.growthTimeout2) LK.clearTimeout(self.growthTimeout2); if (self.growthTimeout3) LK.clearTimeout(self.growthTimeout3); var now = Date.now(); self._growthEnd1 = now + 15000; self.growthTimeout1 = LK.setTimeout(function () { self.setGrowthStage(2); self._growthEnd2 = Date.now() + 15000; // Start timer to wheatthird after 15s self.growthTimeout2 = LK.setTimeout(function () { self.setGrowthStage(3); self._growthEnd3 = Date.now() + 15000; // Start timer to wheatlast after 15s self.growthTimeout3 = LK.setTimeout(function () { self.setGrowthStage(4); }, 15000); }, 15000); }, 15000); } } else if (self.growthStage === 4) { // Collect wheat, reset to soil resourceAmounts.wheat += 3; saveResources(); // Update wheat amount text if present for (var j = 0; j < resourceAmountTexts.length; j++) { if (resourceAmountTexts[j].type === "wheat") { resourceAmountTexts[j].text.setText(resourceAmounts.wheat + ""); break; } } self.setGrowthStage(0); if (self.growthTimeout1) LK.clearTimeout(self.growthTimeout1); if (self.growthTimeout2) LK.clearTimeout(self.growthTimeout2); if (self.growthTimeout3) LK.clearTimeout(self.growthTimeout3); } // Do nothing if in wheatfirst, wheatsec, or wheatthird }; // Make container interactive soilContainer.interactive = true; soilImages.push(soilContainer); } } // Restore soil growth stages and timers from storage if (storage.soilStates && Array.isArray(storage.soilStates)) { for (var i = 0; i < soilImages.length; i++) { var soil = soilImages[i]; var state = storage.soilStates[i]; if (!state) continue; soil.setGrowthStage(state.growthStage || 0); // Clear any running timers if (soil.growthTimeout1) LK.clearTimeout(soil.growthTimeout1); if (soil.growthTimeout2) LK.clearTimeout(soil.growthTimeout2); if (soil.growthTimeout3) LK.clearTimeout(soil.growthTimeout3); var now = Date.now(); // Restore timers for each stage if (state.growthStage === 1 && state.t1 > 0) { soil._growthEnd1 = now + state.t1; soil.growthTimeout1 = LK.setTimeout(function (soilRef) { return function () { soilRef.setGrowthStage(2); soilRef._growthEnd2 = Date.now() + 15000; soilRef.growthTimeout2 = LK.setTimeout(function () { soilRef.setGrowthStage(3); soilRef._growthEnd3 = Date.now() + 15000; soilRef.growthTimeout3 = LK.setTimeout(function () { soilRef.setGrowthStage(4); }, 15000); }, 15000); }; }(soil), state.t1); } else if (state.growthStage === 2 && state.t2 > 0) { soil._growthEnd2 = now + state.t2; soil.growthTimeout2 = LK.setTimeout(function (soilRef) { return function () { soilRef.setGrowthStage(3); soilRef._growthEnd3 = Date.now() + 15000; soilRef.growthTimeout3 = LK.setTimeout(function () { soilRef.setGrowthStage(4); }, 15000); }; }(soil), state.t2); } else if (state.growthStage === 3 && state.t3 > 0) { soil._growthEnd3 = now + state.t3; soil.growthTimeout3 = LK.setTimeout(function (soilRef) { return function () { soilRef.setGrowthStage(4); }; }(soil), state.t3); } } } // --- GLOBAL ARRAYS for resource buttons and amount texts --- var resourceButtons = []; var resourceAmountTexts = []; // Resource amounts (persisted) var resourceAmounts = { cow: storage.cow || 0, fish: storage.fish || 0, wheat: storage.wheat || 0, ore: storage.ore || 0, wood: storage.wood || 0 }; // Save resource amounts to storage function saveResources() { storage.cow = resourceAmounts.cow; storage.fish = resourceAmounts.fish; storage.wheat = resourceAmounts.wheat; storage.ore = resourceAmounts.ore; storage.wood = resourceAmounts.wood; } // Save soil growth stages and timers to storage function saveSoilStates() { var soilStates = []; for (var i = 0; i < soilImages.length; i++) { var soil = soilImages[i]; // Save growthStage and remaining times for each timer var now = Date.now(); var t1 = 0, t2 = 0, t3 = 0; if (soil.growthStage === 1 && soil.growthTimeout1) { t1 = Math.max(0, soil._growthEnd1 - now); } if (soil.growthStage === 2 && soil.growthTimeout2) { t2 = Math.max(0, soil._growthEnd2 - now); } if (soil.growthStage === 3 && soil.growthTimeout3) { t3 = Math.max(0, soil._growthEnd3 - now); } soilStates.push({ growthStage: soil.growthStage, t1: t1, t2: t2, t3: t3 }); } // Store soilStates as a new array of shallow objects to guarantee 1-level deep structure var shallowSoilStates = []; for (var i = 0; i < soilStates.length; i++) { var s = soilStates[i]; // Ensure all values are numbers (not undefined or objects) shallowSoilStates.push({ growthStage: typeof s.growthStage === "number" ? s.growthStage : 0, t1: typeof s.t1 === "number" ? s.t1 : 0, t2: typeof s.t2 === "number" ? s.t2 : 0, t3: typeof s.t3 === "number" ? s.t3 : 0 }); } // Only store an array of plain objects with number values (no references, no nested objects) var safeSoilStates = []; for (var i = 0; i < shallowSoilStates.length; i++) { var s = shallowSoilStates[i]; safeSoilStates.push({ growthStage: Number(s.growthStage) || 0, t1: Number(s.t1) || 0, t2: Number(s.t2) || 0, t3: Number(s.t3) || 0 }); } // Only store an array of plain objects with number values (no references, no nested objects) var finalSoilStates = []; for (var i = 0; i < safeSoilStates.length; i++) { var s = safeSoilStates[i]; finalSoilStates.push({ growthStage: Number(s.growthStage) || 0, t1: Number(s.t1) || 0, t2: Number(s.t2) || 0, t3: Number(s.t3) || 0 }); } storage.soilStates = finalSoilStates; } // Save all game state (resources and soils) function saveAllGameState() { saveResources(); saveSoilStates(); } // Periodically save every 5 seconds var saveInterval = LK.setInterval(saveAllGameState, 5000); // Save on page unload (if possible) if (typeof window !== "undefined" && window.addEventListener) { window.addEventListener("beforeunload", saveAllGameState); } // --- START SCREEN LOGIC --- var startScreenShown = false; var startImage = null; var startTween1 = null; var startTween2 = null; var startTween3 = null; var mainScreenInit = false; // Hide all main game UI until start screen is done function showMainScreen() { if (mainScreenInit) return; mainScreenInit = true; // Create resource buttons var btnSpacing = 350; var btnStartY = 900; var btnX = 2048 / 2; window.resourceButtons = []; for (var i = 0; i < resources.length; i++) { var res = resources[i]; var btn = new ResourceButton(); btn.resourceType = res.type; btn.iconId = res.iconId; btn.cooldown = res.cooldown; btn.x = btnX; btn.y = btnStartY + i * btnSpacing; btn.onCollect = function (rtype, btnIdx) { return function () { resourceAmounts[rtype]++; saveResources(); // Update the corresponding amount text for (var j = 0; j < resourceAmountTexts.length; j++) { if (resourceAmountTexts[j].type === rtype) { resourceAmountTexts[j].text.setText(resourceAmounts[rtype] + ""); break; } } }; }(res.type, i); // Set up icon and overlay after iconId is set if (btn.children.length > 1) { btn.removeChild(btn.children[1]); // Remove placeholder icon if exists } var icon = btn.attachAsset(res.iconId, { anchorX: 0.5, anchorY: 0.5, scaleX: 2, scaleY: 2 }); icon.y = 0; if (btn.children.length > 1) { btn.removeChild(btn.children[1]); // Remove placeholder overlay if exists } var overlay = btn.attachAsset('cooldownOverlay', { anchorX: 0.5, anchorY: 0.5, alpha: 0, scaleX: 2, scaleY: 2 }); // Add to game game.addChild(btn); resourceButtons.push(btn); } // Add resource amount text next to each button (1cm = 40px gap) window.resourceAmountTexts = []; // Amount numbers and frames next to items on the main screen have been removed as requested. } // Show start image and animate, then show main screen function showStartScreen() { if (startScreenShown) return; startScreenShown = true; // Create start image centered startImage = LK.getAsset('Start', { anchorX: 0.5, anchorY: 0.5, scaleX: 1, scaleY: 1 }); startImage.x = 2048 / 2; startImage.y = 2732 / 2; startImage.alpha = 0; startImage.scaleX = 0.7; startImage.scaleY = 0.7; game.addChild(startImage); // Fade in and scale up startTween1 = tween(startImage, { alpha: 1, scaleX: 1.1, scaleY: 1.1 }, { duration: 600, easing: tween.easeOut, onFinish: function onFinish() { // Pulse scale startTween2 = tween(startImage, { scaleX: 1, scaleY: 1 }, { duration: 300, easing: tween.easeInOut, onFinish: function onFinish() { // Wait, then fade out and remove startTween3 = tween(startImage, { alpha: 0, scaleX: 1.2, scaleY: 1.2 }, { duration: 500, easing: tween.easeIn, onFinish: function onFinish() { if (startImage && startImage.parent) startImage.parent.removeChild(startImage); startImage = null; showMainScreen(); } }); } }); } }); } // Start the game with the start screen showStartScreen(); // Place the start button at the same place as the pause button (top right corner) if (typeof LK.gui !== "undefined" && LK.gui.topRight) { // If there is a start button, place it at the top right if (typeof LK.startButton !== "undefined") { LK.gui.topRight.addChild(LK.startButton); } } // Add merchant button with image at the bottom right corner var merchantCornerBtn = LK.getAsset('Merchant', { anchorX: 0.5, anchorY: 0.5 }); merchantCornerBtn.x = 2048 - 180; merchantCornerBtn.y = 2732 - 180; merchantCornerBtn.scaleX = 0.8; merchantCornerBtn.scaleY = 0.8; game.addChild(merchantCornerBtn); // Open merchant popup when tapped merchantCornerBtn.down = function (x, y, obj) { if (merchantPopup) return; // Block input to resource buttons for (var i = 0; i < resourceButtons.length; i++) { resourceButtons[i].interactive = false; } // Directly open the merchant popup logic (copied from yellowBtn.down) if (merchantPopup) return; // Fade overlay merchantFade = new Container(); var fadeBg = LK.getAsset('cooldownOverlay', { anchorX: 0, anchorY: 0, width: 2048, height: 2732, color: 0x000000, alpha: 0.0 }); merchantFade.addChild(fadeBg); merchantFade.interactive = true; // Block input to game behind merchantFade.zIndex = 1000; game.addChild(merchantFade); // Animate fade in tween(fadeBg, { alpha: 0.7 }, { duration: 350, easing: tween.easeOut }); // Popup box merchantPopup = new Container(); var boxW = 1000, boxH = 1400; var popupBg = LK.getAsset('inventoryBg', { anchorX: 0.5, anchorY: 0.5, width: boxW, height: boxH, color: 0x333333 }); merchantPopup.addChild(popupBg); merchantPopup.x = 2048 / 2; merchantPopup.y = 2732 / 2; merchantPopup.zIndex = 1001; // Merchant "avatar" (just a text for now) var merchantText = new Text2("Merchant", { size: 120, fill: 0xFFE066 }); merchantText.anchor.set(0.5, 0); merchantText.x = 0; merchantText.y = -boxH / 2 + 60; merchantPopup.addChild(merchantText); // Info text var infoText = new Text2("Sell your items for gold!", { size: 60, fill: "#fff" }); infoText.anchor.set(0.5, 0); infoText.x = 0; infoText.y = merchantText.y + 150; merchantPopup.addChild(infoText); // Gold display if (typeof storage.gold === "undefined") storage.gold = 0; var goldAmount = storage.gold || 0; var goldText = new Text2("Gold: " + goldAmount, { size: 80, fill: 0xFFD700 }); goldText.anchor.set(0.5, 0); // Add a gap between gold text and info text goldText.x = 0; goldText.y = infoText.y + 80; merchantPopup.addChild(goldText); // Resource sell button definitions var sellDefs = [{ type: "wood", icon: "woodIcon", price: 2, label: "Wood" }, { type: "fish", icon: "fishIcon", price: 1, label: "Fish" }, { type: "cow", icon: "cowIcon", price: 3, label: "Cow" }, { type: "ore", icon: "oreIcon", price: 4, label: "Ore" }, { type: "wheat", icon: "wheatIcon", price: 1, label: "Wheat" }]; // Layout: vertical stack, centered, with clear horizontal separation for icon, label, amount, price, and button // Move sell buttons further down to avoid overlap with gold text var sellBtnStartY = goldText.y + 180; // Increased gap below gold text var sellBtnSpacing = 210; // Increased vertical spacing between rows var sellBtnW = 900, // Slightly wider for more space sellBtnH = 150; var merchantSellBtns = []; for (var i = 0; i < sellDefs.length; i++) { (function (i) { var def = sellDefs[i]; var btnY = sellBtnStartY + i * sellBtnSpacing; // Amount demonstrator (amount owned) - to the left of the icon var amtOwned = resourceAmounts[def.type] || 0; var amtOwnedText = new Text2(amtOwned + "", { size: 64, fill: "#fff" }); amtOwnedText.anchor.set(1, 0.5); // Add a larger gap between amount and icon (was 50, now 10 for more space) amtOwnedText.x = -sellBtnW / 2 + 10; // 10px from left edge for more gap amtOwnedText.y = btnY; merchantPopup.addChild(amtOwnedText); // Icon var icon = LK.getAsset(def.icon, { anchorX: 0.5, anchorY: 0.5 }); // Move icon further right to increase gap from amount (was 100, now 80) icon.x = -sellBtnW / 2 + 80; icon.y = btnY; merchantPopup.addChild(icon); // Resource label var resLabel = new Text2(def.label, { size: 64, fill: "#fff" }); resLabel.anchor.set(0, 0.5); // Add more horizontal space between label and arrows resLabel.x = -sellBtnW / 2 + 200; resLabel.y = btnY; merchantPopup.addChild(resLabel); // Amount owned var amt = resourceAmounts[def.type] || 0; // --- Amount selector state --- var sellAmount = 1; // Down arrow var downArrow = new Text2("▼", { size: 64, fill: "#fff" }); downArrow.anchor.set(0.5, 0.5); // Move arrows and amount text further right to add horizontal space downArrow.x = -sellBtnW / 2 + 520 - 60; downArrow.y = btnY; downArrow.interactive = true; merchantPopup.addChild(downArrow); // Up arrow var upArrow = new Text2("▲", { size: 64, fill: "#fff" }); upArrow.anchor.set(0.5, 0.5); upArrow.x = -sellBtnW / 2 + 520 + 60; upArrow.y = btnY; upArrow.interactive = true; merchantPopup.addChild(upArrow); // Amount text (between arrows) var amtText = new Text2("x" + sellAmount, { size: 64, fill: "#fff" }); amtText.anchor.set(0.5, 0.5); amtText.x = -sellBtnW / 2 + 520; amtText.y = btnY; merchantPopup.addChild(amtText); // Arrow logic downArrow.down = function () { if (sellAmount > 1) { sellAmount--; amtText.setText("x" + sellAmount); } }; upArrow.down = function () { var maxSell = resourceAmounts[def.type]; if (sellAmount < maxSell) { sellAmount++; amtText.setText("x" + sellAmount); } }; // Price var priceText = new Text2(def.price + " coins", { size: 56, fill: 0xFFD700 }); priceText.anchor.set(1, 0.5); // Add more horizontal space between amount selector and coins text priceText.x = sellBtnW / 2 - 100; // was -120, now -100 for more gap after amount selector priceText.y = btnY; merchantPopup.addChild(priceText); // Sell button var sellBtn = LK.getAsset('inventoryBtn', { anchorX: 0.5, anchorY: 0.5, color: 0xFFE066 }); sellBtn.x = sellBtnW / 2 - 30; // was -80, now -30 for more gap after coins text sellBtn.y = btnY; merchantPopup.addChild(sellBtn); // Sell button label (removed) // Sell logic var sellAllTimeout = null; var sellAllInterval = null; sellBtn.down = function (x, y, obj) { // Start a timeout to trigger sell all after 500ms if (resourceAmounts[def.type] > 0) { // Sell the selected amount (or as much as possible) var toSell = Math.min(sellAmount, resourceAmounts[def.type]); if (toSell > 0) { resourceAmounts[def.type] -= toSell; storage[def.type] = resourceAmounts[def.type]; goldAmount += def.price * toSell; storage.gold = goldAmount; LK.getSound('Coin').play(); amtText.setText("x" + Math.min(sellAmount, resourceAmounts[def.type])); goldText.setText("Gold: " + goldAmount); // Also update main screen resource amount for (var j = 0; j < resourceAmountTexts.length; j++) { if (resourceAmountTexts[j].type === def.type) { resourceAmountTexts[j].text.setText(resourceAmounts[def.type] + ""); break; } } // Update merchant popup amount demonstrator amtOwnedText.setText(resourceAmounts[def.type] + ""); // Clamp sellAmount to available if (resourceAmounts[def.type] < sellAmount) { sellAmount = Math.max(1, resourceAmounts[def.type]); amtText.setText("x" + sellAmount); } // Animate gold text goldText.scale.set(1.2, 1.2); tween(goldText.scale, { x: 1, y: 1 }, { duration: 300, easing: tween.easeOut }); } } // Start long-press detection if (sellAllTimeout) LK.clearTimeout(sellAllTimeout); if (sellAllInterval) LK.clearInterval(sellAllInterval); sellAllTimeout = LK.setTimeout(function () { // Start selling all at a fast interval sellAllInterval = LK.setInterval(function () { if (resourceAmounts[def.type] > 0) { // Sell the selected amount (or as much as possible) var toSell = Math.min(sellAmount, resourceAmounts[def.type]); if (toSell > 0) { resourceAmounts[def.type] -= toSell; storage[def.type] = resourceAmounts[def.type]; goldAmount += def.price * toSell; storage.gold = goldAmount; LK.getSound('Coin').play(); amtText.setText("x" + Math.min(sellAmount, resourceAmounts[def.type])); goldText.setText("Gold: " + goldAmount); // Also update main screen resource amount for (var j = 0; j < resourceAmountTexts.length; j++) { if (resourceAmountTexts[j].type === def.type) { resourceAmountTexts[j].text.setText(resourceAmounts[def.type] + ""); break; } } // Update merchant popup amount demonstrator amtOwnedText.setText(resourceAmounts[def.type] + ""); // Clamp sellAmount to available if (resourceAmounts[def.type] < sellAmount) { sellAmount = Math.max(1, resourceAmounts[def.type]); amtText.setText("x" + sellAmount); } // Animate gold text goldText.scale.set(1.2, 1.2); tween(goldText.scale, { x: 1, y: 1 }, { duration: 300, easing: tween.easeOut }); } } else { // Stop interval if nothing left to sell if (sellAllInterval) LK.clearInterval(sellAllInterval); sellAllInterval = null; } }, 50); // Sell every 50ms }, 500); // Long press threshold: 500ms }; // Stop selling on up sellBtn.up = function (x, y, obj) { if (sellAllTimeout) LK.clearTimeout(sellAllTimeout); sellAllTimeout = null; if (sellAllInterval) LK.clearInterval(sellAllInterval); sellAllInterval = null; }; merchantSellBtns.push({ btn: sellBtn, amtText: amtText }); })(i); } // Close button var closeBtn = LK.getAsset('closeBtn', { anchorX: 0.5, anchorY: 0.5 }); closeBtn.x = boxW / 2 - 60; closeBtn.y = -boxH / 2 + 60; merchantPopup.addChild(closeBtn); // Close logic closeBtn.down = function () { // Restore input to resource buttons for (var i = 0; i < resourceButtons.length; i++) { resourceButtons[i].interactive = true; } // Animate fade out if (merchantFade && merchantFade.children.length > 0) { tween(merchantFade.children[0], { alpha: 0 }, { duration: 250, easing: tween.easeIn, onFinish: function onFinish() { if (merchantFade && merchantFade.parent) merchantFade.parent.removeChild(merchantFade); merchantFade = null; } }); } else if (merchantFade && merchantFade.parent) { merchantFade.parent.removeChild(merchantFade); merchantFade = null; } if (merchantPopup && merchantPopup.parent) merchantPopup.parent.removeChild(merchantPopup); merchantPopup = null; }; // Add popup to game game.addChild(merchantPopup); }; // Only keep the merchant button at the bottom right corner // (Removed button "a" and its label) // --- Merchant Popup logic --- var merchantPopup = null; var merchantFade = null; // (yellowBtn and blueBtn handlers removed) // Play background music when the game starts LK.playMusic('Bg'); // Game update loop game.update = function () { // Update all resource buttons (for cooldowns) for (var i = 0; i < resourceButtons.length; i++) { resourceButtons[i].update(); } }; // --- Asset Initialization Section --- // Resource button background // Cooldown overlay (semi-transparent) // Inventory popup background // Inventory button (top right) // Close button for popup // Resource icons // Stop background music when the game is paused game.pause = function () { LK.stopMusic(); }; // Resume background music when the game continues game["continue"] = function () { LK.playMusic('Bg'); };
===================================================================
--- original.js
+++ change.js
@@ -403,9 +403,20 @@
t2: Number(s.t2) || 0,
t3: Number(s.t3) || 0
});
}
- storage.soilStates = safeSoilStates;
+ // Only store an array of plain objects with number values (no references, no nested objects)
+ var finalSoilStates = [];
+ for (var i = 0; i < safeSoilStates.length; i++) {
+ var s = safeSoilStates[i];
+ finalSoilStates.push({
+ growthStage: Number(s.growthStage) || 0,
+ t1: Number(s.t1) || 0,
+ t2: Number(s.t2) || 0,
+ t3: Number(s.t3) || 0
+ });
+ }
+ storage.soilStates = finalSoilStates;
}
// Save all game state (resources and soils)
function saveAllGameState() {
saveResources();
Merchant. In-Game asset. 2d. High contrast. No shadows
Coin, "m" sign. In-Game asset. 2d. High contrast. No shadows
Frame. In-Game asset. 2d. High contrast. No shadows
My farm, wheat, cow, ore, pickaxe. Starting screen style. In-Game asset. 2d. High contrast. No shadows
Movement button, item moving button. In-Game asset. 2d. High contrast. No shadows
A cute middle eastern farmer character. In-Game asset. 2d. High contrast. No shadows
Mowing sickle. In-Game asset. 2d. High contrast. No shadows
Watering waterdrops watering can. In-Game asset. 2d. High contrast. No shadows
Historical frame with beige interior.