This commit is contained in:
Gerard Gascón 2025-04-24 17:23:34 +02:00
commit b99855351d
434 changed files with 50357 additions and 0 deletions

View file

@ -0,0 +1,62 @@
# warning-ignore-all:shadowed_variable
# warning-ignore-all:unused_class_variable
# ############################################################################ #
# Copyright © 2015-2021 inkle Ltd.
# Copyright © 2019-2022 Frédéric Maquin <fred@ephread.com>
# All Rights Reserved
#
# This file is part of inkgd.
# inkgd is licensed under the terms of the MIT license.
# ############################################################################ #
extends InkValue
class_name InkBoolValue
# ############################################################################ #
func get_value_type() -> int:
return ValueType.BOOL
func get_is_truthy() -> bool:
return value
func _init():
value = false
# The method takes a `StoryErrorMetadata` object as a parameter that
# doesn't exist in upstream. The metadat are used in case an 'exception'
# is raised. For more information, see story.gd.
func cast(new_type, metadata = null):
if new_type == self.value_type:
return self
if new_type == ValueType.INT:
return IntValue().new_with(1 if value else 0)
if new_type == ValueType.FLOAT:
return FloatValue().new_with(1.0 if value else 0.0)
if new_type == ValueType.STRING:
return StringValue().new_with("true" if value else "false")
InkUtils.throw_story_exception(bad_cast_exception_message(new_type), false, metadata)
return null
func _to_string() -> String:
return "true" if value else "false"
# ######################################################################## #
# GDScript extra methods
# ######################################################################## #
func is_ink_class(type):
return type == "BoolValue" || super.is_ink_class(type)
func get_ink_class():
return "BoolValue"
static func new_with(val):
var value = BoolValue().new()
value._init_with(val)
return value

View file

@ -0,0 +1,60 @@
# warning-ignore-all:shadowed_variable
# warning-ignore-all:unused_class_variable
# ############################################################################ #
# Copyright © 2015-2021 inkle Ltd.
# Copyright © 2019-2022 Frédéric Maquin <fred@ephread.com>
# All Rights Reserved
#
# This file is part of inkgd.
# inkgd is licensed under the terms of the MIT license.
# ############################################################################ #
extends InkValue
class_name InkDivertTargetValue
# ############################################################################ #
var target_path : get = get_target_path, set = set_target_path # InkPath
func get_target_path():
return value
func set_target_path(value):
self.value = value
func get_value_type():
return ValueType.DIVERT_TARGET
func get_is_truthy():
InkUtils.throw_exception("Shouldn't be checking the truthiness of a divert target")
return false
func _init():
value = null
# The method takes a `StoryErrorMetadata` object as a parameter that
# doesn't exist in upstream. The metadat are used in case an 'exception'
# is raised. For more information, see story.gd.
func cast(new_type, metadata = null):
if new_type == self.value_type:
return self
InkUtils.throw_story_exception(bad_cast_exception_message(new_type), false, metadata)
return null
func _to_string() -> String:
return "DivertTargetValue(" + self.target_path._to_string() + ")"
# ######################################################################## #
# GDScript extra methods
# ######################################################################## #
func is_ink_class(type):
return type == "DivertTargetValue" || super.is_ink_class(type)
func get_ink_class():
return "DivertTargetValue"
static func new_with(val):
var value = DivertTargetValue().new()
value._init_with(val)
return value

View file

@ -0,0 +1,59 @@
# warning-ignore-all:shadowed_variable
# warning-ignore-all:unused_class_variable
# ############################################################################ #
# Copyright © 2015-2021 inkle Ltd.
# Copyright © 2019-2022 Frédéric Maquin <fred@ephread.com>
# All Rights Reserved
#
# This file is part of inkgd.
# inkgd is licensed under the terms of the MIT license.
# ############################################################################ #
extends InkValue
class_name InkFloatValue
# ############################################################################ #
func get_value_type():
return ValueType.FLOAT
func get_is_truthy():
return value != 0.0
func _init():
value = 0.0
# The method takes a `StoryErrorMetadata` object as a parameter that
# doesn't exist in upstream. The metadat are used in case an 'exception'
# is raised. For more information, see story.gd.
func cast(new_type, metadata = null):
if new_type == self.value_type:
return self
if new_type == ValueType.BOOL:
return BoolValue().new_with(false if value == 0 else true)
if new_type == ValueType.INT:
return IntValue().new_with(int(value))
if new_type == ValueType.STRING:
return StringValue().new_with(str(value)) # TODO: Check formating
InkUtils.throw_story_exception(bad_cast_exception_message(new_type), false, metadata)
return null
# ######################################################################## #
# GDScript extra methods
# ######################################################################## #
func is_ink_class(type):
return type == "FloatValue" || super.is_ink_class(type)
func get_ink_class():
return "FloatValue"
static func new_with(val):
var value = FloatValue().new()
value._init_with(val)
return value

View file

@ -0,0 +1,59 @@
# warning-ignore-all:shadowed_variable
# warning-ignore-all:unused_class_variable
# ############################################################################ #
# Copyright © 2015-2021 inkle Ltd.
# Copyright © 2019-2022 Frédéric Maquin <fred@ephread.com>
# All Rights Reserved
#
# This file is part of inkgd.
# inkgd is licensed under the terms of the MIT license.
# ############################################################################ #
extends InkValue
class_name InkIntValue
# ############################################################################ #
func get_value_type():
return ValueType.INT
func get_is_truthy():
return value != 0
func _init():
value = 0
# The method takes a `StoryErrorMetadata` object as a parameter that
# doesn't exist in upstream. The metadat are used in case an 'exception'
# is raised. For more information, see story.gd.
func cast(new_type, metadata = null):
if new_type == self.value_type:
return self
if new_type == ValueType.BOOL:
return BoolValue().new_with(false if value == 0 else true)
if new_type == ValueType.FLOAT:
return FloatValue().new_with(float(value))
if new_type == ValueType.STRING:
return StringValue().new_with(str(value))
InkUtils.throw_story_exception(bad_cast_exception_message(new_type), false, metadata)
return null
# ######################################################################## #
# GDScript extra methods
# ######################################################################## #
func is_ink_class(type):
return type == "IntValue" || super.is_ink_class(type)
func get_ink_class():
return "IntValue"
static func new_with(val):
var value = IntValue().new()
value._init_with(val)
return value

View file

@ -0,0 +1,90 @@
# warning-ignore-all:shadowed_variable
# warning-ignore-all:unused_class_variable
# ############################################################################ #
# Copyright © 2015-2021 inkle Ltd.
# Copyright © 2019-2022 Frédéric Maquin <fred@ephread.com>
# All Rights Reserved
#
# This file is part of inkgd.
# inkgd is licensed under the terms of the MIT license.
# ############################################################################ #
extends InkValue
class_name InkListValue
# ############################################################################ #
func get_value_type():
return ValueType.LIST
func get_is_truthy():
return value.size() > 0
# The method takes a `StoryErrorMetadata` object as a parameter that
# doesn't exist in upstream. The metadat are used in case an 'exception'
# is raised. For more information, see story.gd.
func cast(new_type, metadata = null):
if new_type == ValueType.INT:
var max_item = value.max_item
if max_item.key.is_null:
return IntValue().new_with(0)
else:
return IntValue().new_with(max_item.value)
elif new_type == ValueType.FLOAT:
var max_item = value.max_item
if max_item.key.is_null:
return FloatValue().new_with(0.0)
else:
return FloatValue().new_with(float(max_item.value))
elif new_type == ValueType.STRING:
var max_item = value.max_item
if max_item.key.is_null:
return StringValue().new_with("")
else:
return StringValue().new_with(max_item.key._to_string())
if new_type == self.value_type:
return self
InkUtils.throw_story_exception(bad_cast_exception_message(new_type), false, metadata)
return null
func _init():
value = InkList.new()
func _init_with_list(list):
value = InkList.new_with_ink_list(list)
func _init_with_single_item(single_item, single_value):
value = InkList.new_with_single_item(single_item, single_value)
# (InkObject, InkObject) -> void
static func retain_list_origins_for_assignment(old_value, new_value):
var old_list = InkUtils.as_or_null(old_value, "ListValue")
var new_list = InkUtils.as_or_null(new_value, "ListValue")
if old_list && new_list && new_list.value.size() == 0:
new_list.value.set_initial_origin_names(old_list.value.origin_names)
# ############################################################################ #
# GDScript extra methods
# ############################################################################ #
func is_ink_class(type):
return type == "ListValue" || super.is_ink_class(type)
func get_ink_class():
return "ListValue"
static func new_with(list):
var value = ListValue().new()
value._init_with_list(list)
return value
static func new_with_single_item(single_item, single_value):
var value = ListValue().new()
value._init_with_single_item(single_item, single_value)
return value

View file

@ -0,0 +1,82 @@
# warning-ignore-all:shadowed_variable
# warning-ignore-all:unused_class_variable
# ############################################################################ #
# Copyright © 2015-2021 inkle Ltd.
# Copyright © 2019-2022 Frédéric Maquin <fred@ephread.com>
# All Rights Reserved
#
# This file is part of inkgd.
# inkgd is licensed under the terms of the MIT license.
# ############################################################################ #
extends InkValue
class_name InkStringValue
# ############################################################################ #
func get_value_type():
return ValueType.STRING
func get_is_truthy():
return value.length() > 0
var is_newline: bool
var is_inline_whitespace: bool
var is_non_whitespace: bool:
get:
return !is_newline && !is_inline_whitespace
func _init():
value = ""
self._sanitize_value()
func _init_with(val):
super._init_with(val)
self._sanitize_value()
# The method takes a `StoryErrorMetadata` object as a parameter that
# doesn't exist in upstream. The metadat are used in case an 'exception'
# is raised. For more information, see story.gd.
func cast(new_type, metadata = null):
if new_type == self.value_type:
return self
if new_type == ValueType.INT:
if self.value.is_valid_int():
return IntValue().new_with(int(self.value))
else:
return null
if new_type == ValueType.FLOAT:
if self.value.is_valid_float():
return FloatValue().new_with(float(self.value))
else:
return null
InkUtils.throw_story_exception(bad_cast_exception_message(new_type), false, metadata)
return null
# ######################################################################## #
# GDScript extra methods
# ######################################################################## #
func is_ink_class(type):
return type == "StringValue" || super.is_ink_class(type)
func get_ink_class():
return "StringValue"
func _sanitize_value():
is_newline = (self.value == "\n")
is_inline_whitespace = true
for c in self.value:
if c != ' ' && c != "\t":
is_inline_whitespace = false
break
static func new_with(val):
var value = StringValue().new()
value._init_with(val)
return value

View file

@ -0,0 +1,131 @@
# warning-ignore-all:shadowed_variable
# warning-ignore-all:unused_class_variable
# ############################################################################ #
# Copyright © 2015-2021 inkle Ltd.
# Copyright © 2019-2022 Frédéric Maquin <fred@ephread.com>
# All Rights Reserved
#
# This file is part of inkgd.
# inkgd is licensed under the terms of the MIT license.
# ############################################################################ #
extends InkObject
# This is a merge of the original Value class and its Value<T> subclass.
class_name InkValue
# ############################################################################ #
# IMPORTS
# ############################################################################ #
const ValueType = preload("res://addons/inkgd/runtime/values/value_type.gd").ValueType
var InkList = load("res://addons/inkgd/runtime/lists/ink_list.gd")
# ############################################################################ #
# STATIC REFERENCE
# ############################################################################ #
# TODO: Remove
#static func Utils():
# return load("res://addons/inkgd/runtime/extra/InkUtils.gd")
#
#static func Value():
# return load("res://addons/inkgd/runtime/values/value.gd")
static func BoolValue():
return load("res://addons/inkgd/runtime/values/bool_value.gd")
static func IntValue():
return load("res://addons/inkgd/runtime/values/int_value.gd")
static func FloatValue():
return load("res://addons/inkgd/runtime/values/float_value.gd")
static func StringValue():
return load("res://addons/inkgd/runtime/values/string_value.gd")
static func DivertTargetValue():
return load("res://addons/inkgd/runtime/values/divert_target_value.gd")
static func VariablePointerValue():
return load("res://addons/inkgd/runtime/values/variable_pointer_value.gd")
static func ListValue():
return load("res://addons/inkgd/runtime/values/list_value.gd")
# ############################################################################ #
var value # Variant
# ValueType
var value_type: int: get = get_value_type
func get_value_type() -> int:
return -1
var is_truthy: bool: get = get_is_truthy
func get_is_truthy() -> bool:
return false
# ############################################################################ #
# (ValueType) -> ValueType
func cast(new_type: int) -> InkValue:
return null
var value_object: # Variant
get: return value
# ############################################################################ #
# (Variant) -> Value
func _init_with(val):
value = val
# (Variant) -> Value
static func create(val) -> InkValue:
# Original code lost precision from double to float.
# But it's not applicable here.
if val is bool:
return BoolValue().new_with(val)
if val is int:
return IntValue().new_with(val)
elif val is float:
return FloatValue().new_with(val)
elif val is String:
return StringValue().new_with(val)
elif InkUtils.is_ink_class(val, "InkPath"):
return DivertTargetValue().new_with(val)
elif InkUtils.is_ink_class(val, "InkList"):
return ListValue().new_with(val)
return null
func copy() -> InkValue:
return create(self.value_object)
# (Ink.ValueType) -> StoryException
func bad_cast_exception_message(target_ink_class) -> String:
return "Can't cast " + self.value_object + " from " + self.value_type + " to " + target_ink_class
# () -> String
func _to_string() -> String:
if value is int || value is float || value is String:
return str(value)
else:
return value._to_string()
# ############################################################################ #
# GDScript extra methods
# ############################################################################ #
func is_ink_class(type) -> bool:
return type == "Value" || super.is_ink_class(type)
func get_ink_class() -> String:
return "Value"
static func new_with(val) -> InkValue:
var value = InkValue.new()
value._init_with(val)
return value

View file

@ -0,0 +1,23 @@
# warning-ignore-all:shadowed_variable
# warning-ignore-all:unused_class_variable
# ############################################################################ #
# Copyright © 2015-2021 inkle Ltd.
# Copyright © 2019-2022 Frédéric Maquin <fred@ephread.com>
# All Rights Reserved
#
# This file is part of inkgd.
# inkgd is licensed under the terms of the MIT license.
# ############################################################################ #
enum ValueType {
BOOL = -1,
INT,
FLOAT,
LIST,
STRING,
DIVERT_TARGET,
VARIABLE_POINTER
}

View file

@ -0,0 +1,69 @@
# warning-ignore-all:shadowed_variable
# warning-ignore-all:unused_class_variable
# ############################################################################ #
# Copyright © 2015-2021 inkle Ltd.
# Copyright © 2019-2022 Frédéric Maquin <fred@ephread.com>
# All Rights Reserved
#
# This file is part of inkgd.
# inkgd is licensed under the terms of the MIT license.
# ############################################################################ #
extends InkValue
class_name InkVariablePointerValue
# ############################################################################ #
var variable_name : get = get_variable_name, set = set_variable_name # InkPath
func get_variable_name():
return value
func set_variable_name(value):
self.value = value
func get_value_type():
return ValueType.VARIABLE_POINTER
func get_is_truthy():
InkUtils.throw_exception("Shouldn't be checking the truthiness of a variable pointer")
return false
var context_index = 0 # int
func _init_with_context(variable_name, context_index = -1):
super._init_with(variable_name)
self.context_index = context_index
func _init():
value = null
# The method takes a `StoryErrorMetadata` object as a parameter that
# doesn't exist in upstream. The metadat are used in case an 'exception'
# is raised. For more information, see story.gd.
func cast(new_type, metadata = null):
if new_type == self.value_type:
return self
InkUtils.throw_story_exception(bad_cast_exception_message(new_type), false, metadata)
return null
func _to_string() -> String:
return "VariablePointerValue(" + self.variable_name + ")"
func copy():
return VariablePointerValue().new_with_context(self.variable_name, context_index)
# ######################################################################## #
# GDScript extra methods
# ######################################################################## #
func is_ink_class(type):
return type == "VariablePointerValue" || super.is_ink_class(type)
func get_ink_class():
return "VariablePointerValue"
static func new_with_context(variable_name, context_index = -1):
var value = VariablePointerValue().new()
value._init_with_context(variable_name, context_index)
return value