<NME> describe-inventory.cocoascript
<BEF> 
function DescribeInventory () {}


DescribeInventory.sectionView = function() { return "# View" + ln() }
DescribeInventory.sectionModel = function() { return "# Model" + ln() }

DescribeInventory.generateStateSection = function(layerName, generatedStates) {
	if (generatedStates == nil || generatedStates.length == 0) { return "" }
	
	var stateSectionName = GenerateInventory.clearName(layerName) + ".states.add {" + ln()
	var stateBottomSection = "}" + ln()
	
	var states = ""
	for (var i = 0; i < generatedStates.length; i++) {
		var correctBeginString = generatedStates[i].replace("{,", "{")
		states += tln() + correctBeginString + ln()
	}
	
	return stateSectionName + states + stateBottomSection
}

		}
		else {
			correctBeginString = correctBeginString.replace(/:/g, ": ")
			correctBeginString = correctBeginString.replace(": ", ": { ")


DescribeInventory.generateStateSwitchInstant = function(layerName, stateName) {
	return "" + GenerateInventory.clearName(layerName) + ".states.switchInstant \"" + GenerateInventory.clearName(stateName) + "\"" + dln()
}

DescribeInventory.generateRetinaVariable = function() {
	return stateSectionName + states + stateBottomSection
}

DescribeInventory.generateState = function(stateName, stateContent) {
	if (stateContent == "" || stateContent == nil || stateContent == '') { return "" }
DescribeInventory.generatePhoneModel = function() {
	var model = FramerInventory.getPhoneValue()
	var modelDescription = ""
	
	if (model == 1 || model == 2 || model == 3) {
		modelDescription += "# mobile" + ln()
	} 
	
	if (model == 1) {
		modelDescription += "Framer.Device.deviceType = \"iphone-5s-spacegray\"" + ln()
	}
	else if (model == 2) {
		modelDescription += "Framer.Device.deviceType = \"iphone-6-spacegray\"" + ln()
		modelDescription += "if Screen.width == 640" + ln()
		modelDescription += tln() + "Framer.Device.contentScale = 0.853" + ln()
	}
	else if (model == 3) {
		modelDescription += "Framer.Device.deviceType = \"iphone-6plus-spacegray\"" + ln()
		modelDescription += "if Screen.width == 640" + ln()
		modelDescription += tln() + "Framer.Device.contentScale = 0.515" + ln()
		modelDescription += "if Screen.width == 750" + ln()
		modelDescription += tln() + "Framer.Device.contentScale = 0.604" + ln()
	}
	return modelDescription
}
	else if (model == 4) {
		modelDescription += "Framer.Device.deviceType = \"apple-iphone-6s-plus-space-gray\"" + ln()
	}
	else if (model == 5) {
		modelDescription += "Framer.Device.deviceType = \"google-nexus-5x\"" + ln()
	}
	else if (model == 6) {
		modelDescription += "Framer.Device.deviceType = \"google-nexus-6p\"" + ln()
	}
	return modelDescription + getHelpers(model)
}



function getHelpers(model) {
	var helpers = "Framer.Extras.Hints.disable()" + ln()
	if (model == 0 || model == 1) { helpers += "document.body.style.cursor = \"auto\"" + ln() }
	return helpers
}

function getButtonName() {
	return "cycleButton"
}

DescribeInventory.generateCycleButton = function() {
	return getButtonName() + " = new Layer width: Screen.width, height: Screen.height, backgroundColor: \"transparent\"" + dln()
}



function getCycleArrayName() {
	return "statesFromArtboards"
}

DescribeInventory.generateCycleStates = function(states) {
	var cycleStatesDescription = getCycleArrayName() + " = ["
	for (var i = 0; i < states.length; i++) {
		cycleStatesDescription += "\"" + GenerateInventory.clearName(states[i]) + "\""
		if (i != states.length - 1) { cycleStatesDescription += ", "}
	}
	layersDescription += "]" + ln()
	return layersDescription
	
}


function getLayersArrayName() {
	return "sceneItems"
}

DescribeInventory.generateLayers = function(layers) {
	var layersDescription = getLayersArrayName() + " = ["
	for (var i = 0; i < layers.count(); i++) {
		var layerName = [[layers objectAtIndex: i] name]
		layersDescription += GenerateInventory.clearName(layerName)
		if (i != layers.count() - 1) { layersDescription += ", "}
	}
	layersDescription += "]" + ln()
	return layersDescription

}

DescribeInventory.generateHandler = function() {
	var handlerDescription = ""
	
	if (userDefaults.myAutoplay == 0) {
		handlerDescription = getButtonName() + ".on Events.Click, ->" + ln()
		handlerDescription += tln() + "nextState = " + getCyclerName() + "()" + ln()
		handlerDescription += tln() + "for item in " + getLayersArrayName() + ln()
		handlerDescription += tln() + tln() + "try" + ln()
		handlerDescription += tln() + tln() + tln() + "item.states.switch(nextState)" + ln()
		handlerDescription += tln() + tln() + "catch error" + dln()
	}
	else {
function getFunctionName() {
		handlerDescription += tln() + "nextState = " + getCyclerName() + "()" + ln()
		handlerDescription += tln() + "for item in " + getLayersArrayName() + ln()
		handlerDescription += tln() + tln() + "try" + ln()
		handlerDescription += tln() + tln() + tln() + "item.states.switch(nextState)" + ln()
		handlerDescription += tln() + tln() + "catch error" + ln()
		handlerDescription += tln() + "Utils.delay 2, ->" + ln()
		handlerDescription += tln() + tln() + getFunctionName() + "()" + dln()
		
		handlerDescription += getFunctionName() + "()"
	}
	return handlerDescription
}

	handlerDescription += tln() + "for item in " + getLayersArrayName() + ln()
	handlerDescription += tln() + tln() + "try" + ln()
	handlerDescription += tln() + tln() + tln() + "item.animate(nextState, curve: Spring(damping: 1), time: 0.5)" + ln()
	handlerDescription += tln() + tln() + "catch error" + dln()

	handlerDescription += getButtonName() + ".on Events.Click, ->" + ln()
	handlerDescription += tln() + getHandlerName() + "()"

	return handlerDescription
}

<MSG> Support for Framer v74 states API changes

– changed “states.add” to “states =“
– changed states descriptions
– changed “states.switch” to “animate”
– changed “switchInstant” to “stateSwitch”

– tests are broken!

<DFF> @@ -7,16 +7,18 @@ function DescribeInventory () {}
 
 DescribeInventory.generateStateSection = function(layerName, generatedStates) {
 	if (generatedStates == nil || generatedStates.length == 0) { return "" }
-	
-	var stateSectionName = GenerateInventory.clearName(layerName) + ".states.add {" + ln()
-	var stateBottomSection = "}" + ln()
-	
+
+	var stateSectionName = GenerateInventory.clearName(layerName) + ".states =" + ln()
+	var stateBottomSection = ln()
+
 	var states = ""
 	for (var i = 0; i < generatedStates.length; i++) {
-		var correctBeginString = generatedStates[i].replace("{,", "{")
+		var correctBeginString = generatedStates[i].replace(" {, ", ln()+tln()+tln())
+		correctBeginString = correctBeginString.replace(" { ", ln()+tln()+tln())
+		correctBeginString = correctBeginString.replace("}", "")
 		states += tln() + correctBeginString + ln()
 	}
-	
+
 	return stateSectionName + states + stateBottomSection
 }
 
@@ -27,7 +29,7 @@ DescribeInventory.generateState = function(stateName, stateContent) {
 
 
 DescribeInventory.generateStateSwitchInstant = function(layerName, stateName) {
-	return "" + GenerateInventory.clearName(layerName) + ".states.switchInstant \"" + GenerateInventory.clearName(stateName) + "\"" + dln()
+	return "" + GenerateInventory.clearName(layerName) + ".stateSwitch(\"" + GenerateInventory.clearName(stateName) + "\")" + dln()
 }
 
 DescribeInventory.generateRetinaVariable = function() {
@@ -39,25 +41,25 @@ DescribeInventory.generateRetinaVariable = function() {
 DescribeInventory.generatePhoneModel = function() {
 	var model = FramerInventory.getPhoneValue()
 	var modelDescription = ""
-	
+
 	if (model == 1 || model == 2 || model == 3) {
 		modelDescription += "# mobile" + ln()
-	} 
-	
+	}
+
 	if (model == 1) {
 		modelDescription += "Framer.Device.deviceType = \"iphone-5s-spacegray\"" + ln()
 	}
 	else if (model == 2) {
 		modelDescription += "Framer.Device.deviceType = \"iphone-6-spacegray\"" + ln()
 		modelDescription += "if Screen.width == 640" + ln()
-		modelDescription += tln() + "Framer.Device.contentScale = 0.853" + ln()
+		modelDescription += tln() + "Framer.Device.contentScale = 320/375" + ln()
 	}
 	else if (model == 3) {
 		modelDescription += "Framer.Device.deviceType = \"iphone-6plus-spacegray\"" + ln()
 		modelDescription += "if Screen.width == 640" + ln()
-		modelDescription += tln() + "Framer.Device.contentScale = 0.515" + ln()
+		modelDescription += tln() + "Framer.Device.contentScale = 320/414" + ln()
 		modelDescription += "if Screen.width == 750" + ln()
-		modelDescription += tln() + "Framer.Device.contentScale = 0.604" + ln()
+		modelDescription += tln() + "Framer.Device.contentScale = 375/414" + ln()
 	}
 	return modelDescription
 }
@@ -103,7 +105,7 @@ DescribeInventory.generateLayers = function(layers) {
 	}
 	layersDescription += "]" + ln()
 	return layersDescription
-	
+
 }
 
 
@@ -125,13 +127,13 @@ function getFunctionName() {
 
 DescribeInventory.generateHandler = function() {
 	var handlerDescription = ""
-	
+
 	if (userDefaults.myAutoplay == 0) {
 		handlerDescription = getButtonName() + ".on Events.Click, ->" + ln()
 		handlerDescription += tln() + "nextState = " + getCyclerName() + "()" + ln()
 		handlerDescription += tln() + "for item in " + getLayersArrayName() + ln()
 		handlerDescription += tln() + tln() + "try" + ln()
-		handlerDescription += tln() + tln() + tln() + "item.states.switch(nextState)" + ln()
+		handlerDescription += tln() + tln() + tln() + "item.animate(nextState)" + ln()
 		handlerDescription += tln() + tln() + "catch error" + dln()
 	}
 	else {
@@ -139,13 +141,12 @@ DescribeInventory.generateHandler = function() {
 		handlerDescription += tln() + "nextState = " + getCyclerName() + "()" + ln()
 		handlerDescription += tln() + "for item in " + getLayersArrayName() + ln()
 		handlerDescription += tln() + tln() + "try" + ln()
-		handlerDescription += tln() + tln() + tln() + "item.states.switch(nextState)" + ln()
+		handlerDescription += tln() + tln() + tln() + "item.animate(nextState)" + ln()
 		handlerDescription += tln() + tln() + "catch error" + ln()
 		handlerDescription += tln() + "Utils.delay 2, ->" + ln()
 		handlerDescription += tln() + tln() + getFunctionName() + "()" + dln()
-		
+
 		handlerDescription += getFunctionName() + "()"
 	}
 	return handlerDescription
 }
-

Support for Framer v74 states API changes