Giter Club home page Giter Club logo

Comments (2)

tboby avatar tboby commented on June 15, 2024

Hi!

You're right, the interface has changed since then so that snippet doesn't work.

I've updated it so it works again.

Basically, most of the properties return read-only copies as F# has immutable data by default. There are four ways you can actually modify the data structure:

  1. SetTag which will look for the key and replace it, or add it if it isn't there
  2. AllChildren's setter, which takes a C# List and replaces all current children with it
  3. All's setter, which takes an F# List and replaces all current children with it it
  4. `AllArray', which returns a mutable array (but not resizable), or the setter which replaces all current children with it

For "Leaf", both the Key and Value have setters. For "Node", the Key has a setter too.

            //Add is_triggered_only = true
            var leaf = new Leaf(KeyValueItem.NewKeyValueItem(Key.NewKey("is_triggered_only"), Value.NewBool(true), Operator.Equals), FSharpOption<range>.None);
            myEvent.SetTag(leaf.Key, Child.NewLeafC(leaf));
            // or
            // var newChildren = myEvent.AllChildren;
            // newChildren.Add(Leaf.Create(KeyValueItem.NewKeyValueItem(Key.NewKey("is_triggered_only"), Value.NewBool(true), Operator.Equals), range.Zero));
            // myEvent.AllChildren = newChildren;

Hope that helps a little!

from cwtools.

Nadav-Ruskin avatar Nadav-Ruskin commented on June 15, 2024

Thank you for the in-depth answer!

Speaking of serializing, I have another question. I'm trying to modify a Crusader Kings III file programmatically and iteratively, and since the file is quite big I'd like to pickle the parsed data between runs. Is there a way to do so?

            var processed = CWTools.CSharp.Parsers.ProcessStatements("testevent.txt", "./testevent.txt", eventFile);

            var serialized_processed = JsonSerializer.Serialize(processed);  // <--- Fails here: 			System.NotSupportedException: 'F# discriminated union serialization is not supported. Consider authoring a custom converter for the type.'
            var deserialized_processed = JsonSerializer.Deserialize<Node>(serialized_processed);
            File.AppendAllText("./serialized_node.txt", serialized_processed);

from cwtools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.