@@ -403,7 +403,8 @@ private static float ParseEnergy(string? energy) {
403403 float energyBase = float . Parse ( energy [ ..^ 2 ] ) ;
404404
405405 switch ( energyMul ) {
406- case 'k' : return energyBase * 1e-3f ;
406+ // 2.0 only allows k; 1.1 allows either. Assume 2.0 mods don't rely on whatever Factorio does with 'K'.
407+ case 'k' or 'K' : return energyBase * 1e-3f ;
407408 case 'M' : return energyBase ;
408409 case 'G' : return energyBase * 1e3f ;
409410 case 'T' : return energyBase * 1e6f ;
@@ -418,13 +419,18 @@ private static float ParseEnergy(string? energy) {
418419 return float . Parse ( energy [ ..^ 1 ] ) * 1e-6f ;
419420 }
420421
421- private static Effect ParseEffect ( LuaTable table ) => new Effect {
422- consumption = table . Get ( "consumption" , 0f ) ,
423- speed = table . Get ( "speed" , 0f ) ,
424- productivity = table . Get ( "productivity" , 0f ) ,
425- pollution = table . Get ( "pollution" , 0f ) ,
426- quality = table . Get ( "quality" , 0f ) ,
427- } ;
422+ private static Effect ParseEffect ( LuaTable table ) {
423+ return new Effect {
424+ consumption = load ( table , "consumption" ) ,
425+ speed = load ( table , "speed" ) ,
426+ productivity = load ( table , "productivity" ) ,
427+ pollution = load ( table , "pollution" ) ,
428+ quality = load ( table , "quality" ) ,
429+ } ;
430+
431+ // table[effect].bonus in 1.1; table[effect] in 2.0. Assume [effect] is not a table in 2.0.
432+ static float load ( LuaTable table , string effect ) => table . Get < LuaTable > ( effect ) ? . Get ( "bonus" , 0f ) ?? table . Get ( effect , 0f ) ;
433+ }
428434
429435 private static EffectReceiver ParseEffectReceiver ( LuaTable ? table ) {
430436 if ( table == null ) {
@@ -498,15 +504,21 @@ void readTrigger(LuaTable table) {
498504 }
499505 }
500506
501- if ( table . Get ( "send_to_orbit_mode" , "not-sendable" ) != "not-sendable" || item . factorioType == "space-platform-starter-pack" ) {
502- Product [ ] launchProducts ;
503- if ( table . Get ( "rocket_launch_products" , out LuaTable ? products ) ) {
507+ Product [ ] ? launchProducts = null ;
508+ if ( table . Get ( "send_to_orbit_mode" , "not-sendable" ) != "not-sendable" || item . factorioType == "space-platform-starter-pack"
509+ || factorioVersion < v2_0 ) {
510+
511+ if ( table . Get ( "rocket_launch_product" , out LuaTable ? product ) ) {
512+ launchProducts = [ LoadProduct ( "rocket_launch_product" , item . stackSize ) ( product ) ] ;
513+ }
514+ else if ( table . Get ( "rocket_launch_products" , out LuaTable ? products ) ) {
504515 launchProducts = [ .. products . ArrayElements < LuaTable > ( ) . Select ( LoadProduct ( item . typeDotName , item . stackSize ) ) ] ;
505516 }
506- else {
517+ else if ( factorioVersion >= v2_0 ) {
507518 launchProducts = [ ] ;
508519 }
509-
520+ }
521+ if ( launchProducts != null ) {
510522 EnsureLaunchRecipe ( item , launchProducts ) ;
511523 }
512524
@@ -559,6 +571,10 @@ void readEffect(LuaTable effect) {
559571 // This was constructed from educated guesses and https://forums.factorio.com/viewtopic.php?f=23&t=120781.
560572 // It was compared with https://rocketcal.cc/weights.json. Where the results differed, these results were verified in Factorio.
561573 private void CalculateItemWeights ( ) {
574+ if ( factorioVersion < v2_0 ) {
575+ return ;
576+ }
577+
562578 Dictionary < Item , List < Item > > dependencies = [ ] ;
563579 foreach ( Recipe recipe in allObjects . OfType < Recipe > ( ) ) {
564580 foreach ( Item ingredient in recipe . ingredients . Select ( i => i . goods ) . OfType < Item > ( ) ) {
@@ -656,11 +672,12 @@ private void CalculateItemWeights() {
656672 /// the existing launch products of a preexisting recipe, or set no products for a new recipe.</param>
657673 private void EnsureLaunchRecipe ( Item item , Product [ ] ? launchProducts ) {
658674 Recipe recipe = CreateSpecialRecipe ( item , SpecialNames . RocketLaunch , LSs . SpecialRecipeLaunched ) ;
675+ // When this is called in 2.0, we don't know the item weight or the rocket capacity.
676+ // CalculateItemWeights will scale this ingredient and the products appropriately (but not the launch slot), only in 2.0.
677+ int ingredientCount = factorioVersion < v2_0 ? item . stackSize : 1 ;
659678 recipe . ingredients =
660679 [
661- // When this is called, we don't know the item weight or the rocket capacity.
662- // CalculateItemWeights will scale this ingredient and the products appropriately (but not the launch slot)
663- new Ingredient ( item , 1 ) ,
680+ new Ingredient ( item , ingredientCount ) ,
664681 new Ingredient ( rocketLaunch , 1 ) ,
665682 ] ;
666683 recipe . products = launchProducts ?? recipe . products ?? [ ] ;
@@ -694,6 +711,8 @@ private void DeserializeTile(LuaTable table, ErrorCollector _) {
694711
695712 string recipeCategory = SpecialNames . PumpingRecipe + "tile" ;
696713 Recipe recipe = CreateSpecialRecipe ( pumpingFluid , recipeCategory , LSs . SpecialRecipePumping ) ;
714+ // We changed the names of pumping recipes when adding support for 2.0.
715+ formerAliases [ $ "Mechanics.pump.{ pumpingFluid . name } .{ pumpingFluid . name } "] = recipe ;
697716
698717 if ( recipe . products == null ) {
699718 recipe . products = [ new Product ( pumpingFluid , 1200f ) ] ; // set to Factorio default pump amounts - looks nice in tooltip
@@ -746,6 +765,18 @@ private void DeserializeFluid(LuaTable table, ErrorCollector _) {
746765 return GetObject < Item > ( researchItem ) ;
747766 }
748767 }
768+ else if ( factorioVersion < v2_0 ) {
769+ // In 1.1, type is optional, and an item ingredient/product can be represented as { [1] = "name", [2] = amount }
770+ if ( table . Get ( "name" , out string ? name ) ) {
771+ return GetObject < Item > ( name ) ;
772+ }
773+
774+ if ( table . Get ( 1 , out name ) ) {
775+ // Copy the amount from [2] to ["amount"] to translate for later code.
776+ table [ "amount" ] = table . Get < int > ( 2 ) ;
777+ return GetObject < Item > ( name ) ;
778+ }
779+ }
749780 return null ;
750781 }
751782
@@ -809,12 +840,17 @@ private void DeserializeLocation(LuaTable table, ErrorCollector collector) {
809840 // These are the only expected sizes for icons we render.
810841 // New classes of icons (e.g. achievements) will need new cases to make IconParts with default scale render correctly.
811842 // https://lua-api.factorio.com/latest/types/IconData.html
812- Technology => 256 ,
843+ Technology => 256 , // I think this should be 512 in 1.1, but that doesn't fix vanilla icons, and makes SE icons worse.
813844 _ => 64
814845 } ;
815846
816847 FactorioIconPart part = new ( path ) { size = x . Get ( "icon_size" , 64 ) } ;
817848 part . scale = x . Get ( "scale" , expectedSize / 2f / part . size ) ;
849+ if ( factorioVersion < v2_0 ) {
850+ // Mystery adjustment that makes 1.1 technology icons render correctly, and doesn't appear to mess up the recipe icons.
851+ // (Checked many of vanilla/SE's tech icons and the se-simulation-* recipes.)
852+ part . scale *= part . size / 64f ;
853+ }
818854
819855 if ( x . Get ( "shift" , out LuaTable ? shift ) ) {
820856 part . x = shift . Get < float > ( 1 ) ;
0 commit comments