private void OnSerialize(bool saving, TankPreset.BlockSpec blockSpec)
        {
            if (saving)
            {
                ModuleProcedural.SerialData serialData = new ModuleProcedural.SerialData()
                {
                    size     = this.Size,
                    position = base.block.cachedLocalPosition,
                    faces    = this.faces,
                    inverted = this.inverted,
                    texture  = this.texture
                };
                serialData.Store(blockSpec.saveState);
            }
            else
            {
                ModuleProcedural.SerialData serialData2 = Module.SerialData <ModuleProcedural.SerialData> .Retrieve(blockSpec.saveState);

                if (serialData2 != null)
                {
                    this.Size    = serialData2.size;
                    this.Texture = serialData2.texture;
                }
            }
        }
Beispiel #2
0
        private void OnSerialize(bool saving, TankPreset.BlockSpec blockSpec)
        {
            if (saving)
            {
                var serialDataSave = new SerialData();
                var list           = new List <WeaponGroupSerial>();
                foreach (var group in groups)
                {
                    list.Add(new WeaponGroupSerial()
                    {
                        name      = group.name,
                        positions = group.weapons.Select(w => w.block.cachedLocalPosition).ToArray(),
                        keyCode   = (int)group.keyCode
                    });
                }
                serialDataSave.groups = list.ToArray();
                serialDataSave.Store(blockSpec.saveState);
                return;
            }
            SerialData serialData = Module.SerialData <ModuleWeaponGroupController.SerialData> .Retrieve(blockSpec.saveState);

            if (serialData != null)
            {
                data = serialData;
                base.block.tank.ResetPhysicsEvent.Subscribe(this.OnTankPostSpawn);
            }
        }
Beispiel #3
0
        private void OnSerialize(bool saving, TankPreset.BlockSpec blockSpec)
        {
            if (saving)
            {
                ModuleSteeringRegulator.SerialData serialData = new ModuleSteeringRegulator.SerialData()
                {
                    dist     = MaxDist,
                    drive    = DriveMod,
                    throttle = ThrottleMod,
                    dampen   = VelocityDampen
                };
                serialData.Store(blockSpec.saveState);
            }
            else
            {
                ModuleSteeringRegulator.SerialData serialData2 = Module.SerialData <ModuleSteeringRegulator.SerialData> .Retrieve(blockSpec.saveState);

                if (serialData2 != null)
                {
                    DriveMod       = serialData2.drive;
                    ThrottleMod    = serialData2.throttle;
                    MaxDist        = serialData2.dist;
                    VelocityDampen = serialData2.dampen;
                }
            }
        }
Beispiel #4
0
        private void OnSerialize(bool saving, TankPreset.BlockSpec blockSpec)
        {
            var  corp = ManSpawn.inst.GetCorporation(block.BlockType);
            byte f    = (byte)corp;

            if (Main.SwapDictByteToID.ContainsKey(f))
            {
                if (saving)
                {
                    try
                    {
                        if (Main.SwapDictByteToID.ContainsKey(f) && Main.SwapDictByteToID[f].TryGetValue(block.GetSkinIndex(), out string NewSkinName))
                        {
                            blockSpec.Store(Type, "SkinName", NewSkinName);
                        }
                        else if (block.GetSkinIndex() != 0)
                        {
                            Console.WriteLine();
                        }
                    }
                    catch { Console.WriteLine("TextureSwapper [Save] FAILED"); }
                }
                else
                {
                    try
                    {
                        string str = null;

                        CustomSkinIndexer.SerialData serialData2 = Module.SerialData <CustomSkinIndexer.SerialData> .Retrieve(blockSpec.saveState);

                        if (serialData2 != null)
                        {
                            str = serialData2.SkinName;
                        }
                        else
                        {
                            string prefix = string.Format("{0} {1} ", Type, "SkinName");
                            try
                            {
                                str = blockSpec.textSerialData.Single((string s) => s.StartsWith(prefix)).Substring(prefix.Length);
                            }
                            catch { }
                        }

                        if (!string.IsNullOrEmpty(str) && Main.SwapDictIDToByte.ContainsKey(f) && Main.SwapDictIDToByte[f].TryGetValue(str, out byte Index))
                        {
                            block.SetSkinIndex(Index);
                        }
                    }
                    catch { Console.WriteLine("TextureSwapper [load] FAILED"); }
                }
            }
            new CustomSkinIndexer.SerialData().Remove(blockSpec.saveState);
        }
Beispiel #5
0
        private void OnSerialize(bool saving, TankPreset.BlockSpec spec)
        {
            if (saving)
            {
                var serialData = new ContainerData
                {
                    SavedTech = _savedTech,
                };
                serialData.Store(spec.saveState);
            }
            else
            {
                var data = SerialData <ContainerData> .Retrieve(spec.saveState);

                _savedTech = data.SavedTech;
            }
        }
Beispiel #6
0
        private void OnSerializeSliced(bool saving, TankPreset.BlockSpec blockSpec)
        {
            if (saving)
            {
                var serialData = new ModuleProceduralSlicedMesh.SerialData()
                {
                    slicedMeshName = slicedMeshName
                };
                serialData.Store(blockSpec.saveState);
            }
            else
            {
                var serialData2 = Module.SerialData <ModuleProceduralSlicedMesh.SerialData> .Retrieve(blockSpec.saveState);

                if (serialData2 != null)
                {
                    this.SlicedMeshName = serialData2.slicedMeshName;
                }
            }
        }
Beispiel #7
0
        private void OnSerialize(bool saving, TankPreset.BlockSpec blockSpec)
        {
            if (saving)
            {
                ModuleDensityShift.SerialData serialData = new ModuleDensityShift.SerialData()
                {
                    mass = Mass
                };
                serialData.Store(blockSpec.saveState);
            }
            else
            {
                ModuleDensityShift.SerialData serialData2 = Module.SerialData <ModuleDensityShift.SerialData> .Retrieve(blockSpec.saveState);

                if (serialData2 != null)
                {
                    SetMass(serialData2.mass);
                }
            }
        }
Beispiel #8
0
        private void OnSerialize(bool saving, TankPreset.BlockSpec blockSpec)
        {
            if (saving)
            {
                ModuleColor.SerialData serialData = new ModuleColor.SerialData()
                {
                    color = string.Format("{0},{1},{2}", this.color.r, this.color.g, this.color.b)
                };
                serialData.Store(blockSpec.saveState);
            }
            else
            {
                ModuleColor.SerialData serialData2 = Module.SerialData <ModuleColor.SerialData> .Retrieve(blockSpec.saveState);

                if (serialData2 != null)
                {
                    var c = serialData2.color.Split(',');
                    this.Color = new Color(float.Parse(c[0]), float.Parse(c[1]), float.Parse(c[2]));
                }
            }
        }
            void OnSerialize(bool saving, TankPreset.BlockSpec blockSpec)
            {
                if (saving)
                {
                    new ModuleReactorHolder.SerialData
                    {
                        charge = EnergyNetActive ? NetCharge / NetMaxCharge * ThisCapacity : ThisCharge,
                        remain = ChargeLeftToAdd
                    }.Store(blockSpec.saveState);
                }
                else
                {
                    ModuleReactorHolder.SerialData sd = SerialData <ModuleReactorHolder.SerialData> .Retrieve(blockSpec.saveState);

                    if (sd != null)
                    {
                        ThisCharge      = sd.charge;
                        ChargeLeftToAdd = sd.remain;
                    }
                }
            }
        private void OnSerialize(bool saving, TankPreset.BlockSpec blockSpec)
        {
            if (saving)
            {
                var serialDataSave = new SerialData();
                var list           = new List <OutgridBlock>();
                foreach (var block in base.block.tank.blockman.IterateBlocks())
                {
                    list.Add(new OutgridBlock(block));
                }
                serialDataSave.blocks = list.ToArray();
                serialDataSave.Store(blockSpec.saveState);
                return;
            }
            SerialData serialData = Module.SerialData <ModuleOffgridStore.SerialData> .Retrieve(blockSpec.saveState);

            if (serialData != null)
            {
                data = serialData;
                base.block.tank.ResetPhysicsEvent.Subscribe(this.OnTankPostSpawn);
            }
        }
            public Tank ToTech(Vector3 position, Quaternion rotation)
            {
                var spawnParams = new ManSpawn.TankSpawnParams()
                {
                    forceSpawn = true,
                    grounded   = true,
                    position   = position,
                    rotation   = rotation,
                    placement  = ManSpawn.TankSpawnParams.Placement.PlacedAtPosition,
                    techData   = new TechData()
                    {
                        Name           = this.Name,
                        m_CreationData = new TechData.CreationData(),
                        m_BlockSpecs   = new List <TankPreset.BlockSpec>()
                    }
                };

                /*var root = this.Blocks.First(b => b.IsRootBlock);
                 * this.Blocks.Remove(root);
                 * var rblock = root.ToBlock(position - Vector3.one, rotation);
                 * rblock.trans.localPosition = root.Position;
                 * cachedLocalRotation.SetValue(rblock, root.OrthoRotation, null);
                 * var rblockspec = new TankPreset.BlockSpec();
                 * rblockspec.InitFromBlockState(rblock, true);
                 * spawnParams.techData.m_BlockSpecs.Add(rblockspec);
                 *
                 * rblock.visible.RemoveFromGame();*/

                foreach (var b in Blocks)
                {
                    var rB = b.ToBlock(position - Vector3.one, rotation);
                    rB.trans.localPosition = b.Position;
                    cachedLocalRotation.SetValue(rB, b.OrthoRotation, null);
                    var rBSpec = new TankPreset.BlockSpec();
                    rBSpec.InitFromBlockState(rB, true);
                    spawnParams.techData.m_BlockSpecs.Add(rBSpec);
                    rB.visible.RemoveFromGame();
                }

                var tech = ManSpawn.inst.SpawnUnmanagedTank(spawnParams);

                var blockman = tech.blockman;

                foreach (var b in Blocks)
                {
                    var block = blockman.GetBlockAtPosition(b.Position);
                    block.trans.localPosition    = b.localPosition;
                    block.trans.localEulerAngles = b.localEulerAngles;
                    block.trans.localScale       = b.localScale;
                }

                /*Blocks.Add(root);
                 *
                 * var blocks = tech.blockman.GetLowestBlocks();
                 * foreach (var b in blocks)
                 * {
                 *  var jb = Blocks.First(bb => bb.Position == b.cachedLocalPosition);
                 *  b.trans.localEulerAngles = jb.localEulerAngles;
                 *  b.trans.localPosition = jb.localPosition;
                 *  b.trans.localScale = jb.localScale;
                 * }*/

                return(tech);
            }
Beispiel #12
0
        private void DoWindow(int id)
        {
            scrollPos = GUILayout.BeginScrollView(scrollPos);
            foreach (var image in Directory.GetFiles(Path.GetFullPath(ProceduralBlocks.ProceduralBlocksMod.TechArtFolder), "*.png"))
            {
                if (GUILayout.Button(Path.GetFileNameWithoutExtension(image), new GUIStyle(GUI.skin.button)
                {
                    richText = true, alignment = TextAnchor.MiddleLeft
                }))
                {
                    path = image;
                }
            }
            GUILayout.EndScrollView();
            GUILayout.TextField(path);

            useModBlock = GUILayout.Toggle(useModBlock, "Use mod block");
            if (!useModBlock)
            {
                useFlesh = GUILayout.Toggle(useFlesh, "Use flesh blocks");
            }
            if (GUILayout.Button("Load"))
            {
                try
                {
                    Texture2D image = new Texture2D(0, 0);
                    image.LoadImage(File.ReadAllBytes(path));

                    if (image.width <= 64 && image.height <= 64)
                    {
                        blocks = new List <Temp>();
                        Vector3    position = Singleton.playerTank.trans.position;
                        Quaternion rotation = Singleton.playerTank.trans.rotation;

                        TankBlock root = Singleton.Manager <ManSpawn> .inst.SpawnBlock(BlockTypes.GSOCockpit_111, Vector3.zero, rotation);

                        root.trans.localPosition = Vector3.zero;

                        var spawnParams = new ManSpawn.TankSpawnParams()
                        {
                            forceSpawn = true,
                            grounded   = true,
                            position   = position,
                            rotation   = rotation,
                            placement  = ManSpawn.TankSpawnParams.Placement.PlacedAtPosition,
                            techData   = new TechData()
                            {
                                Name           = Path.GetFileNameWithoutExtension(path),
                                m_CreationData = new TechData.CreationData(),
                                m_BlockSpecs   = new List <TankPreset.BlockSpec>()
                            }
                        };

                        var spec = new TankPreset.BlockSpec();
                        spec.InitFromBlockState(root, false);

                        spawnParams.techData.m_BlockSpecs.Add(spec);

                        for (int x = 0; x < image.width; x++)
                        {
                            for (int y = 0; y < image.height; y++)
                            {
                                if (x == 0 && y == 0)
                                {
                                    continue;
                                }
                                var c    = image.GetPixel(x, y);
                                var type = (BlockTypes)7000;
                                if (!useModBlock)
                                {
                                    var sw = float.MaxValue;
                                    var cc = Color.white;
                                    foreach (var color in color_blocks.Keys.ToList())
                                    {
                                        if (!useFlesh && color_blocks[color].ToString().Contains("Flesh"))
                                        {
                                            continue;
                                        }
                                        var w = (float)Math.Sqrt(Math.Pow(c.r - color.r, 2) + Math.Pow(c.g - color.g, 2) + Math.Pow(c.b - color.b, 2));
                                        if (w < sw)
                                        {
                                            sw = w;
                                            cc = color;
                                        }
                                    }
                                    type = color_blocks[cc];
                                }

                                TankBlock b = Singleton.Manager <ManSpawn> .inst.SpawnBlock(type, new Vector3(x, y, 0), rotation);

                                b.trans.localPosition = new Vector3(x, y, 0);
                                if (useModBlock)
                                {
                                    b.GetComponent <ModuleColor>().Color = c;
                                }
                                spec = new TankPreset.BlockSpec();
                                spec.InitFromBlockState(b, false);
                                spawnParams.techData.m_BlockSpecs.Add(spec);
                                b.visible.RemoveFromGame();
                            }
                        }
                        tech = ManSpawn.inst.SpawnUnmanagedTank(spawnParams);
                        Tank playerTank = Singleton.playerTank;
                        Singleton.Manager <ManTechs> .inst.SetPlayerTankLocally(null, true);

                        playerTank.visible.RemoveFromGame();

                        Singleton.Manager <ManTechs> .inst.SetPlayerTankLocally(tech, true);
                    }
                }
                catch (Exception e) { Console.WriteLine(e); }
                visible = false;
            }
            if (GUILayout.Button("Cancel"))
            {
                visible = false;
            }
            GUI.DragWindow();
        }