Exemplo n.º 1
0
 public void SavePreferences(float value)
 {
     GD.Print("SAVED");
     ResourceSaver.Save(ApplicationPreferences.ResourcePath, ApplicationPreferences);
     ResourceSaver.Save(ViewPreferences.ResourcePath, ViewPreferences);
     ResourceSaver.Save(AppearancePreferences.ResourcePath, AppearancePreferences);
 }
Exemplo n.º 2
0
    private TileSet buildTileSet(int num)
    {
        string cached_path = $"user://Cache/{GDWorld.KWorld.WorldDirectoryName}/Tileset{num}.res";

        if (new File().FileExists(cached_path))
        {
            return(ResourceLoader.Load <TileSet>(cached_path));
        }

        var texture = GDWorld.KWorld.getWorldTexture($"Tilesets/Tileset{num}.png");

        switch (texture)
        {
        case Texture t:
            // Preprocess the texture if no alpha channel
            TileSet new_tileset = makeTileset(t.HasAlpha() ? t : preprocessTilesetTexture(t), true);
            ensureDirExists($"user://Cache/{GDWorld.KWorld.WorldDirectoryName}");
            ResourceSaver.Save(cached_path, new_tileset, ResourceSaver.SaverFlags.Compress);
            return(new_tileset);

        case TileSet ts: return(ts);

        default: return(null);
        }
    }
Exemplo n.º 3
0
    // Call this in any level-optimizing procedure (level load screen, post-download processing, special button).
    public static void compileInternalTileset(KnyttWorld world, bool recompile)
    {
        ensureDirExists($"user://Cache/{world.WorldDirectoryName}");

        for (int num = 0; num < 256; num++)
        {
            string tileset_path = $"Tilesets/Tileset{num}.png";
            if (!world.worldFileExists(tileset_path))
            {
                continue;
            }

            string cached_path = $"user://Cache/{world.WorldDirectoryName}/Tileset{num}.res";
            if (!recompile && new File().FileExists(cached_path))
            {
                continue;
            }

            var texture = world.getWorldTexture(tileset_path);
            if (texture is Texture t)
            {
                t = preprocessTilesetTexture(t);
                ResourceSaver.Save(cached_path, makeTileset(t, true), ResourceSaver.SaverFlags.Compress);
            }
        }
    }
    public void OnConvexShapeSaveOK(string path)
    {
        var sphere = _gen.GetNode <Icosphere>("IcosphereInstance");
        var shape  = sphere.Mesh.CreateConvexShape();

        ResourceSaver.Save(path, shape);
    }
Exemplo n.º 5
0
 // Create "user://tilesets" directory and call this function at start to compile default tilesets
 public static void compileTileset()
 {
     for (int i = 0; i < 256; i++)
     {
         GD.Print($"Compiling tileset #{i}");
         var texture = loadInternalTexture($"res://knytt/data/Tilesets/Tileset{i}.png");
         var tileset = makeTileset(texture, true);
         GD.PrintErr(ResourceSaver.Save($"user://tilesets/Tileset{i}.png.res", tileset, ResourceSaver.SaverFlags.Compress));
     }
 }
Exemplo n.º 6
0
    public void SaveLevel(string pPath)
    {
        PackedScene savedLevel = new PackedScene();

        CurrentLevel = GetTree().GetRoot().GetNode("Editor/ViewportContainer/Viewport/CurrentLevel") as Level;
        SetOwners(CurrentLevel);
        GD.Print("[Editor] - Setting Owners...");
        savedLevel.Pack(CurrentLevel);         // Packs the level into a scene.
        ResourceSaver.Save(pPath, savedLevel); // Save the PackedScene
        GD.Print("[Editor] Level Saved.");
    }
Exemplo n.º 7
0
    // returns location of Dino stats save
    public string GetDinoSaveLocation(Enums.Dinos dinoType)
    {
        string dinoNameNoSpaces = EnumUtils.GetDinoName(dinoType).Replace(" ", string.Empty);
        string userSaveLocation = $"user://{dinoNameNoSpaces}StatsSave.tres";

        // make a savefile in the user:// location if none exists yet
        if (!ResourceLoader.Exists(userSaveLocation))
        {
            string projectStatsLocation = $"res://src/combat/dinos/stats/{dinoNameNoSpaces}.tres";
            ResourceSaver.Save(userSaveLocation, ResourceLoader.Load <DinoInfoResource>(projectStatsLocation, null, true));
        }

        return(userSaveLocation);
    }
Exemplo n.º 8
0
    public void _OnInventoryChanged(GenericInventory inventory)
    {
        // GD.Print("Save inven: ", inventory.Items[0].itemReference.name);
        // SaveManager.SaveInventory(inventory);
        GD.Print("inventory: ", inventory.Items);
        // var x = new List<GenericItem>();
        // x.Add(inventory.Items[0].itemReference);
        Error err = ResourceSaver.Save("user://inventory.tres", inventory, ResourceSaver.SaverFlags.BundleResources);

        // Error err = (Error)GetTree().Root.GetNode("/root/ResSaver").Call("save_inventory", inventory);
        if (err != Error.Ok)
        {
            GD.Print("Save error");
        }
        // GenericItem item = (GenericItem)ResourceLoader.Load("user://inventory.tres");
        // GD.Print(item.name);
    }
Exemplo n.º 9
0
    public override void _Ready()
    {
        Instance = this;

        // load player stats; make a new one if none exists from the pre-existing one in the project
        string statsSaveLocation    = "user://PlayerStatsSave.tres";
        string projectStatsLocation = "res://src/resources/PlayerStats.tres";

        if (!ResourceLoader.Exists(statsSaveLocation))
        {
            ResourceSaver.Save(statsSaveLocation, ResourceLoader.Load <PlayerStatsResource>(projectStatsLocation));
        }
        statsResource = ResourceLoader.Load <PlayerStatsResource>("user://PlayerStatsSave.tres", null, true);

        dinosUnlocked = statsResource.dinosUnlocked;
        genesFound    = statsResource.genesFound;
    }
        protected sealed override Error Import()
        {
            SceneContext = GetContext();

            if (UsedExtension is not null)
            {
                typeof(SceneImportExtension <SceneBase, Context>)
                .GetProperty(nameof(SceneImportExtension <SceneBase, Context> .SceneContext)) !
                .SetValue(UsedExtension, SceneContext);
            }

            ulong buildedSceneId;

            try
            {
                SceneBase sceneNode = BuildScene();
                buildedSceneId = sceneNode.GetInstanceId();
                UsedExtension?.OnSceneBuilt(sceneNode);
            }
            catch (Exception error)
            {
                GD.PushError(error.Message);
                return(Error.Bug);
            }

            SceneBase buildedScene = (GD.InstanceFromId(buildedSceneId) as SceneBase) !;

            foreach (Node child in buildedScene.GetChildren())
            {
                SetOwnerRecursive(child, buildedScene);
            }

            var packedScene = new PackedScene();

            packedScene.TakeOverPath(ImportContext.SavePath);

            if (packedScene.Pack(buildedScene) != Error.Ok)
            {
                return(Error.Failed);
            }

            return(ResourceSaver.Save($"{ImportContext.SavePath}.{GetSaveExtension()}", packedScene));
        }
Exemplo n.º 11
0
    public override void _Ready()
    {
        _sprite = (Sprite)GetNode("Sprite");
        var     texture   = _sprite.Texture;
        var     texwidth  = texture.GetWidth() / Tilesize.x;
        var     texheight = texture.GetHeight() / Tilesize.y;
        TileSet tileSet   = new TileSet();

        for (int x = 0; x < texwidth; x++)
        {
            for (int y = 0; y < texheight; y++)
            {
                var region = new Rect2(x * Tilesize.y, y * Tilesize.y, Tilesize.x, Tilesize.y);
                var id     = x + y * 10;
                tileSet.CreateTile(id);
                tileSet.TileSetTexture(id, texture);
                tileSet.TileSetRegion(id, region);
            }
        }

        ResourceSaver.Save("res://terrain/terrain_tiles.tres", tileSet);
    }
    public override void _Ready()
    {
        sprite  = (Sprite)GetNode("Sprite");
        texture = sprite.Texture;

        var width  = texture.GetWidth() / TileWidth;
        var height = texture.GetHeight() / TileHeight;
        var ts     = new TileSet();

        for (int x = 0; x < width; x++)
        {
            for (int y = 0; y < height; y++)
            {
                var region = new Rect2(x * TileWidth, y * TileHeight, TileWidth, TileHeight);
                var id     = x + y * 10;
                ts.CreateTile(id);
                ts.TileSetTexture(id, texture);
                ts.TileSetRegion(id, region);
                ResourceSaver.Save("res://terrain/terrain_tiles.tres", ts);
            }
        }

        base._Ready();
    }
Exemplo n.º 13
0
    // Called when the node enters the scene tree for the first time.
    public override void _Ready()
    {
        Vector2 tileSize = new Vector2(128, 128);
        Sprite  sprite   = (Sprite)GetNode("Sprite");
        Texture texture  = sprite.Texture;

        float txWidth  = texture.GetWidth() / tileSize.x;
        float txheight = texture.GetHeight() / tileSize.y;

        TileSet ts = new TileSet();

        for (int x = 0; x <= txWidth; x++)
        {
            for (int y = 0; y <= txheight; y++)
            {
                Rect2 region = new Rect2(x * tileSize.x, y * tileSize.y, tileSize.x, tileSize.y);
                int   id     = x + y * 10;
                ts.CreateTile(id);
                ts.TileSetTexture(id, texture);
                ts.TileSetRegion(id, region);
            }
        }
        ResourceSaver.Save("res://terrain/terrain_tiles.tres", ts);
    }
Exemplo n.º 14
0
    public bool DebugInput(Crawler crawler, InputEvent ev)
    {
        if (ev.IsActionPressed("quicksave", false))
        {
            temp = crawler.Model.SaveToDictionary();

            PackedScene packed = new PackedScene();
            packed.Pack(crawler.Model);
            ResourceSaver.Save("res://dump.tscn", packed);
            return(true);
        }

        if (ev.IsActionPressed("quickload", false))
        {
            // Delete the old stuff.
            {
                View old = crawler.GetNode <View>("View");
                crawler.RemoveChild(old);
                old.QueueFree();

                Model oldd = crawler.Model;
                crawler.RemoveChild(oldd);
                oldd.QueueFree();
            }

            // Add the new stuff.
            {
                // PackedScene modelScene = GD.Load<PackedScene>("res://dump.tscn");
                PackedScene modelScene = GD.Load <PackedScene>((string)temp["Filename"]);
                Model       model      = (Model)modelScene.Instance();
                model.Name = "Model";
                crawler.AddChild(model);

                PackedScene viewScene = GD.Load <PackedScene>("res://Crawler/View/View.tscn");
                View        view      = (View)viewScene.Instance();
                view.Name = "View";
                crawler.AddChild(view);

                view.ConnectToModel(model);

                LoadedGenerator gen = new LoadedGenerator(temp);
                gen.Generate(crawler.Model);
            }

            return(true);
        }

        if (ev is InputEventKey eventKey && eventKey.Pressed && !eventKey.IsEcho())
        {
            if (eventKey.Scancode == (int)KeyList.F1)
            {
                crawler.View.impatientMode = !crawler.View.impatientMode;
                string thing = (crawler.View.impatientMode ? "on" : "off");

                crawler.View.GetNode <RichTextLabel>("UILayer/MessageLog").AppendBbcode($"\n * Impatient mode {thing}!");
                return(true);
            }

            if (eventKey.Scancode == (int)KeyList.F9)
            {
                Node2D map = (Node2D)crawler.Model.FindNode("Map");
                map.Visible = !map.Visible;
                return(true);
            }

            // this makes people very confused. also its a hack anyways.
            // if (eventKey.Scancode == (int)KeyList.F11)
            // {
            //     GetTree().ChangeScene("res://Crawler/Crawler.tscn");
            //     return true;
            // }

            if (eventKey.Scancode == (int)KeyList.Quoteleft)
            {
                Control debugLog = crawler.View.GetNode <Control>("UILayer/DebugLog");
                debugLog.Visible = !debugLog.Visible;
                return(true);
            }
        }

        return(false);
    }
    public void OnMeshSaveOK(string path)
    {
        var sphere = _gen.GetNode <Icosphere>("IcosphereInstance");

        ResourceSaver.Save(path, sphere.Mesh);
    }
Exemplo n.º 16
0
 public void SaveViewPreferences(bool visible)
 {
     GD.Print("SAVED");
     ResourceSaver.Save(ViewPreferences.ResourcePath, ViewPreferences);
 }
Exemplo n.º 17
0
    public void SaveResource()
    {
        string saveLocation = DinoInfo.Instance.GetDinoSaveLocation(dinoType);

        ResourceSaver.Save(saveLocation, this);
    }
Exemplo n.º 18
0
 public void SaveResource()
 {
     ResourceSaver.Save("user://PlayerStatsSave.tres", this);
 }