From a077704eaf6bd13098632e7dbdddf97c2dcd389f Mon Sep 17 00:00:00 2001 From: dk1a Date: Mon, 1 May 2023 11:40:22 +0300 Subject: [PATCH 1/6] refactor: unfinished mud2 conversion --- .../contracts/{src => _old_src}/BaseTest.ejs | 0 .../{src => _old_src}/SingletonID.sol | 0 packages/contracts/_old_src/Types.sol | 49 ++ .../{src => _old_src}/Uint256SetComponent.sol | 0 .../affix/AffixAvailabilityComponent.sol | 0 .../affix/AffixNamingComponent.sol | 0 .../affix/AffixPrototypeComponent.sol | 0 .../affix/AffixPrototypeGroupComponent.sol | 0 .../affix/LibPickAffixes.sol | 0 .../charstat/ExperienceComponent.sol | 0 .../charstat/LibCharstat.sol | 0 .../charstat/LibExperience.sol | 0 .../charstat/LifeCurrentComponent.sol | 0 .../charstat/ManaCurrentComponent.sol | 0 .../{src => _old_src}/charstat/Topics.sol | 0 .../combat/ActiveCombatComponent.sol | 0 .../combat/CombatSubSystem.sol | 0 .../combat/LibActiveCombat.sol | 0 .../combat/LibCombatAction.sol | 0 .../combat/test/CombatSubsystem.t.sol | 0 .../common/ComponentDevSystem.sol | 0 .../common/FromPrototypeComponent.sol | 0 .../common/NameComponent.sol | 0 .../common/OwnedByComponent.sol | 0 .../common/ReverseHashNameComponent.sol | 0 .../common/ReverseHashNameSystem.sol | 0 .../cycle/ActiveCycleComponent.sol | 0 .../cycle/ActiveCyclePreviousComponent.sol | 0 .../cycle/ClaimCycleTurnsSystem.sol | 0 .../cycle/CompleteCycleSystem.sol | 0 .../cycle/CycleActivateCombatSystem.sol | 0 .../cycle/CycleBossesDefeatedComponent.sol | 0 .../CycleCombatRewardRequestComponent.sol | 0 .../cycle/CycleCombatRewardSystem.sol | 0 .../cycle/CycleCombatSystem.sol | 0 .../cycle/CycleEquipmentSystem.sol | 0 .../cycle/CycleToWandererComponent.sol | 0 .../cycle/CycleTurnsComponent.sol | 0 .../cycle/CycleTurnsLastClaimedComponent.sol | 0 .../cycle/LearnCycleSkillSystem.sol | 0 .../{src => _old_src}/cycle/LibCycle.sol | 0 .../cycle/LibCycleCombatRewardRequest.sol | 0 .../{src => _old_src}/cycle/LibCycleTurns.sol | 0 .../cycle/PassCycleTurnSystem.sol | 0 .../cycle/StartCycleSystem.sol | 0 .../cycle/test/CycleCombatSystem.t.sol | 0 .../cycle/test/CycleEquipmentSystem.t.sol | 0 .../cycle/test/LearnCycleSkillSystem.t.sol | 0 .../cycle/test/LibCycleTurns.t.sol | 0 .../cycle/test/PassCycleTurnSystem.t.sol | 0 .../cycle/test/StartCycleSystem.t.sol | 0 .../duration/DurationOnEndComponent.sol | 0 .../duration/DurationScopeComponent.sol | 0 .../duration/DurationSubSystem.sol | 0 .../duration/DurationValueComponent.sol | 0 .../effect/AppliedEffectComponent.sol | 0 .../effect/EffectPrototypeComponent.sol | 0 .../effect/EffectSubSystem.sol | 0 .../effect/LibEffectPrototype.sol | 0 .../effect/makeEffectPrototype.sol | 0 .../equipment/EquipmentPrototypeComponent.sol | 0 .../equipment/EquipmentPrototypes.sol | 0 .../EquipmentSlotAllowedComponent.sol | 0 .../equipment/EquipmentSlotComponent.sol | 0 .../equipment/EquipmentSubSystem.sol | 0 .../equipment/LibSpawnEquipmentSlots.sol | 0 .../equipment/test/EquipmentSubsystem.t.sol | 0 .../guise/ActiveGuiseComponent.sol | 0 .../guise/GuisePrototypeComponent.sol | 0 .../guise/GuiseSkillsComponent.sol | 0 .../{src => _old_src}/guise/LibGuiseLevel.sol | 0 .../init/LibBaseInitAffix.sol | 0 .../init/LibBaseInitSkill.sol | 0 .../init/LibInitAuthorizeSubsystems.sol | 0 .../init/LibInitEquipmentAffix.sol | 0 .../init/LibInitEquipmentPrototype.sol | 0 .../{src => _old_src}/init/LibInitGuise.sol | 0 .../init/LibInitMapAffix.sol | 0 .../init/LibInitMapPrototype.sol | 0 .../init/LibInitMapsBoss.sol | 0 .../init/LibInitMapsGlobal.sol | 0 .../init/LibInitReverseHashName.ejs | 0 .../{src => _old_src}/init/LibInitSkill.sol | 0 .../{src => _old_src}/init/LibInitStatmod.sol | 0 .../{src => _old_src}/init/LibInitWheel.sol | 0 .../{src => _old_src}/libraries/LibArray.sol | 0 .../loot/LibLootEquipment.sol | 0 .../{src => _old_src}/loot/LibLootMap.sol | 0 .../{src => _old_src}/loot/LibLootMint.sol | 0 .../{src => _old_src}/loot/LibLootOwner.sol | 0 .../{src => _old_src}/loot/LootComponent.sol | 0 .../loot/RandomEquipmentSubSystem.sol | 0 .../loot/RandomMapSubSystem.sol | 0 .../loot/test/RandomEquipmentSubsystem.t.sol | 0 .../map/MapPrototypeComponent.sol | 0 .../{src => _old_src}/map/MapPrototypes.sol | 0 .../{src => _old_src}/rng/LibRNG.sol | 0 .../rng/RNGPrecommitComponent.sol | 0 .../rng/RNGRequestOwnerComponent.sol | 0 .../{src => _old_src}/rng/test/LibRNG.t.sol | 0 .../skill/LearnedSkillsComponent.sol | 0 .../skill/LibLearnedSkills.sol | 0 .../{src => _old_src}/skill/LibSkill.sol | 0 .../skill/NoncombatSkillSystem.sol | 0 .../skill/SkillDescriptionComponent.sol | 0 .../skill/SkillPrototypeComponent.sol | 0 .../skill/test/LibSkill.t.sol | 0 .../skill/test/SkillPrototypeComponent.t.sol | 0 .../contracts/_old_src/statmod/Statmod.sol | 192 +++++ .../statmod/StatmodPrototypeComponent.sol | 70 ++ .../statmod/StatmodScopeComponent.sol | 11 + .../statmod/StatmodValueComponent.sol | 11 + .../_old_src/statmod/statmodName.sol | 74 ++ .../_old_src/statmod/test/Statmod.t.sol | 121 +++ .../statmod/test/StatmodPrototype.t.sol | 26 + .../{src => _old_src}/token/LibToken.sol | 0 .../{src => _old_src}/token/WFTSystem.sol | 0 .../{src => _old_src}/token/WNFTSystem.sol | 0 .../{src => _old_src}/uri/LibUri.sol | 0 .../{src => _old_src}/uri/LibUriEquipment.sol | 0 .../{src => _old_src}/uri/LibUriMisc.sol | 0 .../{src => _old_src}/uri/LibUriWanderer.sol | 0 .../{src => _old_src}/uri/UriUtils.sol | 0 .../wanderer/IdentityComponent.sol | 0 .../wanderer/LibWanderer.sol | 0 .../wanderer/PermSkillSystem.sol | 0 .../wanderer/WandererComponent.sol | 0 .../wanderer/WandererSpawnSystem.sol | 0 .../wanderer/test/WandererSpawnSystem.t.sol | 0 .../wheel/ActiveWheelComponent.sol | 0 .../wheel/DefaultWheelComponent.sol | 0 .../wheel/WheelComponent.sol | 0 .../wheel/WheelsCompletedComponent.sol | 0 packages/contracts/mud.config.mts | 367 +++++++++ packages/contracts/package.json | 18 +- packages/contracts/script/PostDeploy.s.sol | 24 + packages/contracts/src/AbstractComponent.sol | 90 --- packages/contracts/src/MapSetBatchable.sol | 78 -- packages/contracts/src/codegen/Tables.sol | 64 ++ packages/contracts/src/codegen/Types.sol | 49 ++ .../src/codegen/tables/ActiveCombat.sol | 122 +++ .../src/codegen/tables/ActiveGuise.sol | 122 +++ .../src/codegen/tables/ActiveWheel.sol | 122 +++ .../contracts/src/codegen/tables/Affix.sol | 260 ++++++ .../src/codegen/tables/AffixAvailable.sol | 205 +++++ .../src/codegen/tables/AffixNaming.sol | 217 +++++ .../src/codegen/tables/AffixProtoGroup.sol | 122 +++ .../src/codegen/tables/AffixProtoIndex.sol | 129 +++ .../src/codegen/tables/AffixPrototype.sol | 356 +++++++++ .../src/codegen/tables/AvailableSkills.sol | 158 ++++ .../src/codegen/tables/BossesDefeated.sol | 158 ++++ .../src/codegen/tables/CurrentCycle.sol | 122 +++ .../src/codegen/tables/CycleCombatRReq.sol | 473 +++++++++++ .../src/codegen/tables/CycleTurns.sol | 122 +++ .../codegen/tables/CycleTurnsLastClaimed.sol | 122 +++ .../src/codegen/tables/DefaultWheel.sol | 115 +++ .../src/codegen/tables/DurationOnEnd.sol | 318 ++++++++ .../src/codegen/tables/DurationScope.sol | 129 +++ .../src/codegen/tables/DurationValue.sol | 129 +++ .../src/codegen/tables/EffectApplied.sol | 354 +++++++++ .../src/codegen/tables/EffectDuration.sol | 218 ++++++ .../src/codegen/tables/EffectRemovability.sol | 125 +++ .../src/codegen/tables/EffectTemplate.sol | 301 +++++++ .../contracts/src/codegen/tables/EqptBase.sol | 122 +++ .../src/codegen/tables/ExpGainMul.sol | 176 +++++ .../src/codegen/tables/Experience.sol | 176 +++++ .../src/codegen/tables/FromEqptBase.sol | 122 +++ .../src/codegen/tables/FromMapBase.sol | 122 +++ .../src/codegen/tables/FromMetaEntity.sol | 122 +++ .../src/codegen/tables/FromPrototype.sol | 122 +++ .../src/codegen/tables/FromStatmodBase.sol | 122 +++ .../contracts/src/codegen/tables/Identity.sol | 122 +++ .../src/codegen/tables/LearnedSkills.sol | 158 ++++ .../src/codegen/tables/LifeCurrent.sol | 122 +++ .../src/codegen/tables/LootAffixes.sol | 158 ++++ .../contracts/src/codegen/tables/LootIlvl.sol | 122 +++ .../contracts/src/codegen/tables/ManaCost.sol | 176 +++++ .../src/codegen/tables/ManaCurrent.sol | 122 +++ .../contracts/src/codegen/tables/MapBase.sol | 122 +++ .../contracts/src/codegen/tables/Name.sol | 158 ++++ .../contracts/src/codegen/tables/OwnedBy.sol | 122 +++ .../src/codegen/tables/PreviousCycle.sol | 122 +++ .../src/codegen/tables/RNGPrecommit.sol | 122 +++ .../src/codegen/tables/RNGRequestOwner.sol | 122 +++ .../src/codegen/tables/SkillCooldown.sol | 218 ++++++ .../src/codegen/tables/SkillDescription.sol | 158 ++++ .../src/codegen/tables/SkillTemplate.sol | 424 ++++++++++ .../src/codegen/tables/SlotAllowedBases.sol | 158 ++++ .../src/codegen/tables/SlotEquipment.sol | 122 +++ .../src/codegen/tables/SpellDamage.sol | 176 +++++ .../src/codegen/tables/StatmodBase.sol | 122 +++ .../src/codegen/tables/StatmodBaseOpts.sol | 221 ++++++ .../src/codegen/tables/StatmodScope.sol | 129 +++ .../src/codegen/tables/StatmodValue.sol | 129 +++ .../src/codegen/tables/WNFTOwnership.sol | 122 +++ .../contracts/src/codegen/tables/Wanderer.sol | 128 +++ .../contracts/src/codegen/tables/Wheel.sol | 266 +++++++ .../src/codegen/tables/WheelsCompleted.sol | 129 +++ .../keyvalueindex/KeyValueIndexHook.sol | 71 ++ .../keyvalueindex/KeyValueIndexModule.sol | 67 ++ .../src/modules/keyvalueindex/constants.sol | 7 + .../modules/keyvalueindex/getKeysForIndex.sol | 38 + .../keyvalueindex/tables/KeyValueIndex.sol | 159 ++++ .../contracts/src/modules/utils/ArrayLib.sol | 32 + .../contracts/src/statmod/ScopedValue.sol | 299 +++++++ packages/contracts/src/statmod/Statmod.sol | 125 +-- packages/contracts/tsconfig.json | 1 + yarn.lock | 741 ++++++++---------- 208 files changed, 11981 insertions(+), 636 deletions(-) rename packages/contracts/{src => _old_src}/BaseTest.ejs (100%) rename packages/contracts/{src => _old_src}/SingletonID.sol (100%) create mode 100644 packages/contracts/_old_src/Types.sol rename packages/contracts/{src => _old_src}/Uint256SetComponent.sol (100%) rename packages/contracts/{src => _old_src}/affix/AffixAvailabilityComponent.sol (100%) rename packages/contracts/{src => _old_src}/affix/AffixNamingComponent.sol (100%) rename packages/contracts/{src => _old_src}/affix/AffixPrototypeComponent.sol (100%) rename packages/contracts/{src => _old_src}/affix/AffixPrototypeGroupComponent.sol (100%) rename packages/contracts/{src => _old_src}/affix/LibPickAffixes.sol (100%) rename packages/contracts/{src => _old_src}/charstat/ExperienceComponent.sol (100%) rename packages/contracts/{src => _old_src}/charstat/LibCharstat.sol (100%) rename packages/contracts/{src => _old_src}/charstat/LibExperience.sol (100%) rename packages/contracts/{src => _old_src}/charstat/LifeCurrentComponent.sol (100%) rename packages/contracts/{src => _old_src}/charstat/ManaCurrentComponent.sol (100%) rename packages/contracts/{src => _old_src}/charstat/Topics.sol (100%) rename packages/contracts/{src => _old_src}/combat/ActiveCombatComponent.sol (100%) rename packages/contracts/{src => _old_src}/combat/CombatSubSystem.sol (100%) rename packages/contracts/{src => _old_src}/combat/LibActiveCombat.sol (100%) rename packages/contracts/{src => _old_src}/combat/LibCombatAction.sol (100%) rename packages/contracts/{src => _old_src}/combat/test/CombatSubsystem.t.sol (100%) rename packages/contracts/{src => _old_src}/common/ComponentDevSystem.sol (100%) rename packages/contracts/{src => _old_src}/common/FromPrototypeComponent.sol (100%) rename packages/contracts/{src => _old_src}/common/NameComponent.sol (100%) rename packages/contracts/{src => _old_src}/common/OwnedByComponent.sol (100%) rename packages/contracts/{src => _old_src}/common/ReverseHashNameComponent.sol (100%) rename packages/contracts/{src => _old_src}/common/ReverseHashNameSystem.sol (100%) rename packages/contracts/{src => _old_src}/cycle/ActiveCycleComponent.sol (100%) rename packages/contracts/{src => _old_src}/cycle/ActiveCyclePreviousComponent.sol (100%) rename packages/contracts/{src => _old_src}/cycle/ClaimCycleTurnsSystem.sol (100%) rename packages/contracts/{src => _old_src}/cycle/CompleteCycleSystem.sol (100%) rename packages/contracts/{src => _old_src}/cycle/CycleActivateCombatSystem.sol (100%) rename packages/contracts/{src => _old_src}/cycle/CycleBossesDefeatedComponent.sol (100%) rename packages/contracts/{src => _old_src}/cycle/CycleCombatRewardRequestComponent.sol (100%) rename packages/contracts/{src => _old_src}/cycle/CycleCombatRewardSystem.sol (100%) rename packages/contracts/{src => _old_src}/cycle/CycleCombatSystem.sol (100%) rename packages/contracts/{src => _old_src}/cycle/CycleEquipmentSystem.sol (100%) rename packages/contracts/{src => _old_src}/cycle/CycleToWandererComponent.sol (100%) rename packages/contracts/{src => _old_src}/cycle/CycleTurnsComponent.sol (100%) rename packages/contracts/{src => _old_src}/cycle/CycleTurnsLastClaimedComponent.sol (100%) rename packages/contracts/{src => _old_src}/cycle/LearnCycleSkillSystem.sol (100%) rename packages/contracts/{src => _old_src}/cycle/LibCycle.sol (100%) rename packages/contracts/{src => _old_src}/cycle/LibCycleCombatRewardRequest.sol (100%) rename packages/contracts/{src => _old_src}/cycle/LibCycleTurns.sol (100%) rename packages/contracts/{src => _old_src}/cycle/PassCycleTurnSystem.sol (100%) rename packages/contracts/{src => _old_src}/cycle/StartCycleSystem.sol (100%) rename packages/contracts/{src => _old_src}/cycle/test/CycleCombatSystem.t.sol (100%) rename packages/contracts/{src => _old_src}/cycle/test/CycleEquipmentSystem.t.sol (100%) rename packages/contracts/{src => _old_src}/cycle/test/LearnCycleSkillSystem.t.sol (100%) rename packages/contracts/{src => _old_src}/cycle/test/LibCycleTurns.t.sol (100%) rename packages/contracts/{src => _old_src}/cycle/test/PassCycleTurnSystem.t.sol (100%) rename packages/contracts/{src => _old_src}/cycle/test/StartCycleSystem.t.sol (100%) rename packages/contracts/{src => _old_src}/duration/DurationOnEndComponent.sol (100%) rename packages/contracts/{src => _old_src}/duration/DurationScopeComponent.sol (100%) rename packages/contracts/{src => _old_src}/duration/DurationSubSystem.sol (100%) rename packages/contracts/{src => _old_src}/duration/DurationValueComponent.sol (100%) rename packages/contracts/{src => _old_src}/effect/AppliedEffectComponent.sol (100%) rename packages/contracts/{src => _old_src}/effect/EffectPrototypeComponent.sol (100%) rename packages/contracts/{src => _old_src}/effect/EffectSubSystem.sol (100%) rename packages/contracts/{src => _old_src}/effect/LibEffectPrototype.sol (100%) rename packages/contracts/{src => _old_src}/effect/makeEffectPrototype.sol (100%) rename packages/contracts/{src => _old_src}/equipment/EquipmentPrototypeComponent.sol (100%) rename packages/contracts/{src => _old_src}/equipment/EquipmentPrototypes.sol (100%) rename packages/contracts/{src => _old_src}/equipment/EquipmentSlotAllowedComponent.sol (100%) rename packages/contracts/{src => _old_src}/equipment/EquipmentSlotComponent.sol (100%) rename packages/contracts/{src => _old_src}/equipment/EquipmentSubSystem.sol (100%) rename packages/contracts/{src => _old_src}/equipment/LibSpawnEquipmentSlots.sol (100%) rename packages/contracts/{src => _old_src}/equipment/test/EquipmentSubsystem.t.sol (100%) rename packages/contracts/{src => _old_src}/guise/ActiveGuiseComponent.sol (100%) rename packages/contracts/{src => _old_src}/guise/GuisePrototypeComponent.sol (100%) rename packages/contracts/{src => _old_src}/guise/GuiseSkillsComponent.sol (100%) rename packages/contracts/{src => _old_src}/guise/LibGuiseLevel.sol (100%) rename packages/contracts/{src => _old_src}/init/LibBaseInitAffix.sol (100%) rename packages/contracts/{src => _old_src}/init/LibBaseInitSkill.sol (100%) rename packages/contracts/{src => _old_src}/init/LibInitAuthorizeSubsystems.sol (100%) rename packages/contracts/{src => _old_src}/init/LibInitEquipmentAffix.sol (100%) rename packages/contracts/{src => _old_src}/init/LibInitEquipmentPrototype.sol (100%) rename packages/contracts/{src => _old_src}/init/LibInitGuise.sol (100%) rename packages/contracts/{src => _old_src}/init/LibInitMapAffix.sol (100%) rename packages/contracts/{src => _old_src}/init/LibInitMapPrototype.sol (100%) rename packages/contracts/{src => _old_src}/init/LibInitMapsBoss.sol (100%) rename packages/contracts/{src => _old_src}/init/LibInitMapsGlobal.sol (100%) rename packages/contracts/{src => _old_src}/init/LibInitReverseHashName.ejs (100%) rename packages/contracts/{src => _old_src}/init/LibInitSkill.sol (100%) rename packages/contracts/{src => _old_src}/init/LibInitStatmod.sol (100%) rename packages/contracts/{src => _old_src}/init/LibInitWheel.sol (100%) rename packages/contracts/{src => _old_src}/libraries/LibArray.sol (100%) rename packages/contracts/{src => _old_src}/loot/LibLootEquipment.sol (100%) rename packages/contracts/{src => _old_src}/loot/LibLootMap.sol (100%) rename packages/contracts/{src => _old_src}/loot/LibLootMint.sol (100%) rename packages/contracts/{src => _old_src}/loot/LibLootOwner.sol (100%) rename packages/contracts/{src => _old_src}/loot/LootComponent.sol (100%) rename packages/contracts/{src => _old_src}/loot/RandomEquipmentSubSystem.sol (100%) rename packages/contracts/{src => _old_src}/loot/RandomMapSubSystem.sol (100%) rename packages/contracts/{src => _old_src}/loot/test/RandomEquipmentSubsystem.t.sol (100%) rename packages/contracts/{src => _old_src}/map/MapPrototypeComponent.sol (100%) rename packages/contracts/{src => _old_src}/map/MapPrototypes.sol (100%) rename packages/contracts/{src => _old_src}/rng/LibRNG.sol (100%) rename packages/contracts/{src => _old_src}/rng/RNGPrecommitComponent.sol (100%) rename packages/contracts/{src => _old_src}/rng/RNGRequestOwnerComponent.sol (100%) rename packages/contracts/{src => _old_src}/rng/test/LibRNG.t.sol (100%) rename packages/contracts/{src => _old_src}/skill/LearnedSkillsComponent.sol (100%) rename packages/contracts/{src => _old_src}/skill/LibLearnedSkills.sol (100%) rename packages/contracts/{src => _old_src}/skill/LibSkill.sol (100%) rename packages/contracts/{src => _old_src}/skill/NoncombatSkillSystem.sol (100%) rename packages/contracts/{src => _old_src}/skill/SkillDescriptionComponent.sol (100%) rename packages/contracts/{src => _old_src}/skill/SkillPrototypeComponent.sol (100%) rename packages/contracts/{src => _old_src}/skill/test/LibSkill.t.sol (100%) rename packages/contracts/{src => _old_src}/skill/test/SkillPrototypeComponent.t.sol (100%) create mode 100644 packages/contracts/_old_src/statmod/Statmod.sol create mode 100644 packages/contracts/_old_src/statmod/StatmodPrototypeComponent.sol create mode 100644 packages/contracts/_old_src/statmod/StatmodScopeComponent.sol create mode 100644 packages/contracts/_old_src/statmod/StatmodValueComponent.sol create mode 100644 packages/contracts/_old_src/statmod/statmodName.sol create mode 100644 packages/contracts/_old_src/statmod/test/Statmod.t.sol create mode 100644 packages/contracts/_old_src/statmod/test/StatmodPrototype.t.sol rename packages/contracts/{src => _old_src}/token/LibToken.sol (100%) rename packages/contracts/{src => _old_src}/token/WFTSystem.sol (100%) rename packages/contracts/{src => _old_src}/token/WNFTSystem.sol (100%) rename packages/contracts/{src => _old_src}/uri/LibUri.sol (100%) rename packages/contracts/{src => _old_src}/uri/LibUriEquipment.sol (100%) rename packages/contracts/{src => _old_src}/uri/LibUriMisc.sol (100%) rename packages/contracts/{src => _old_src}/uri/LibUriWanderer.sol (100%) rename packages/contracts/{src => _old_src}/uri/UriUtils.sol (100%) rename packages/contracts/{src => _old_src}/wanderer/IdentityComponent.sol (100%) rename packages/contracts/{src => _old_src}/wanderer/LibWanderer.sol (100%) rename packages/contracts/{src => _old_src}/wanderer/PermSkillSystem.sol (100%) rename packages/contracts/{src => _old_src}/wanderer/WandererComponent.sol (100%) rename packages/contracts/{src => _old_src}/wanderer/WandererSpawnSystem.sol (100%) rename packages/contracts/{src => _old_src}/wanderer/test/WandererSpawnSystem.t.sol (100%) rename packages/contracts/{src => _old_src}/wheel/ActiveWheelComponent.sol (100%) rename packages/contracts/{src => _old_src}/wheel/DefaultWheelComponent.sol (100%) rename packages/contracts/{src => _old_src}/wheel/WheelComponent.sol (100%) rename packages/contracts/{src => _old_src}/wheel/WheelsCompletedComponent.sol (100%) create mode 100644 packages/contracts/mud.config.mts create mode 100644 packages/contracts/script/PostDeploy.s.sol delete mode 100644 packages/contracts/src/AbstractComponent.sol delete mode 100644 packages/contracts/src/MapSetBatchable.sol create mode 100644 packages/contracts/src/codegen/Tables.sol create mode 100644 packages/contracts/src/codegen/Types.sol create mode 100644 packages/contracts/src/codegen/tables/ActiveCombat.sol create mode 100644 packages/contracts/src/codegen/tables/ActiveGuise.sol create mode 100644 packages/contracts/src/codegen/tables/ActiveWheel.sol create mode 100644 packages/contracts/src/codegen/tables/Affix.sol create mode 100644 packages/contracts/src/codegen/tables/AffixAvailable.sol create mode 100644 packages/contracts/src/codegen/tables/AffixNaming.sol create mode 100644 packages/contracts/src/codegen/tables/AffixProtoGroup.sol create mode 100644 packages/contracts/src/codegen/tables/AffixProtoIndex.sol create mode 100644 packages/contracts/src/codegen/tables/AffixPrototype.sol create mode 100644 packages/contracts/src/codegen/tables/AvailableSkills.sol create mode 100644 packages/contracts/src/codegen/tables/BossesDefeated.sol create mode 100644 packages/contracts/src/codegen/tables/CurrentCycle.sol create mode 100644 packages/contracts/src/codegen/tables/CycleCombatRReq.sol create mode 100644 packages/contracts/src/codegen/tables/CycleTurns.sol create mode 100644 packages/contracts/src/codegen/tables/CycleTurnsLastClaimed.sol create mode 100644 packages/contracts/src/codegen/tables/DefaultWheel.sol create mode 100644 packages/contracts/src/codegen/tables/DurationOnEnd.sol create mode 100644 packages/contracts/src/codegen/tables/DurationScope.sol create mode 100644 packages/contracts/src/codegen/tables/DurationValue.sol create mode 100644 packages/contracts/src/codegen/tables/EffectApplied.sol create mode 100644 packages/contracts/src/codegen/tables/EffectDuration.sol create mode 100644 packages/contracts/src/codegen/tables/EffectRemovability.sol create mode 100644 packages/contracts/src/codegen/tables/EffectTemplate.sol create mode 100644 packages/contracts/src/codegen/tables/EqptBase.sol create mode 100644 packages/contracts/src/codegen/tables/ExpGainMul.sol create mode 100644 packages/contracts/src/codegen/tables/Experience.sol create mode 100644 packages/contracts/src/codegen/tables/FromEqptBase.sol create mode 100644 packages/contracts/src/codegen/tables/FromMapBase.sol create mode 100644 packages/contracts/src/codegen/tables/FromMetaEntity.sol create mode 100644 packages/contracts/src/codegen/tables/FromPrototype.sol create mode 100644 packages/contracts/src/codegen/tables/FromStatmodBase.sol create mode 100644 packages/contracts/src/codegen/tables/Identity.sol create mode 100644 packages/contracts/src/codegen/tables/LearnedSkills.sol create mode 100644 packages/contracts/src/codegen/tables/LifeCurrent.sol create mode 100644 packages/contracts/src/codegen/tables/LootAffixes.sol create mode 100644 packages/contracts/src/codegen/tables/LootIlvl.sol create mode 100644 packages/contracts/src/codegen/tables/ManaCost.sol create mode 100644 packages/contracts/src/codegen/tables/ManaCurrent.sol create mode 100644 packages/contracts/src/codegen/tables/MapBase.sol create mode 100644 packages/contracts/src/codegen/tables/Name.sol create mode 100644 packages/contracts/src/codegen/tables/OwnedBy.sol create mode 100644 packages/contracts/src/codegen/tables/PreviousCycle.sol create mode 100644 packages/contracts/src/codegen/tables/RNGPrecommit.sol create mode 100644 packages/contracts/src/codegen/tables/RNGRequestOwner.sol create mode 100644 packages/contracts/src/codegen/tables/SkillCooldown.sol create mode 100644 packages/contracts/src/codegen/tables/SkillDescription.sol create mode 100644 packages/contracts/src/codegen/tables/SkillTemplate.sol create mode 100644 packages/contracts/src/codegen/tables/SlotAllowedBases.sol create mode 100644 packages/contracts/src/codegen/tables/SlotEquipment.sol create mode 100644 packages/contracts/src/codegen/tables/SpellDamage.sol create mode 100644 packages/contracts/src/codegen/tables/StatmodBase.sol create mode 100644 packages/contracts/src/codegen/tables/StatmodBaseOpts.sol create mode 100644 packages/contracts/src/codegen/tables/StatmodScope.sol create mode 100644 packages/contracts/src/codegen/tables/StatmodValue.sol create mode 100644 packages/contracts/src/codegen/tables/WNFTOwnership.sol create mode 100644 packages/contracts/src/codegen/tables/Wanderer.sol create mode 100644 packages/contracts/src/codegen/tables/Wheel.sol create mode 100644 packages/contracts/src/codegen/tables/WheelsCompleted.sol create mode 100644 packages/contracts/src/modules/keyvalueindex/KeyValueIndexHook.sol create mode 100644 packages/contracts/src/modules/keyvalueindex/KeyValueIndexModule.sol create mode 100644 packages/contracts/src/modules/keyvalueindex/constants.sol create mode 100644 packages/contracts/src/modules/keyvalueindex/getKeysForIndex.sol create mode 100644 packages/contracts/src/modules/keyvalueindex/tables/KeyValueIndex.sol create mode 100644 packages/contracts/src/modules/utils/ArrayLib.sol create mode 100644 packages/contracts/src/statmod/ScopedValue.sol diff --git a/packages/contracts/src/BaseTest.ejs b/packages/contracts/_old_src/BaseTest.ejs similarity index 100% rename from packages/contracts/src/BaseTest.ejs rename to packages/contracts/_old_src/BaseTest.ejs diff --git a/packages/contracts/src/SingletonID.sol b/packages/contracts/_old_src/SingletonID.sol similarity index 100% rename from packages/contracts/src/SingletonID.sol rename to packages/contracts/_old_src/SingletonID.sol diff --git a/packages/contracts/_old_src/Types.sol b/packages/contracts/_old_src/Types.sol new file mode 100644 index 00000000..81ea525d --- /dev/null +++ b/packages/contracts/_old_src/Types.sol @@ -0,0 +1,49 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +enum AffixPartId { + IMPLICIT, + PREFIX, + SUFFIX +} + +enum EffectRemovabilityId { + BUFF, + DEBUFF, + PERSISTENT +} + +enum PStat { + STRENGTH, + ARCANA, + DEXTERITY +} + +enum EleStat { + NONE, + PHYSICAL, + FIRE, + COLD, + POISON +} + +enum SkillType { + COMBAT, + NONCOMBAT, + PASSIVE +} + +enum TargetType { + SELF, + ENEMY, + ALLY, + SELF_OR_ALLY +} + +enum StatmodOp { + ADD, + MUL, + BADD +} diff --git a/packages/contracts/src/Uint256SetComponent.sol b/packages/contracts/_old_src/Uint256SetComponent.sol similarity index 100% rename from packages/contracts/src/Uint256SetComponent.sol rename to packages/contracts/_old_src/Uint256SetComponent.sol diff --git a/packages/contracts/src/affix/AffixAvailabilityComponent.sol b/packages/contracts/_old_src/affix/AffixAvailabilityComponent.sol similarity index 100% rename from packages/contracts/src/affix/AffixAvailabilityComponent.sol rename to packages/contracts/_old_src/affix/AffixAvailabilityComponent.sol diff --git a/packages/contracts/src/affix/AffixNamingComponent.sol b/packages/contracts/_old_src/affix/AffixNamingComponent.sol similarity index 100% rename from packages/contracts/src/affix/AffixNamingComponent.sol rename to packages/contracts/_old_src/affix/AffixNamingComponent.sol diff --git a/packages/contracts/src/affix/AffixPrototypeComponent.sol b/packages/contracts/_old_src/affix/AffixPrototypeComponent.sol similarity index 100% rename from packages/contracts/src/affix/AffixPrototypeComponent.sol rename to packages/contracts/_old_src/affix/AffixPrototypeComponent.sol diff --git a/packages/contracts/src/affix/AffixPrototypeGroupComponent.sol b/packages/contracts/_old_src/affix/AffixPrototypeGroupComponent.sol similarity index 100% rename from packages/contracts/src/affix/AffixPrototypeGroupComponent.sol rename to packages/contracts/_old_src/affix/AffixPrototypeGroupComponent.sol diff --git a/packages/contracts/src/affix/LibPickAffixes.sol b/packages/contracts/_old_src/affix/LibPickAffixes.sol similarity index 100% rename from packages/contracts/src/affix/LibPickAffixes.sol rename to packages/contracts/_old_src/affix/LibPickAffixes.sol diff --git a/packages/contracts/src/charstat/ExperienceComponent.sol b/packages/contracts/_old_src/charstat/ExperienceComponent.sol similarity index 100% rename from packages/contracts/src/charstat/ExperienceComponent.sol rename to packages/contracts/_old_src/charstat/ExperienceComponent.sol diff --git a/packages/contracts/src/charstat/LibCharstat.sol b/packages/contracts/_old_src/charstat/LibCharstat.sol similarity index 100% rename from packages/contracts/src/charstat/LibCharstat.sol rename to packages/contracts/_old_src/charstat/LibCharstat.sol diff --git a/packages/contracts/src/charstat/LibExperience.sol b/packages/contracts/_old_src/charstat/LibExperience.sol similarity index 100% rename from packages/contracts/src/charstat/LibExperience.sol rename to packages/contracts/_old_src/charstat/LibExperience.sol diff --git a/packages/contracts/src/charstat/LifeCurrentComponent.sol b/packages/contracts/_old_src/charstat/LifeCurrentComponent.sol similarity index 100% rename from packages/contracts/src/charstat/LifeCurrentComponent.sol rename to packages/contracts/_old_src/charstat/LifeCurrentComponent.sol diff --git a/packages/contracts/src/charstat/ManaCurrentComponent.sol b/packages/contracts/_old_src/charstat/ManaCurrentComponent.sol similarity index 100% rename from packages/contracts/src/charstat/ManaCurrentComponent.sol rename to packages/contracts/_old_src/charstat/ManaCurrentComponent.sol diff --git a/packages/contracts/src/charstat/Topics.sol b/packages/contracts/_old_src/charstat/Topics.sol similarity index 100% rename from packages/contracts/src/charstat/Topics.sol rename to packages/contracts/_old_src/charstat/Topics.sol diff --git a/packages/contracts/src/combat/ActiveCombatComponent.sol b/packages/contracts/_old_src/combat/ActiveCombatComponent.sol similarity index 100% rename from packages/contracts/src/combat/ActiveCombatComponent.sol rename to packages/contracts/_old_src/combat/ActiveCombatComponent.sol diff --git a/packages/contracts/src/combat/CombatSubSystem.sol b/packages/contracts/_old_src/combat/CombatSubSystem.sol similarity index 100% rename from packages/contracts/src/combat/CombatSubSystem.sol rename to packages/contracts/_old_src/combat/CombatSubSystem.sol diff --git a/packages/contracts/src/combat/LibActiveCombat.sol b/packages/contracts/_old_src/combat/LibActiveCombat.sol similarity index 100% rename from packages/contracts/src/combat/LibActiveCombat.sol rename to packages/contracts/_old_src/combat/LibActiveCombat.sol diff --git a/packages/contracts/src/combat/LibCombatAction.sol b/packages/contracts/_old_src/combat/LibCombatAction.sol similarity index 100% rename from packages/contracts/src/combat/LibCombatAction.sol rename to packages/contracts/_old_src/combat/LibCombatAction.sol diff --git a/packages/contracts/src/combat/test/CombatSubsystem.t.sol b/packages/contracts/_old_src/combat/test/CombatSubsystem.t.sol similarity index 100% rename from packages/contracts/src/combat/test/CombatSubsystem.t.sol rename to packages/contracts/_old_src/combat/test/CombatSubsystem.t.sol diff --git a/packages/contracts/src/common/ComponentDevSystem.sol b/packages/contracts/_old_src/common/ComponentDevSystem.sol similarity index 100% rename from packages/contracts/src/common/ComponentDevSystem.sol rename to packages/contracts/_old_src/common/ComponentDevSystem.sol diff --git a/packages/contracts/src/common/FromPrototypeComponent.sol b/packages/contracts/_old_src/common/FromPrototypeComponent.sol similarity index 100% rename from packages/contracts/src/common/FromPrototypeComponent.sol rename to packages/contracts/_old_src/common/FromPrototypeComponent.sol diff --git a/packages/contracts/src/common/NameComponent.sol b/packages/contracts/_old_src/common/NameComponent.sol similarity index 100% rename from packages/contracts/src/common/NameComponent.sol rename to packages/contracts/_old_src/common/NameComponent.sol diff --git a/packages/contracts/src/common/OwnedByComponent.sol b/packages/contracts/_old_src/common/OwnedByComponent.sol similarity index 100% rename from packages/contracts/src/common/OwnedByComponent.sol rename to packages/contracts/_old_src/common/OwnedByComponent.sol diff --git a/packages/contracts/src/common/ReverseHashNameComponent.sol b/packages/contracts/_old_src/common/ReverseHashNameComponent.sol similarity index 100% rename from packages/contracts/src/common/ReverseHashNameComponent.sol rename to packages/contracts/_old_src/common/ReverseHashNameComponent.sol diff --git a/packages/contracts/src/common/ReverseHashNameSystem.sol b/packages/contracts/_old_src/common/ReverseHashNameSystem.sol similarity index 100% rename from packages/contracts/src/common/ReverseHashNameSystem.sol rename to packages/contracts/_old_src/common/ReverseHashNameSystem.sol diff --git a/packages/contracts/src/cycle/ActiveCycleComponent.sol b/packages/contracts/_old_src/cycle/ActiveCycleComponent.sol similarity index 100% rename from packages/contracts/src/cycle/ActiveCycleComponent.sol rename to packages/contracts/_old_src/cycle/ActiveCycleComponent.sol diff --git a/packages/contracts/src/cycle/ActiveCyclePreviousComponent.sol b/packages/contracts/_old_src/cycle/ActiveCyclePreviousComponent.sol similarity index 100% rename from packages/contracts/src/cycle/ActiveCyclePreviousComponent.sol rename to packages/contracts/_old_src/cycle/ActiveCyclePreviousComponent.sol diff --git a/packages/contracts/src/cycle/ClaimCycleTurnsSystem.sol b/packages/contracts/_old_src/cycle/ClaimCycleTurnsSystem.sol similarity index 100% rename from packages/contracts/src/cycle/ClaimCycleTurnsSystem.sol rename to packages/contracts/_old_src/cycle/ClaimCycleTurnsSystem.sol diff --git a/packages/contracts/src/cycle/CompleteCycleSystem.sol b/packages/contracts/_old_src/cycle/CompleteCycleSystem.sol similarity index 100% rename from packages/contracts/src/cycle/CompleteCycleSystem.sol rename to packages/contracts/_old_src/cycle/CompleteCycleSystem.sol diff --git a/packages/contracts/src/cycle/CycleActivateCombatSystem.sol b/packages/contracts/_old_src/cycle/CycleActivateCombatSystem.sol similarity index 100% rename from packages/contracts/src/cycle/CycleActivateCombatSystem.sol rename to packages/contracts/_old_src/cycle/CycleActivateCombatSystem.sol diff --git a/packages/contracts/src/cycle/CycleBossesDefeatedComponent.sol b/packages/contracts/_old_src/cycle/CycleBossesDefeatedComponent.sol similarity index 100% rename from packages/contracts/src/cycle/CycleBossesDefeatedComponent.sol rename to packages/contracts/_old_src/cycle/CycleBossesDefeatedComponent.sol diff --git a/packages/contracts/src/cycle/CycleCombatRewardRequestComponent.sol b/packages/contracts/_old_src/cycle/CycleCombatRewardRequestComponent.sol similarity index 100% rename from packages/contracts/src/cycle/CycleCombatRewardRequestComponent.sol rename to packages/contracts/_old_src/cycle/CycleCombatRewardRequestComponent.sol diff --git a/packages/contracts/src/cycle/CycleCombatRewardSystem.sol b/packages/contracts/_old_src/cycle/CycleCombatRewardSystem.sol similarity index 100% rename from packages/contracts/src/cycle/CycleCombatRewardSystem.sol rename to packages/contracts/_old_src/cycle/CycleCombatRewardSystem.sol diff --git a/packages/contracts/src/cycle/CycleCombatSystem.sol b/packages/contracts/_old_src/cycle/CycleCombatSystem.sol similarity index 100% rename from packages/contracts/src/cycle/CycleCombatSystem.sol rename to packages/contracts/_old_src/cycle/CycleCombatSystem.sol diff --git a/packages/contracts/src/cycle/CycleEquipmentSystem.sol b/packages/contracts/_old_src/cycle/CycleEquipmentSystem.sol similarity index 100% rename from packages/contracts/src/cycle/CycleEquipmentSystem.sol rename to packages/contracts/_old_src/cycle/CycleEquipmentSystem.sol diff --git a/packages/contracts/src/cycle/CycleToWandererComponent.sol b/packages/contracts/_old_src/cycle/CycleToWandererComponent.sol similarity index 100% rename from packages/contracts/src/cycle/CycleToWandererComponent.sol rename to packages/contracts/_old_src/cycle/CycleToWandererComponent.sol diff --git a/packages/contracts/src/cycle/CycleTurnsComponent.sol b/packages/contracts/_old_src/cycle/CycleTurnsComponent.sol similarity index 100% rename from packages/contracts/src/cycle/CycleTurnsComponent.sol rename to packages/contracts/_old_src/cycle/CycleTurnsComponent.sol diff --git a/packages/contracts/src/cycle/CycleTurnsLastClaimedComponent.sol b/packages/contracts/_old_src/cycle/CycleTurnsLastClaimedComponent.sol similarity index 100% rename from packages/contracts/src/cycle/CycleTurnsLastClaimedComponent.sol rename to packages/contracts/_old_src/cycle/CycleTurnsLastClaimedComponent.sol diff --git a/packages/contracts/src/cycle/LearnCycleSkillSystem.sol b/packages/contracts/_old_src/cycle/LearnCycleSkillSystem.sol similarity index 100% rename from packages/contracts/src/cycle/LearnCycleSkillSystem.sol rename to packages/contracts/_old_src/cycle/LearnCycleSkillSystem.sol diff --git a/packages/contracts/src/cycle/LibCycle.sol b/packages/contracts/_old_src/cycle/LibCycle.sol similarity index 100% rename from packages/contracts/src/cycle/LibCycle.sol rename to packages/contracts/_old_src/cycle/LibCycle.sol diff --git a/packages/contracts/src/cycle/LibCycleCombatRewardRequest.sol b/packages/contracts/_old_src/cycle/LibCycleCombatRewardRequest.sol similarity index 100% rename from packages/contracts/src/cycle/LibCycleCombatRewardRequest.sol rename to packages/contracts/_old_src/cycle/LibCycleCombatRewardRequest.sol diff --git a/packages/contracts/src/cycle/LibCycleTurns.sol b/packages/contracts/_old_src/cycle/LibCycleTurns.sol similarity index 100% rename from packages/contracts/src/cycle/LibCycleTurns.sol rename to packages/contracts/_old_src/cycle/LibCycleTurns.sol diff --git a/packages/contracts/src/cycle/PassCycleTurnSystem.sol b/packages/contracts/_old_src/cycle/PassCycleTurnSystem.sol similarity index 100% rename from packages/contracts/src/cycle/PassCycleTurnSystem.sol rename to packages/contracts/_old_src/cycle/PassCycleTurnSystem.sol diff --git a/packages/contracts/src/cycle/StartCycleSystem.sol b/packages/contracts/_old_src/cycle/StartCycleSystem.sol similarity index 100% rename from packages/contracts/src/cycle/StartCycleSystem.sol rename to packages/contracts/_old_src/cycle/StartCycleSystem.sol diff --git a/packages/contracts/src/cycle/test/CycleCombatSystem.t.sol b/packages/contracts/_old_src/cycle/test/CycleCombatSystem.t.sol similarity index 100% rename from packages/contracts/src/cycle/test/CycleCombatSystem.t.sol rename to packages/contracts/_old_src/cycle/test/CycleCombatSystem.t.sol diff --git a/packages/contracts/src/cycle/test/CycleEquipmentSystem.t.sol b/packages/contracts/_old_src/cycle/test/CycleEquipmentSystem.t.sol similarity index 100% rename from packages/contracts/src/cycle/test/CycleEquipmentSystem.t.sol rename to packages/contracts/_old_src/cycle/test/CycleEquipmentSystem.t.sol diff --git a/packages/contracts/src/cycle/test/LearnCycleSkillSystem.t.sol b/packages/contracts/_old_src/cycle/test/LearnCycleSkillSystem.t.sol similarity index 100% rename from packages/contracts/src/cycle/test/LearnCycleSkillSystem.t.sol rename to packages/contracts/_old_src/cycle/test/LearnCycleSkillSystem.t.sol diff --git a/packages/contracts/src/cycle/test/LibCycleTurns.t.sol b/packages/contracts/_old_src/cycle/test/LibCycleTurns.t.sol similarity index 100% rename from packages/contracts/src/cycle/test/LibCycleTurns.t.sol rename to packages/contracts/_old_src/cycle/test/LibCycleTurns.t.sol diff --git a/packages/contracts/src/cycle/test/PassCycleTurnSystem.t.sol b/packages/contracts/_old_src/cycle/test/PassCycleTurnSystem.t.sol similarity index 100% rename from packages/contracts/src/cycle/test/PassCycleTurnSystem.t.sol rename to packages/contracts/_old_src/cycle/test/PassCycleTurnSystem.t.sol diff --git a/packages/contracts/src/cycle/test/StartCycleSystem.t.sol b/packages/contracts/_old_src/cycle/test/StartCycleSystem.t.sol similarity index 100% rename from packages/contracts/src/cycle/test/StartCycleSystem.t.sol rename to packages/contracts/_old_src/cycle/test/StartCycleSystem.t.sol diff --git a/packages/contracts/src/duration/DurationOnEndComponent.sol b/packages/contracts/_old_src/duration/DurationOnEndComponent.sol similarity index 100% rename from packages/contracts/src/duration/DurationOnEndComponent.sol rename to packages/contracts/_old_src/duration/DurationOnEndComponent.sol diff --git a/packages/contracts/src/duration/DurationScopeComponent.sol b/packages/contracts/_old_src/duration/DurationScopeComponent.sol similarity index 100% rename from packages/contracts/src/duration/DurationScopeComponent.sol rename to packages/contracts/_old_src/duration/DurationScopeComponent.sol diff --git a/packages/contracts/src/duration/DurationSubSystem.sol b/packages/contracts/_old_src/duration/DurationSubSystem.sol similarity index 100% rename from packages/contracts/src/duration/DurationSubSystem.sol rename to packages/contracts/_old_src/duration/DurationSubSystem.sol diff --git a/packages/contracts/src/duration/DurationValueComponent.sol b/packages/contracts/_old_src/duration/DurationValueComponent.sol similarity index 100% rename from packages/contracts/src/duration/DurationValueComponent.sol rename to packages/contracts/_old_src/duration/DurationValueComponent.sol diff --git a/packages/contracts/src/effect/AppliedEffectComponent.sol b/packages/contracts/_old_src/effect/AppliedEffectComponent.sol similarity index 100% rename from packages/contracts/src/effect/AppliedEffectComponent.sol rename to packages/contracts/_old_src/effect/AppliedEffectComponent.sol diff --git a/packages/contracts/src/effect/EffectPrototypeComponent.sol b/packages/contracts/_old_src/effect/EffectPrototypeComponent.sol similarity index 100% rename from packages/contracts/src/effect/EffectPrototypeComponent.sol rename to packages/contracts/_old_src/effect/EffectPrototypeComponent.sol diff --git a/packages/contracts/src/effect/EffectSubSystem.sol b/packages/contracts/_old_src/effect/EffectSubSystem.sol similarity index 100% rename from packages/contracts/src/effect/EffectSubSystem.sol rename to packages/contracts/_old_src/effect/EffectSubSystem.sol diff --git a/packages/contracts/src/effect/LibEffectPrototype.sol b/packages/contracts/_old_src/effect/LibEffectPrototype.sol similarity index 100% rename from packages/contracts/src/effect/LibEffectPrototype.sol rename to packages/contracts/_old_src/effect/LibEffectPrototype.sol diff --git a/packages/contracts/src/effect/makeEffectPrototype.sol b/packages/contracts/_old_src/effect/makeEffectPrototype.sol similarity index 100% rename from packages/contracts/src/effect/makeEffectPrototype.sol rename to packages/contracts/_old_src/effect/makeEffectPrototype.sol diff --git a/packages/contracts/src/equipment/EquipmentPrototypeComponent.sol b/packages/contracts/_old_src/equipment/EquipmentPrototypeComponent.sol similarity index 100% rename from packages/contracts/src/equipment/EquipmentPrototypeComponent.sol rename to packages/contracts/_old_src/equipment/EquipmentPrototypeComponent.sol diff --git a/packages/contracts/src/equipment/EquipmentPrototypes.sol b/packages/contracts/_old_src/equipment/EquipmentPrototypes.sol similarity index 100% rename from packages/contracts/src/equipment/EquipmentPrototypes.sol rename to packages/contracts/_old_src/equipment/EquipmentPrototypes.sol diff --git a/packages/contracts/src/equipment/EquipmentSlotAllowedComponent.sol b/packages/contracts/_old_src/equipment/EquipmentSlotAllowedComponent.sol similarity index 100% rename from packages/contracts/src/equipment/EquipmentSlotAllowedComponent.sol rename to packages/contracts/_old_src/equipment/EquipmentSlotAllowedComponent.sol diff --git a/packages/contracts/src/equipment/EquipmentSlotComponent.sol b/packages/contracts/_old_src/equipment/EquipmentSlotComponent.sol similarity index 100% rename from packages/contracts/src/equipment/EquipmentSlotComponent.sol rename to packages/contracts/_old_src/equipment/EquipmentSlotComponent.sol diff --git a/packages/contracts/src/equipment/EquipmentSubSystem.sol b/packages/contracts/_old_src/equipment/EquipmentSubSystem.sol similarity index 100% rename from packages/contracts/src/equipment/EquipmentSubSystem.sol rename to packages/contracts/_old_src/equipment/EquipmentSubSystem.sol diff --git a/packages/contracts/src/equipment/LibSpawnEquipmentSlots.sol b/packages/contracts/_old_src/equipment/LibSpawnEquipmentSlots.sol similarity index 100% rename from packages/contracts/src/equipment/LibSpawnEquipmentSlots.sol rename to packages/contracts/_old_src/equipment/LibSpawnEquipmentSlots.sol diff --git a/packages/contracts/src/equipment/test/EquipmentSubsystem.t.sol b/packages/contracts/_old_src/equipment/test/EquipmentSubsystem.t.sol similarity index 100% rename from packages/contracts/src/equipment/test/EquipmentSubsystem.t.sol rename to packages/contracts/_old_src/equipment/test/EquipmentSubsystem.t.sol diff --git a/packages/contracts/src/guise/ActiveGuiseComponent.sol b/packages/contracts/_old_src/guise/ActiveGuiseComponent.sol similarity index 100% rename from packages/contracts/src/guise/ActiveGuiseComponent.sol rename to packages/contracts/_old_src/guise/ActiveGuiseComponent.sol diff --git a/packages/contracts/src/guise/GuisePrototypeComponent.sol b/packages/contracts/_old_src/guise/GuisePrototypeComponent.sol similarity index 100% rename from packages/contracts/src/guise/GuisePrototypeComponent.sol rename to packages/contracts/_old_src/guise/GuisePrototypeComponent.sol diff --git a/packages/contracts/src/guise/GuiseSkillsComponent.sol b/packages/contracts/_old_src/guise/GuiseSkillsComponent.sol similarity index 100% rename from packages/contracts/src/guise/GuiseSkillsComponent.sol rename to packages/contracts/_old_src/guise/GuiseSkillsComponent.sol diff --git a/packages/contracts/src/guise/LibGuiseLevel.sol b/packages/contracts/_old_src/guise/LibGuiseLevel.sol similarity index 100% rename from packages/contracts/src/guise/LibGuiseLevel.sol rename to packages/contracts/_old_src/guise/LibGuiseLevel.sol diff --git a/packages/contracts/src/init/LibBaseInitAffix.sol b/packages/contracts/_old_src/init/LibBaseInitAffix.sol similarity index 100% rename from packages/contracts/src/init/LibBaseInitAffix.sol rename to packages/contracts/_old_src/init/LibBaseInitAffix.sol diff --git a/packages/contracts/src/init/LibBaseInitSkill.sol b/packages/contracts/_old_src/init/LibBaseInitSkill.sol similarity index 100% rename from packages/contracts/src/init/LibBaseInitSkill.sol rename to packages/contracts/_old_src/init/LibBaseInitSkill.sol diff --git a/packages/contracts/src/init/LibInitAuthorizeSubsystems.sol b/packages/contracts/_old_src/init/LibInitAuthorizeSubsystems.sol similarity index 100% rename from packages/contracts/src/init/LibInitAuthorizeSubsystems.sol rename to packages/contracts/_old_src/init/LibInitAuthorizeSubsystems.sol diff --git a/packages/contracts/src/init/LibInitEquipmentAffix.sol b/packages/contracts/_old_src/init/LibInitEquipmentAffix.sol similarity index 100% rename from packages/contracts/src/init/LibInitEquipmentAffix.sol rename to packages/contracts/_old_src/init/LibInitEquipmentAffix.sol diff --git a/packages/contracts/src/init/LibInitEquipmentPrototype.sol b/packages/contracts/_old_src/init/LibInitEquipmentPrototype.sol similarity index 100% rename from packages/contracts/src/init/LibInitEquipmentPrototype.sol rename to packages/contracts/_old_src/init/LibInitEquipmentPrototype.sol diff --git a/packages/contracts/src/init/LibInitGuise.sol b/packages/contracts/_old_src/init/LibInitGuise.sol similarity index 100% rename from packages/contracts/src/init/LibInitGuise.sol rename to packages/contracts/_old_src/init/LibInitGuise.sol diff --git a/packages/contracts/src/init/LibInitMapAffix.sol b/packages/contracts/_old_src/init/LibInitMapAffix.sol similarity index 100% rename from packages/contracts/src/init/LibInitMapAffix.sol rename to packages/contracts/_old_src/init/LibInitMapAffix.sol diff --git a/packages/contracts/src/init/LibInitMapPrototype.sol b/packages/contracts/_old_src/init/LibInitMapPrototype.sol similarity index 100% rename from packages/contracts/src/init/LibInitMapPrototype.sol rename to packages/contracts/_old_src/init/LibInitMapPrototype.sol diff --git a/packages/contracts/src/init/LibInitMapsBoss.sol b/packages/contracts/_old_src/init/LibInitMapsBoss.sol similarity index 100% rename from packages/contracts/src/init/LibInitMapsBoss.sol rename to packages/contracts/_old_src/init/LibInitMapsBoss.sol diff --git a/packages/contracts/src/init/LibInitMapsGlobal.sol b/packages/contracts/_old_src/init/LibInitMapsGlobal.sol similarity index 100% rename from packages/contracts/src/init/LibInitMapsGlobal.sol rename to packages/contracts/_old_src/init/LibInitMapsGlobal.sol diff --git a/packages/contracts/src/init/LibInitReverseHashName.ejs b/packages/contracts/_old_src/init/LibInitReverseHashName.ejs similarity index 100% rename from packages/contracts/src/init/LibInitReverseHashName.ejs rename to packages/contracts/_old_src/init/LibInitReverseHashName.ejs diff --git a/packages/contracts/src/init/LibInitSkill.sol b/packages/contracts/_old_src/init/LibInitSkill.sol similarity index 100% rename from packages/contracts/src/init/LibInitSkill.sol rename to packages/contracts/_old_src/init/LibInitSkill.sol diff --git a/packages/contracts/src/init/LibInitStatmod.sol b/packages/contracts/_old_src/init/LibInitStatmod.sol similarity index 100% rename from packages/contracts/src/init/LibInitStatmod.sol rename to packages/contracts/_old_src/init/LibInitStatmod.sol diff --git a/packages/contracts/src/init/LibInitWheel.sol b/packages/contracts/_old_src/init/LibInitWheel.sol similarity index 100% rename from packages/contracts/src/init/LibInitWheel.sol rename to packages/contracts/_old_src/init/LibInitWheel.sol diff --git a/packages/contracts/src/libraries/LibArray.sol b/packages/contracts/_old_src/libraries/LibArray.sol similarity index 100% rename from packages/contracts/src/libraries/LibArray.sol rename to packages/contracts/_old_src/libraries/LibArray.sol diff --git a/packages/contracts/src/loot/LibLootEquipment.sol b/packages/contracts/_old_src/loot/LibLootEquipment.sol similarity index 100% rename from packages/contracts/src/loot/LibLootEquipment.sol rename to packages/contracts/_old_src/loot/LibLootEquipment.sol diff --git a/packages/contracts/src/loot/LibLootMap.sol b/packages/contracts/_old_src/loot/LibLootMap.sol similarity index 100% rename from packages/contracts/src/loot/LibLootMap.sol rename to packages/contracts/_old_src/loot/LibLootMap.sol diff --git a/packages/contracts/src/loot/LibLootMint.sol b/packages/contracts/_old_src/loot/LibLootMint.sol similarity index 100% rename from packages/contracts/src/loot/LibLootMint.sol rename to packages/contracts/_old_src/loot/LibLootMint.sol diff --git a/packages/contracts/src/loot/LibLootOwner.sol b/packages/contracts/_old_src/loot/LibLootOwner.sol similarity index 100% rename from packages/contracts/src/loot/LibLootOwner.sol rename to packages/contracts/_old_src/loot/LibLootOwner.sol diff --git a/packages/contracts/src/loot/LootComponent.sol b/packages/contracts/_old_src/loot/LootComponent.sol similarity index 100% rename from packages/contracts/src/loot/LootComponent.sol rename to packages/contracts/_old_src/loot/LootComponent.sol diff --git a/packages/contracts/src/loot/RandomEquipmentSubSystem.sol b/packages/contracts/_old_src/loot/RandomEquipmentSubSystem.sol similarity index 100% rename from packages/contracts/src/loot/RandomEquipmentSubSystem.sol rename to packages/contracts/_old_src/loot/RandomEquipmentSubSystem.sol diff --git a/packages/contracts/src/loot/RandomMapSubSystem.sol b/packages/contracts/_old_src/loot/RandomMapSubSystem.sol similarity index 100% rename from packages/contracts/src/loot/RandomMapSubSystem.sol rename to packages/contracts/_old_src/loot/RandomMapSubSystem.sol diff --git a/packages/contracts/src/loot/test/RandomEquipmentSubsystem.t.sol b/packages/contracts/_old_src/loot/test/RandomEquipmentSubsystem.t.sol similarity index 100% rename from packages/contracts/src/loot/test/RandomEquipmentSubsystem.t.sol rename to packages/contracts/_old_src/loot/test/RandomEquipmentSubsystem.t.sol diff --git a/packages/contracts/src/map/MapPrototypeComponent.sol b/packages/contracts/_old_src/map/MapPrototypeComponent.sol similarity index 100% rename from packages/contracts/src/map/MapPrototypeComponent.sol rename to packages/contracts/_old_src/map/MapPrototypeComponent.sol diff --git a/packages/contracts/src/map/MapPrototypes.sol b/packages/contracts/_old_src/map/MapPrototypes.sol similarity index 100% rename from packages/contracts/src/map/MapPrototypes.sol rename to packages/contracts/_old_src/map/MapPrototypes.sol diff --git a/packages/contracts/src/rng/LibRNG.sol b/packages/contracts/_old_src/rng/LibRNG.sol similarity index 100% rename from packages/contracts/src/rng/LibRNG.sol rename to packages/contracts/_old_src/rng/LibRNG.sol diff --git a/packages/contracts/src/rng/RNGPrecommitComponent.sol b/packages/contracts/_old_src/rng/RNGPrecommitComponent.sol similarity index 100% rename from packages/contracts/src/rng/RNGPrecommitComponent.sol rename to packages/contracts/_old_src/rng/RNGPrecommitComponent.sol diff --git a/packages/contracts/src/rng/RNGRequestOwnerComponent.sol b/packages/contracts/_old_src/rng/RNGRequestOwnerComponent.sol similarity index 100% rename from packages/contracts/src/rng/RNGRequestOwnerComponent.sol rename to packages/contracts/_old_src/rng/RNGRequestOwnerComponent.sol diff --git a/packages/contracts/src/rng/test/LibRNG.t.sol b/packages/contracts/_old_src/rng/test/LibRNG.t.sol similarity index 100% rename from packages/contracts/src/rng/test/LibRNG.t.sol rename to packages/contracts/_old_src/rng/test/LibRNG.t.sol diff --git a/packages/contracts/src/skill/LearnedSkillsComponent.sol b/packages/contracts/_old_src/skill/LearnedSkillsComponent.sol similarity index 100% rename from packages/contracts/src/skill/LearnedSkillsComponent.sol rename to packages/contracts/_old_src/skill/LearnedSkillsComponent.sol diff --git a/packages/contracts/src/skill/LibLearnedSkills.sol b/packages/contracts/_old_src/skill/LibLearnedSkills.sol similarity index 100% rename from packages/contracts/src/skill/LibLearnedSkills.sol rename to packages/contracts/_old_src/skill/LibLearnedSkills.sol diff --git a/packages/contracts/src/skill/LibSkill.sol b/packages/contracts/_old_src/skill/LibSkill.sol similarity index 100% rename from packages/contracts/src/skill/LibSkill.sol rename to packages/contracts/_old_src/skill/LibSkill.sol diff --git a/packages/contracts/src/skill/NoncombatSkillSystem.sol b/packages/contracts/_old_src/skill/NoncombatSkillSystem.sol similarity index 100% rename from packages/contracts/src/skill/NoncombatSkillSystem.sol rename to packages/contracts/_old_src/skill/NoncombatSkillSystem.sol diff --git a/packages/contracts/src/skill/SkillDescriptionComponent.sol b/packages/contracts/_old_src/skill/SkillDescriptionComponent.sol similarity index 100% rename from packages/contracts/src/skill/SkillDescriptionComponent.sol rename to packages/contracts/_old_src/skill/SkillDescriptionComponent.sol diff --git a/packages/contracts/src/skill/SkillPrototypeComponent.sol b/packages/contracts/_old_src/skill/SkillPrototypeComponent.sol similarity index 100% rename from packages/contracts/src/skill/SkillPrototypeComponent.sol rename to packages/contracts/_old_src/skill/SkillPrototypeComponent.sol diff --git a/packages/contracts/src/skill/test/LibSkill.t.sol b/packages/contracts/_old_src/skill/test/LibSkill.t.sol similarity index 100% rename from packages/contracts/src/skill/test/LibSkill.t.sol rename to packages/contracts/_old_src/skill/test/LibSkill.t.sol diff --git a/packages/contracts/src/skill/test/SkillPrototypeComponent.t.sol b/packages/contracts/_old_src/skill/test/SkillPrototypeComponent.t.sol similarity index 100% rename from packages/contracts/src/skill/test/SkillPrototypeComponent.t.sol rename to packages/contracts/_old_src/skill/test/SkillPrototypeComponent.t.sol diff --git a/packages/contracts/_old_src/statmod/Statmod.sol b/packages/contracts/_old_src/statmod/Statmod.sol new file mode 100644 index 00000000..b6038c65 --- /dev/null +++ b/packages/contracts/_old_src/statmod/Statmod.sol @@ -0,0 +1,192 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.17; + +import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; +import { getAddressById } from "solecs/utils.sol"; +import { StatmodPrototype, Op, OP_L, OP_FINAL, Element, EL_L, StatmodPrototypeComponent, ID as StatmodPrototypeComponentID } from "./StatmodPrototypeComponent.sol"; + +import { ScopedValue } from "@dk1a/solecslib/contracts/scoped-value/ScopedValue.sol"; +import { FromPrototype } from "@dk1a/solecslib/contracts/prototype/FromPrototype.sol"; +import { ScopedValueFromPrototype } from "@dk1a/solecslib/contracts/scoped-value/ScopedValueFromPrototype.sol"; +import { ID as StatmodScopeComponentID } from "./StatmodScopeComponent.sol"; +import { ID as StatmodValueComponentID } from "./StatmodValueComponent.sol"; +import { ID as FromPrototypeComponentID } from "../common/FromPrototypeComponent.sol"; + +/** + * @title Scoped statmod values with aggregation depending on prototype. + */ +library Statmod { + using ScopedValueFromPrototype for ScopedValueFromPrototype.Self; + + struct Self { + StatmodPrototypeComponent protoComp; + ScopedValueFromPrototype.Self sv; + uint256 targetEntity; + } + + /** + * @param components world.components() + * @param targetEntity context for instances of protoEntities. + * Modifying the same protoEntity with different targetEntities will not affect each other. + */ + function __construct(IUint256Component components, uint256 targetEntity) internal view returns (Self memory) { + return + Self({ + protoComp: StatmodPrototypeComponent(getAddressById(components, StatmodPrototypeComponentID)), + sv: ScopedValueFromPrototype.__construct( + ScopedValue.__construct(components, StatmodScopeComponentID, StatmodValueComponentID), + FromPrototype.__construct( + components, + FromPrototypeComponentID, + // instance context + abi.encode("Statmod", targetEntity) + ) + ), + targetEntity: targetEntity + }); + } + + function _scope(Self memory __self, uint256 topicEntity) private pure returns (string memory) { + return string(abi.encode(__self.targetEntity, topicEntity)); + } + + // ========== WRITE ========== + + /** + * @dev Increase statmod value for instantiated protoEntity. + */ + function increase(Self memory __self, uint256 protoEntity, uint256 value) internal returns (bool isUpdate) { + StatmodPrototype memory prototype = __self.protoComp.getValue(protoEntity); + + return __self.sv.increaseEntity(_scope(__self, prototype.topicEntity), protoEntity, value); + } + + /** + * @dev Decrease statmod value for instantiated protoEntity. + */ + function decrease(Self memory __self, uint256 protoEntity, uint256 value) internal returns (bool isUpdate) { + StatmodPrototype memory prototype = __self.protoComp.getValue(protoEntity); + + return __self.sv.decreaseEntity(_scope(__self, prototype.topicEntity), protoEntity, value); + } + + // ========== READ ========== + + /** + * @dev Sum all statmod values for `topicEntity` + * TODO is this even useful anywhere? + */ + function getTotal(Self memory __self, uint256 topicEntity) internal view returns (uint32 result) { + (, uint256[] memory values) = __self.sv.getEntitiesValues(_scope(__self, topicEntity)); + + for (uint256 i; i < values.length; i++) { + result += uint32(values[i]); + } + } + + /** + * @dev Sum statmod values for `topicEntity`, grouped by Op. + * This method shouldn't usually be needed externally, see getValues. + */ + function getOperands(Self memory __self, uint256 topicEntity) internal view returns (uint32[OP_L] memory result) { + (uint256[] memory protoEntities, uint256[] memory values) = __self.sv.getEntitiesValues( + _scope(__self, topicEntity) + ); + + for (uint256 i; i < protoEntities.length; i++) { + StatmodPrototype memory prototype = __self.protoComp.getValue(protoEntities[i]); + + result[uint256(prototype.op)] += uint32(values[i]); + } + } + + /** + * @dev Sum statmod values for `topicEntity`, grouped by Element and Op. + * This method shouldn't usually be needed externally, see getValuesElemental. + */ + function getOperandsElemental( + Self memory __self, + uint256 topicEntity + ) internal view returns (uint32[EL_L][OP_L] memory result) { + (uint256[] memory protoEntities, uint256[] memory values) = __self.sv.getEntitiesValues( + _scope(__self, topicEntity) + ); + + for (uint256 i; i < protoEntities.length; i++) { + StatmodPrototype memory prototype = __self.protoComp.getValue(protoEntities[i]); + + result[uint256(prototype.op)][uint256(prototype.element)] += uint32(values[i]); + } + + // Element.ALL applies to all other elements at the same time + for (uint256 el; el < EL_L; el++) { + if (el == uint256(Element.ALL)) continue; + + result[uint256(Op.ADD)][el] += result[uint256(Op.ADD)][uint256(Element.ALL)]; + result[uint256(Op.MUL)][el] += result[uint256(Op.MUL)][uint256(Element.ALL)]; + result[uint256(Op.BADD)][el] += result[uint256(Op.BADD)][uint256(Element.ALL)]; + } + } + + /** + * @dev Return statmod values grouped by results of operations. + * Usually you want OP_FINAL - the last operation in their sequence. + * The others give access to intermediate values like 'base life' + * @param baseValue inherent base, may be 0 + * @return result results of operations upon `baseValue` + */ + function getValues( + Self memory __self, + uint256 topicEntity, + uint32 baseValue + ) internal view returns (uint32[OP_L] memory result) { + uint32[OP_L] memory ops = getOperands(__self, topicEntity); + result[uint256(Op.BADD)] = baseValue + ops[uint256(Op.BADD)]; + result[uint256(Op.MUL)] = (result[uint256(Op.BADD)] * (100 + ops[uint256(Op.MUL)])) / 100; + result[uint256(Op.ADD)] = result[uint256(Op.MUL)] + ops[uint256(Op.ADD)]; + } + + /** + * @dev Result of all `topicEntity` operations upon `baseValue` + */ + function getValuesFinal(Self memory __self, uint256 topicEntity, uint32 baseValue) internal view returns (uint32) { + return getValues(__self, topicEntity, baseValue)[OP_FINAL]; + } + + /** + * @dev Return values grouped by Element and Op + * See getValues for details on Op grouping + */ + function getValuesElemental( + Self memory __self, + uint256 topicEntity, + uint32[EL_L] memory baseValues + ) internal view returns (uint32[EL_L][OP_L] memory result) { + uint32[EL_L][OP_L] memory ops = getOperandsElemental(__self, topicEntity); + // el is Element enum values + for (uint256 el; el < EL_L; el++) { + uint32 baseValue = baseValues[el]; + + // Element.ALL adds to all other elements at the same time + if (el != uint256(Element.ALL)) { + baseValue += baseValues[uint256(Element.ALL)]; + } + + result[uint256(Op.BADD)][el] = baseValue + ops[uint256(Op.BADD)][el]; + result[uint256(Op.MUL)][el] = (result[uint256(Op.BADD)][el] * (100 + ops[uint256(Op.MUL)][el])) / 100; + result[uint256(Op.ADD)][el] = result[uint256(Op.MUL)][el] + ops[uint256(Op.ADD)][el]; + } + } + + /** + * @dev Result of all `topicEntity` operations upon `baseValue` grouped by Element + */ + function getValuesElementalFinal( + Self memory __self, + uint256 topicEntity, + uint32[EL_L] memory baseValues + ) internal view returns (uint32[EL_L] memory) { + return getValuesElemental(__self, topicEntity, baseValues)[OP_FINAL]; + } +} diff --git a/packages/contracts/_old_src/statmod/StatmodPrototypeComponent.sol b/packages/contracts/_old_src/statmod/StatmodPrototypeComponent.sol new file mode 100644 index 00000000..c17f5ba2 --- /dev/null +++ b/packages/contracts/_old_src/statmod/StatmodPrototypeComponent.sol @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.17; + +import { LibTypes } from "solecs/LibTypes.sol"; +import { BareComponent } from "solecs/BareComponent.sol"; + +uint256 constant ID = uint256(keccak256("component.StatmodPrototype")); + +/** + * @dev Statmod protoEntity = hashed(ID, StatmodPrototype) + */ +function getStatmodProtoEntity(StatmodPrototype memory proto) pure returns (uint256) { + return uint256(keccak256(abi.encode(ID, proto))); +} + +enum Op { + ADD, + MUL, + BADD +} +uint256 constant OP_L = 3; +uint256 constant OP_FINAL = uint256(Op.ADD); + +enum Element { + ALL, + PHYSICAL, + FIRE, + COLD, + POISON +} +uint256 constant EL_L = 5; + +struct StatmodPrototype { + uint256 topicEntity; + Op op; + Element element; +} + +contract StatmodPrototypeComponent is BareComponent { + error StatmodPrototypeComponent__AbsentEntity(); + + constructor(address world) BareComponent(world, ID) {} + + function getSchema() public pure override returns (string[] memory keys, LibTypes.SchemaValue[] memory values) { + keys = new string[](3); + values = new LibTypes.SchemaValue[](3); + + keys[0] = "topicEntity"; + values[0] = LibTypes.SchemaValue.UINT256; + + keys[1] = "op"; + values[1] = LibTypes.SchemaValue.UINT8; + + keys[2] = "element"; + values[2] = LibTypes.SchemaValue.UINT8; + } + + function set(uint256 entity, StatmodPrototype memory value) public { + set(entity, abi.encode(value)); + } + + function getValue(uint256 entity) public view returns (StatmodPrototype memory) { + bytes memory rawValue = getRawValue(entity); + if (rawValue.length == 0) { + revert StatmodPrototypeComponent__AbsentEntity(); + } + return abi.decode(rawValue, (StatmodPrototype)); + } +} diff --git a/packages/contracts/_old_src/statmod/StatmodScopeComponent.sol b/packages/contracts/_old_src/statmod/StatmodScopeComponent.sol new file mode 100644 index 00000000..842cd1d3 --- /dev/null +++ b/packages/contracts/_old_src/statmod/StatmodScopeComponent.sol @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.17; + +import { ScopeComponent } from "@dk1a/solecslib/contracts/scoped-value/ScopeComponent.sol"; + +uint256 constant ID = uint256(keccak256("component.StatmodScope")); + +contract StatmodScopeComponent is ScopeComponent { + constructor(address _world) ScopeComponent(_world, ID) {} +} diff --git a/packages/contracts/_old_src/statmod/StatmodValueComponent.sol b/packages/contracts/_old_src/statmod/StatmodValueComponent.sol new file mode 100644 index 00000000..199be282 --- /dev/null +++ b/packages/contracts/_old_src/statmod/StatmodValueComponent.sol @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.17; + +import { ValueComponent } from "@dk1a/solecslib/contracts/scoped-value/ValueComponent.sol"; + +uint256 constant ID = uint256(keccak256("component.StatmodValue")); + +contract StatmodValueComponent is ValueComponent { + constructor(address _world) ValueComponent(_world, ID) {} +} diff --git a/packages/contracts/_old_src/statmod/statmodName.sol b/packages/contracts/_old_src/statmod/statmodName.sol new file mode 100644 index 00000000..97d13aeb --- /dev/null +++ b/packages/contracts/_old_src/statmod/statmodName.sol @@ -0,0 +1,74 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.17; + +import { IWorld } from "solecs/interfaces/IWorld.sol"; +import { getAddressById } from "solecs/utils.sol"; + +import { StrSlice, toSlice } from "@dk1a/solidity-stringutils/src/StrSlice.sol"; + +import { ReverseHashNameComponent } from "../common/ReverseHashNameComponent.sol"; +import { Op, Element } from "./StatmodPrototypeComponent.sol"; + +using { toSlice } for string; + +// utils for autogenerating a name for a statmod prototype + +function statmodName(ReverseHashNameComponent rhNameComp, uint256 topicEntity, Op op) view returns (string memory) { + return statmodName(rhNameComp, topicEntity, op, Element.ALL); +} + +function statmodName( + ReverseHashNameComponent rhNameComp, + uint256 topicEntity, + Op op, + Element element +) view returns (string memory) { + StrSlice topicName = toSlice(rhNameComp.getValue(topicEntity)); + + StrSlice[] memory nameParts = new StrSlice[](2); + // prefix + if (op == Op.ADD) { + nameParts[0] = toSlice("+#"); + } else if (op == Op.MUL) { + nameParts[0] = toSlice("#% increased"); + } else if (op == Op.BADD) { + nameParts[0] = toSlice("+# base"); + } else { + revert("unknown op"); + } + // element + topic + if (element != Element.ALL) { + StrSlice elementName = _elementName(element); + // check if topicName has "{element}" placeholder + (bool found, StrSlice prefix, StrSlice suffix) = topicName.splitOnce(toSlice("{element}")); + + if (found) { + // replace {element} with the actual element name + nameParts[1] = prefix.add(elementName).toSlice().add(suffix).toSlice(); + } else { + // prepend element name to topicName + nameParts[1] = elementName.add(toSlice(" ")).toSlice().add(topicName).toSlice(); + } + } else if (element == Element.ALL) { + if (topicName.contains(toSlice("{element}"))) revert("invalid element placeholder"); + // just topicName, no element + nameParts[1] = topicName; + } + + return toSlice(" ").join(nameParts); +} + +function _elementName(Element element) pure returns (StrSlice) { + if (element == Element.PHYSICAL) { + return toSlice("physical"); + } else if (element == Element.FIRE) { + return toSlice("fire"); + } else if (element == Element.COLD) { + return toSlice("cold"); + } else if (element == Element.POISON) { + return toSlice("poison"); + } else { + revert("unknown element"); + } +} diff --git a/packages/contracts/_old_src/statmod/test/Statmod.t.sol b/packages/contracts/_old_src/statmod/test/Statmod.t.sol new file mode 100644 index 00000000..53038329 --- /dev/null +++ b/packages/contracts/_old_src/statmod/test/Statmod.t.sol @@ -0,0 +1,121 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.17; + +import { BaseTest } from "../../BaseTest.sol"; + +import { Topics } from "../../charstat/Topics.sol"; +import { Statmod } from "../Statmod.sol"; +import { + Op, OP_L, OP_FINAL, + Element, EL_L, + getStatmodProtoEntity, + StatmodPrototype +} from "../StatmodPrototypeComponent.sol"; + +contract StatmodTest is BaseTest { + using Statmod for Statmod.Self; + + // this should normally be an in-memory object, it's in storage for testing convenience + Statmod.Self _statmod; + + // some statmod prototype entities and their topics + uint256 lifeTopic = Topics.LIFE.toEntity(); + uint256 addLifePE = Topics.LIFE.toStatmodEntity(Op.ADD, Element.ALL); + uint256 mulLifePE = Topics.LIFE.toStatmodEntity(Op.MUL, Element.ALL); + uint256 baddLifePE = Topics.LIFE.toStatmodEntity(Op.BADD, Element.ALL); + + uint256 attackTopic = Topics.ATTACK.toEntity(); + uint256 mulAttackPE = Topics.ATTACK.toStatmodEntity(Op.MUL, Element.ALL); + uint256 mulFireAttackPE = Topics.ATTACK.toStatmodEntity(Op.MUL, Element.FIRE); + uint256 addFireAttackPE = Topics.ATTACK.toStatmodEntity(Op.ADD, Element.FIRE); + uint256 addColdAttackPE = Topics.ATTACK.toStatmodEntity(Op.ADD, Element.COLD); + + function setUp() public override { + super.setUp(); + + // init library's object + _statmod = Statmod.__construct( + world.components(), + uint256(keccak256('mainEntity')) + ); + } + + function test_statmod_getValues_parallelChanges() public { + // a bunch of changes to make sure they don't interfere with each other + _statmod.increase(mulLifePE, 11); + + _statmod.increase(addLifePE, 80); + + _statmod.decrease(mulLifePE, 2); + + _statmod.decrease(addLifePE, 10); + + _statmod.increase(mulLifePE, 1); + + _statmod.increase(baddLifePE, 54); + _statmod.decrease(baddLifePE, 27); + + _statmod.increase(mulLifePE, 2); + _statmod.increase(mulLifePE, 5); + + // (10 + 27) * (100 + 17) / 100 + 70 + uint32[OP_L] memory result = _statmod.getValues(lifeTopic, 10); + assertEq(result[uint256(Op.BADD)], 37); + assertEq(result[uint256(Op.MUL)], 43); + assertEq(result[uint256(Op.ADD)], 113); + } + + function test_statmod_getValuesFinal() public { + _statmod.increase(baddLifePE, 27); + _statmod.increase(mulLifePE, 17); + _statmod.increase(addLifePE, 70); + + // (10 + 27) * (100 + 17) / 100 + 70 + uint32 result = _statmod.getValuesFinal(lifeTopic, 10); + assertEq(result, 113); + } + + function test_statmod_getValuesElementalFinal() public { + _statmod.increase(mulAttackPE, 40); + _statmod.increase(addFireAttackPE, 100); + _statmod.increase(mulFireAttackPE, 40); + _statmod.increase(addColdAttackPE, 50); + + uint32[EL_L] memory result + = _statmod.getValuesElementalFinal(attackTopic, [uint32(0), 200, 300, 400, 500]); + + uint32[EL_L] memory expected; + expected[uint256(Element.ALL)] = 0; + expected[uint256(Element.PHYSICAL)] = 280; + expected[uint256(Element.FIRE)] = 640; + expected[uint256(Element.COLD)] = 610; + expected[uint256(Element.POISON)] = 700; + + for (uint256 el; el < EL_L; el++) { + assertEq(result[el], expected[el]); + } + } + + // TODO Element.ALL is confusing and useless. You should replace it with NONE and make this test obsolete + function test_statmod_getValuesElemental_withBaseAll() public { + _statmod.increase(mulAttackPE, 40); + _statmod.increase(addFireAttackPE, 100); + _statmod.increase(mulFireAttackPE, 40); + _statmod.increase(addColdAttackPE, 50); + + uint32[EL_L] memory result + = _statmod.getValuesElementalFinal(attackTopic, [uint32(100), 200, 300, 400, 500]); + + uint32[EL_L] memory expected; + expected[uint256(Element.ALL)] = 140; + expected[uint256(Element.PHYSICAL)] = 420; + expected[uint256(Element.FIRE)] = 820; + expected[uint256(Element.COLD)] = 750; + expected[uint256(Element.POISON)] = 840; + + for (uint256 el; el < EL_L; el++) { + assertEq(result[el], expected[el]); + } + } +} \ No newline at end of file diff --git a/packages/contracts/_old_src/statmod/test/StatmodPrototype.t.sol b/packages/contracts/_old_src/statmod/test/StatmodPrototype.t.sol new file mode 100644 index 00000000..db7a731d --- /dev/null +++ b/packages/contracts/_old_src/statmod/test/StatmodPrototype.t.sol @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.17; + +import { Assertions } from "@dk1a/solidity-stringutils/src/test/Assertions.sol"; + +import { BaseTest } from "../../BaseTest.sol"; + +import { Topics } from "../../charstat/Topics.sol"; +import { Op, Element } from "../StatmodPrototypeComponent.sol"; + +contract StatmodPrototypeTest is BaseTest, Assertions { + // some statmod prototype entities and their topics + uint256 lifeTopic = Topics.LIFE.toEntity(); + uint256 addLifePE = Topics.LIFE.toStatmodEntity(Op.ADD, Element.ALL); + + function setUp() public override { + super.setUp(); + } + + function test_statmodPrototype_name() public { + string memory topicName = reverseHashNameComponent.getValue(lifeTopic); + string memory name = nameComponent.getValue(addLifePE); + assertContains(name, topicName); + } +} \ No newline at end of file diff --git a/packages/contracts/src/token/LibToken.sol b/packages/contracts/_old_src/token/LibToken.sol similarity index 100% rename from packages/contracts/src/token/LibToken.sol rename to packages/contracts/_old_src/token/LibToken.sol diff --git a/packages/contracts/src/token/WFTSystem.sol b/packages/contracts/_old_src/token/WFTSystem.sol similarity index 100% rename from packages/contracts/src/token/WFTSystem.sol rename to packages/contracts/_old_src/token/WFTSystem.sol diff --git a/packages/contracts/src/token/WNFTSystem.sol b/packages/contracts/_old_src/token/WNFTSystem.sol similarity index 100% rename from packages/contracts/src/token/WNFTSystem.sol rename to packages/contracts/_old_src/token/WNFTSystem.sol diff --git a/packages/contracts/src/uri/LibUri.sol b/packages/contracts/_old_src/uri/LibUri.sol similarity index 100% rename from packages/contracts/src/uri/LibUri.sol rename to packages/contracts/_old_src/uri/LibUri.sol diff --git a/packages/contracts/src/uri/LibUriEquipment.sol b/packages/contracts/_old_src/uri/LibUriEquipment.sol similarity index 100% rename from packages/contracts/src/uri/LibUriEquipment.sol rename to packages/contracts/_old_src/uri/LibUriEquipment.sol diff --git a/packages/contracts/src/uri/LibUriMisc.sol b/packages/contracts/_old_src/uri/LibUriMisc.sol similarity index 100% rename from packages/contracts/src/uri/LibUriMisc.sol rename to packages/contracts/_old_src/uri/LibUriMisc.sol diff --git a/packages/contracts/src/uri/LibUriWanderer.sol b/packages/contracts/_old_src/uri/LibUriWanderer.sol similarity index 100% rename from packages/contracts/src/uri/LibUriWanderer.sol rename to packages/contracts/_old_src/uri/LibUriWanderer.sol diff --git a/packages/contracts/src/uri/UriUtils.sol b/packages/contracts/_old_src/uri/UriUtils.sol similarity index 100% rename from packages/contracts/src/uri/UriUtils.sol rename to packages/contracts/_old_src/uri/UriUtils.sol diff --git a/packages/contracts/src/wanderer/IdentityComponent.sol b/packages/contracts/_old_src/wanderer/IdentityComponent.sol similarity index 100% rename from packages/contracts/src/wanderer/IdentityComponent.sol rename to packages/contracts/_old_src/wanderer/IdentityComponent.sol diff --git a/packages/contracts/src/wanderer/LibWanderer.sol b/packages/contracts/_old_src/wanderer/LibWanderer.sol similarity index 100% rename from packages/contracts/src/wanderer/LibWanderer.sol rename to packages/contracts/_old_src/wanderer/LibWanderer.sol diff --git a/packages/contracts/src/wanderer/PermSkillSystem.sol b/packages/contracts/_old_src/wanderer/PermSkillSystem.sol similarity index 100% rename from packages/contracts/src/wanderer/PermSkillSystem.sol rename to packages/contracts/_old_src/wanderer/PermSkillSystem.sol diff --git a/packages/contracts/src/wanderer/WandererComponent.sol b/packages/contracts/_old_src/wanderer/WandererComponent.sol similarity index 100% rename from packages/contracts/src/wanderer/WandererComponent.sol rename to packages/contracts/_old_src/wanderer/WandererComponent.sol diff --git a/packages/contracts/src/wanderer/WandererSpawnSystem.sol b/packages/contracts/_old_src/wanderer/WandererSpawnSystem.sol similarity index 100% rename from packages/contracts/src/wanderer/WandererSpawnSystem.sol rename to packages/contracts/_old_src/wanderer/WandererSpawnSystem.sol diff --git a/packages/contracts/src/wanderer/test/WandererSpawnSystem.t.sol b/packages/contracts/_old_src/wanderer/test/WandererSpawnSystem.t.sol similarity index 100% rename from packages/contracts/src/wanderer/test/WandererSpawnSystem.t.sol rename to packages/contracts/_old_src/wanderer/test/WandererSpawnSystem.t.sol diff --git a/packages/contracts/src/wheel/ActiveWheelComponent.sol b/packages/contracts/_old_src/wheel/ActiveWheelComponent.sol similarity index 100% rename from packages/contracts/src/wheel/ActiveWheelComponent.sol rename to packages/contracts/_old_src/wheel/ActiveWheelComponent.sol diff --git a/packages/contracts/src/wheel/DefaultWheelComponent.sol b/packages/contracts/_old_src/wheel/DefaultWheelComponent.sol similarity index 100% rename from packages/contracts/src/wheel/DefaultWheelComponent.sol rename to packages/contracts/_old_src/wheel/DefaultWheelComponent.sol diff --git a/packages/contracts/src/wheel/WheelComponent.sol b/packages/contracts/_old_src/wheel/WheelComponent.sol similarity index 100% rename from packages/contracts/src/wheel/WheelComponent.sol rename to packages/contracts/_old_src/wheel/WheelComponent.sol diff --git a/packages/contracts/src/wheel/WheelsCompletedComponent.sol b/packages/contracts/_old_src/wheel/WheelsCompletedComponent.sol similarity index 100% rename from packages/contracts/src/wheel/WheelsCompletedComponent.sol rename to packages/contracts/_old_src/wheel/WheelsCompletedComponent.sol diff --git a/packages/contracts/mud.config.mts b/packages/contracts/mud.config.mts new file mode 100644 index 00000000..07b35bca --- /dev/null +++ b/packages/contracts/mud.config.mts @@ -0,0 +1,367 @@ +import { mudConfig, resolveTableId } from "@latticexyz/config"; + +// TODO user-defined type +const EntityId = "uint256" as const +const EntityIdArray = "uint256[]" as const +// TODO set +const EntityIdSet = "uint256[]" as const + +const entityKey = { + primaryKeys: { + entity: EntityId, + }, +} as const + +const entityRelation = { + ...entityKey, + schema: EntityId, +} as const + +const systemCallbackSchema = { + namespace: "bytes16", + file: "bytes16", + funcSelectorAndArgs: "bytes" +} as const + +const scopedDurationSchema = { + scope: "bytes32", + value: "uint48" +} as const + +const enumPStat = ["STRENGTH", "ARCANA", "DEXTERITY"] +const arrayPStat = `uint32[${enumPStat.length}]` as const + +const enumEleStat = ["NONE", "PHYSICAL", "FIRE", "COLD", "POISON"] +const arrayEleStat = `uint32[${enumEleStat.length}]` as const + +const keysWithValue = (tableNames: string[]) => tableNames.map(tableName => ({ + name: "KeysWithValueModule", + root: true, + args: [resolveTableId(tableName)], +})) + +export default mudConfig({ + tables: { + KeyValueIndex: { + directory: "../modules/keyvalueindex/tables", + primaryKeys: { + keyValueHash: "bytes32", + }, + schema: { + indexedKeys: "bytes32[]", + }, + storeArgument: true, + tableIdArgument: true, + }, + + Name: { + ...entityKey, + schema: "string", + }, + FromPrototype: entityRelation, + OwnedBy: entityRelation, + FromMetaEntity: entityRelation, + + AffixAvailable: { + primaryKeys: { + affixPart: "AffixPartId", + targetEntity: EntityId, + ilvl: "uint32", + }, + schema: "uint256[]", + }, + AffixNaming: { + primaryKeys: { + affixPart: "AffixPartId", + targetEntity: EntityId, + protoEntity: EntityId, + }, + schema: "string", + }, + AffixPrototype: { + ...entityKey, + schema: { + statmodProtoEntity: EntityId, + tier: "uint32", + requiredLevel: "uint32", + min: "uint32", + max: "uint32", + }, + }, + AffixProtoIndex: { + primaryKeys: { + nameHash: "bytes32", + tier: "uint32", + }, + schema: EntityId, + }, + AffixProtoGroup: { + primaryKeys: { + nameHash: "bytes32", + }, + schema: EntityId, + }, + Affix: { + ...entityKey, + schema: { + partId: "AffixPartId", + protoEntity: EntityId, + value: "uint32" + } + }, + + Experience: { + ...entityKey, + schema: arrayPStat + }, + LifeCurrent: { + ...entityKey, + schema: "uint32", + }, + ManaCurrent: { + ...entityKey, + schema: "uint32", + }, + + // initiatorEntity => retaliatorEntity + // An entity can initiate only 1 combat at a time + ActiveCombat: entityRelation, + + BossesDefeated: { + ...entityKey, + schema: "uint256[]", + }, + CycleCombatRReq: { + primaryKeys: { + requestId: "bytes32" + }, + schema: { + mapEntity: EntityId, + connection: "uint32", + fortune: "uint32", + winnerPStats: arrayPStat, + loserPStats: arrayPStat + } + }, + CurrentCycle: entityRelation, + PreviousCycle: entityRelation, + CycleTurns: { + ...entityKey, + schema: "uint32", + }, + CycleTurnsLastClaimed: { + ...entityKey, + schema: "uint48", + }, + + DurationScope: { + primaryKeys: { + targetEntity: EntityId, + baseEntity: EntityId, + }, + schema: "bytes32" + }, + DurationValue: { + primaryKeys: { + targetEntity: EntityId, + baseEntity: EntityId, + }, + schema: "uint48" + }, + DurationOnEnd: { + ...entityKey, + schema: systemCallbackSchema + }, + + EffectTemplate: { + ...entityKey, + schema: { + entities: EntityIdArray, + values: "uint32[]", + } + }, + EffectRemovability: { + ...entityKey, + schema: "EffectRemovabilityId", + }, + EffectDuration: { + ...entityKey, + schema: scopedDurationSchema + }, + EffectApplied: { + primaryKeys: { + targetEntity: EntityId, + sourceEntity: EntityId, + }, + schema: { + entities: EntityIdArray, + values: "uint32[]", + } + }, + + EqptBase: { + ...entityKey, + schema: "bytes32" + }, + FromEqptBase: entityRelation, + SlotAllowedBases: { + ...entityKey, + // set of base equipment entities + schema: EntityIdSet + }, + SlotEquipment: { + ...entityKey, + // equipment entity (not base) + schema: EntityId + }, + + ActiveGuise: entityRelation, + ExpGainMul: { + ...entityKey, + schema: arrayPStat + }, + AvailableSkills: { + ...entityKey, + schema: EntityIdSet + }, + + LootAffixes: { + ...entityKey, + // affix entities + schema: EntityIdArray + }, + LootIlvl: { + ...entityKey, + schema: "uint32" + }, + + MapBase: { + ...entityKey, + schema: "bytes32", + }, + FromMapBase: entityRelation, + + RNGPrecommit: { + ...entityKey, + schema: "uint256", + }, + // requestId => ownerEntity + RNGRequestOwner: entityRelation, + + LearnedSkills: { + ...entityKey, + schema: EntityIdSet + }, + SkillDescription: { + ...entityKey, + schema: "string" + }, + SkillCooldown: { + ...entityKey, + schema: scopedDurationSchema + }, + ManaCost: { + ...entityKey, + schema: arrayEleStat + }, + SpellDamage: { + ...entityKey, + schema: arrayEleStat + }, + // most skill entities also have EffectTemplate for the effect triggered by skill use + SkillTemplate: { + ...entityKey, + schema: { + // level required to learn it + requiredLevel: "uint8", + // when/how it can be used + skillType: "SkillType", + // flag to also trigger an attack afterwards (base attack damage is not based on the skill) + withAttack: "bool", + // flag to also trigger a spell afterwards (`SpellDamage` is used for base damage) + withSpell: "bool", + // mana cost to be subtracted on use + cost: "uint32", + // who it can be used on + targetType: "TargetType" + } + }, + + StatmodBase: { + ...entityKey, + schema: "bytes32", + }, + FromStatmodBase: entityRelation, + StatmodBaseOpts: { + ...entityKey, + schema: { + statmodOp: "StatmodOp", + eleStat: "EleStat", + } + }, + StatmodScope: { + primaryKeys: { + targetEntity: EntityId, + baseEntity: EntityId, + }, + schema: "bytes32" + }, + StatmodValue: { + primaryKeys: { + targetEntity: EntityId, + baseEntity: EntityId, + }, + schema: "uint32" + }, + + // TODO implement a proper ERC721 + WNFTOwnership: { + primaryKeys: { + tokenId: "uint256" + }, + schema: "address" + }, + + Identity: { + ...entityKey, + schema: "uint32" + }, + Wanderer: { + ...entityKey, + schema: "bool" + }, + + ActiveWheel: entityRelation, + DefaultWheel: { + primaryKeys: {}, + schema: EntityId + }, + Wheel: { + ...entityKey, + schema: { + totalIdentityRequired: "uint32", + charges: "uint32", + isIsolated: "bool" + } + }, + WheelsCompleted: { + primaryKeys: { + wandererEntity: EntityId, + wheelEntity: EntityId + }, + schema: "uint32" + } + }, + + enums: { + AffixPartId: ["IMPLICIT", "PREFIX", "SUFFIX"], + EffectRemovabilityId: ["BUFF", "DEBUFF", "PERSISTENT"], + PStat: enumPStat, + EleStat: enumEleStat, + SkillType: ["COMBAT", "NONCOMBAT", "PASSIVE"], + TargetType: ["SELF", "ENEMY", "ALLY", "SELF_OR_ALLY"], + StatmodOp: ["ADD", "MUL", "BADD"], + }, + + modules: [...keysWithValue(["DurationScope", "StatmodScope"])], +}) \ No newline at end of file diff --git a/packages/contracts/package.json b/packages/contracts/package.json index 18e87843..1e7e7a90 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -4,12 +4,12 @@ "private": true, "license": "MIT", "scripts": { - "prepare": "yarn codegen && mud types", "devnode": "rm -rf ~/.foundry/anvil/tmp && rm -rf broadcast && anvil --block-base-fee-per-gas 0", "test": "yarn codegen && cross-env FOUNDRY_PROFILE=test mud test", "types": "yarn codegen && mud types", "dev": "yarn codegen && mud deploy-contracts --dev", - "codegen": "ts-node ./scripts/codegen.ts" + "codegen": "ts-node ./scripts/codegen.ts", + "tablegen": "mud tablegen" }, "files": [ "/**/*.sol", @@ -19,7 +19,10 @@ "@ethersproject/bytes": "^5.7.0", "@ethersproject/hash": "^5.7.0", "@ethersproject/strings": "^5.7.0", - "@latticexyz/cli": "https://gitpkg.now.sh/dk1a/mud/packages/cli?b102cd16ac81233df9c90e86797f551dae7ab2eb", + "@latticexyz/cli": "2.0.0-alpha.1.33", + "@latticexyz/config": "2.0.0-alpha.1.33", + "@latticexyz/store": "2.0.0-alpha.1.33", + "@latticexyz/world": "2.0.0-alpha.1.33", "@prb/test": "^0.4.0", "@solidity-parser/parser": "^0.14.5", "@typechain/ethers-v5": "^10.1.1", @@ -30,18 +33,9 @@ "ejs": "^3.1.8", "forge-std": "github:foundry-rs/forge-std", "glob": "^8.0.3", - "hardhat": "^2.12.2", - "hardhat-preprocessor": "^0.1.5", - "memmove": "github:brockelmore/memmove", "prettier-plugin-solidity": "^1.1.2", "ts-node": "^10.9.1", "typechain": "^8.1.1", "typescript": "^4.9.5" - }, - "dependencies": { - "@dk1a/solecslib": "^0.4.2", - "@dk1a/solidity-stringutils": "^0.3.3", - "@latticexyz/solecs": "https://gitpkg.now.sh/dk1a/mud/packages/solecs?b102cd16ac81233df9c90e86797f551dae7ab2eb", - "@latticexyz/std-contracts": "^1.39.0" } } diff --git a/packages/contracts/script/PostDeploy.s.sol b/packages/contracts/script/PostDeploy.s.sol new file mode 100644 index 00000000..73352976 --- /dev/null +++ b/packages/contracts/script/PostDeploy.s.sol @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.17; + +import { Script } from "forge-std/Script.sol"; +import { IWorld } from "../src/codegen/world/IWorld.sol"; + +contract PostDeploy is Script { + function run(address worldAddress) external { + // Load the private key from the `PRIVATE_KEY` environment variable (in .env) + uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY"); + + // Start broadcasting transactions from the deployer account + vm.startBroadcast(deployerPrivateKey); + + // ------------------ EXAMPLES ------------------ + + // Call increment on the world via the registered function selector + uint32 newValue = IWorld(worldAddress).increment(); + console.log("Increment via IWorld:", newValue); + + vm.stopBroadcast(); + } +} \ No newline at end of file diff --git a/packages/contracts/src/AbstractComponent.sol b/packages/contracts/src/AbstractComponent.sol deleted file mode 100644 index 7e6cef12..00000000 --- a/packages/contracts/src/AbstractComponent.sol +++ /dev/null @@ -1,90 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { IComponent } from "solecs/interfaces/IComponent.sol"; - -/** - * Components are a key-value store from entity id to component value. - * They are registered in the World and register updates to their state in the World. - * They have an owner, who can grant write access to more addresses. - * (Systems that want to write to a component need to be given write access first.) - * Everyone has read access. - */ -abstract contract AbstractComponent is IComponent { - /** Reference to the World contract this component is registered in */ - address public world; - - /** Owner of the component has write access and can given write access to other addresses */ - address internal _owner; - - /** Addresses with write access to this component */ - mapping(address => bool) public writeAccess; - - /** Public identifier of this component */ - uint256 public id; - - constructor(address _world, uint256 _id) { - _owner = msg.sender; - writeAccess[msg.sender] = true; - id = _id; - if (_world != address(0)) registerWorld(_world); - } - - /** Revert if caller is not the owner of this component */ - modifier onlyOwner() { - require(msg.sender == _owner, "ONLY_OWNER"); - _; - } - - /** Revert if caller does not have write access to this component */ - modifier onlyWriter() { - require(writeAccess[msg.sender], "ONLY_WRITER"); - _; - } - - /** Get the owner of this component */ - function owner() public view override returns (address) { - return _owner; - } - - /** - * Transfer ownership of this component to a new owner. - * Can only be called by the current owner. - * @param newOwner Address of the new owner. - */ - function transferOwnership(address newOwner) public override onlyOwner { - //emit OwnershipTransferred(_owner, newOwner); - writeAccess[msg.sender] = false; - _owner = newOwner; - writeAccess[newOwner] = true; - } - - /** - * Register this component in the given world. - * @param _world Address of the World contract. - */ - function registerWorld(address _world) public onlyOwner { - world = _world; - IWorld(world).registerComponent(address(this), id); - } - - /** - * Grant write access to this component to the given address. - * Can only be called by the owner of this component. - * @param writer Address to grant write access to. - */ - function authorizeWriter(address writer) public override onlyOwner { - writeAccess[writer] = true; - } - - /** - * Revoke write access to this component to the given address. - * Can only be called by the owner of this component. - * @param writer Address to revoke write access . - */ - function unauthorizeWriter(address writer) public override onlyOwner { - delete writeAccess[writer]; - } -} diff --git a/packages/contracts/src/MapSetBatchable.sol b/packages/contracts/src/MapSetBatchable.sol deleted file mode 100644 index 165541cf..00000000 --- a/packages/contracts/src/MapSetBatchable.sol +++ /dev/null @@ -1,78 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -contract MapSetBatchable { - address private owner; - mapping(uint256 => uint256[]) private items; - mapping(uint256 => mapping(uint256 => uint256)) private itemToIndex; - - constructor() { - owner = msg.sender; - } - - modifier onlyOwner() { - require(msg.sender == owner, "ONLY_OWNER"); - _; - } - - function add(uint256 setKey, uint256 item) public onlyOwner { - if (has(setKey, item)) return; - - itemToIndex[setKey][item] = items[setKey].length; - items[setKey].push(item); - } - - function remove(uint256 setKey, uint256 item) public onlyOwner { - if (!has(setKey, item)) return; - - // Copy the last item to the given item's index - items[setKey][itemToIndex[setKey][item]] = items[setKey][items[setKey].length - 1]; - - // Update the moved item's stored index to the new index - itemToIndex[setKey][items[setKey][itemToIndex[setKey][item]]] = itemToIndex[setKey][item]; - - // Remove the given item's stored index - delete itemToIndex[setKey][item]; - - // Remove the last item - items[setKey].pop(); - } - - function removeAll(uint256 setKey) public onlyOwner { - if (size(setKey) == 0) return; - - uint256 length = items[setKey].length; - for (uint256 i; i < length; i++) { - // Remove each item's stored index - delete itemToIndex[setKey][items[setKey][i]]; - } - - // Remove the list of items - delete items[setKey]; - } - - function replaceAll(uint256 setKey, uint256[] calldata _items) public onlyOwner { - removeAll(setKey); - - items[setKey] = _items; - - for (uint256 i; i < _items.length; i++) { - itemToIndex[setKey][_items[i]] = i; - } - } - - function has(uint256 setKey, uint256 item) public view returns (bool) { - if (items[setKey].length == 0) return false; - if (itemToIndex[setKey][item] == 0) return items[setKey][0] == item; - return itemToIndex[setKey][item] != 0; - } - - function getItems(uint256 setKey) public view returns (uint256[] memory) { - return items[setKey]; - } - - function size(uint256 setKey) public view returns (uint256) { - return items[setKey].length; - } -} diff --git a/packages/contracts/src/codegen/Tables.sol b/packages/contracts/src/codegen/Tables.sol new file mode 100644 index 00000000..bfdba265 --- /dev/null +++ b/packages/contracts/src/codegen/Tables.sol @@ -0,0 +1,64 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +import { KeyValueIndex } from "./../modules/keyvalueindex/tables/KeyValueIndex.sol"; +import { Name, NameTableId } from "./tables/Name.sol"; +import { FromPrototype, FromPrototypeTableId } from "./tables/FromPrototype.sol"; +import { OwnedBy, OwnedByTableId } from "./tables/OwnedBy.sol"; +import { FromMetaEntity, FromMetaEntityTableId } from "./tables/FromMetaEntity.sol"; +import { AffixAvailable, AffixAvailableTableId } from "./tables/AffixAvailable.sol"; +import { AffixNaming, AffixNamingTableId } from "./tables/AffixNaming.sol"; +import { AffixPrototype, AffixPrototypeData, AffixPrototypeTableId } from "./tables/AffixPrototype.sol"; +import { AffixProtoIndex, AffixProtoIndexTableId } from "./tables/AffixProtoIndex.sol"; +import { AffixProtoGroup, AffixProtoGroupTableId } from "./tables/AffixProtoGroup.sol"; +import { Affix, AffixData, AffixTableId } from "./tables/Affix.sol"; +import { Experience, ExperienceTableId } from "./tables/Experience.sol"; +import { LifeCurrent, LifeCurrentTableId } from "./tables/LifeCurrent.sol"; +import { ManaCurrent, ManaCurrentTableId } from "./tables/ManaCurrent.sol"; +import { ActiveCombat, ActiveCombatTableId } from "./tables/ActiveCombat.sol"; +import { BossesDefeated, BossesDefeatedTableId } from "./tables/BossesDefeated.sol"; +import { CycleCombatRReq, CycleCombatRReqData, CycleCombatRReqTableId } from "./tables/CycleCombatRReq.sol"; +import { CurrentCycle, CurrentCycleTableId } from "./tables/CurrentCycle.sol"; +import { PreviousCycle, PreviousCycleTableId } from "./tables/PreviousCycle.sol"; +import { CycleTurns, CycleTurnsTableId } from "./tables/CycleTurns.sol"; +import { CycleTurnsLastClaimed, CycleTurnsLastClaimedTableId } from "./tables/CycleTurnsLastClaimed.sol"; +import { DurationScope, DurationScopeTableId } from "./tables/DurationScope.sol"; +import { DurationValue, DurationValueTableId } from "./tables/DurationValue.sol"; +import { DurationOnEnd, DurationOnEndData, DurationOnEndTableId } from "./tables/DurationOnEnd.sol"; +import { EffectTemplate, EffectTemplateData, EffectTemplateTableId } from "./tables/EffectTemplate.sol"; +import { EffectRemovability, EffectRemovabilityTableId } from "./tables/EffectRemovability.sol"; +import { EffectDuration, EffectDurationData, EffectDurationTableId } from "./tables/EffectDuration.sol"; +import { EffectApplied, EffectAppliedData, EffectAppliedTableId } from "./tables/EffectApplied.sol"; +import { EqptBase, EqptBaseTableId } from "./tables/EqptBase.sol"; +import { FromEqptBase, FromEqptBaseTableId } from "./tables/FromEqptBase.sol"; +import { SlotAllowedBases, SlotAllowedBasesTableId } from "./tables/SlotAllowedBases.sol"; +import { SlotEquipment, SlotEquipmentTableId } from "./tables/SlotEquipment.sol"; +import { ActiveGuise, ActiveGuiseTableId } from "./tables/ActiveGuise.sol"; +import { ExpGainMul, ExpGainMulTableId } from "./tables/ExpGainMul.sol"; +import { AvailableSkills, AvailableSkillsTableId } from "./tables/AvailableSkills.sol"; +import { LootAffixes, LootAffixesTableId } from "./tables/LootAffixes.sol"; +import { LootIlvl, LootIlvlTableId } from "./tables/LootIlvl.sol"; +import { MapBase, MapBaseTableId } from "./tables/MapBase.sol"; +import { FromMapBase, FromMapBaseTableId } from "./tables/FromMapBase.sol"; +import { RNGPrecommit, RNGPrecommitTableId } from "./tables/RNGPrecommit.sol"; +import { RNGRequestOwner, RNGRequestOwnerTableId } from "./tables/RNGRequestOwner.sol"; +import { LearnedSkills, LearnedSkillsTableId } from "./tables/LearnedSkills.sol"; +import { SkillDescription, SkillDescriptionTableId } from "./tables/SkillDescription.sol"; +import { SkillCooldown, SkillCooldownData, SkillCooldownTableId } from "./tables/SkillCooldown.sol"; +import { ManaCost, ManaCostTableId } from "./tables/ManaCost.sol"; +import { SpellDamage, SpellDamageTableId } from "./tables/SpellDamage.sol"; +import { SkillTemplate, SkillTemplateData, SkillTemplateTableId } from "./tables/SkillTemplate.sol"; +import { StatmodBase, StatmodBaseTableId } from "./tables/StatmodBase.sol"; +import { FromStatmodBase, FromStatmodBaseTableId } from "./tables/FromStatmodBase.sol"; +import { StatmodBaseOpts, StatmodBaseOptsData, StatmodBaseOptsTableId } from "./tables/StatmodBaseOpts.sol"; +import { StatmodScope, StatmodScopeTableId } from "./tables/StatmodScope.sol"; +import { StatmodValue, StatmodValueTableId } from "./tables/StatmodValue.sol"; +import { WNFTOwnership, WNFTOwnershipTableId } from "./tables/WNFTOwnership.sol"; +import { Identity, IdentityTableId } from "./tables/Identity.sol"; +import { Wanderer, WandererTableId } from "./tables/Wanderer.sol"; +import { ActiveWheel, ActiveWheelTableId } from "./tables/ActiveWheel.sol"; +import { DefaultWheel, DefaultWheelTableId } from "./tables/DefaultWheel.sol"; +import { Wheel, WheelData, WheelTableId } from "./tables/Wheel.sol"; +import { WheelsCompleted, WheelsCompletedTableId } from "./tables/WheelsCompleted.sol"; diff --git a/packages/contracts/src/codegen/Types.sol b/packages/contracts/src/codegen/Types.sol new file mode 100644 index 00000000..81ea525d --- /dev/null +++ b/packages/contracts/src/codegen/Types.sol @@ -0,0 +1,49 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +enum AffixPartId { + IMPLICIT, + PREFIX, + SUFFIX +} + +enum EffectRemovabilityId { + BUFF, + DEBUFF, + PERSISTENT +} + +enum PStat { + STRENGTH, + ARCANA, + DEXTERITY +} + +enum EleStat { + NONE, + PHYSICAL, + FIRE, + COLD, + POISON +} + +enum SkillType { + COMBAT, + NONCOMBAT, + PASSIVE +} + +enum TargetType { + SELF, + ENEMY, + ALLY, + SELF_OR_ALLY +} + +enum StatmodOp { + ADD, + MUL, + BADD +} diff --git a/packages/contracts/src/codegen/tables/ActiveCombat.sol b/packages/contracts/src/codegen/tables/ActiveCombat.sol new file mode 100644 index 00000000..cbf57649 --- /dev/null +++ b/packages/contracts/src/codegen/tables/ActiveCombat.sol @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("ActiveCombat"))); +bytes32 constant ActiveCombatTableId = _tableId; + +library ActiveCombat { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("ActiveCombat", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (uint256 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (uint256 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Set value */ + function set(uint256 entity, uint256 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, uint256 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint256 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/ActiveGuise.sol b/packages/contracts/src/codegen/tables/ActiveGuise.sol new file mode 100644 index 00000000..93645bfe --- /dev/null +++ b/packages/contracts/src/codegen/tables/ActiveGuise.sol @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("ActiveGuise"))); +bytes32 constant ActiveGuiseTableId = _tableId; + +library ActiveGuise { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("ActiveGuise", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (uint256 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (uint256 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Set value */ + function set(uint256 entity, uint256 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, uint256 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint256 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/ActiveWheel.sol b/packages/contracts/src/codegen/tables/ActiveWheel.sol new file mode 100644 index 00000000..293b1c30 --- /dev/null +++ b/packages/contracts/src/codegen/tables/ActiveWheel.sol @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("ActiveWheel"))); +bytes32 constant ActiveWheelTableId = _tableId; + +library ActiveWheel { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("ActiveWheel", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (uint256 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (uint256 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Set value */ + function set(uint256 entity, uint256 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, uint256 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint256 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/Affix.sol b/packages/contracts/src/codegen/tables/Affix.sol new file mode 100644 index 00000000..c9774338 --- /dev/null +++ b/packages/contracts/src/codegen/tables/Affix.sol @@ -0,0 +1,260 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +// Import user types +import { AffixPartId } from "./../Types.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("Affix"))); +bytes32 constant AffixTableId = _tableId; + +struct AffixData { + AffixPartId partId; + uint256 protoEntity; + uint32 value; +} + +library Affix { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](3); + _schema[0] = SchemaType.UINT8; + _schema[1] = SchemaType.UINT256; + _schema[2] = SchemaType.UINT32; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](3); + _fieldNames[0] = "partId"; + _fieldNames[1] = "protoEntity"; + _fieldNames[2] = "value"; + return ("Affix", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get partId */ + function getPartId(uint256 entity) internal view returns (AffixPartId partId) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return AffixPartId(uint8(Bytes.slice1(_blob, 0))); + } + + /** Get partId (using the specified store) */ + function getPartId(IStore _store, uint256 entity) internal view returns (AffixPartId partId) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return AffixPartId(uint8(Bytes.slice1(_blob, 0))); + } + + /** Set partId */ + function setPartId(uint256 entity, AffixPartId partId) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked(uint8(partId))); + } + + /** Set partId (using the specified store) */ + function setPartId(IStore _store, uint256 entity, AffixPartId partId) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked(uint8(partId))); + } + + /** Get protoEntity */ + function getProtoEntity(uint256 entity) internal view returns (uint256 protoEntity) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 1); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Get protoEntity (using the specified store) */ + function getProtoEntity(IStore _store, uint256 entity) internal view returns (uint256 protoEntity) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 1); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Set protoEntity */ + function setProtoEntity(uint256 entity, uint256 protoEntity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 1, abi.encodePacked((protoEntity))); + } + + /** Set protoEntity (using the specified store) */ + function setProtoEntity(IStore _store, uint256 entity, uint256 protoEntity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 1, abi.encodePacked((protoEntity))); + } + + /** Get value */ + function getValue(uint256 entity) internal view returns (uint32 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 2); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Get value (using the specified store) */ + function getValue(IStore _store, uint256 entity) internal view returns (uint32 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 2); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Set value */ + function setValue(uint256 entity, uint32 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 2, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function setValue(IStore _store, uint256 entity, uint32 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 2, abi.encodePacked((value))); + } + + /** Get the full data */ + function get(uint256 entity) internal view returns (AffixData memory _table) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getRecord(_tableId, _primaryKeys, getSchema()); + return decode(_blob); + } + + /** Get the full data (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (AffixData memory _table) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getRecord(_tableId, _primaryKeys, getSchema()); + return decode(_blob); + } + + /** Set the full data using individual values */ + function set(uint256 entity, AffixPartId partId, uint256 protoEntity, uint32 value) internal { + bytes memory _data = encode(partId, protoEntity, value); + + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setRecord(_tableId, _primaryKeys, _data); + } + + /** Set the full data using individual values (using the specified store) */ + function set(IStore _store, uint256 entity, AffixPartId partId, uint256 protoEntity, uint32 value) internal { + bytes memory _data = encode(partId, protoEntity, value); + + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setRecord(_tableId, _primaryKeys, _data); + } + + /** Set the full data using the data struct */ + function set(uint256 entity, AffixData memory _table) internal { + set(entity, _table.partId, _table.protoEntity, _table.value); + } + + /** Set the full data using the data struct (using the specified store) */ + function set(IStore _store, uint256 entity, AffixData memory _table) internal { + set(_store, entity, _table.partId, _table.protoEntity, _table.value); + } + + /** Decode the tightly packed blob using this table's schema */ + function decode(bytes memory _blob) internal pure returns (AffixData memory _table) { + _table.partId = AffixPartId(uint8(Bytes.slice1(_blob, 0))); + + _table.protoEntity = (uint256(Bytes.slice32(_blob, 1))); + + _table.value = (uint32(Bytes.slice4(_blob, 33))); + } + + /** Tightly pack full data using this table's schema */ + function encode(AffixPartId partId, uint256 protoEntity, uint32 value) internal view returns (bytes memory) { + return abi.encodePacked(partId, protoEntity, value); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/AffixAvailable.sol b/packages/contracts/src/codegen/tables/AffixAvailable.sol new file mode 100644 index 00000000..08ea57f2 --- /dev/null +++ b/packages/contracts/src/codegen/tables/AffixAvailable.sol @@ -0,0 +1,205 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +// Import user types +import { AffixPartId } from "./../Types.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("AffixAvailable"))); +bytes32 constant AffixAvailableTableId = _tableId; + +library AffixAvailable { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256_ARRAY; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](3); + _schema[0] = SchemaType.UINT8; + _schema[1] = SchemaType.UINT256; + _schema[2] = SchemaType.UINT32; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("AffixAvailable", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get( + AffixPartId affixPart, + uint256 targetEntity, + uint32 ilvl + ) internal view returns (uint256[] memory value) { + bytes32[] memory _primaryKeys = new bytes32[](3); + _primaryKeys[0] = bytes32(uint256(uint8(affixPart))); + _primaryKeys[1] = bytes32(uint256((targetEntity))); + _primaryKeys[2] = bytes32(uint256((ilvl))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint256()); + } + + /** Get value (using the specified store) */ + function get( + IStore _store, + AffixPartId affixPart, + uint256 targetEntity, + uint32 ilvl + ) internal view returns (uint256[] memory value) { + bytes32[] memory _primaryKeys = new bytes32[](3); + _primaryKeys[0] = bytes32(uint256(uint8(affixPart))); + _primaryKeys[1] = bytes32(uint256((targetEntity))); + _primaryKeys[2] = bytes32(uint256((ilvl))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint256()); + } + + /** Set value */ + function set(AffixPartId affixPart, uint256 targetEntity, uint32 ilvl, uint256[] memory value) internal { + bytes32[] memory _primaryKeys = new bytes32[](3); + _primaryKeys[0] = bytes32(uint256(uint8(affixPart))); + _primaryKeys[1] = bytes32(uint256((targetEntity))); + _primaryKeys[2] = bytes32(uint256((ilvl))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, EncodeArray.encode((value))); + } + + /** Set value (using the specified store) */ + function set( + IStore _store, + AffixPartId affixPart, + uint256 targetEntity, + uint32 ilvl, + uint256[] memory value + ) internal { + bytes32[] memory _primaryKeys = new bytes32[](3); + _primaryKeys[0] = bytes32(uint256(uint8(affixPart))); + _primaryKeys[1] = bytes32(uint256((targetEntity))); + _primaryKeys[2] = bytes32(uint256((ilvl))); + + _store.setField(_tableId, _primaryKeys, 0, EncodeArray.encode((value))); + } + + /** Push an element to value */ + function push(AffixPartId affixPart, uint256 targetEntity, uint32 ilvl, uint256 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](3); + _primaryKeys[0] = bytes32(uint256(uint8(affixPart))); + _primaryKeys[1] = bytes32(uint256((targetEntity))); + _primaryKeys[2] = bytes32(uint256((ilvl))); + + StoreSwitch.pushToField(_tableId, _primaryKeys, 0, abi.encodePacked((_element))); + } + + /** Push an element to value (using the specified store) */ + function push(IStore _store, AffixPartId affixPart, uint256 targetEntity, uint32 ilvl, uint256 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](3); + _primaryKeys[0] = bytes32(uint256(uint8(affixPart))); + _primaryKeys[1] = bytes32(uint256((targetEntity))); + _primaryKeys[2] = bytes32(uint256((ilvl))); + + _store.pushToField(_tableId, _primaryKeys, 0, abi.encodePacked((_element))); + } + + /** Update an element of value at `_index` */ + function update(AffixPartId affixPart, uint256 targetEntity, uint32 ilvl, uint256 _index, uint256 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](3); + _primaryKeys[0] = bytes32(uint256(uint8(affixPart))); + _primaryKeys[1] = bytes32(uint256((targetEntity))); + _primaryKeys[2] = bytes32(uint256((ilvl))); + + StoreSwitch.updateInField(_tableId, _primaryKeys, 0, _index * 32, abi.encodePacked((_element))); + } + + /** Update an element of value (using the specified store) at `_index` */ + function update( + IStore _store, + AffixPartId affixPart, + uint256 targetEntity, + uint32 ilvl, + uint256 _index, + uint256 _element + ) internal { + bytes32[] memory _primaryKeys = new bytes32[](3); + _primaryKeys[0] = bytes32(uint256(uint8(affixPart))); + _primaryKeys[1] = bytes32(uint256((targetEntity))); + _primaryKeys[2] = bytes32(uint256((ilvl))); + + _store.updateInField(_tableId, _primaryKeys, 0, _index * 32, abi.encodePacked((_element))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint256[] memory value) internal view returns (bytes memory) { + uint16[] memory _counters = new uint16[](1); + _counters[0] = uint16(value.length * 32); + PackedCounter _encodedLengths = PackedCounterLib.pack(_counters); + + return abi.encodePacked(_encodedLengths.unwrap(), EncodeArray.encode((value))); + } + + /* Delete all data for given keys */ + function deleteRecord(AffixPartId affixPart, uint256 targetEntity, uint32 ilvl) internal { + bytes32[] memory _primaryKeys = new bytes32[](3); + _primaryKeys[0] = bytes32(uint256(uint8(affixPart))); + _primaryKeys[1] = bytes32(uint256((targetEntity))); + _primaryKeys[2] = bytes32(uint256((ilvl))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, AffixPartId affixPart, uint256 targetEntity, uint32 ilvl) internal { + bytes32[] memory _primaryKeys = new bytes32[](3); + _primaryKeys[0] = bytes32(uint256(uint8(affixPart))); + _primaryKeys[1] = bytes32(uint256((targetEntity))); + _primaryKeys[2] = bytes32(uint256((ilvl))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/AffixNaming.sol b/packages/contracts/src/codegen/tables/AffixNaming.sol new file mode 100644 index 00000000..a6abeb49 --- /dev/null +++ b/packages/contracts/src/codegen/tables/AffixNaming.sol @@ -0,0 +1,217 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +// Import user types +import { AffixPartId } from "./../Types.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("AffixNaming"))); +bytes32 constant AffixNamingTableId = _tableId; + +library AffixNaming { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.STRING; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](3); + _schema[0] = SchemaType.UINT8; + _schema[1] = SchemaType.UINT256; + _schema[2] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("AffixNaming", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get( + AffixPartId affixPart, + uint256 targetEntity, + uint256 protoEntity + ) internal view returns (string memory value) { + bytes32[] memory _primaryKeys = new bytes32[](3); + _primaryKeys[0] = bytes32(uint256(uint8(affixPart))); + _primaryKeys[1] = bytes32(uint256((targetEntity))); + _primaryKeys[2] = bytes32(uint256((protoEntity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (string(_blob)); + } + + /** Get value (using the specified store) */ + function get( + IStore _store, + AffixPartId affixPart, + uint256 targetEntity, + uint256 protoEntity + ) internal view returns (string memory value) { + bytes32[] memory _primaryKeys = new bytes32[](3); + _primaryKeys[0] = bytes32(uint256(uint8(affixPart))); + _primaryKeys[1] = bytes32(uint256((targetEntity))); + _primaryKeys[2] = bytes32(uint256((protoEntity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (string(_blob)); + } + + /** Set value */ + function set(AffixPartId affixPart, uint256 targetEntity, uint256 protoEntity, string memory value) internal { + bytes32[] memory _primaryKeys = new bytes32[](3); + _primaryKeys[0] = bytes32(uint256(uint8(affixPart))); + _primaryKeys[1] = bytes32(uint256((targetEntity))); + _primaryKeys[2] = bytes32(uint256((protoEntity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, bytes((value))); + } + + /** Set value (using the specified store) */ + function set( + IStore _store, + AffixPartId affixPart, + uint256 targetEntity, + uint256 protoEntity, + string memory value + ) internal { + bytes32[] memory _primaryKeys = new bytes32[](3); + _primaryKeys[0] = bytes32(uint256(uint8(affixPart))); + _primaryKeys[1] = bytes32(uint256((targetEntity))); + _primaryKeys[2] = bytes32(uint256((protoEntity))); + + _store.setField(_tableId, _primaryKeys, 0, bytes((value))); + } + + /** Push a slice to value */ + function push(AffixPartId affixPart, uint256 targetEntity, uint256 protoEntity, string memory _slice) internal { + bytes32[] memory _primaryKeys = new bytes32[](3); + _primaryKeys[0] = bytes32(uint256(uint8(affixPart))); + _primaryKeys[1] = bytes32(uint256((targetEntity))); + _primaryKeys[2] = bytes32(uint256((protoEntity))); + + StoreSwitch.pushToField(_tableId, _primaryKeys, 0, bytes((_slice))); + } + + /** Push a slice to value (using the specified store) */ + function push( + IStore _store, + AffixPartId affixPart, + uint256 targetEntity, + uint256 protoEntity, + string memory _slice + ) internal { + bytes32[] memory _primaryKeys = new bytes32[](3); + _primaryKeys[0] = bytes32(uint256(uint8(affixPart))); + _primaryKeys[1] = bytes32(uint256((targetEntity))); + _primaryKeys[2] = bytes32(uint256((protoEntity))); + + _store.pushToField(_tableId, _primaryKeys, 0, bytes((_slice))); + } + + /** Update a slice of value at `_index` */ + function update( + AffixPartId affixPart, + uint256 targetEntity, + uint256 protoEntity, + uint256 _index, + string memory _slice + ) internal { + bytes32[] memory _primaryKeys = new bytes32[](3); + _primaryKeys[0] = bytes32(uint256(uint8(affixPart))); + _primaryKeys[1] = bytes32(uint256((targetEntity))); + _primaryKeys[2] = bytes32(uint256((protoEntity))); + + StoreSwitch.updateInField(_tableId, _primaryKeys, 0, _index * 1, bytes((_slice))); + } + + /** Update a slice of value (using the specified store) at `_index` */ + function update( + IStore _store, + AffixPartId affixPart, + uint256 targetEntity, + uint256 protoEntity, + uint256 _index, + string memory _slice + ) internal { + bytes32[] memory _primaryKeys = new bytes32[](3); + _primaryKeys[0] = bytes32(uint256(uint8(affixPart))); + _primaryKeys[1] = bytes32(uint256((targetEntity))); + _primaryKeys[2] = bytes32(uint256((protoEntity))); + + _store.updateInField(_tableId, _primaryKeys, 0, _index * 1, bytes((_slice))); + } + + /** Tightly pack full data using this table's schema */ + function encode(string memory value) internal view returns (bytes memory) { + uint16[] memory _counters = new uint16[](1); + _counters[0] = uint16(bytes(value).length); + PackedCounter _encodedLengths = PackedCounterLib.pack(_counters); + + return abi.encodePacked(_encodedLengths.unwrap(), bytes((value))); + } + + /* Delete all data for given keys */ + function deleteRecord(AffixPartId affixPart, uint256 targetEntity, uint256 protoEntity) internal { + bytes32[] memory _primaryKeys = new bytes32[](3); + _primaryKeys[0] = bytes32(uint256(uint8(affixPart))); + _primaryKeys[1] = bytes32(uint256((targetEntity))); + _primaryKeys[2] = bytes32(uint256((protoEntity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, AffixPartId affixPart, uint256 targetEntity, uint256 protoEntity) internal { + bytes32[] memory _primaryKeys = new bytes32[](3); + _primaryKeys[0] = bytes32(uint256(uint8(affixPart))); + _primaryKeys[1] = bytes32(uint256((targetEntity))); + _primaryKeys[2] = bytes32(uint256((protoEntity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/AffixProtoGroup.sol b/packages/contracts/src/codegen/tables/AffixProtoGroup.sol new file mode 100644 index 00000000..b3968fad --- /dev/null +++ b/packages/contracts/src/codegen/tables/AffixProtoGroup.sol @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("AffixProtoGroup"))); +bytes32 constant AffixProtoGroupTableId = _tableId; + +library AffixProtoGroup { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.BYTES32; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("AffixProtoGroup", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(bytes32 nameHash) internal view returns (uint256 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((nameHash)); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Get value (using the specified store) */ + function get(IStore _store, bytes32 nameHash) internal view returns (uint256 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((nameHash)); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Set value */ + function set(bytes32 nameHash, uint256 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((nameHash)); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, bytes32 nameHash, uint256 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((nameHash)); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint256 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /* Delete all data for given keys */ + function deleteRecord(bytes32 nameHash) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((nameHash)); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, bytes32 nameHash) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((nameHash)); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/AffixProtoIndex.sol b/packages/contracts/src/codegen/tables/AffixProtoIndex.sol new file mode 100644 index 00000000..7b3b1d8f --- /dev/null +++ b/packages/contracts/src/codegen/tables/AffixProtoIndex.sol @@ -0,0 +1,129 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("AffixProtoIndex"))); +bytes32 constant AffixProtoIndexTableId = _tableId; + +library AffixProtoIndex { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](2); + _schema[0] = SchemaType.BYTES32; + _schema[1] = SchemaType.UINT32; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("AffixProtoIndex", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(bytes32 nameHash, uint32 tier) internal view returns (uint256 value) { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32((nameHash)); + _primaryKeys[1] = bytes32(uint256((tier))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Get value (using the specified store) */ + function get(IStore _store, bytes32 nameHash, uint32 tier) internal view returns (uint256 value) { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32((nameHash)); + _primaryKeys[1] = bytes32(uint256((tier))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Set value */ + function set(bytes32 nameHash, uint32 tier, uint256 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32((nameHash)); + _primaryKeys[1] = bytes32(uint256((tier))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, bytes32 nameHash, uint32 tier, uint256 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32((nameHash)); + _primaryKeys[1] = bytes32(uint256((tier))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint256 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /* Delete all data for given keys */ + function deleteRecord(bytes32 nameHash, uint32 tier) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32((nameHash)); + _primaryKeys[1] = bytes32(uint256((tier))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, bytes32 nameHash, uint32 tier) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32((nameHash)); + _primaryKeys[1] = bytes32(uint256((tier))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/AffixPrototype.sol b/packages/contracts/src/codegen/tables/AffixPrototype.sol new file mode 100644 index 00000000..852452f4 --- /dev/null +++ b/packages/contracts/src/codegen/tables/AffixPrototype.sol @@ -0,0 +1,356 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("AffixPrototype"))); +bytes32 constant AffixPrototypeTableId = _tableId; + +struct AffixPrototypeData { + uint256 statmodProtoEntity; + uint32 tier; + uint32 requiredLevel; + uint32 min; + uint32 max; +} + +library AffixPrototype { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](5); + _schema[0] = SchemaType.UINT256; + _schema[1] = SchemaType.UINT32; + _schema[2] = SchemaType.UINT32; + _schema[3] = SchemaType.UINT32; + _schema[4] = SchemaType.UINT32; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](5); + _fieldNames[0] = "statmodProtoEntity"; + _fieldNames[1] = "tier"; + _fieldNames[2] = "requiredLevel"; + _fieldNames[3] = "min"; + _fieldNames[4] = "max"; + return ("AffixPrototype", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get statmodProtoEntity */ + function getStatmodProtoEntity(uint256 entity) internal view returns (uint256 statmodProtoEntity) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Get statmodProtoEntity (using the specified store) */ + function getStatmodProtoEntity(IStore _store, uint256 entity) internal view returns (uint256 statmodProtoEntity) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Set statmodProtoEntity */ + function setStatmodProtoEntity(uint256 entity, uint256 statmodProtoEntity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((statmodProtoEntity))); + } + + /** Set statmodProtoEntity (using the specified store) */ + function setStatmodProtoEntity(IStore _store, uint256 entity, uint256 statmodProtoEntity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((statmodProtoEntity))); + } + + /** Get tier */ + function getTier(uint256 entity) internal view returns (uint32 tier) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 1); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Get tier (using the specified store) */ + function getTier(IStore _store, uint256 entity) internal view returns (uint32 tier) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 1); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Set tier */ + function setTier(uint256 entity, uint32 tier) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 1, abi.encodePacked((tier))); + } + + /** Set tier (using the specified store) */ + function setTier(IStore _store, uint256 entity, uint32 tier) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 1, abi.encodePacked((tier))); + } + + /** Get requiredLevel */ + function getRequiredLevel(uint256 entity) internal view returns (uint32 requiredLevel) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 2); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Get requiredLevel (using the specified store) */ + function getRequiredLevel(IStore _store, uint256 entity) internal view returns (uint32 requiredLevel) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 2); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Set requiredLevel */ + function setRequiredLevel(uint256 entity, uint32 requiredLevel) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 2, abi.encodePacked((requiredLevel))); + } + + /** Set requiredLevel (using the specified store) */ + function setRequiredLevel(IStore _store, uint256 entity, uint32 requiredLevel) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 2, abi.encodePacked((requiredLevel))); + } + + /** Get min */ + function getMin(uint256 entity) internal view returns (uint32 min) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 3); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Get min (using the specified store) */ + function getMin(IStore _store, uint256 entity) internal view returns (uint32 min) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 3); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Set min */ + function setMin(uint256 entity, uint32 min) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 3, abi.encodePacked((min))); + } + + /** Set min (using the specified store) */ + function setMin(IStore _store, uint256 entity, uint32 min) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 3, abi.encodePacked((min))); + } + + /** Get max */ + function getMax(uint256 entity) internal view returns (uint32 max) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 4); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Get max (using the specified store) */ + function getMax(IStore _store, uint256 entity) internal view returns (uint32 max) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 4); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Set max */ + function setMax(uint256 entity, uint32 max) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 4, abi.encodePacked((max))); + } + + /** Set max (using the specified store) */ + function setMax(IStore _store, uint256 entity, uint32 max) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 4, abi.encodePacked((max))); + } + + /** Get the full data */ + function get(uint256 entity) internal view returns (AffixPrototypeData memory _table) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getRecord(_tableId, _primaryKeys, getSchema()); + return decode(_blob); + } + + /** Get the full data (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (AffixPrototypeData memory _table) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getRecord(_tableId, _primaryKeys, getSchema()); + return decode(_blob); + } + + /** Set the full data using individual values */ + function set( + uint256 entity, + uint256 statmodProtoEntity, + uint32 tier, + uint32 requiredLevel, + uint32 min, + uint32 max + ) internal { + bytes memory _data = encode(statmodProtoEntity, tier, requiredLevel, min, max); + + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setRecord(_tableId, _primaryKeys, _data); + } + + /** Set the full data using individual values (using the specified store) */ + function set( + IStore _store, + uint256 entity, + uint256 statmodProtoEntity, + uint32 tier, + uint32 requiredLevel, + uint32 min, + uint32 max + ) internal { + bytes memory _data = encode(statmodProtoEntity, tier, requiredLevel, min, max); + + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setRecord(_tableId, _primaryKeys, _data); + } + + /** Set the full data using the data struct */ + function set(uint256 entity, AffixPrototypeData memory _table) internal { + set(entity, _table.statmodProtoEntity, _table.tier, _table.requiredLevel, _table.min, _table.max); + } + + /** Set the full data using the data struct (using the specified store) */ + function set(IStore _store, uint256 entity, AffixPrototypeData memory _table) internal { + set(_store, entity, _table.statmodProtoEntity, _table.tier, _table.requiredLevel, _table.min, _table.max); + } + + /** Decode the tightly packed blob using this table's schema */ + function decode(bytes memory _blob) internal pure returns (AffixPrototypeData memory _table) { + _table.statmodProtoEntity = (uint256(Bytes.slice32(_blob, 0))); + + _table.tier = (uint32(Bytes.slice4(_blob, 32))); + + _table.requiredLevel = (uint32(Bytes.slice4(_blob, 36))); + + _table.min = (uint32(Bytes.slice4(_blob, 40))); + + _table.max = (uint32(Bytes.slice4(_blob, 44))); + } + + /** Tightly pack full data using this table's schema */ + function encode( + uint256 statmodProtoEntity, + uint32 tier, + uint32 requiredLevel, + uint32 min, + uint32 max + ) internal view returns (bytes memory) { + return abi.encodePacked(statmodProtoEntity, tier, requiredLevel, min, max); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/AvailableSkills.sol b/packages/contracts/src/codegen/tables/AvailableSkills.sol new file mode 100644 index 00000000..686c6738 --- /dev/null +++ b/packages/contracts/src/codegen/tables/AvailableSkills.sol @@ -0,0 +1,158 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("AvailableSkills"))); +bytes32 constant AvailableSkillsTableId = _tableId; + +library AvailableSkills { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256_ARRAY; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("AvailableSkills", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (uint256[] memory value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint256()); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (uint256[] memory value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint256()); + } + + /** Set value */ + function set(uint256 entity, uint256[] memory value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, EncodeArray.encode((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, uint256[] memory value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, EncodeArray.encode((value))); + } + + /** Push an element to value */ + function push(uint256 entity, uint256 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.pushToField(_tableId, _primaryKeys, 0, abi.encodePacked((_element))); + } + + /** Push an element to value (using the specified store) */ + function push(IStore _store, uint256 entity, uint256 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.pushToField(_tableId, _primaryKeys, 0, abi.encodePacked((_element))); + } + + /** Update an element of value at `_index` */ + function update(uint256 entity, uint256 _index, uint256 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.updateInField(_tableId, _primaryKeys, 0, _index * 32, abi.encodePacked((_element))); + } + + /** Update an element of value (using the specified store) at `_index` */ + function update(IStore _store, uint256 entity, uint256 _index, uint256 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.updateInField(_tableId, _primaryKeys, 0, _index * 32, abi.encodePacked((_element))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint256[] memory value) internal view returns (bytes memory) { + uint16[] memory _counters = new uint16[](1); + _counters[0] = uint16(value.length * 32); + PackedCounter _encodedLengths = PackedCounterLib.pack(_counters); + + return abi.encodePacked(_encodedLengths.unwrap(), EncodeArray.encode((value))); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/BossesDefeated.sol b/packages/contracts/src/codegen/tables/BossesDefeated.sol new file mode 100644 index 00000000..5500ea98 --- /dev/null +++ b/packages/contracts/src/codegen/tables/BossesDefeated.sol @@ -0,0 +1,158 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("BossesDefeated"))); +bytes32 constant BossesDefeatedTableId = _tableId; + +library BossesDefeated { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256_ARRAY; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("BossesDefeated", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (uint256[] memory value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint256()); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (uint256[] memory value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint256()); + } + + /** Set value */ + function set(uint256 entity, uint256[] memory value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, EncodeArray.encode((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, uint256[] memory value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, EncodeArray.encode((value))); + } + + /** Push an element to value */ + function push(uint256 entity, uint256 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.pushToField(_tableId, _primaryKeys, 0, abi.encodePacked((_element))); + } + + /** Push an element to value (using the specified store) */ + function push(IStore _store, uint256 entity, uint256 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.pushToField(_tableId, _primaryKeys, 0, abi.encodePacked((_element))); + } + + /** Update an element of value at `_index` */ + function update(uint256 entity, uint256 _index, uint256 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.updateInField(_tableId, _primaryKeys, 0, _index * 32, abi.encodePacked((_element))); + } + + /** Update an element of value (using the specified store) at `_index` */ + function update(IStore _store, uint256 entity, uint256 _index, uint256 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.updateInField(_tableId, _primaryKeys, 0, _index * 32, abi.encodePacked((_element))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint256[] memory value) internal view returns (bytes memory) { + uint16[] memory _counters = new uint16[](1); + _counters[0] = uint16(value.length * 32); + PackedCounter _encodedLengths = PackedCounterLib.pack(_counters); + + return abi.encodePacked(_encodedLengths.unwrap(), EncodeArray.encode((value))); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/CurrentCycle.sol b/packages/contracts/src/codegen/tables/CurrentCycle.sol new file mode 100644 index 00000000..07271432 --- /dev/null +++ b/packages/contracts/src/codegen/tables/CurrentCycle.sol @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("CurrentCycle"))); +bytes32 constant CurrentCycleTableId = _tableId; + +library CurrentCycle { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("CurrentCycle", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (uint256 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (uint256 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Set value */ + function set(uint256 entity, uint256 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, uint256 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint256 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/CycleCombatRReq.sol b/packages/contracts/src/codegen/tables/CycleCombatRReq.sol new file mode 100644 index 00000000..5de8ecae --- /dev/null +++ b/packages/contracts/src/codegen/tables/CycleCombatRReq.sol @@ -0,0 +1,473 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("CycleCombatRReq"))); +bytes32 constant CycleCombatRReqTableId = _tableId; + +struct CycleCombatRReqData { + uint256 mapEntity; + uint32 connection; + uint32 fortune; + uint32[3] winnerPStats; + uint32[3] loserPStats; +} + +library CycleCombatRReq { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](5); + _schema[0] = SchemaType.UINT256; + _schema[1] = SchemaType.UINT32; + _schema[2] = SchemaType.UINT32; + _schema[3] = SchemaType.UINT32_ARRAY; + _schema[4] = SchemaType.UINT32_ARRAY; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.BYTES32; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](5); + _fieldNames[0] = "mapEntity"; + _fieldNames[1] = "connection"; + _fieldNames[2] = "fortune"; + _fieldNames[3] = "winnerPStats"; + _fieldNames[4] = "loserPStats"; + return ("CycleCombatRReq", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get mapEntity */ + function getMapEntity(bytes32 requestId) internal view returns (uint256 mapEntity) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((requestId)); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Get mapEntity (using the specified store) */ + function getMapEntity(IStore _store, bytes32 requestId) internal view returns (uint256 mapEntity) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((requestId)); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Set mapEntity */ + function setMapEntity(bytes32 requestId, uint256 mapEntity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((requestId)); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((mapEntity))); + } + + /** Set mapEntity (using the specified store) */ + function setMapEntity(IStore _store, bytes32 requestId, uint256 mapEntity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((requestId)); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((mapEntity))); + } + + /** Get connection */ + function getConnection(bytes32 requestId) internal view returns (uint32 connection) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((requestId)); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 1); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Get connection (using the specified store) */ + function getConnection(IStore _store, bytes32 requestId) internal view returns (uint32 connection) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((requestId)); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 1); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Set connection */ + function setConnection(bytes32 requestId, uint32 connection) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((requestId)); + + StoreSwitch.setField(_tableId, _primaryKeys, 1, abi.encodePacked((connection))); + } + + /** Set connection (using the specified store) */ + function setConnection(IStore _store, bytes32 requestId, uint32 connection) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((requestId)); + + _store.setField(_tableId, _primaryKeys, 1, abi.encodePacked((connection))); + } + + /** Get fortune */ + function getFortune(bytes32 requestId) internal view returns (uint32 fortune) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((requestId)); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 2); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Get fortune (using the specified store) */ + function getFortune(IStore _store, bytes32 requestId) internal view returns (uint32 fortune) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((requestId)); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 2); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Set fortune */ + function setFortune(bytes32 requestId, uint32 fortune) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((requestId)); + + StoreSwitch.setField(_tableId, _primaryKeys, 2, abi.encodePacked((fortune))); + } + + /** Set fortune (using the specified store) */ + function setFortune(IStore _store, bytes32 requestId, uint32 fortune) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((requestId)); + + _store.setField(_tableId, _primaryKeys, 2, abi.encodePacked((fortune))); + } + + /** Get winnerPStats */ + function getWinnerPStats(bytes32 requestId) internal view returns (uint32[3] memory winnerPStats) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((requestId)); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 3); + return toStaticArray_uint32_3(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); + } + + /** Get winnerPStats (using the specified store) */ + function getWinnerPStats(IStore _store, bytes32 requestId) internal view returns (uint32[3] memory winnerPStats) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((requestId)); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 3); + return toStaticArray_uint32_3(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); + } + + /** Set winnerPStats */ + function setWinnerPStats(bytes32 requestId, uint32[3] memory winnerPStats) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((requestId)); + + StoreSwitch.setField(_tableId, _primaryKeys, 3, EncodeArray.encode(fromStaticArray_uint32_3(winnerPStats))); + } + + /** Set winnerPStats (using the specified store) */ + function setWinnerPStats(IStore _store, bytes32 requestId, uint32[3] memory winnerPStats) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((requestId)); + + _store.setField(_tableId, _primaryKeys, 3, EncodeArray.encode(fromStaticArray_uint32_3(winnerPStats))); + } + + /** Push an element to winnerPStats */ + function pushWinnerPStats(bytes32 requestId, uint32 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((requestId)); + + StoreSwitch.pushToField(_tableId, _primaryKeys, 3, abi.encodePacked((_element))); + } + + /** Push an element to winnerPStats (using the specified store) */ + function pushWinnerPStats(IStore _store, bytes32 requestId, uint32 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((requestId)); + + _store.pushToField(_tableId, _primaryKeys, 3, abi.encodePacked((_element))); + } + + /** Update an element of winnerPStats at `_index` */ + function updateWinnerPStats(bytes32 requestId, uint256 _index, uint32 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((requestId)); + + StoreSwitch.updateInField(_tableId, _primaryKeys, 3, _index * 4, abi.encodePacked((_element))); + } + + /** Update an element of winnerPStats (using the specified store) at `_index` */ + function updateWinnerPStats(IStore _store, bytes32 requestId, uint256 _index, uint32 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((requestId)); + + _store.updateInField(_tableId, _primaryKeys, 3, _index * 4, abi.encodePacked((_element))); + } + + /** Get loserPStats */ + function getLoserPStats(bytes32 requestId) internal view returns (uint32[3] memory loserPStats) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((requestId)); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 4); + return toStaticArray_uint32_3(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); + } + + /** Get loserPStats (using the specified store) */ + function getLoserPStats(IStore _store, bytes32 requestId) internal view returns (uint32[3] memory loserPStats) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((requestId)); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 4); + return toStaticArray_uint32_3(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); + } + + /** Set loserPStats */ + function setLoserPStats(bytes32 requestId, uint32[3] memory loserPStats) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((requestId)); + + StoreSwitch.setField(_tableId, _primaryKeys, 4, EncodeArray.encode(fromStaticArray_uint32_3(loserPStats))); + } + + /** Set loserPStats (using the specified store) */ + function setLoserPStats(IStore _store, bytes32 requestId, uint32[3] memory loserPStats) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((requestId)); + + _store.setField(_tableId, _primaryKeys, 4, EncodeArray.encode(fromStaticArray_uint32_3(loserPStats))); + } + + /** Push an element to loserPStats */ + function pushLoserPStats(bytes32 requestId, uint32 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((requestId)); + + StoreSwitch.pushToField(_tableId, _primaryKeys, 4, abi.encodePacked((_element))); + } + + /** Push an element to loserPStats (using the specified store) */ + function pushLoserPStats(IStore _store, bytes32 requestId, uint32 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((requestId)); + + _store.pushToField(_tableId, _primaryKeys, 4, abi.encodePacked((_element))); + } + + /** Update an element of loserPStats at `_index` */ + function updateLoserPStats(bytes32 requestId, uint256 _index, uint32 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((requestId)); + + StoreSwitch.updateInField(_tableId, _primaryKeys, 4, _index * 4, abi.encodePacked((_element))); + } + + /** Update an element of loserPStats (using the specified store) at `_index` */ + function updateLoserPStats(IStore _store, bytes32 requestId, uint256 _index, uint32 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((requestId)); + + _store.updateInField(_tableId, _primaryKeys, 4, _index * 4, abi.encodePacked((_element))); + } + + /** Get the full data */ + function get(bytes32 requestId) internal view returns (CycleCombatRReqData memory _table) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((requestId)); + + bytes memory _blob = StoreSwitch.getRecord(_tableId, _primaryKeys, getSchema()); + return decode(_blob); + } + + /** Get the full data (using the specified store) */ + function get(IStore _store, bytes32 requestId) internal view returns (CycleCombatRReqData memory _table) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((requestId)); + + bytes memory _blob = _store.getRecord(_tableId, _primaryKeys, getSchema()); + return decode(_blob); + } + + /** Set the full data using individual values */ + function set( + bytes32 requestId, + uint256 mapEntity, + uint32 connection, + uint32 fortune, + uint32[3] memory winnerPStats, + uint32[3] memory loserPStats + ) internal { + bytes memory _data = encode(mapEntity, connection, fortune, winnerPStats, loserPStats); + + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((requestId)); + + StoreSwitch.setRecord(_tableId, _primaryKeys, _data); + } + + /** Set the full data using individual values (using the specified store) */ + function set( + IStore _store, + bytes32 requestId, + uint256 mapEntity, + uint32 connection, + uint32 fortune, + uint32[3] memory winnerPStats, + uint32[3] memory loserPStats + ) internal { + bytes memory _data = encode(mapEntity, connection, fortune, winnerPStats, loserPStats); + + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((requestId)); + + _store.setRecord(_tableId, _primaryKeys, _data); + } + + /** Set the full data using the data struct */ + function set(bytes32 requestId, CycleCombatRReqData memory _table) internal { + set(requestId, _table.mapEntity, _table.connection, _table.fortune, _table.winnerPStats, _table.loserPStats); + } + + /** Set the full data using the data struct (using the specified store) */ + function set(IStore _store, bytes32 requestId, CycleCombatRReqData memory _table) internal { + set( + _store, + requestId, + _table.mapEntity, + _table.connection, + _table.fortune, + _table.winnerPStats, + _table.loserPStats + ); + } + + /** Decode the tightly packed blob using this table's schema */ + function decode(bytes memory _blob) internal view returns (CycleCombatRReqData memory _table) { + // 40 is the total byte length of static data + PackedCounter _encodedLengths = PackedCounter.wrap(Bytes.slice32(_blob, 40)); + + _table.mapEntity = (uint256(Bytes.slice32(_blob, 0))); + + _table.connection = (uint32(Bytes.slice4(_blob, 32))); + + _table.fortune = (uint32(Bytes.slice4(_blob, 36))); + + // Store trims the blob if dynamic fields are all empty + if (_blob.length > 40) { + uint256 _start; + // skip static data length + dynamic lengths word + uint256 _end = 72; + + _start = _end; + _end += _encodedLengths.atIndex(0); + _table.winnerPStats = toStaticArray_uint32_3(SliceLib.getSubslice(_blob, _start, _end).decodeArray_uint32()); + + _start = _end; + _end += _encodedLengths.atIndex(1); + _table.loserPStats = toStaticArray_uint32_3(SliceLib.getSubslice(_blob, _start, _end).decodeArray_uint32()); + } + } + + /** Tightly pack full data using this table's schema */ + function encode( + uint256 mapEntity, + uint32 connection, + uint32 fortune, + uint32[3] memory winnerPStats, + uint32[3] memory loserPStats + ) internal view returns (bytes memory) { + uint16[] memory _counters = new uint16[](2); + _counters[0] = uint16(winnerPStats.length * 4); + _counters[1] = uint16(loserPStats.length * 4); + PackedCounter _encodedLengths = PackedCounterLib.pack(_counters); + + return + abi.encodePacked( + mapEntity, + connection, + fortune, + _encodedLengths.unwrap(), + EncodeArray.encode(fromStaticArray_uint32_3(winnerPStats)), + EncodeArray.encode(fromStaticArray_uint32_3(loserPStats)) + ); + } + + /* Delete all data for given keys */ + function deleteRecord(bytes32 requestId) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((requestId)); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, bytes32 requestId) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((requestId)); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} + +function toStaticArray_uint32_3(uint32[] memory _value) pure returns (uint32[3] memory _result) { + // in memory static arrays are just dynamic arrays without the length byte + assembly { + _result := add(_value, 0x20) + } +} + +function fromStaticArray_uint32_3(uint32[3] memory _value) view returns (uint32[] memory _result) { + _result = new uint32[](3); + uint256 fromPointer; + uint256 toPointer; + assembly { + fromPointer := _value + toPointer := add(_result, 0x20) + } + Memory.copy(fromPointer, toPointer, 96); +} diff --git a/packages/contracts/src/codegen/tables/CycleTurns.sol b/packages/contracts/src/codegen/tables/CycleTurns.sol new file mode 100644 index 00000000..74029b63 --- /dev/null +++ b/packages/contracts/src/codegen/tables/CycleTurns.sol @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("CycleTurns"))); +bytes32 constant CycleTurnsTableId = _tableId; + +library CycleTurns { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT32; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("CycleTurns", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (uint32 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (uint32 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Set value */ + function set(uint256 entity, uint32 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, uint32 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint32 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/CycleTurnsLastClaimed.sol b/packages/contracts/src/codegen/tables/CycleTurnsLastClaimed.sol new file mode 100644 index 00000000..990d852b --- /dev/null +++ b/packages/contracts/src/codegen/tables/CycleTurnsLastClaimed.sol @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("CycleTurnsLastClaimed"))); +bytes32 constant CycleTurnsLastClaimedTableId = _tableId; + +library CycleTurnsLastClaimed { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT48; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("CycleTurnsLastClaimed", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (uint48 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (uint48(Bytes.slice6(_blob, 0))); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (uint48 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (uint48(Bytes.slice6(_blob, 0))); + } + + /** Set value */ + function set(uint256 entity, uint48 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, uint48 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint48 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/DefaultWheel.sol b/packages/contracts/src/codegen/tables/DefaultWheel.sol new file mode 100644 index 00000000..96336433 --- /dev/null +++ b/packages/contracts/src/codegen/tables/DefaultWheel.sol @@ -0,0 +1,115 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("DefaultWheel"))); +bytes32 constant DefaultWheelTableId = _tableId; + +library DefaultWheel { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](0); + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("DefaultWheel", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get() internal view returns (uint256 value) { + bytes32[] memory _primaryKeys = new bytes32[](0); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Get value (using the specified store) */ + function get(IStore _store) internal view returns (uint256 value) { + bytes32[] memory _primaryKeys = new bytes32[](0); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Set value */ + function set(uint256 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](0); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](0); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint256 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /* Delete all data for given keys */ + function deleteRecord() internal { + bytes32[] memory _primaryKeys = new bytes32[](0); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store) internal { + bytes32[] memory _primaryKeys = new bytes32[](0); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/DurationOnEnd.sol b/packages/contracts/src/codegen/tables/DurationOnEnd.sol new file mode 100644 index 00000000..a5eec5b2 --- /dev/null +++ b/packages/contracts/src/codegen/tables/DurationOnEnd.sol @@ -0,0 +1,318 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("DurationOnEnd"))); +bytes32 constant DurationOnEndTableId = _tableId; + +struct DurationOnEndData { + bytes16 namespace; + bytes16 file; + bytes funcSelectorAndArgs; +} + +library DurationOnEnd { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](3); + _schema[0] = SchemaType.BYTES16; + _schema[1] = SchemaType.BYTES16; + _schema[2] = SchemaType.BYTES; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](3); + _fieldNames[0] = "namespace"; + _fieldNames[1] = "file"; + _fieldNames[2] = "funcSelectorAndArgs"; + return ("DurationOnEnd", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get namespace */ + function getNamespace(uint256 entity) internal view returns (bytes16 namespace) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (Bytes.slice16(_blob, 0)); + } + + /** Get namespace (using the specified store) */ + function getNamespace(IStore _store, uint256 entity) internal view returns (bytes16 namespace) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (Bytes.slice16(_blob, 0)); + } + + /** Set namespace */ + function setNamespace(uint256 entity, bytes16 namespace) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((namespace))); + } + + /** Set namespace (using the specified store) */ + function setNamespace(IStore _store, uint256 entity, bytes16 namespace) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((namespace))); + } + + /** Get file */ + function getFile(uint256 entity) internal view returns (bytes16 file) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 1); + return (Bytes.slice16(_blob, 0)); + } + + /** Get file (using the specified store) */ + function getFile(IStore _store, uint256 entity) internal view returns (bytes16 file) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 1); + return (Bytes.slice16(_blob, 0)); + } + + /** Set file */ + function setFile(uint256 entity, bytes16 file) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 1, abi.encodePacked((file))); + } + + /** Set file (using the specified store) */ + function setFile(IStore _store, uint256 entity, bytes16 file) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 1, abi.encodePacked((file))); + } + + /** Get funcSelectorAndArgs */ + function getFuncSelectorAndArgs(uint256 entity) internal view returns (bytes memory funcSelectorAndArgs) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 2); + return (bytes(_blob)); + } + + /** Get funcSelectorAndArgs (using the specified store) */ + function getFuncSelectorAndArgs( + IStore _store, + uint256 entity + ) internal view returns (bytes memory funcSelectorAndArgs) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 2); + return (bytes(_blob)); + } + + /** Set funcSelectorAndArgs */ + function setFuncSelectorAndArgs(uint256 entity, bytes memory funcSelectorAndArgs) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 2, bytes((funcSelectorAndArgs))); + } + + /** Set funcSelectorAndArgs (using the specified store) */ + function setFuncSelectorAndArgs(IStore _store, uint256 entity, bytes memory funcSelectorAndArgs) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 2, bytes((funcSelectorAndArgs))); + } + + /** Push a slice to funcSelectorAndArgs */ + function pushFuncSelectorAndArgs(uint256 entity, bytes memory _slice) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.pushToField(_tableId, _primaryKeys, 2, bytes((_slice))); + } + + /** Push a slice to funcSelectorAndArgs (using the specified store) */ + function pushFuncSelectorAndArgs(IStore _store, uint256 entity, bytes memory _slice) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.pushToField(_tableId, _primaryKeys, 2, bytes((_slice))); + } + + /** Update a slice of funcSelectorAndArgs at `_index` */ + function updateFuncSelectorAndArgs(uint256 entity, uint256 _index, bytes memory _slice) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.updateInField(_tableId, _primaryKeys, 2, _index * 1, bytes((_slice))); + } + + /** Update a slice of funcSelectorAndArgs (using the specified store) at `_index` */ + function updateFuncSelectorAndArgs(IStore _store, uint256 entity, uint256 _index, bytes memory _slice) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.updateInField(_tableId, _primaryKeys, 2, _index * 1, bytes((_slice))); + } + + /** Get the full data */ + function get(uint256 entity) internal view returns (DurationOnEndData memory _table) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getRecord(_tableId, _primaryKeys, getSchema()); + return decode(_blob); + } + + /** Get the full data (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (DurationOnEndData memory _table) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getRecord(_tableId, _primaryKeys, getSchema()); + return decode(_blob); + } + + /** Set the full data using individual values */ + function set(uint256 entity, bytes16 namespace, bytes16 file, bytes memory funcSelectorAndArgs) internal { + bytes memory _data = encode(namespace, file, funcSelectorAndArgs); + + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setRecord(_tableId, _primaryKeys, _data); + } + + /** Set the full data using individual values (using the specified store) */ + function set( + IStore _store, + uint256 entity, + bytes16 namespace, + bytes16 file, + bytes memory funcSelectorAndArgs + ) internal { + bytes memory _data = encode(namespace, file, funcSelectorAndArgs); + + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setRecord(_tableId, _primaryKeys, _data); + } + + /** Set the full data using the data struct */ + function set(uint256 entity, DurationOnEndData memory _table) internal { + set(entity, _table.namespace, _table.file, _table.funcSelectorAndArgs); + } + + /** Set the full data using the data struct (using the specified store) */ + function set(IStore _store, uint256 entity, DurationOnEndData memory _table) internal { + set(_store, entity, _table.namespace, _table.file, _table.funcSelectorAndArgs); + } + + /** Decode the tightly packed blob using this table's schema */ + function decode(bytes memory _blob) internal view returns (DurationOnEndData memory _table) { + // 32 is the total byte length of static data + PackedCounter _encodedLengths = PackedCounter.wrap(Bytes.slice32(_blob, 32)); + + _table.namespace = (Bytes.slice16(_blob, 0)); + + _table.file = (Bytes.slice16(_blob, 16)); + + // Store trims the blob if dynamic fields are all empty + if (_blob.length > 32) { + uint256 _start; + // skip static data length + dynamic lengths word + uint256 _end = 64; + + _start = _end; + _end += _encodedLengths.atIndex(0); + _table.funcSelectorAndArgs = (bytes(SliceLib.getSubslice(_blob, _start, _end).toBytes())); + } + } + + /** Tightly pack full data using this table's schema */ + function encode( + bytes16 namespace, + bytes16 file, + bytes memory funcSelectorAndArgs + ) internal view returns (bytes memory) { + uint16[] memory _counters = new uint16[](1); + _counters[0] = uint16(bytes(funcSelectorAndArgs).length); + PackedCounter _encodedLengths = PackedCounterLib.pack(_counters); + + return abi.encodePacked(namespace, file, _encodedLengths.unwrap(), bytes((funcSelectorAndArgs))); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/DurationScope.sol b/packages/contracts/src/codegen/tables/DurationScope.sol new file mode 100644 index 00000000..eb8ccea9 --- /dev/null +++ b/packages/contracts/src/codegen/tables/DurationScope.sol @@ -0,0 +1,129 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("DurationScope"))); +bytes32 constant DurationScopeTableId = _tableId; + +library DurationScope { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.BYTES32; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](2); + _schema[0] = SchemaType.UINT256; + _schema[1] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("DurationScope", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 targetEntity, uint256 baseEntity) internal view returns (bytes32 value) { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((baseEntity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (Bytes.slice32(_blob, 0)); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 targetEntity, uint256 baseEntity) internal view returns (bytes32 value) { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((baseEntity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (Bytes.slice32(_blob, 0)); + } + + /** Set value */ + function set(uint256 targetEntity, uint256 baseEntity, bytes32 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((baseEntity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 targetEntity, uint256 baseEntity, bytes32 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((baseEntity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(bytes32 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 targetEntity, uint256 baseEntity) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((baseEntity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 targetEntity, uint256 baseEntity) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((baseEntity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/DurationValue.sol b/packages/contracts/src/codegen/tables/DurationValue.sol new file mode 100644 index 00000000..e60055be --- /dev/null +++ b/packages/contracts/src/codegen/tables/DurationValue.sol @@ -0,0 +1,129 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("DurationValue"))); +bytes32 constant DurationValueTableId = _tableId; + +library DurationValue { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT48; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](2); + _schema[0] = SchemaType.UINT256; + _schema[1] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("DurationValue", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 targetEntity, uint256 baseEntity) internal view returns (uint48 value) { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((baseEntity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (uint48(Bytes.slice6(_blob, 0))); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 targetEntity, uint256 baseEntity) internal view returns (uint48 value) { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((baseEntity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (uint48(Bytes.slice6(_blob, 0))); + } + + /** Set value */ + function set(uint256 targetEntity, uint256 baseEntity, uint48 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((baseEntity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 targetEntity, uint256 baseEntity, uint48 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((baseEntity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint48 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 targetEntity, uint256 baseEntity) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((baseEntity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 targetEntity, uint256 baseEntity) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((baseEntity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/EffectApplied.sol b/packages/contracts/src/codegen/tables/EffectApplied.sol new file mode 100644 index 00000000..1866a9fa --- /dev/null +++ b/packages/contracts/src/codegen/tables/EffectApplied.sol @@ -0,0 +1,354 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("EffectApplied"))); +bytes32 constant EffectAppliedTableId = _tableId; + +struct EffectAppliedData { + uint256[] entities; + uint32[] values; +} + +library EffectApplied { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](2); + _schema[0] = SchemaType.UINT256_ARRAY; + _schema[1] = SchemaType.UINT32_ARRAY; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](2); + _schema[0] = SchemaType.UINT256; + _schema[1] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](2); + _fieldNames[0] = "entities"; + _fieldNames[1] = "values"; + return ("EffectApplied", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get entities */ + function getEntities(uint256 targetEntity, uint256 sourceEntity) internal view returns (uint256[] memory entities) { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((sourceEntity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint256()); + } + + /** Get entities (using the specified store) */ + function getEntities( + IStore _store, + uint256 targetEntity, + uint256 sourceEntity + ) internal view returns (uint256[] memory entities) { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((sourceEntity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint256()); + } + + /** Set entities */ + function setEntities(uint256 targetEntity, uint256 sourceEntity, uint256[] memory entities) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((sourceEntity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, EncodeArray.encode((entities))); + } + + /** Set entities (using the specified store) */ + function setEntities(IStore _store, uint256 targetEntity, uint256 sourceEntity, uint256[] memory entities) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((sourceEntity))); + + _store.setField(_tableId, _primaryKeys, 0, EncodeArray.encode((entities))); + } + + /** Push an element to entities */ + function pushEntities(uint256 targetEntity, uint256 sourceEntity, uint256 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((sourceEntity))); + + StoreSwitch.pushToField(_tableId, _primaryKeys, 0, abi.encodePacked((_element))); + } + + /** Push an element to entities (using the specified store) */ + function pushEntities(IStore _store, uint256 targetEntity, uint256 sourceEntity, uint256 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((sourceEntity))); + + _store.pushToField(_tableId, _primaryKeys, 0, abi.encodePacked((_element))); + } + + /** Update an element of entities at `_index` */ + function updateEntities(uint256 targetEntity, uint256 sourceEntity, uint256 _index, uint256 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((sourceEntity))); + + StoreSwitch.updateInField(_tableId, _primaryKeys, 0, _index * 32, abi.encodePacked((_element))); + } + + /** Update an element of entities (using the specified store) at `_index` */ + function updateEntities( + IStore _store, + uint256 targetEntity, + uint256 sourceEntity, + uint256 _index, + uint256 _element + ) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((sourceEntity))); + + _store.updateInField(_tableId, _primaryKeys, 0, _index * 32, abi.encodePacked((_element))); + } + + /** Get values */ + function getValues(uint256 targetEntity, uint256 sourceEntity) internal view returns (uint32[] memory values) { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((sourceEntity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 1); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); + } + + /** Get values (using the specified store) */ + function getValues( + IStore _store, + uint256 targetEntity, + uint256 sourceEntity + ) internal view returns (uint32[] memory values) { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((sourceEntity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 1); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); + } + + /** Set values */ + function setValues(uint256 targetEntity, uint256 sourceEntity, uint32[] memory values) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((sourceEntity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 1, EncodeArray.encode((values))); + } + + /** Set values (using the specified store) */ + function setValues(IStore _store, uint256 targetEntity, uint256 sourceEntity, uint32[] memory values) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((sourceEntity))); + + _store.setField(_tableId, _primaryKeys, 1, EncodeArray.encode((values))); + } + + /** Push an element to values */ + function pushValues(uint256 targetEntity, uint256 sourceEntity, uint32 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((sourceEntity))); + + StoreSwitch.pushToField(_tableId, _primaryKeys, 1, abi.encodePacked((_element))); + } + + /** Push an element to values (using the specified store) */ + function pushValues(IStore _store, uint256 targetEntity, uint256 sourceEntity, uint32 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((sourceEntity))); + + _store.pushToField(_tableId, _primaryKeys, 1, abi.encodePacked((_element))); + } + + /** Update an element of values at `_index` */ + function updateValues(uint256 targetEntity, uint256 sourceEntity, uint256 _index, uint32 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((sourceEntity))); + + StoreSwitch.updateInField(_tableId, _primaryKeys, 1, _index * 4, abi.encodePacked((_element))); + } + + /** Update an element of values (using the specified store) at `_index` */ + function updateValues( + IStore _store, + uint256 targetEntity, + uint256 sourceEntity, + uint256 _index, + uint32 _element + ) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((sourceEntity))); + + _store.updateInField(_tableId, _primaryKeys, 1, _index * 4, abi.encodePacked((_element))); + } + + /** Get the full data */ + function get(uint256 targetEntity, uint256 sourceEntity) internal view returns (EffectAppliedData memory _table) { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((sourceEntity))); + + bytes memory _blob = StoreSwitch.getRecord(_tableId, _primaryKeys, getSchema()); + return decode(_blob); + } + + /** Get the full data (using the specified store) */ + function get( + IStore _store, + uint256 targetEntity, + uint256 sourceEntity + ) internal view returns (EffectAppliedData memory _table) { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((sourceEntity))); + + bytes memory _blob = _store.getRecord(_tableId, _primaryKeys, getSchema()); + return decode(_blob); + } + + /** Set the full data using individual values */ + function set(uint256 targetEntity, uint256 sourceEntity, uint256[] memory entities, uint32[] memory values) internal { + bytes memory _data = encode(entities, values); + + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((sourceEntity))); + + StoreSwitch.setRecord(_tableId, _primaryKeys, _data); + } + + /** Set the full data using individual values (using the specified store) */ + function set( + IStore _store, + uint256 targetEntity, + uint256 sourceEntity, + uint256[] memory entities, + uint32[] memory values + ) internal { + bytes memory _data = encode(entities, values); + + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((sourceEntity))); + + _store.setRecord(_tableId, _primaryKeys, _data); + } + + /** Set the full data using the data struct */ + function set(uint256 targetEntity, uint256 sourceEntity, EffectAppliedData memory _table) internal { + set(targetEntity, sourceEntity, _table.entities, _table.values); + } + + /** Set the full data using the data struct (using the specified store) */ + function set(IStore _store, uint256 targetEntity, uint256 sourceEntity, EffectAppliedData memory _table) internal { + set(_store, targetEntity, sourceEntity, _table.entities, _table.values); + } + + /** Decode the tightly packed blob using this table's schema */ + function decode(bytes memory _blob) internal view returns (EffectAppliedData memory _table) { + // 0 is the total byte length of static data + PackedCounter _encodedLengths = PackedCounter.wrap(Bytes.slice32(_blob, 0)); + + // Store trims the blob if dynamic fields are all empty + if (_blob.length > 0) { + uint256 _start; + // skip static data length + dynamic lengths word + uint256 _end = 32; + + _start = _end; + _end += _encodedLengths.atIndex(0); + _table.entities = (SliceLib.getSubslice(_blob, _start, _end).decodeArray_uint256()); + + _start = _end; + _end += _encodedLengths.atIndex(1); + _table.values = (SliceLib.getSubslice(_blob, _start, _end).decodeArray_uint32()); + } + } + + /** Tightly pack full data using this table's schema */ + function encode(uint256[] memory entities, uint32[] memory values) internal view returns (bytes memory) { + uint16[] memory _counters = new uint16[](2); + _counters[0] = uint16(entities.length * 32); + _counters[1] = uint16(values.length * 4); + PackedCounter _encodedLengths = PackedCounterLib.pack(_counters); + + return abi.encodePacked(_encodedLengths.unwrap(), EncodeArray.encode((entities)), EncodeArray.encode((values))); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 targetEntity, uint256 sourceEntity) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((sourceEntity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 targetEntity, uint256 sourceEntity) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((sourceEntity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/EffectDuration.sol b/packages/contracts/src/codegen/tables/EffectDuration.sol new file mode 100644 index 00000000..7cc6aa3c --- /dev/null +++ b/packages/contracts/src/codegen/tables/EffectDuration.sol @@ -0,0 +1,218 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("EffectDuration"))); +bytes32 constant EffectDurationTableId = _tableId; + +struct EffectDurationData { + bytes32 scope; + uint48 value; +} + +library EffectDuration { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](2); + _schema[0] = SchemaType.BYTES32; + _schema[1] = SchemaType.UINT48; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](2); + _fieldNames[0] = "scope"; + _fieldNames[1] = "value"; + return ("EffectDuration", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get scope */ + function getScope(uint256 entity) internal view returns (bytes32 scope) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (Bytes.slice32(_blob, 0)); + } + + /** Get scope (using the specified store) */ + function getScope(IStore _store, uint256 entity) internal view returns (bytes32 scope) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (Bytes.slice32(_blob, 0)); + } + + /** Set scope */ + function setScope(uint256 entity, bytes32 scope) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((scope))); + } + + /** Set scope (using the specified store) */ + function setScope(IStore _store, uint256 entity, bytes32 scope) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((scope))); + } + + /** Get value */ + function getValue(uint256 entity) internal view returns (uint48 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 1); + return (uint48(Bytes.slice6(_blob, 0))); + } + + /** Get value (using the specified store) */ + function getValue(IStore _store, uint256 entity) internal view returns (uint48 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 1); + return (uint48(Bytes.slice6(_blob, 0))); + } + + /** Set value */ + function setValue(uint256 entity, uint48 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 1, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function setValue(IStore _store, uint256 entity, uint48 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 1, abi.encodePacked((value))); + } + + /** Get the full data */ + function get(uint256 entity) internal view returns (EffectDurationData memory _table) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getRecord(_tableId, _primaryKeys, getSchema()); + return decode(_blob); + } + + /** Get the full data (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (EffectDurationData memory _table) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getRecord(_tableId, _primaryKeys, getSchema()); + return decode(_blob); + } + + /** Set the full data using individual values */ + function set(uint256 entity, bytes32 scope, uint48 value) internal { + bytes memory _data = encode(scope, value); + + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setRecord(_tableId, _primaryKeys, _data); + } + + /** Set the full data using individual values (using the specified store) */ + function set(IStore _store, uint256 entity, bytes32 scope, uint48 value) internal { + bytes memory _data = encode(scope, value); + + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setRecord(_tableId, _primaryKeys, _data); + } + + /** Set the full data using the data struct */ + function set(uint256 entity, EffectDurationData memory _table) internal { + set(entity, _table.scope, _table.value); + } + + /** Set the full data using the data struct (using the specified store) */ + function set(IStore _store, uint256 entity, EffectDurationData memory _table) internal { + set(_store, entity, _table.scope, _table.value); + } + + /** Decode the tightly packed blob using this table's schema */ + function decode(bytes memory _blob) internal pure returns (EffectDurationData memory _table) { + _table.scope = (Bytes.slice32(_blob, 0)); + + _table.value = (uint48(Bytes.slice6(_blob, 32))); + } + + /** Tightly pack full data using this table's schema */ + function encode(bytes32 scope, uint48 value) internal view returns (bytes memory) { + return abi.encodePacked(scope, value); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/EffectRemovability.sol b/packages/contracts/src/codegen/tables/EffectRemovability.sol new file mode 100644 index 00000000..52c24446 --- /dev/null +++ b/packages/contracts/src/codegen/tables/EffectRemovability.sol @@ -0,0 +1,125 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +// Import user types +import { EffectRemovabilityId } from "./../Types.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("EffectRemovability"))); +bytes32 constant EffectRemovabilityTableId = _tableId; + +library EffectRemovability { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT8; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("EffectRemovability", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (EffectRemovabilityId value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return EffectRemovabilityId(uint8(Bytes.slice1(_blob, 0))); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (EffectRemovabilityId value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return EffectRemovabilityId(uint8(Bytes.slice1(_blob, 0))); + } + + /** Set value */ + function set(uint256 entity, EffectRemovabilityId value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked(uint8(value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, EffectRemovabilityId value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked(uint8(value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(EffectRemovabilityId value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/EffectTemplate.sol b/packages/contracts/src/codegen/tables/EffectTemplate.sol new file mode 100644 index 00000000..f5b2a081 --- /dev/null +++ b/packages/contracts/src/codegen/tables/EffectTemplate.sol @@ -0,0 +1,301 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("EffectTemplate"))); +bytes32 constant EffectTemplateTableId = _tableId; + +struct EffectTemplateData { + uint256[] entities; + uint32[] values; +} + +library EffectTemplate { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](2); + _schema[0] = SchemaType.UINT256_ARRAY; + _schema[1] = SchemaType.UINT32_ARRAY; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](2); + _fieldNames[0] = "entities"; + _fieldNames[1] = "values"; + return ("EffectTemplate", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get entities */ + function getEntities(uint256 entity) internal view returns (uint256[] memory entities) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint256()); + } + + /** Get entities (using the specified store) */ + function getEntities(IStore _store, uint256 entity) internal view returns (uint256[] memory entities) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint256()); + } + + /** Set entities */ + function setEntities(uint256 entity, uint256[] memory entities) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, EncodeArray.encode((entities))); + } + + /** Set entities (using the specified store) */ + function setEntities(IStore _store, uint256 entity, uint256[] memory entities) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, EncodeArray.encode((entities))); + } + + /** Push an element to entities */ + function pushEntities(uint256 entity, uint256 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.pushToField(_tableId, _primaryKeys, 0, abi.encodePacked((_element))); + } + + /** Push an element to entities (using the specified store) */ + function pushEntities(IStore _store, uint256 entity, uint256 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.pushToField(_tableId, _primaryKeys, 0, abi.encodePacked((_element))); + } + + /** Update an element of entities at `_index` */ + function updateEntities(uint256 entity, uint256 _index, uint256 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.updateInField(_tableId, _primaryKeys, 0, _index * 32, abi.encodePacked((_element))); + } + + /** Update an element of entities (using the specified store) at `_index` */ + function updateEntities(IStore _store, uint256 entity, uint256 _index, uint256 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.updateInField(_tableId, _primaryKeys, 0, _index * 32, abi.encodePacked((_element))); + } + + /** Get values */ + function getValues(uint256 entity) internal view returns (uint32[] memory values) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 1); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); + } + + /** Get values (using the specified store) */ + function getValues(IStore _store, uint256 entity) internal view returns (uint32[] memory values) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 1); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); + } + + /** Set values */ + function setValues(uint256 entity, uint32[] memory values) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 1, EncodeArray.encode((values))); + } + + /** Set values (using the specified store) */ + function setValues(IStore _store, uint256 entity, uint32[] memory values) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 1, EncodeArray.encode((values))); + } + + /** Push an element to values */ + function pushValues(uint256 entity, uint32 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.pushToField(_tableId, _primaryKeys, 1, abi.encodePacked((_element))); + } + + /** Push an element to values (using the specified store) */ + function pushValues(IStore _store, uint256 entity, uint32 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.pushToField(_tableId, _primaryKeys, 1, abi.encodePacked((_element))); + } + + /** Update an element of values at `_index` */ + function updateValues(uint256 entity, uint256 _index, uint32 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.updateInField(_tableId, _primaryKeys, 1, _index * 4, abi.encodePacked((_element))); + } + + /** Update an element of values (using the specified store) at `_index` */ + function updateValues(IStore _store, uint256 entity, uint256 _index, uint32 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.updateInField(_tableId, _primaryKeys, 1, _index * 4, abi.encodePacked((_element))); + } + + /** Get the full data */ + function get(uint256 entity) internal view returns (EffectTemplateData memory _table) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getRecord(_tableId, _primaryKeys, getSchema()); + return decode(_blob); + } + + /** Get the full data (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (EffectTemplateData memory _table) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getRecord(_tableId, _primaryKeys, getSchema()); + return decode(_blob); + } + + /** Set the full data using individual values */ + function set(uint256 entity, uint256[] memory entities, uint32[] memory values) internal { + bytes memory _data = encode(entities, values); + + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setRecord(_tableId, _primaryKeys, _data); + } + + /** Set the full data using individual values (using the specified store) */ + function set(IStore _store, uint256 entity, uint256[] memory entities, uint32[] memory values) internal { + bytes memory _data = encode(entities, values); + + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setRecord(_tableId, _primaryKeys, _data); + } + + /** Set the full data using the data struct */ + function set(uint256 entity, EffectTemplateData memory _table) internal { + set(entity, _table.entities, _table.values); + } + + /** Set the full data using the data struct (using the specified store) */ + function set(IStore _store, uint256 entity, EffectTemplateData memory _table) internal { + set(_store, entity, _table.entities, _table.values); + } + + /** Decode the tightly packed blob using this table's schema */ + function decode(bytes memory _blob) internal view returns (EffectTemplateData memory _table) { + // 0 is the total byte length of static data + PackedCounter _encodedLengths = PackedCounter.wrap(Bytes.slice32(_blob, 0)); + + // Store trims the blob if dynamic fields are all empty + if (_blob.length > 0) { + uint256 _start; + // skip static data length + dynamic lengths word + uint256 _end = 32; + + _start = _end; + _end += _encodedLengths.atIndex(0); + _table.entities = (SliceLib.getSubslice(_blob, _start, _end).decodeArray_uint256()); + + _start = _end; + _end += _encodedLengths.atIndex(1); + _table.values = (SliceLib.getSubslice(_blob, _start, _end).decodeArray_uint32()); + } + } + + /** Tightly pack full data using this table's schema */ + function encode(uint256[] memory entities, uint32[] memory values) internal view returns (bytes memory) { + uint16[] memory _counters = new uint16[](2); + _counters[0] = uint16(entities.length * 32); + _counters[1] = uint16(values.length * 4); + PackedCounter _encodedLengths = PackedCounterLib.pack(_counters); + + return abi.encodePacked(_encodedLengths.unwrap(), EncodeArray.encode((entities)), EncodeArray.encode((values))); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/EqptBase.sol b/packages/contracts/src/codegen/tables/EqptBase.sol new file mode 100644 index 00000000..5dfab7cd --- /dev/null +++ b/packages/contracts/src/codegen/tables/EqptBase.sol @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("EqptBase"))); +bytes32 constant EqptBaseTableId = _tableId; + +library EqptBase { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.BYTES32; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("EqptBase", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (bytes32 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (Bytes.slice32(_blob, 0)); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (bytes32 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (Bytes.slice32(_blob, 0)); + } + + /** Set value */ + function set(uint256 entity, bytes32 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, bytes32 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(bytes32 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/ExpGainMul.sol b/packages/contracts/src/codegen/tables/ExpGainMul.sol new file mode 100644 index 00000000..0a00f7fe --- /dev/null +++ b/packages/contracts/src/codegen/tables/ExpGainMul.sol @@ -0,0 +1,176 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("ExpGainMul"))); +bytes32 constant ExpGainMulTableId = _tableId; + +library ExpGainMul { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT32_ARRAY; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("ExpGainMul", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (uint32[3] memory value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return toStaticArray_uint32_3(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (uint32[3] memory value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return toStaticArray_uint32_3(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); + } + + /** Set value */ + function set(uint256 entity, uint32[3] memory value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, EncodeArray.encode(fromStaticArray_uint32_3(value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, uint32[3] memory value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, EncodeArray.encode(fromStaticArray_uint32_3(value))); + } + + /** Push an element to value */ + function push(uint256 entity, uint32 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.pushToField(_tableId, _primaryKeys, 0, abi.encodePacked((_element))); + } + + /** Push an element to value (using the specified store) */ + function push(IStore _store, uint256 entity, uint32 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.pushToField(_tableId, _primaryKeys, 0, abi.encodePacked((_element))); + } + + /** Update an element of value at `_index` */ + function update(uint256 entity, uint256 _index, uint32 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.updateInField(_tableId, _primaryKeys, 0, _index * 4, abi.encodePacked((_element))); + } + + /** Update an element of value (using the specified store) at `_index` */ + function update(IStore _store, uint256 entity, uint256 _index, uint32 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.updateInField(_tableId, _primaryKeys, 0, _index * 4, abi.encodePacked((_element))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint32[3] memory value) internal view returns (bytes memory) { + uint16[] memory _counters = new uint16[](1); + _counters[0] = uint16(value.length * 4); + PackedCounter _encodedLengths = PackedCounterLib.pack(_counters); + + return abi.encodePacked(_encodedLengths.unwrap(), EncodeArray.encode(fromStaticArray_uint32_3(value))); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} + +function toStaticArray_uint32_3(uint32[] memory _value) pure returns (uint32[3] memory _result) { + // in memory static arrays are just dynamic arrays without the length byte + assembly { + _result := add(_value, 0x20) + } +} + +function fromStaticArray_uint32_3(uint32[3] memory _value) view returns (uint32[] memory _result) { + _result = new uint32[](3); + uint256 fromPointer; + uint256 toPointer; + assembly { + fromPointer := _value + toPointer := add(_result, 0x20) + } + Memory.copy(fromPointer, toPointer, 96); +} diff --git a/packages/contracts/src/codegen/tables/Experience.sol b/packages/contracts/src/codegen/tables/Experience.sol new file mode 100644 index 00000000..f27da6bc --- /dev/null +++ b/packages/contracts/src/codegen/tables/Experience.sol @@ -0,0 +1,176 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("Experience"))); +bytes32 constant ExperienceTableId = _tableId; + +library Experience { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT32_ARRAY; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("Experience", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (uint32[3] memory value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return toStaticArray_uint32_3(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (uint32[3] memory value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return toStaticArray_uint32_3(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); + } + + /** Set value */ + function set(uint256 entity, uint32[3] memory value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, EncodeArray.encode(fromStaticArray_uint32_3(value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, uint32[3] memory value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, EncodeArray.encode(fromStaticArray_uint32_3(value))); + } + + /** Push an element to value */ + function push(uint256 entity, uint32 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.pushToField(_tableId, _primaryKeys, 0, abi.encodePacked((_element))); + } + + /** Push an element to value (using the specified store) */ + function push(IStore _store, uint256 entity, uint32 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.pushToField(_tableId, _primaryKeys, 0, abi.encodePacked((_element))); + } + + /** Update an element of value at `_index` */ + function update(uint256 entity, uint256 _index, uint32 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.updateInField(_tableId, _primaryKeys, 0, _index * 4, abi.encodePacked((_element))); + } + + /** Update an element of value (using the specified store) at `_index` */ + function update(IStore _store, uint256 entity, uint256 _index, uint32 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.updateInField(_tableId, _primaryKeys, 0, _index * 4, abi.encodePacked((_element))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint32[3] memory value) internal view returns (bytes memory) { + uint16[] memory _counters = new uint16[](1); + _counters[0] = uint16(value.length * 4); + PackedCounter _encodedLengths = PackedCounterLib.pack(_counters); + + return abi.encodePacked(_encodedLengths.unwrap(), EncodeArray.encode(fromStaticArray_uint32_3(value))); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} + +function toStaticArray_uint32_3(uint32[] memory _value) pure returns (uint32[3] memory _result) { + // in memory static arrays are just dynamic arrays without the length byte + assembly { + _result := add(_value, 0x20) + } +} + +function fromStaticArray_uint32_3(uint32[3] memory _value) view returns (uint32[] memory _result) { + _result = new uint32[](3); + uint256 fromPointer; + uint256 toPointer; + assembly { + fromPointer := _value + toPointer := add(_result, 0x20) + } + Memory.copy(fromPointer, toPointer, 96); +} diff --git a/packages/contracts/src/codegen/tables/FromEqptBase.sol b/packages/contracts/src/codegen/tables/FromEqptBase.sol new file mode 100644 index 00000000..6a4ebda4 --- /dev/null +++ b/packages/contracts/src/codegen/tables/FromEqptBase.sol @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("FromEqptBase"))); +bytes32 constant FromEqptBaseTableId = _tableId; + +library FromEqptBase { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("FromEqptBase", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (uint256 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (uint256 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Set value */ + function set(uint256 entity, uint256 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, uint256 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint256 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/FromMapBase.sol b/packages/contracts/src/codegen/tables/FromMapBase.sol new file mode 100644 index 00000000..102adfa3 --- /dev/null +++ b/packages/contracts/src/codegen/tables/FromMapBase.sol @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("FromMapBase"))); +bytes32 constant FromMapBaseTableId = _tableId; + +library FromMapBase { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("FromMapBase", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (uint256 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (uint256 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Set value */ + function set(uint256 entity, uint256 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, uint256 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint256 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/FromMetaEntity.sol b/packages/contracts/src/codegen/tables/FromMetaEntity.sol new file mode 100644 index 00000000..b0cc0779 --- /dev/null +++ b/packages/contracts/src/codegen/tables/FromMetaEntity.sol @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("FromMetaEntity"))); +bytes32 constant FromMetaEntityTableId = _tableId; + +library FromMetaEntity { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("FromMetaEntity", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (uint256 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (uint256 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Set value */ + function set(uint256 entity, uint256 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, uint256 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint256 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/FromPrototype.sol b/packages/contracts/src/codegen/tables/FromPrototype.sol new file mode 100644 index 00000000..9f4fc338 --- /dev/null +++ b/packages/contracts/src/codegen/tables/FromPrototype.sol @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("FromPrototype"))); +bytes32 constant FromPrototypeTableId = _tableId; + +library FromPrototype { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("FromPrototype", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (uint256 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (uint256 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Set value */ + function set(uint256 entity, uint256 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, uint256 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint256 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/FromStatmodBase.sol b/packages/contracts/src/codegen/tables/FromStatmodBase.sol new file mode 100644 index 00000000..e51bad3e --- /dev/null +++ b/packages/contracts/src/codegen/tables/FromStatmodBase.sol @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("FromStatmodBase"))); +bytes32 constant FromStatmodBaseTableId = _tableId; + +library FromStatmodBase { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("FromStatmodBase", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (uint256 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (uint256 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Set value */ + function set(uint256 entity, uint256 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, uint256 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint256 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/Identity.sol b/packages/contracts/src/codegen/tables/Identity.sol new file mode 100644 index 00000000..78e03206 --- /dev/null +++ b/packages/contracts/src/codegen/tables/Identity.sol @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("Identity"))); +bytes32 constant IdentityTableId = _tableId; + +library Identity { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT32; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("Identity", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (uint32 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (uint32 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Set value */ + function set(uint256 entity, uint32 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, uint32 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint32 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/LearnedSkills.sol b/packages/contracts/src/codegen/tables/LearnedSkills.sol new file mode 100644 index 00000000..efa611f3 --- /dev/null +++ b/packages/contracts/src/codegen/tables/LearnedSkills.sol @@ -0,0 +1,158 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("LearnedSkills"))); +bytes32 constant LearnedSkillsTableId = _tableId; + +library LearnedSkills { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256_ARRAY; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("LearnedSkills", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (uint256[] memory value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint256()); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (uint256[] memory value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint256()); + } + + /** Set value */ + function set(uint256 entity, uint256[] memory value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, EncodeArray.encode((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, uint256[] memory value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, EncodeArray.encode((value))); + } + + /** Push an element to value */ + function push(uint256 entity, uint256 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.pushToField(_tableId, _primaryKeys, 0, abi.encodePacked((_element))); + } + + /** Push an element to value (using the specified store) */ + function push(IStore _store, uint256 entity, uint256 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.pushToField(_tableId, _primaryKeys, 0, abi.encodePacked((_element))); + } + + /** Update an element of value at `_index` */ + function update(uint256 entity, uint256 _index, uint256 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.updateInField(_tableId, _primaryKeys, 0, _index * 32, abi.encodePacked((_element))); + } + + /** Update an element of value (using the specified store) at `_index` */ + function update(IStore _store, uint256 entity, uint256 _index, uint256 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.updateInField(_tableId, _primaryKeys, 0, _index * 32, abi.encodePacked((_element))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint256[] memory value) internal view returns (bytes memory) { + uint16[] memory _counters = new uint16[](1); + _counters[0] = uint16(value.length * 32); + PackedCounter _encodedLengths = PackedCounterLib.pack(_counters); + + return abi.encodePacked(_encodedLengths.unwrap(), EncodeArray.encode((value))); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/LifeCurrent.sol b/packages/contracts/src/codegen/tables/LifeCurrent.sol new file mode 100644 index 00000000..f6f0f965 --- /dev/null +++ b/packages/contracts/src/codegen/tables/LifeCurrent.sol @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("LifeCurrent"))); +bytes32 constant LifeCurrentTableId = _tableId; + +library LifeCurrent { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT32; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("LifeCurrent", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (uint32 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (uint32 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Set value */ + function set(uint256 entity, uint32 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, uint32 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint32 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/LootAffixes.sol b/packages/contracts/src/codegen/tables/LootAffixes.sol new file mode 100644 index 00000000..52e4ea46 --- /dev/null +++ b/packages/contracts/src/codegen/tables/LootAffixes.sol @@ -0,0 +1,158 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("LootAffixes"))); +bytes32 constant LootAffixesTableId = _tableId; + +library LootAffixes { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256_ARRAY; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("LootAffixes", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (uint256[] memory value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint256()); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (uint256[] memory value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint256()); + } + + /** Set value */ + function set(uint256 entity, uint256[] memory value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, EncodeArray.encode((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, uint256[] memory value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, EncodeArray.encode((value))); + } + + /** Push an element to value */ + function push(uint256 entity, uint256 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.pushToField(_tableId, _primaryKeys, 0, abi.encodePacked((_element))); + } + + /** Push an element to value (using the specified store) */ + function push(IStore _store, uint256 entity, uint256 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.pushToField(_tableId, _primaryKeys, 0, abi.encodePacked((_element))); + } + + /** Update an element of value at `_index` */ + function update(uint256 entity, uint256 _index, uint256 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.updateInField(_tableId, _primaryKeys, 0, _index * 32, abi.encodePacked((_element))); + } + + /** Update an element of value (using the specified store) at `_index` */ + function update(IStore _store, uint256 entity, uint256 _index, uint256 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.updateInField(_tableId, _primaryKeys, 0, _index * 32, abi.encodePacked((_element))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint256[] memory value) internal view returns (bytes memory) { + uint16[] memory _counters = new uint16[](1); + _counters[0] = uint16(value.length * 32); + PackedCounter _encodedLengths = PackedCounterLib.pack(_counters); + + return abi.encodePacked(_encodedLengths.unwrap(), EncodeArray.encode((value))); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/LootIlvl.sol b/packages/contracts/src/codegen/tables/LootIlvl.sol new file mode 100644 index 00000000..fcf4616a --- /dev/null +++ b/packages/contracts/src/codegen/tables/LootIlvl.sol @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("LootIlvl"))); +bytes32 constant LootIlvlTableId = _tableId; + +library LootIlvl { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT32; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("LootIlvl", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (uint32 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (uint32 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Set value */ + function set(uint256 entity, uint32 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, uint32 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint32 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/ManaCost.sol b/packages/contracts/src/codegen/tables/ManaCost.sol new file mode 100644 index 00000000..ae4e0dd4 --- /dev/null +++ b/packages/contracts/src/codegen/tables/ManaCost.sol @@ -0,0 +1,176 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("ManaCost"))); +bytes32 constant ManaCostTableId = _tableId; + +library ManaCost { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT32_ARRAY; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("ManaCost", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (uint32[5] memory value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return toStaticArray_uint32_5(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (uint32[5] memory value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return toStaticArray_uint32_5(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); + } + + /** Set value */ + function set(uint256 entity, uint32[5] memory value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, EncodeArray.encode(fromStaticArray_uint32_5(value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, uint32[5] memory value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, EncodeArray.encode(fromStaticArray_uint32_5(value))); + } + + /** Push an element to value */ + function push(uint256 entity, uint32 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.pushToField(_tableId, _primaryKeys, 0, abi.encodePacked((_element))); + } + + /** Push an element to value (using the specified store) */ + function push(IStore _store, uint256 entity, uint32 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.pushToField(_tableId, _primaryKeys, 0, abi.encodePacked((_element))); + } + + /** Update an element of value at `_index` */ + function update(uint256 entity, uint256 _index, uint32 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.updateInField(_tableId, _primaryKeys, 0, _index * 4, abi.encodePacked((_element))); + } + + /** Update an element of value (using the specified store) at `_index` */ + function update(IStore _store, uint256 entity, uint256 _index, uint32 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.updateInField(_tableId, _primaryKeys, 0, _index * 4, abi.encodePacked((_element))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint32[5] memory value) internal view returns (bytes memory) { + uint16[] memory _counters = new uint16[](1); + _counters[0] = uint16(value.length * 4); + PackedCounter _encodedLengths = PackedCounterLib.pack(_counters); + + return abi.encodePacked(_encodedLengths.unwrap(), EncodeArray.encode(fromStaticArray_uint32_5(value))); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} + +function toStaticArray_uint32_5(uint32[] memory _value) pure returns (uint32[5] memory _result) { + // in memory static arrays are just dynamic arrays without the length byte + assembly { + _result := add(_value, 0x20) + } +} + +function fromStaticArray_uint32_5(uint32[5] memory _value) view returns (uint32[] memory _result) { + _result = new uint32[](5); + uint256 fromPointer; + uint256 toPointer; + assembly { + fromPointer := _value + toPointer := add(_result, 0x20) + } + Memory.copy(fromPointer, toPointer, 160); +} diff --git a/packages/contracts/src/codegen/tables/ManaCurrent.sol b/packages/contracts/src/codegen/tables/ManaCurrent.sol new file mode 100644 index 00000000..dcbceb87 --- /dev/null +++ b/packages/contracts/src/codegen/tables/ManaCurrent.sol @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("ManaCurrent"))); +bytes32 constant ManaCurrentTableId = _tableId; + +library ManaCurrent { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT32; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("ManaCurrent", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (uint32 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (uint32 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Set value */ + function set(uint256 entity, uint32 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, uint32 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint32 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/MapBase.sol b/packages/contracts/src/codegen/tables/MapBase.sol new file mode 100644 index 00000000..7f3d9bcc --- /dev/null +++ b/packages/contracts/src/codegen/tables/MapBase.sol @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("MapBase"))); +bytes32 constant MapBaseTableId = _tableId; + +library MapBase { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.BYTES32; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("MapBase", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (bytes32 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (Bytes.slice32(_blob, 0)); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (bytes32 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (Bytes.slice32(_blob, 0)); + } + + /** Set value */ + function set(uint256 entity, bytes32 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, bytes32 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(bytes32 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/Name.sol b/packages/contracts/src/codegen/tables/Name.sol new file mode 100644 index 00000000..7725cea0 --- /dev/null +++ b/packages/contracts/src/codegen/tables/Name.sol @@ -0,0 +1,158 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("Name"))); +bytes32 constant NameTableId = _tableId; + +library Name { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.STRING; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("Name", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (string memory value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (string(_blob)); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (string memory value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (string(_blob)); + } + + /** Set value */ + function set(uint256 entity, string memory value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, bytes((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, string memory value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, bytes((value))); + } + + /** Push a slice to value */ + function push(uint256 entity, string memory _slice) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.pushToField(_tableId, _primaryKeys, 0, bytes((_slice))); + } + + /** Push a slice to value (using the specified store) */ + function push(IStore _store, uint256 entity, string memory _slice) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.pushToField(_tableId, _primaryKeys, 0, bytes((_slice))); + } + + /** Update a slice of value at `_index` */ + function update(uint256 entity, uint256 _index, string memory _slice) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.updateInField(_tableId, _primaryKeys, 0, _index * 1, bytes((_slice))); + } + + /** Update a slice of value (using the specified store) at `_index` */ + function update(IStore _store, uint256 entity, uint256 _index, string memory _slice) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.updateInField(_tableId, _primaryKeys, 0, _index * 1, bytes((_slice))); + } + + /** Tightly pack full data using this table's schema */ + function encode(string memory value) internal view returns (bytes memory) { + uint16[] memory _counters = new uint16[](1); + _counters[0] = uint16(bytes(value).length); + PackedCounter _encodedLengths = PackedCounterLib.pack(_counters); + + return abi.encodePacked(_encodedLengths.unwrap(), bytes((value))); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/OwnedBy.sol b/packages/contracts/src/codegen/tables/OwnedBy.sol new file mode 100644 index 00000000..ee557a01 --- /dev/null +++ b/packages/contracts/src/codegen/tables/OwnedBy.sol @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("OwnedBy"))); +bytes32 constant OwnedByTableId = _tableId; + +library OwnedBy { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("OwnedBy", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (uint256 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (uint256 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Set value */ + function set(uint256 entity, uint256 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, uint256 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint256 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/PreviousCycle.sol b/packages/contracts/src/codegen/tables/PreviousCycle.sol new file mode 100644 index 00000000..fbea1c1e --- /dev/null +++ b/packages/contracts/src/codegen/tables/PreviousCycle.sol @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("PreviousCycle"))); +bytes32 constant PreviousCycleTableId = _tableId; + +library PreviousCycle { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("PreviousCycle", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (uint256 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (uint256 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Set value */ + function set(uint256 entity, uint256 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, uint256 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint256 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/RNGPrecommit.sol b/packages/contracts/src/codegen/tables/RNGPrecommit.sol new file mode 100644 index 00000000..4911e26c --- /dev/null +++ b/packages/contracts/src/codegen/tables/RNGPrecommit.sol @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("RNGPrecommit"))); +bytes32 constant RNGPrecommitTableId = _tableId; + +library RNGPrecommit { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("RNGPrecommit", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (uint256 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (uint256 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Set value */ + function set(uint256 entity, uint256 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, uint256 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint256 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/RNGRequestOwner.sol b/packages/contracts/src/codegen/tables/RNGRequestOwner.sol new file mode 100644 index 00000000..0d6c2657 --- /dev/null +++ b/packages/contracts/src/codegen/tables/RNGRequestOwner.sol @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("RNGRequestOwner"))); +bytes32 constant RNGRequestOwnerTableId = _tableId; + +library RNGRequestOwner { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("RNGRequestOwner", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (uint256 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (uint256 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Set value */ + function set(uint256 entity, uint256 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, uint256 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint256 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/SkillCooldown.sol b/packages/contracts/src/codegen/tables/SkillCooldown.sol new file mode 100644 index 00000000..1bf5c715 --- /dev/null +++ b/packages/contracts/src/codegen/tables/SkillCooldown.sol @@ -0,0 +1,218 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("SkillCooldown"))); +bytes32 constant SkillCooldownTableId = _tableId; + +struct SkillCooldownData { + bytes32 scope; + uint48 value; +} + +library SkillCooldown { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](2); + _schema[0] = SchemaType.BYTES32; + _schema[1] = SchemaType.UINT48; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](2); + _fieldNames[0] = "scope"; + _fieldNames[1] = "value"; + return ("SkillCooldown", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get scope */ + function getScope(uint256 entity) internal view returns (bytes32 scope) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (Bytes.slice32(_blob, 0)); + } + + /** Get scope (using the specified store) */ + function getScope(IStore _store, uint256 entity) internal view returns (bytes32 scope) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (Bytes.slice32(_blob, 0)); + } + + /** Set scope */ + function setScope(uint256 entity, bytes32 scope) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((scope))); + } + + /** Set scope (using the specified store) */ + function setScope(IStore _store, uint256 entity, bytes32 scope) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((scope))); + } + + /** Get value */ + function getValue(uint256 entity) internal view returns (uint48 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 1); + return (uint48(Bytes.slice6(_blob, 0))); + } + + /** Get value (using the specified store) */ + function getValue(IStore _store, uint256 entity) internal view returns (uint48 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 1); + return (uint48(Bytes.slice6(_blob, 0))); + } + + /** Set value */ + function setValue(uint256 entity, uint48 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 1, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function setValue(IStore _store, uint256 entity, uint48 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 1, abi.encodePacked((value))); + } + + /** Get the full data */ + function get(uint256 entity) internal view returns (SkillCooldownData memory _table) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getRecord(_tableId, _primaryKeys, getSchema()); + return decode(_blob); + } + + /** Get the full data (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (SkillCooldownData memory _table) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getRecord(_tableId, _primaryKeys, getSchema()); + return decode(_blob); + } + + /** Set the full data using individual values */ + function set(uint256 entity, bytes32 scope, uint48 value) internal { + bytes memory _data = encode(scope, value); + + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setRecord(_tableId, _primaryKeys, _data); + } + + /** Set the full data using individual values (using the specified store) */ + function set(IStore _store, uint256 entity, bytes32 scope, uint48 value) internal { + bytes memory _data = encode(scope, value); + + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setRecord(_tableId, _primaryKeys, _data); + } + + /** Set the full data using the data struct */ + function set(uint256 entity, SkillCooldownData memory _table) internal { + set(entity, _table.scope, _table.value); + } + + /** Set the full data using the data struct (using the specified store) */ + function set(IStore _store, uint256 entity, SkillCooldownData memory _table) internal { + set(_store, entity, _table.scope, _table.value); + } + + /** Decode the tightly packed blob using this table's schema */ + function decode(bytes memory _blob) internal pure returns (SkillCooldownData memory _table) { + _table.scope = (Bytes.slice32(_blob, 0)); + + _table.value = (uint48(Bytes.slice6(_blob, 32))); + } + + /** Tightly pack full data using this table's schema */ + function encode(bytes32 scope, uint48 value) internal view returns (bytes memory) { + return abi.encodePacked(scope, value); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/SkillDescription.sol b/packages/contracts/src/codegen/tables/SkillDescription.sol new file mode 100644 index 00000000..68686ee0 --- /dev/null +++ b/packages/contracts/src/codegen/tables/SkillDescription.sol @@ -0,0 +1,158 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("SkillDescription"))); +bytes32 constant SkillDescriptionTableId = _tableId; + +library SkillDescription { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.STRING; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("SkillDescription", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (string memory value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (string(_blob)); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (string memory value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (string(_blob)); + } + + /** Set value */ + function set(uint256 entity, string memory value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, bytes((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, string memory value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, bytes((value))); + } + + /** Push a slice to value */ + function push(uint256 entity, string memory _slice) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.pushToField(_tableId, _primaryKeys, 0, bytes((_slice))); + } + + /** Push a slice to value (using the specified store) */ + function push(IStore _store, uint256 entity, string memory _slice) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.pushToField(_tableId, _primaryKeys, 0, bytes((_slice))); + } + + /** Update a slice of value at `_index` */ + function update(uint256 entity, uint256 _index, string memory _slice) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.updateInField(_tableId, _primaryKeys, 0, _index * 1, bytes((_slice))); + } + + /** Update a slice of value (using the specified store) at `_index` */ + function update(IStore _store, uint256 entity, uint256 _index, string memory _slice) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.updateInField(_tableId, _primaryKeys, 0, _index * 1, bytes((_slice))); + } + + /** Tightly pack full data using this table's schema */ + function encode(string memory value) internal view returns (bytes memory) { + uint16[] memory _counters = new uint16[](1); + _counters[0] = uint16(bytes(value).length); + PackedCounter _encodedLengths = PackedCounterLib.pack(_counters); + + return abi.encodePacked(_encodedLengths.unwrap(), bytes((value))); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/SkillTemplate.sol b/packages/contracts/src/codegen/tables/SkillTemplate.sol new file mode 100644 index 00000000..c43023c1 --- /dev/null +++ b/packages/contracts/src/codegen/tables/SkillTemplate.sol @@ -0,0 +1,424 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +// Import user types +import { SkillType, TargetType } from "./../Types.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("SkillTemplate"))); +bytes32 constant SkillTemplateTableId = _tableId; + +struct SkillTemplateData { + uint8 requiredLevel; + SkillType skillType; + bool withAttack; + bool withSpell; + uint32 cost; + TargetType targetType; +} + +library SkillTemplate { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](6); + _schema[0] = SchemaType.UINT8; + _schema[1] = SchemaType.UINT8; + _schema[2] = SchemaType.BOOL; + _schema[3] = SchemaType.BOOL; + _schema[4] = SchemaType.UINT32; + _schema[5] = SchemaType.UINT8; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](6); + _fieldNames[0] = "requiredLevel"; + _fieldNames[1] = "skillType"; + _fieldNames[2] = "withAttack"; + _fieldNames[3] = "withSpell"; + _fieldNames[4] = "cost"; + _fieldNames[5] = "targetType"; + return ("SkillTemplate", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get requiredLevel */ + function getRequiredLevel(uint256 entity) internal view returns (uint8 requiredLevel) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (uint8(Bytes.slice1(_blob, 0))); + } + + /** Get requiredLevel (using the specified store) */ + function getRequiredLevel(IStore _store, uint256 entity) internal view returns (uint8 requiredLevel) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (uint8(Bytes.slice1(_blob, 0))); + } + + /** Set requiredLevel */ + function setRequiredLevel(uint256 entity, uint8 requiredLevel) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((requiredLevel))); + } + + /** Set requiredLevel (using the specified store) */ + function setRequiredLevel(IStore _store, uint256 entity, uint8 requiredLevel) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((requiredLevel))); + } + + /** Get skillType */ + function getSkillType(uint256 entity) internal view returns (SkillType skillType) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 1); + return SkillType(uint8(Bytes.slice1(_blob, 0))); + } + + /** Get skillType (using the specified store) */ + function getSkillType(IStore _store, uint256 entity) internal view returns (SkillType skillType) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 1); + return SkillType(uint8(Bytes.slice1(_blob, 0))); + } + + /** Set skillType */ + function setSkillType(uint256 entity, SkillType skillType) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 1, abi.encodePacked(uint8(skillType))); + } + + /** Set skillType (using the specified store) */ + function setSkillType(IStore _store, uint256 entity, SkillType skillType) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 1, abi.encodePacked(uint8(skillType))); + } + + /** Get withAttack */ + function getWithAttack(uint256 entity) internal view returns (bool withAttack) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 2); + return (_toBool(uint8(Bytes.slice1(_blob, 0)))); + } + + /** Get withAttack (using the specified store) */ + function getWithAttack(IStore _store, uint256 entity) internal view returns (bool withAttack) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 2); + return (_toBool(uint8(Bytes.slice1(_blob, 0)))); + } + + /** Set withAttack */ + function setWithAttack(uint256 entity, bool withAttack) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 2, abi.encodePacked((withAttack))); + } + + /** Set withAttack (using the specified store) */ + function setWithAttack(IStore _store, uint256 entity, bool withAttack) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 2, abi.encodePacked((withAttack))); + } + + /** Get withSpell */ + function getWithSpell(uint256 entity) internal view returns (bool withSpell) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 3); + return (_toBool(uint8(Bytes.slice1(_blob, 0)))); + } + + /** Get withSpell (using the specified store) */ + function getWithSpell(IStore _store, uint256 entity) internal view returns (bool withSpell) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 3); + return (_toBool(uint8(Bytes.slice1(_blob, 0)))); + } + + /** Set withSpell */ + function setWithSpell(uint256 entity, bool withSpell) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 3, abi.encodePacked((withSpell))); + } + + /** Set withSpell (using the specified store) */ + function setWithSpell(IStore _store, uint256 entity, bool withSpell) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 3, abi.encodePacked((withSpell))); + } + + /** Get cost */ + function getCost(uint256 entity) internal view returns (uint32 cost) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 4); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Get cost (using the specified store) */ + function getCost(IStore _store, uint256 entity) internal view returns (uint32 cost) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 4); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Set cost */ + function setCost(uint256 entity, uint32 cost) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 4, abi.encodePacked((cost))); + } + + /** Set cost (using the specified store) */ + function setCost(IStore _store, uint256 entity, uint32 cost) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 4, abi.encodePacked((cost))); + } + + /** Get targetType */ + function getTargetType(uint256 entity) internal view returns (TargetType targetType) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 5); + return TargetType(uint8(Bytes.slice1(_blob, 0))); + } + + /** Get targetType (using the specified store) */ + function getTargetType(IStore _store, uint256 entity) internal view returns (TargetType targetType) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 5); + return TargetType(uint8(Bytes.slice1(_blob, 0))); + } + + /** Set targetType */ + function setTargetType(uint256 entity, TargetType targetType) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 5, abi.encodePacked(uint8(targetType))); + } + + /** Set targetType (using the specified store) */ + function setTargetType(IStore _store, uint256 entity, TargetType targetType) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 5, abi.encodePacked(uint8(targetType))); + } + + /** Get the full data */ + function get(uint256 entity) internal view returns (SkillTemplateData memory _table) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getRecord(_tableId, _primaryKeys, getSchema()); + return decode(_blob); + } + + /** Get the full data (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (SkillTemplateData memory _table) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getRecord(_tableId, _primaryKeys, getSchema()); + return decode(_blob); + } + + /** Set the full data using individual values */ + function set( + uint256 entity, + uint8 requiredLevel, + SkillType skillType, + bool withAttack, + bool withSpell, + uint32 cost, + TargetType targetType + ) internal { + bytes memory _data = encode(requiredLevel, skillType, withAttack, withSpell, cost, targetType); + + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setRecord(_tableId, _primaryKeys, _data); + } + + /** Set the full data using individual values (using the specified store) */ + function set( + IStore _store, + uint256 entity, + uint8 requiredLevel, + SkillType skillType, + bool withAttack, + bool withSpell, + uint32 cost, + TargetType targetType + ) internal { + bytes memory _data = encode(requiredLevel, skillType, withAttack, withSpell, cost, targetType); + + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setRecord(_tableId, _primaryKeys, _data); + } + + /** Set the full data using the data struct */ + function set(uint256 entity, SkillTemplateData memory _table) internal { + set( + entity, + _table.requiredLevel, + _table.skillType, + _table.withAttack, + _table.withSpell, + _table.cost, + _table.targetType + ); + } + + /** Set the full data using the data struct (using the specified store) */ + function set(IStore _store, uint256 entity, SkillTemplateData memory _table) internal { + set( + _store, + entity, + _table.requiredLevel, + _table.skillType, + _table.withAttack, + _table.withSpell, + _table.cost, + _table.targetType + ); + } + + /** Decode the tightly packed blob using this table's schema */ + function decode(bytes memory _blob) internal pure returns (SkillTemplateData memory _table) { + _table.requiredLevel = (uint8(Bytes.slice1(_blob, 0))); + + _table.skillType = SkillType(uint8(Bytes.slice1(_blob, 1))); + + _table.withAttack = (_toBool(uint8(Bytes.slice1(_blob, 2)))); + + _table.withSpell = (_toBool(uint8(Bytes.slice1(_blob, 3)))); + + _table.cost = (uint32(Bytes.slice4(_blob, 4))); + + _table.targetType = TargetType(uint8(Bytes.slice1(_blob, 8))); + } + + /** Tightly pack full data using this table's schema */ + function encode( + uint8 requiredLevel, + SkillType skillType, + bool withAttack, + bool withSpell, + uint32 cost, + TargetType targetType + ) internal view returns (bytes memory) { + return abi.encodePacked(requiredLevel, skillType, withAttack, withSpell, cost, targetType); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} + +function _toBool(uint8 value) pure returns (bool result) { + assembly { + result := value + } +} diff --git a/packages/contracts/src/codegen/tables/SlotAllowedBases.sol b/packages/contracts/src/codegen/tables/SlotAllowedBases.sol new file mode 100644 index 00000000..c3dffd9a --- /dev/null +++ b/packages/contracts/src/codegen/tables/SlotAllowedBases.sol @@ -0,0 +1,158 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("SlotAllowedBases"))); +bytes32 constant SlotAllowedBasesTableId = _tableId; + +library SlotAllowedBases { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256_ARRAY; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("SlotAllowedBases", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (uint256[] memory value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint256()); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (uint256[] memory value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint256()); + } + + /** Set value */ + function set(uint256 entity, uint256[] memory value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, EncodeArray.encode((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, uint256[] memory value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, EncodeArray.encode((value))); + } + + /** Push an element to value */ + function push(uint256 entity, uint256 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.pushToField(_tableId, _primaryKeys, 0, abi.encodePacked((_element))); + } + + /** Push an element to value (using the specified store) */ + function push(IStore _store, uint256 entity, uint256 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.pushToField(_tableId, _primaryKeys, 0, abi.encodePacked((_element))); + } + + /** Update an element of value at `_index` */ + function update(uint256 entity, uint256 _index, uint256 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.updateInField(_tableId, _primaryKeys, 0, _index * 32, abi.encodePacked((_element))); + } + + /** Update an element of value (using the specified store) at `_index` */ + function update(IStore _store, uint256 entity, uint256 _index, uint256 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.updateInField(_tableId, _primaryKeys, 0, _index * 32, abi.encodePacked((_element))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint256[] memory value) internal view returns (bytes memory) { + uint16[] memory _counters = new uint16[](1); + _counters[0] = uint16(value.length * 32); + PackedCounter _encodedLengths = PackedCounterLib.pack(_counters); + + return abi.encodePacked(_encodedLengths.unwrap(), EncodeArray.encode((value))); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/SlotEquipment.sol b/packages/contracts/src/codegen/tables/SlotEquipment.sol new file mode 100644 index 00000000..4cbabdaa --- /dev/null +++ b/packages/contracts/src/codegen/tables/SlotEquipment.sol @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("SlotEquipment"))); +bytes32 constant SlotEquipmentTableId = _tableId; + +library SlotEquipment { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("SlotEquipment", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (uint256 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (uint256 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (uint256(Bytes.slice32(_blob, 0))); + } + + /** Set value */ + function set(uint256 entity, uint256 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, uint256 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint256 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/SpellDamage.sol b/packages/contracts/src/codegen/tables/SpellDamage.sol new file mode 100644 index 00000000..9ab945ab --- /dev/null +++ b/packages/contracts/src/codegen/tables/SpellDamage.sol @@ -0,0 +1,176 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("SpellDamage"))); +bytes32 constant SpellDamageTableId = _tableId; + +library SpellDamage { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT32_ARRAY; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("SpellDamage", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (uint32[5] memory value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return toStaticArray_uint32_5(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (uint32[5] memory value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return toStaticArray_uint32_5(SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_uint32()); + } + + /** Set value */ + function set(uint256 entity, uint32[5] memory value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, EncodeArray.encode(fromStaticArray_uint32_5(value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, uint32[5] memory value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, EncodeArray.encode(fromStaticArray_uint32_5(value))); + } + + /** Push an element to value */ + function push(uint256 entity, uint32 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.pushToField(_tableId, _primaryKeys, 0, abi.encodePacked((_element))); + } + + /** Push an element to value (using the specified store) */ + function push(IStore _store, uint256 entity, uint32 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.pushToField(_tableId, _primaryKeys, 0, abi.encodePacked((_element))); + } + + /** Update an element of value at `_index` */ + function update(uint256 entity, uint256 _index, uint32 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.updateInField(_tableId, _primaryKeys, 0, _index * 4, abi.encodePacked((_element))); + } + + /** Update an element of value (using the specified store) at `_index` */ + function update(IStore _store, uint256 entity, uint256 _index, uint32 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.updateInField(_tableId, _primaryKeys, 0, _index * 4, abi.encodePacked((_element))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint32[5] memory value) internal view returns (bytes memory) { + uint16[] memory _counters = new uint16[](1); + _counters[0] = uint16(value.length * 4); + PackedCounter _encodedLengths = PackedCounterLib.pack(_counters); + + return abi.encodePacked(_encodedLengths.unwrap(), EncodeArray.encode(fromStaticArray_uint32_5(value))); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} + +function toStaticArray_uint32_5(uint32[] memory _value) pure returns (uint32[5] memory _result) { + // in memory static arrays are just dynamic arrays without the length byte + assembly { + _result := add(_value, 0x20) + } +} + +function fromStaticArray_uint32_5(uint32[5] memory _value) view returns (uint32[] memory _result) { + _result = new uint32[](5); + uint256 fromPointer; + uint256 toPointer; + assembly { + fromPointer := _value + toPointer := add(_result, 0x20) + } + Memory.copy(fromPointer, toPointer, 160); +} diff --git a/packages/contracts/src/codegen/tables/StatmodBase.sol b/packages/contracts/src/codegen/tables/StatmodBase.sol new file mode 100644 index 00000000..ecbe01c3 --- /dev/null +++ b/packages/contracts/src/codegen/tables/StatmodBase.sol @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("StatmodBase"))); +bytes32 constant StatmodBaseTableId = _tableId; + +library StatmodBase { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.BYTES32; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("StatmodBase", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (bytes32 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (Bytes.slice32(_blob, 0)); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (bytes32 value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (Bytes.slice32(_blob, 0)); + } + + /** Set value */ + function set(uint256 entity, bytes32 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, bytes32 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(bytes32 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/StatmodBaseOpts.sol b/packages/contracts/src/codegen/tables/StatmodBaseOpts.sol new file mode 100644 index 00000000..6f039857 --- /dev/null +++ b/packages/contracts/src/codegen/tables/StatmodBaseOpts.sol @@ -0,0 +1,221 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +// Import user types +import { StatmodOp, EleStat } from "./../Types.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("StatmodBaseOpts"))); +bytes32 constant StatmodBaseOptsTableId = _tableId; + +struct StatmodBaseOptsData { + StatmodOp statmodOp; + EleStat eleStat; +} + +library StatmodBaseOpts { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](2); + _schema[0] = SchemaType.UINT8; + _schema[1] = SchemaType.UINT8; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](2); + _fieldNames[0] = "statmodOp"; + _fieldNames[1] = "eleStat"; + return ("StatmodBaseOpts", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get statmodOp */ + function getStatmodOp(uint256 entity) internal view returns (StatmodOp statmodOp) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return StatmodOp(uint8(Bytes.slice1(_blob, 0))); + } + + /** Get statmodOp (using the specified store) */ + function getStatmodOp(IStore _store, uint256 entity) internal view returns (StatmodOp statmodOp) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return StatmodOp(uint8(Bytes.slice1(_blob, 0))); + } + + /** Set statmodOp */ + function setStatmodOp(uint256 entity, StatmodOp statmodOp) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked(uint8(statmodOp))); + } + + /** Set statmodOp (using the specified store) */ + function setStatmodOp(IStore _store, uint256 entity, StatmodOp statmodOp) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked(uint8(statmodOp))); + } + + /** Get eleStat */ + function getEleStat(uint256 entity) internal view returns (EleStat eleStat) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 1); + return EleStat(uint8(Bytes.slice1(_blob, 0))); + } + + /** Get eleStat (using the specified store) */ + function getEleStat(IStore _store, uint256 entity) internal view returns (EleStat eleStat) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 1); + return EleStat(uint8(Bytes.slice1(_blob, 0))); + } + + /** Set eleStat */ + function setEleStat(uint256 entity, EleStat eleStat) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 1, abi.encodePacked(uint8(eleStat))); + } + + /** Set eleStat (using the specified store) */ + function setEleStat(IStore _store, uint256 entity, EleStat eleStat) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 1, abi.encodePacked(uint8(eleStat))); + } + + /** Get the full data */ + function get(uint256 entity) internal view returns (StatmodBaseOptsData memory _table) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getRecord(_tableId, _primaryKeys, getSchema()); + return decode(_blob); + } + + /** Get the full data (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (StatmodBaseOptsData memory _table) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getRecord(_tableId, _primaryKeys, getSchema()); + return decode(_blob); + } + + /** Set the full data using individual values */ + function set(uint256 entity, StatmodOp statmodOp, EleStat eleStat) internal { + bytes memory _data = encode(statmodOp, eleStat); + + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setRecord(_tableId, _primaryKeys, _data); + } + + /** Set the full data using individual values (using the specified store) */ + function set(IStore _store, uint256 entity, StatmodOp statmodOp, EleStat eleStat) internal { + bytes memory _data = encode(statmodOp, eleStat); + + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setRecord(_tableId, _primaryKeys, _data); + } + + /** Set the full data using the data struct */ + function set(uint256 entity, StatmodBaseOptsData memory _table) internal { + set(entity, _table.statmodOp, _table.eleStat); + } + + /** Set the full data using the data struct (using the specified store) */ + function set(IStore _store, uint256 entity, StatmodBaseOptsData memory _table) internal { + set(_store, entity, _table.statmodOp, _table.eleStat); + } + + /** Decode the tightly packed blob using this table's schema */ + function decode(bytes memory _blob) internal pure returns (StatmodBaseOptsData memory _table) { + _table.statmodOp = StatmodOp(uint8(Bytes.slice1(_blob, 0))); + + _table.eleStat = EleStat(uint8(Bytes.slice1(_blob, 1))); + } + + /** Tightly pack full data using this table's schema */ + function encode(StatmodOp statmodOp, EleStat eleStat) internal view returns (bytes memory) { + return abi.encodePacked(statmodOp, eleStat); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/StatmodScope.sol b/packages/contracts/src/codegen/tables/StatmodScope.sol new file mode 100644 index 00000000..dfc40393 --- /dev/null +++ b/packages/contracts/src/codegen/tables/StatmodScope.sol @@ -0,0 +1,129 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("StatmodScope"))); +bytes32 constant StatmodScopeTableId = _tableId; + +library StatmodScope { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.BYTES32; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](2); + _schema[0] = SchemaType.UINT256; + _schema[1] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("StatmodScope", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 targetEntity, uint256 baseEntity) internal view returns (bytes32 value) { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((baseEntity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (Bytes.slice32(_blob, 0)); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 targetEntity, uint256 baseEntity) internal view returns (bytes32 value) { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((baseEntity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (Bytes.slice32(_blob, 0)); + } + + /** Set value */ + function set(uint256 targetEntity, uint256 baseEntity, bytes32 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((baseEntity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 targetEntity, uint256 baseEntity, bytes32 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((baseEntity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(bytes32 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 targetEntity, uint256 baseEntity) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((baseEntity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 targetEntity, uint256 baseEntity) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((baseEntity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/StatmodValue.sol b/packages/contracts/src/codegen/tables/StatmodValue.sol new file mode 100644 index 00000000..ce6e275d --- /dev/null +++ b/packages/contracts/src/codegen/tables/StatmodValue.sol @@ -0,0 +1,129 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("StatmodValue"))); +bytes32 constant StatmodValueTableId = _tableId; + +library StatmodValue { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT32; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](2); + _schema[0] = SchemaType.UINT256; + _schema[1] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("StatmodValue", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 targetEntity, uint256 baseEntity) internal view returns (uint32 value) { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((baseEntity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 targetEntity, uint256 baseEntity) internal view returns (uint32 value) { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((baseEntity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Set value */ + function set(uint256 targetEntity, uint256 baseEntity, uint32 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((baseEntity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 targetEntity, uint256 baseEntity, uint32 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((baseEntity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint32 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 targetEntity, uint256 baseEntity) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((baseEntity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 targetEntity, uint256 baseEntity) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((targetEntity))); + _primaryKeys[1] = bytes32(uint256((baseEntity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/WNFTOwnership.sol b/packages/contracts/src/codegen/tables/WNFTOwnership.sol new file mode 100644 index 00000000..443d6870 --- /dev/null +++ b/packages/contracts/src/codegen/tables/WNFTOwnership.sol @@ -0,0 +1,122 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("WNFTOwnership"))); +bytes32 constant WNFTOwnershipTableId = _tableId; + +library WNFTOwnership { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.ADDRESS; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("WNFTOwnership", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 tokenId) internal view returns (address value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((tokenId))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (address(Bytes.slice20(_blob, 0))); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 tokenId) internal view returns (address value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((tokenId))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (address(Bytes.slice20(_blob, 0))); + } + + /** Set value */ + function set(uint256 tokenId, address value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((tokenId))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 tokenId, address value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((tokenId))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(address value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 tokenId) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((tokenId))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 tokenId) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((tokenId))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/codegen/tables/Wanderer.sol b/packages/contracts/src/codegen/tables/Wanderer.sol new file mode 100644 index 00000000..e3cae094 --- /dev/null +++ b/packages/contracts/src/codegen/tables/Wanderer.sol @@ -0,0 +1,128 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("Wanderer"))); +bytes32 constant WandererTableId = _tableId; + +library Wanderer { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.BOOL; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("Wanderer", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 entity) internal view returns (bool value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (_toBool(uint8(Bytes.slice1(_blob, 0)))); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (bool value) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (_toBool(uint8(Bytes.slice1(_blob, 0)))); + } + + /** Set value */ + function set(uint256 entity, bool value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 entity, bool value) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(bool value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} + +function _toBool(uint8 value) pure returns (bool result) { + assembly { + result := value + } +} diff --git a/packages/contracts/src/codegen/tables/Wheel.sol b/packages/contracts/src/codegen/tables/Wheel.sol new file mode 100644 index 00000000..a380206a --- /dev/null +++ b/packages/contracts/src/codegen/tables/Wheel.sol @@ -0,0 +1,266 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("Wheel"))); +bytes32 constant WheelTableId = _tableId; + +struct WheelData { + uint32 totalIdentityRequired; + uint32 charges; + bool isIsolated; +} + +library Wheel { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](3); + _schema[0] = SchemaType.UINT32; + _schema[1] = SchemaType.UINT32; + _schema[2] = SchemaType.BOOL; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](3); + _fieldNames[0] = "totalIdentityRequired"; + _fieldNames[1] = "charges"; + _fieldNames[2] = "isIsolated"; + return ("Wheel", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get totalIdentityRequired */ + function getTotalIdentityRequired(uint256 entity) internal view returns (uint32 totalIdentityRequired) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Get totalIdentityRequired (using the specified store) */ + function getTotalIdentityRequired( + IStore _store, + uint256 entity + ) internal view returns (uint32 totalIdentityRequired) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Set totalIdentityRequired */ + function setTotalIdentityRequired(uint256 entity, uint32 totalIdentityRequired) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((totalIdentityRequired))); + } + + /** Set totalIdentityRequired (using the specified store) */ + function setTotalIdentityRequired(IStore _store, uint256 entity, uint32 totalIdentityRequired) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((totalIdentityRequired))); + } + + /** Get charges */ + function getCharges(uint256 entity) internal view returns (uint32 charges) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 1); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Get charges (using the specified store) */ + function getCharges(IStore _store, uint256 entity) internal view returns (uint32 charges) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 1); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Set charges */ + function setCharges(uint256 entity, uint32 charges) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 1, abi.encodePacked((charges))); + } + + /** Set charges (using the specified store) */ + function setCharges(IStore _store, uint256 entity, uint32 charges) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 1, abi.encodePacked((charges))); + } + + /** Get isIsolated */ + function getIsIsolated(uint256 entity) internal view returns (bool isIsolated) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 2); + return (_toBool(uint8(Bytes.slice1(_blob, 0)))); + } + + /** Get isIsolated (using the specified store) */ + function getIsIsolated(IStore _store, uint256 entity) internal view returns (bool isIsolated) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 2); + return (_toBool(uint8(Bytes.slice1(_blob, 0)))); + } + + /** Set isIsolated */ + function setIsIsolated(uint256 entity, bool isIsolated) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 2, abi.encodePacked((isIsolated))); + } + + /** Set isIsolated (using the specified store) */ + function setIsIsolated(IStore _store, uint256 entity, bool isIsolated) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setField(_tableId, _primaryKeys, 2, abi.encodePacked((isIsolated))); + } + + /** Get the full data */ + function get(uint256 entity) internal view returns (WheelData memory _table) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = StoreSwitch.getRecord(_tableId, _primaryKeys, getSchema()); + return decode(_blob); + } + + /** Get the full data (using the specified store) */ + function get(IStore _store, uint256 entity) internal view returns (WheelData memory _table) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + bytes memory _blob = _store.getRecord(_tableId, _primaryKeys, getSchema()); + return decode(_blob); + } + + /** Set the full data using individual values */ + function set(uint256 entity, uint32 totalIdentityRequired, uint32 charges, bool isIsolated) internal { + bytes memory _data = encode(totalIdentityRequired, charges, isIsolated); + + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.setRecord(_tableId, _primaryKeys, _data); + } + + /** Set the full data using individual values (using the specified store) */ + function set(IStore _store, uint256 entity, uint32 totalIdentityRequired, uint32 charges, bool isIsolated) internal { + bytes memory _data = encode(totalIdentityRequired, charges, isIsolated); + + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.setRecord(_tableId, _primaryKeys, _data); + } + + /** Set the full data using the data struct */ + function set(uint256 entity, WheelData memory _table) internal { + set(entity, _table.totalIdentityRequired, _table.charges, _table.isIsolated); + } + + /** Set the full data using the data struct (using the specified store) */ + function set(IStore _store, uint256 entity, WheelData memory _table) internal { + set(_store, entity, _table.totalIdentityRequired, _table.charges, _table.isIsolated); + } + + /** Decode the tightly packed blob using this table's schema */ + function decode(bytes memory _blob) internal pure returns (WheelData memory _table) { + _table.totalIdentityRequired = (uint32(Bytes.slice4(_blob, 0))); + + _table.charges = (uint32(Bytes.slice4(_blob, 4))); + + _table.isIsolated = (_toBool(uint8(Bytes.slice1(_blob, 8)))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint32 totalIdentityRequired, uint32 charges, bool isIsolated) internal view returns (bytes memory) { + return abi.encodePacked(totalIdentityRequired, charges, isIsolated); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 entity) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32(uint256((entity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} + +function _toBool(uint8 value) pure returns (bool result) { + assembly { + result := value + } +} diff --git a/packages/contracts/src/codegen/tables/WheelsCompleted.sol b/packages/contracts/src/codegen/tables/WheelsCompleted.sol new file mode 100644 index 00000000..18a4a22b --- /dev/null +++ b/packages/contracts/src/codegen/tables/WheelsCompleted.sol @@ -0,0 +1,129 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +bytes32 constant _tableId = bytes32(abi.encodePacked(bytes16(""), bytes16("WheelsCompleted"))); +bytes32 constant WheelsCompletedTableId = _tableId; + +library WheelsCompleted { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.UINT32; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](2); + _schema[0] = SchemaType.UINT256; + _schema[1] = SchemaType.UINT256; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "value"; + return ("WheelsCompleted", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema() internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata() internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get value */ + function get(uint256 wandererEntity, uint256 wheelEntity) internal view returns (uint32 value) { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((wandererEntity))); + _primaryKeys[1] = bytes32(uint256((wheelEntity))); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Get value (using the specified store) */ + function get(IStore _store, uint256 wandererEntity, uint256 wheelEntity) internal view returns (uint32 value) { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((wandererEntity))); + _primaryKeys[1] = bytes32(uint256((wheelEntity))); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (uint32(Bytes.slice4(_blob, 0))); + } + + /** Set value */ + function set(uint256 wandererEntity, uint256 wheelEntity, uint32 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((wandererEntity))); + _primaryKeys[1] = bytes32(uint256((wheelEntity))); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Set value (using the specified store) */ + function set(IStore _store, uint256 wandererEntity, uint256 wheelEntity, uint32 value) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((wandererEntity))); + _primaryKeys[1] = bytes32(uint256((wheelEntity))); + + _store.setField(_tableId, _primaryKeys, 0, abi.encodePacked((value))); + } + + /** Tightly pack full data using this table's schema */ + function encode(uint32 value) internal view returns (bytes memory) { + return abi.encodePacked(value); + } + + /* Delete all data for given keys */ + function deleteRecord(uint256 wandererEntity, uint256 wheelEntity) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((wandererEntity))); + _primaryKeys[1] = bytes32(uint256((wheelEntity))); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, uint256 wandererEntity, uint256 wheelEntity) internal { + bytes32[] memory _primaryKeys = new bytes32[](2); + _primaryKeys[0] = bytes32(uint256((wandererEntity))); + _primaryKeys[1] = bytes32(uint256((wheelEntity))); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/modules/keyvalueindex/KeyValueIndexHook.sol b/packages/contracts/src/modules/keyvalueindex/KeyValueIndexHook.sol new file mode 100644 index 00000000..27df0a09 --- /dev/null +++ b/packages/contracts/src/modules/keyvalueindex/KeyValueIndexHook.sol @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +import { IStoreHook } from "@latticexyz/store/src/IStore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { IBaseWorld } from "@latticexyz/world/src/interfaces/IBaseWorld.sol"; + +import { ResourceSelector } from "@latticexyz/world/src/ResourceSelector.sol"; + +import { MODULE_NAMESPACE } from "./constants.sol"; +import { KeyValueIndex } from "./tables/KeyValueIndex.sol"; +import { ArrayLib } from "@latticexyz/world/src/modules/utils/ArrayLib.sol"; +import { getTargetTableSelector } from "@latticexyz/world/src/modules/utils/getTargetTableSelector.sol"; + +/** + * This is a very naive and inefficient implementation for now. + * We can optimize this by adding support for `setIndexOfField` in Store + * and then replicate logic from solecs's Set.sol. + * (See https://github.com/latticexyz/mud/issues/444) + * + * Note: if a table with composite keys is used, only the first key is indexed + */ +contract KeysWithValueHook is IStoreHook { + using ArrayLib for bytes32[]; + using ResourceSelector for bytes32; + + function onSetRecord(uint256 sourceTableId, bytes32[] memory key, bytes memory data) public { + uint256 targetTableId = getTargetTableSelector(MODULE_NAMESPACE, sourceTableId).toTableId(); + + // Get the previous value + bytes32 previousValue = keccak256(IBaseWorld(msg.sender).getRecord(sourceTableId, key)); + + // Return if the value hasn't changed + if (previousValue == keccak256(data)) return; + + // Remove the key from the list of keys with the previous value + _removeKeyFromList(targetTableId, key[0], previousValue); + + // Push the key to the list of keys with the new value + KeysWithValue.push(targetTableId, keccak256(data), key[0]); + } + + function onBeforeSetField(uint256 sourceTableId, bytes32[] memory key, uint8, bytes memory) public { + // Remove the key from the list of keys with the previous value + bytes32 previousValue = keccak256(IBaseWorld(msg.sender).getRecord(sourceTableId, key)); + uint256 targetTableId = getTargetTableSelector(MODULE_NAMESPACE, sourceTableId).toTableId(); + _removeKeyFromList(targetTableId, key[0], previousValue); + } + + function onAfterSetField(uint256 sourceTableId, bytes32[] memory key, uint8, bytes memory) public { + // Add the key to the list of keys with the new value + bytes32 newValue = keccak256(IBaseWorld(msg.sender).getRecord(sourceTableId, key)); + uint256 targetTableId = getTargetTableSelector(MODULE_NAMESPACE, sourceTableId).toTableId(); + KeysWithValue.push(targetTableId, newValue, key[0]); + } + + function onDeleteRecord(uint256 sourceTableId, bytes32[] memory key) public { + // Remove the key from the list of keys with the previous value + bytes32 previousValue = keccak256(IBaseWorld(msg.sender).getRecord(sourceTableId, key)); + uint256 targetTableId = getTargetTableSelector(MODULE_NAMESPACE, sourceTableId).toTableId(); + _removeKeyFromList(targetTableId, key[0], previousValue); + } + + function _removeKeyFromList(uint256 targetTableId, bytes32 key, bytes32 valueHash) internal { + // Get the keys with the previous value excluding the current key + bytes32[] memory keysWithPreviousValue = KeysWithValue.get(targetTableId, valueHash).filter(key); + + // Set the keys with the previous value + KeysWithValue.set(targetTableId, valueHash, keysWithPreviousValue); + } +} diff --git a/packages/contracts/src/modules/keyvalueindex/KeyValueIndexModule.sol b/packages/contracts/src/modules/keyvalueindex/KeyValueIndexModule.sol new file mode 100644 index 00000000..0a197378 --- /dev/null +++ b/packages/contracts/src/modules/keyvalueindex/KeyValueIndexModule.sol @@ -0,0 +1,67 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; + +import { IBaseWorld } from "../../interfaces/IBaseWorld.sol"; +import { IModule } from "../../interfaces/IModule.sol"; + +import { WorldContext } from "../../WorldContext.sol"; +import { ResourceSelector } from "../../ResourceSelector.sol"; + +import { MODULE_NAMESPACE } from "./constants.sol"; +import { KeysWithValueHook } from "./KeysWithValueHook.sol"; +import { KeysWithValue } from "./tables/KeysWithValue.sol"; +import { getTargetTableSelector } from "../utils/getTargetTableSelector.sol"; + +/** + * This module deploys a hook that is called when a value is set in the `sourceTableId` + * provided in the install methods arguments. The hook keeps track of the keys that map to a given value. + * from value to list of keys with this value. This mapping is stored in a table registered + * by the module at the `targetTableId` provided in the install methods arguments. + * + * Note: if a table with composite keys is used, only the first key is indexed + * + * Note: this module currently expects to be `delegatecalled` via World.installRootModule. + * Support for installing it via `World.installModule` depends on `World.callFrom` being implemented. + */ +contract KeysWithValueModule is IModule, WorldContext { + using ResourceSelector for bytes32; + + // The KeysWithValueHook is deployed once and infers the target table id + // from the source table id (passed as argument to the hook methods) + KeysWithValueHook immutable hook = new KeysWithValueHook(); + + function getName() public pure returns (bytes16) { + return bytes16("index"); + } + + function install(bytes memory args) public override { + // Extract source table id from args + uint256 sourceTableId = abi.decode(args, (uint256)); + bytes32 targetTableSelector = getTargetTableSelector(MODULE_NAMESPACE, sourceTableId); + + // Register the target table + IBaseWorld(_world()).registerTable( + targetTableSelector.getNamespace(), + targetTableSelector.getFile(), + KeysWithValue.getSchema(), + KeysWithValue.getKeySchema() + ); + + // Register metadata for the target table + (string memory tableName, string[] memory fieldNames) = KeysWithValue.getMetadata(); + IBaseWorld(_world()).setMetadata( + targetTableSelector.getNamespace(), + targetTableSelector.getFile(), + tableName, + fieldNames + ); + + // Grant the hook access to the target table + IBaseWorld(_world()).grantAccess(targetTableSelector.getNamespace(), targetTableSelector.getFile(), address(hook)); + + // Register a hook that is called when a value is set in the source table + StoreSwitch.registerStoreHook(sourceTableId, hook); + } +} diff --git a/packages/contracts/src/modules/keyvalueindex/constants.sol b/packages/contracts/src/modules/keyvalueindex/constants.sol new file mode 100644 index 00000000..dcf875b4 --- /dev/null +++ b/packages/contracts/src/modules/keyvalueindex/constants.sol @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +// Limiting the module namespace to 8 bytes so the last 8 bytes +// can be used for an identifier of the source table namespace to avoid +// collisions between tables with the same name in different namespaces +bytes8 constant MODULE_NAMESPACE = "kvindex"; diff --git a/packages/contracts/src/modules/keyvalueindex/getKeysForIndex.sol b/packages/contracts/src/modules/keyvalueindex/getKeysForIndex.sol new file mode 100644 index 00000000..ef961058 --- /dev/null +++ b/packages/contracts/src/modules/keyvalueindex/getKeysForIndex.sol @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +import { IStore } from "@latticexyz/store/src/IStore.sol"; + +import { getTargetTableSelector } from "@latticexyz/world/src/modules/utils/getTargetTableSelector.sol"; + +import { MODULE_NAMESPACE } from "./constants.sol"; +import { KeysWithValue } from "./tables/KeysWithValue.sol"; + +/** + * Get a list of keys with the given value. + * + * Note: this util can only be called within the context of a Store (e.g. from a System or Module). + * For usage outside of a Store, use the overload that takes an explicit store argument. + */ +function getKeysWithValue(uint256 tableId, bytes memory value) view returns (bytes32[] memory keysWithValue) { + // Get the corresponding reverse mapping table + uint256 keysWithValueTableId = uint256(getTargetTableSelector(MODULE_NAMESPACE, tableId)); + + // Get the keys with the given value + keysWithValue = KeysWithValue.get(keysWithValueTableId, keccak256(value)); +} + +/** + * Get a list of keys with the given value for the given store. + */ +function getKeysWithValue( + IStore store, + uint256 tableId, + bytes memory value +) view returns (bytes32[] memory keysWithValue) { + // Get the corresponding reverse mapping table + uint256 keysWithValueTableId = uint256(getTargetTableSelector(MODULE_NAMESPACE, tableId)); + + // Get the keys with the given value + keysWithValue = KeysWithValue.get(store, keysWithValueTableId, keccak256(value)); +} diff --git a/packages/contracts/src/modules/keyvalueindex/tables/KeyValueIndex.sol b/packages/contracts/src/modules/keyvalueindex/tables/KeyValueIndex.sol new file mode 100644 index 00000000..7af435e9 --- /dev/null +++ b/packages/contracts/src/modules/keyvalueindex/tables/KeyValueIndex.sol @@ -0,0 +1,159 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +/* Autogenerated file. Do not edit manually. */ + +// Import schema type +import { SchemaType } from "@latticexyz/schema-type/src/solidity/SchemaType.sol"; + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { Schema, SchemaLib } from "@latticexyz/store/src/Schema.sol"; +import { PackedCounter, PackedCounterLib } from "@latticexyz/store/src/PackedCounter.sol"; + +library KeyValueIndex { + /** Get the table's schema */ + function getSchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.BYTES32_ARRAY; + + return SchemaLib.encode(_schema); + } + + function getKeySchema() internal pure returns (Schema) { + SchemaType[] memory _schema = new SchemaType[](1); + _schema[0] = SchemaType.BYTES32; + + return SchemaLib.encode(_schema); + } + + /** Get the table's metadata */ + function getMetadata() internal pure returns (string memory, string[] memory) { + string[] memory _fieldNames = new string[](1); + _fieldNames[0] = "indexedKeys"; + return ("KeyValueIndex", _fieldNames); + } + + /** Register the table's schema */ + function registerSchema(bytes32 _tableId) internal { + StoreSwitch.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Register the table's schema (using the specified store) */ + function registerSchema(IStore _store, bytes32 _tableId) internal { + _store.registerSchema(_tableId, getSchema(), getKeySchema()); + } + + /** Set the table's metadata */ + function setMetadata(bytes32 _tableId) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + StoreSwitch.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Set the table's metadata (using the specified store) */ + function setMetadata(IStore _store, bytes32 _tableId) internal { + (string memory _tableName, string[] memory _fieldNames) = getMetadata(); + _store.setMetadata(_tableId, _tableName, _fieldNames); + } + + /** Get indexedKeys */ + function get(bytes32 _tableId, bytes32 keyValueHash) internal view returns (bytes32[] memory indexedKeys) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((keyValueHash)); + + bytes memory _blob = StoreSwitch.getField(_tableId, _primaryKeys, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); + } + + /** Get indexedKeys (using the specified store) */ + function get( + IStore _store, + bytes32 _tableId, + bytes32 keyValueHash + ) internal view returns (bytes32[] memory indexedKeys) { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((keyValueHash)); + + bytes memory _blob = _store.getField(_tableId, _primaryKeys, 0); + return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_bytes32()); + } + + /** Set indexedKeys */ + function set(bytes32 _tableId, bytes32 keyValueHash, bytes32[] memory indexedKeys) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((keyValueHash)); + + StoreSwitch.setField(_tableId, _primaryKeys, 0, EncodeArray.encode((indexedKeys))); + } + + /** Set indexedKeys (using the specified store) */ + function set(IStore _store, bytes32 _tableId, bytes32 keyValueHash, bytes32[] memory indexedKeys) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((keyValueHash)); + + _store.setField(_tableId, _primaryKeys, 0, EncodeArray.encode((indexedKeys))); + } + + /** Push an element to indexedKeys */ + function push(bytes32 _tableId, bytes32 keyValueHash, bytes32 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((keyValueHash)); + + StoreSwitch.pushToField(_tableId, _primaryKeys, 0, abi.encodePacked((_element))); + } + + /** Push an element to indexedKeys (using the specified store) */ + function push(IStore _store, bytes32 _tableId, bytes32 keyValueHash, bytes32 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((keyValueHash)); + + _store.pushToField(_tableId, _primaryKeys, 0, abi.encodePacked((_element))); + } + + /** Update an element of indexedKeys at `_index` */ + function update(bytes32 _tableId, bytes32 keyValueHash, uint256 _index, bytes32 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((keyValueHash)); + + StoreSwitch.updateInField(_tableId, _primaryKeys, 0, _index * 32, abi.encodePacked((_element))); + } + + /** Update an element of indexedKeys (using the specified store) at `_index` */ + function update(IStore _store, bytes32 _tableId, bytes32 keyValueHash, uint256 _index, bytes32 _element) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((keyValueHash)); + + _store.updateInField(_tableId, _primaryKeys, 0, _index * 32, abi.encodePacked((_element))); + } + + /** Tightly pack full data using this table's schema */ + function encode(bytes32[] memory indexedKeys) internal view returns (bytes memory) { + uint16[] memory _counters = new uint16[](1); + _counters[0] = uint16(indexedKeys.length * 32); + PackedCounter _encodedLengths = PackedCounterLib.pack(_counters); + + return abi.encodePacked(_encodedLengths.unwrap(), EncodeArray.encode((indexedKeys))); + } + + /* Delete all data for given keys */ + function deleteRecord(bytes32 _tableId, bytes32 keyValueHash) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((keyValueHash)); + + StoreSwitch.deleteRecord(_tableId, _primaryKeys); + } + + /* Delete all data for given keys (using the specified store) */ + function deleteRecord(IStore _store, bytes32 _tableId, bytes32 keyValueHash) internal { + bytes32[] memory _primaryKeys = new bytes32[](1); + _primaryKeys[0] = bytes32((keyValueHash)); + + _store.deleteRecord(_tableId, _primaryKeys); + } +} diff --git a/packages/contracts/src/modules/utils/ArrayLib.sol b/packages/contracts/src/modules/utils/ArrayLib.sol new file mode 100644 index 00000000..2fdcd039 --- /dev/null +++ b/packages/contracts/src/modules/utils/ArrayLib.sol @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.0; + +library ArrayLib { + function includes(bytes32[] memory arr, bytes32 element) internal pure returns (bool) { + for (uint256 i; i < arr.length; i++) { + if (arr[i] == element) { + return true; + } + } + return false; + } + + function filter(bytes32[] memory arr, bytes32 element) internal pure returns (bytes32[] memory) { + bytes32[] memory filtered = new bytes32[](arr.length); + uint256 filteredIndex = 0; + for (uint256 i; i < arr.length; i++) { + if (arr[i] != element) { + filtered[filteredIndex] = arr[i]; + filteredIndex++; + } + } + + // In-place update the length of the array + // (Note: this does not update the free memory pointer) + assembly { + mstore(filtered, filteredIndex) + } + + return filtered; + } +} diff --git a/packages/contracts/src/statmod/ScopedValue.sol b/packages/contracts/src/statmod/ScopedValue.sol new file mode 100644 index 00000000..b917f8e0 --- /dev/null +++ b/packages/contracts/src/statmod/ScopedValue.sol @@ -0,0 +1,299 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.17; + +import { IUint256Component } from "@latticexyz/solecs/src/interfaces/IUint256Component.sol"; +import { getAddressById } from "@latticexyz/solecs/src/utils.sol"; + +import { ScopeComponent } from "./ScopeComponent.sol"; +import { ValueComponent } from "./ValueComponent.sol"; + +/** + * @title Interact with batches (identified by scope) of entity values, or individual entity values. + * @dev Scope is for doing batched read/increase/decrease without looping through everything. + * Value is any kind of entity to counter mapping. + * + * You can see a simple example with turn-based time in tests. + * + * A more complex use case: + * A status effect system adds 3 modifiers to playerEntity: + * [ + * { value: 2, op: "add", element: "fire", topic: "attack", mod: "+# fire to attack" }, + * { value: 50, op: "mul", element: "fire", topic: "attack", mod: "#% increased fire attack" }, + * { value: 10 op: "add", element: "none", topic: "life", mod: "+# life" } + * ] + * scoped by affected playerEntity and topic: {playerEntity, topic}. + * Now if you need attack for player #7, use {7, 'attack'} scope to avoid looping everything. + * This is only useful if you have many modififers with different topics. + * And without parameterization (element, op), you could just sum up values and not need scope=>entity mapping. + * + * Generally you would need only a subset of ScopedValue's methods, + * the status effect example wouldn't care about scope modifications (increaseScope/decreaseScope), + * whereas the time example doesn't care about scope reads (getEntities). + */ +library ScopedValue { + error ScopedValue__IncreaseByZero(); + error ScopedValue__DecreaseByZero(); + error ScopedValue__EntityAbsent(); + + struct Self { + ScopeComponent scopeComp; + ValueComponent valueComp; + } + + /** + * @param components world.components() + * @param scopeComponentId ID of ScopeComponent implementation + * @param valueComponentId ID of ValueComponent implementation + */ + function __construct( + IUint256Component components, + uint256 scopeComponentId, + uint256 valueComponentId + ) internal view returns (Self memory) { + return Self({ + scopeComp: ScopeComponent(getAddressById(components, scopeComponentId)), + valueComp: ValueComponent(getAddressById(components, valueComponentId)) + }); + } + + /*////////////////////////////////////////////////////////////// + READ + //////////////////////////////////////////////////////////////*/ + + /** + * @notice Whether both scope and value have `entity` + */ + function has( + Self memory __self, + uint256 entity + ) internal view returns (bool) { + // invariant: scopeComp.has(entity) == valueComp.has(entity) + return __self.scopeComp.has(entity); + } + + /** + * @notice Get value for `entity` + */ + function getValue( + Self memory __self, + uint256 entity + ) internal view returns (uint256) { + return __self.valueComp.getValue(entity); + } + + /** + * @notice Get scope for `entity` + */ + function getScope( + Self memory __self, + uint256 entity + ) internal view returns (string memory) { + return __self.scopeComp.getValue(entity); + } + + /** + * @notice Get array of `entities` within `scope` + */ + function getEntities( + Self memory __self, + string memory scope + ) internal view returns (uint256[] memory entities) { + return __self.scopeComp.getEntitiesWithValue(scope); + } + + /** + * @notice Get array of `entities` within `scope`, and their `values` + */ + function getEntitiesValues( + Self memory __self, + string memory scope + ) internal view returns (uint256[] memory entities, uint256[] memory values) { + entities = getEntities(__self, scope); + // get values for entities + values = new uint256[](entities.length); + for (uint256 i; i < entities.length; i++) { + values[i] = __self.valueComp.getValue(entities[i]); + } + } + + /*////////////////////////////////////////////////////////////// + WRITE + //////////////////////////////////////////////////////////////*/ + + /** + * @notice Increase value for `entity`; update scope if necessary + * @return isUpdate true if only updated, false if created + */ + function increaseEntity( + Self memory __self, + string memory scope, + uint256 entity, + uint256 value + ) internal returns (bool isUpdate) { + // zero increase is invalid + if (value == 0) { + revert ScopedValue__IncreaseByZero(); + } + + // get stored data + isUpdate = has(__self, entity); + if (isUpdate) { + uint256 storedValue = __self.valueComp.getValue(entity); + _update(__self, scope, entity, storedValue + value); + } else { + // set scope and value + __self.scopeComp.set(entity, scope); + __self.valueComp.set(entity, value); + } + } + + /** + * @notice Decrease value for `entity`; update scope if necessary + * @dev When a value would become <= 0, it is removed instead + * @return isUpdate true if only updated, false if removed + */ + function decreaseEntity( + Self memory __self, + string memory scope, + uint256 entity, + uint256 value + ) internal returns (bool isUpdate) { + // zero decrease is invalid + if (value == 0) { + revert ScopedValue__DecreaseByZero(); + } + // can't decrease nonexistent value + if (!has(__self, entity)) { + revert ScopedValue__EntityAbsent(); + } + + uint256 storedValue = __self.valueComp.getValue(entity); + isUpdate = storedValue > value; + if (isUpdate) { + _update(__self, scope, entity, storedValue - value); + } else { + removeEntity(__self, entity); + } + } + + /** + * @dev sets new entity values for both increase and decrease + */ + function _update( + Self memory __self, + string memory newScope, + uint256 entity, + uint256 newValue + ) private { + // update scope if necessary + if (keccak256(bytes(newScope)) != keccak256(bytes(__self.scopeComp.getValue(entity)))) { + __self.scopeComp.set(entity, newScope); + } + // decrease value + __self.valueComp.set(entity, newValue); + } + + /** + * @notice Within `scope` increase all values + * + * TODO should this return updated values? + */ + function increaseScope( + Self memory __self, + string memory scope, + uint256 value + ) internal { + // zero increase is invalid + if (value == 0) { + revert ScopedValue__IncreaseByZero(); + } + + uint256[] memory entities = __self.scopeComp.getEntitiesWithValue(scope); + // loop all entities within scope + for (uint256 i; i < entities.length; i++) { + uint256 entity = entities[i]; + uint256 storedValue = __self.valueComp.getValue(entity); + // increase + __self.valueComp.set(entity, storedValue + value); + } + } + + /** + * @notice Within `scope` decrease all values + * @dev When a value would become <= 0, it is removed instead + * @return removedEntities entities that were removed due to being <= 0 + */ + function decreaseScope( + Self memory __self, + string memory scope, + uint256 value + ) internal returns (uint256[] memory) { + // zero decrease is invalid + if (value == 0) { + revert ScopedValue__DecreaseByZero(); + } + + uint256[] memory entities = __self.scopeComp.getEntitiesWithValue(scope); + // track removed entities + uint256[] memory removedEntities = new uint256[](entities.length); + uint256 removedLength; + // loop all entities within scope + for (uint256 i; i < entities.length; i++) { + uint256 entity = entities[i]; + uint256 storedValue = __self.valueComp.getValue(entity); + + // if decrease >= stored + if (value >= storedValue) { + // remove + removeEntity(__self, entity); + + removedEntities[removedLength++] = entity; + } else { + // decrease + __self.valueComp.set(entity, storedValue - value); + } + } + + // return removedEntities with unused space sliced off + if (removedEntities.length == removedLength) { + return removedEntities; + } + // TODO I think this can be replaced with something like + // mstore(removedEntities, sub(mload(removedEntities), lengthDiff)) + uint256[] memory removedEntitiesSliced = new uint256[](removedLength); + for (uint256 i; i < removedLength; i++) { + removedEntitiesSliced[i] = removedEntities[i]; + } + return removedEntitiesSliced; + } + + /** + * @notice Remove `entity` from value and scope components + */ + function removeEntity( + Self memory __self, + uint256 entity + ) internal { + // can't remove nonexistent value + if (!has(__self, entity)) { + revert ScopedValue__EntityAbsent(); + } + __self.valueComp.remove(entity); + __self.scopeComp.remove(entity); + } + + /** + * @notice Remove all entities within `scope` from value and scope components + */ + function removeScope( + Self memory __self, + string memory scope + ) internal { + uint256[] memory entities = __self.scopeComp.getEntitiesWithValue(scope); + for (uint256 i; i < entities.length; i++) { + __self.valueComp.remove(entities[i]); + __self.scopeComp.remove(entities[i]); + } + } +} \ No newline at end of file diff --git a/packages/contracts/src/statmod/Statmod.sol b/packages/contracts/src/statmod/Statmod.sol index b6038c65..db7223af 100644 --- a/packages/contracts/src/statmod/Statmod.sol +++ b/packages/contracts/src/statmod/Statmod.sol @@ -9,90 +9,97 @@ import { StatmodPrototype, Op, OP_L, OP_FINAL, Element, EL_L, StatmodPrototypeCo import { ScopedValue } from "@dk1a/solecslib/contracts/scoped-value/ScopedValue.sol"; import { FromPrototype } from "@dk1a/solecslib/contracts/prototype/FromPrototype.sol"; import { ScopedValueFromPrototype } from "@dk1a/solecslib/contracts/scoped-value/ScopedValueFromPrototype.sol"; -import { ID as StatmodScopeComponentID } from "./StatmodScopeComponent.sol"; -import { ID as StatmodValueComponentID } from "./StatmodValueComponent.sol"; -import { ID as FromPrototypeComponentID } from "../common/FromPrototypeComponent.sol"; + +/*StatmodBase: { + ...entityKey, + schema: "bytes32", +}, +FromStatmodBase: entityRelation, +StatmodBaseOpts: { + ...entityKey, + schema: { + statmodOp: "StatmodOp", + eleStat: "EleStat", + } +}, +StatmodScope: { + primaryKeys: { + targetEntity: EntityId, + baseEntity: EntityId, + }, + schema: "bytes32" +}, +StatmodValue: { + primaryKeys: { + targetEntity: EntityId, + baseEntity: EntityId, + }, + schema: "uint32" +},*/ + +import { getKeysWithValue } from "@latticexyz/world/src/modules/keyswithvalue/getKeysWithValue.sol"; + +import { StatmodBase, FromStatmodBase, StatmodBaseOpts, StatmodScope, StatmodValue } from "../codegen/Tables.sol"; /** * @title Scoped statmod values with aggregation depending on prototype. */ library Statmod { - using ScopedValueFromPrototype for ScopedValueFromPrototype.Self; - - struct Self { - StatmodPrototypeComponent protoComp; - ScopedValueFromPrototype.Self sv; - uint256 targetEntity; - } + error Statmod_IncreaseByZero(); + error Statmod_DecreaseByZero(); + error Statmod_EntityAbsent(); /** - * @param components world.components() - * @param targetEntity context for instances of protoEntities. - * Modifying the same protoEntity with different targetEntities will not affect each other. + * @dev Increase statmod value for targeted baseEntity. */ - function __construct(IUint256Component components, uint256 targetEntity) internal view returns (Self memory) { - return - Self({ - protoComp: StatmodPrototypeComponent(getAddressById(components, StatmodPrototypeComponentID)), - sv: ScopedValueFromPrototype.__construct( - ScopedValue.__construct(components, StatmodScopeComponentID, StatmodValueComponentID), - FromPrototype.__construct( - components, - FromPrototypeComponentID, - // instance context - abi.encode("Statmod", targetEntity) - ) - ), - targetEntity: targetEntity - }); - } + function increase(uint256 targetEntity, uint256 baseEntity, uint256 value) internal returns (bool isUpdate) { + if (value == 0) revert Statmod_IncreaseByZero(); - function _scope(Self memory __self, uint256 topicEntity) private pure returns (string memory) { - return string(abi.encode(__self.targetEntity, topicEntity)); - } + uint32 storedValue = StatmodValue.get(targetEntity, baseEntity); - // ========== WRITE ========== + bytes32 statmodBase = StatmodBase.get(baseEntity); - /** - * @dev Increase statmod value for instantiated protoEntity. - */ - function increase(Self memory __self, uint256 protoEntity, uint256 value) internal returns (bool isUpdate) { - StatmodPrototype memory prototype = __self.protoComp.getValue(protoEntity); + isUpdate = storedValue != 0; + if (statmodBase != StatmodScope.get(targetEntity, baseEntity)) { + StatmodScope.set(targetEntity, baseEntity, statmodBase); + } + StatmodValue.set(targetEntity, baseEntity, storedValue + value); - return __self.sv.increaseEntity(_scope(__self, prototype.topicEntity), protoEntity, value); + return isUpdate; } /** - * @dev Decrease statmod value for instantiated protoEntity. + * @dev Decrease statmod value for targeted baseEntity. */ - function decrease(Self memory __self, uint256 protoEntity, uint256 value) internal returns (bool isUpdate) { - StatmodPrototype memory prototype = __self.protoComp.getValue(protoEntity); + function decrease(uint256 targetEntity, uint256 baseEntity, uint256 value) internal returns (bool isUpdate) { + if (value == 0) revert ScopedValue__DecreaseByZero(); - return __self.sv.decreaseEntity(_scope(__self, prototype.topicEntity), protoEntity, value); - } + uint32 storedValue = StatmodValue.get(targetEntity, baseEntity); + if (storedValue == 0) revert ScopedValue__EntityAbsent(); - // ========== READ ========== + bytes32 statmodBase = StatmodBase.get(baseEntity); - /** - * @dev Sum all statmod values for `topicEntity` - * TODO is this even useful anywhere? - */ - function getTotal(Self memory __self, uint256 topicEntity) internal view returns (uint32 result) { - (, uint256[] memory values) = __self.sv.getEntitiesValues(_scope(__self, topicEntity)); - - for (uint256 i; i < values.length; i++) { - result += uint32(values[i]); + isUpdate = storedValue > value; + if (statmodBase != StatmodScope.get(targetEntity, baseEntity)) { + StatmodScope.set(targetEntity, baseEntity, statmodBase); } + if (isUpdate) { + StatmodValue.set(targetEntity, baseEntity, storedValue - value); + } else { + StatmodValue.deleteRecord(targetEntity, baseEntity); + } + + return isUpdate; } + // ========== READ ========== + /** - * @dev Sum statmod values for `topicEntity`, grouped by Op. + * @dev Sum statmod values for `baseEntity`, grouped by Op. * This method shouldn't usually be needed externally, see getValues. */ - function getOperands(Self memory __self, uint256 topicEntity) internal view returns (uint32[OP_L] memory result) { - (uint256[] memory protoEntities, uint256[] memory values) = __self.sv.getEntitiesValues( - _scope(__self, topicEntity) - ); + function getOperands(uint256 targetEntity, uint256 baseEntity) internal view returns (uint32[OP_L] memory result) { + (uint256[] memory protoEntities, uint256[] memory values) = getKeysWithValue() for (uint256 i; i < protoEntities.length; i++) { StatmodPrototype memory prototype = __self.protoComp.getValue(protoEntities[i]); diff --git a/packages/contracts/tsconfig.json b/packages/contracts/tsconfig.json index 54ac79e9..56b6bd6e 100644 --- a/packages/contracts/tsconfig.json +++ b/packages/contracts/tsconfig.json @@ -2,6 +2,7 @@ "compilerOptions": { "target": "ES2022", "module": "commonjs", + "moduleResolution": "node", "strict": true, "resolveJsonModule": true, "esModuleInterop": true, diff --git a/yarn.lock b/yarn.lock index 6fd634cf..b6eaf98e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -327,16 +327,126 @@ resolved "https://registry.yarnpkg.com/@emotion/weak-memoize/-/weak-memoize-0.3.0.tgz#ea89004119dc42db2e1dba0f97d553f7372f6fcb" integrity sha512-AHPmaAx+RYfZz0eYu6Gviiagpmiyw98ySSlQvCUhVGDRtDFe4DBS0x1bSjdF3gqUDYOczB+yYvBTtEylYSdRhg== +"@esbuild/android-arm64@0.17.18": + version "0.17.18" + resolved "https://registry.yarnpkg.com/@esbuild/android-arm64/-/android-arm64-0.17.18.tgz#4aa8d8afcffb4458736ca9b32baa97d7cb5861ea" + integrity sha512-/iq0aK0eeHgSC3z55ucMAHO05OIqmQehiGay8eP5l/5l+iEr4EIbh4/MI8xD9qRFjqzgkc0JkX0LculNC9mXBw== + "@esbuild/android-arm@0.15.18": version "0.15.18" resolved "https://registry.yarnpkg.com/@esbuild/android-arm/-/android-arm-0.15.18.tgz#266d40b8fdcf87962df8af05b76219bc786b4f80" integrity sha512-5GT+kcs2WVGjVs7+boataCkO5Fg0y4kCjzkB5bAip7H4jfnOS3dA6KPiww9W1OEKTKeAcUVhdZGvgI65OXmUnw== +"@esbuild/android-arm@0.17.18": + version "0.17.18" + resolved "https://registry.yarnpkg.com/@esbuild/android-arm/-/android-arm-0.17.18.tgz#74a7e95af4ee212ebc9db9baa87c06a594f2a427" + integrity sha512-EmwL+vUBZJ7mhFCs5lA4ZimpUH3WMAoqvOIYhVQwdIgSpHC8ImHdsRyhHAVxpDYUSm0lWvd63z0XH1IlImS2Qw== + +"@esbuild/android-x64@0.17.18": + version "0.17.18" + resolved "https://registry.yarnpkg.com/@esbuild/android-x64/-/android-x64-0.17.18.tgz#1dcd13f201997c9fe0b204189d3a0da4eb4eb9b6" + integrity sha512-x+0efYNBF3NPW2Xc5bFOSFW7tTXdAcpfEg2nXmxegm4mJuVeS+i109m/7HMiOQ6M12aVGGFlqJX3RhNdYM2lWg== + +"@esbuild/darwin-arm64@0.17.18": + version "0.17.18" + resolved "https://registry.yarnpkg.com/@esbuild/darwin-arm64/-/darwin-arm64-0.17.18.tgz#444f3b961d4da7a89eb9bd35cfa4415141537c2a" + integrity sha512-6tY+djEAdF48M1ONWnQb1C+6LiXrKjmqjzPNPWXhu/GzOHTHX2nh8Mo2ZAmBFg0kIodHhciEgUBtcYCAIjGbjQ== + +"@esbuild/darwin-x64@0.17.18": + version "0.17.18" + resolved "https://registry.yarnpkg.com/@esbuild/darwin-x64/-/darwin-x64-0.17.18.tgz#a6da308d0ac8a498c54d62e0b2bfb7119b22d315" + integrity sha512-Qq84ykvLvya3dO49wVC9FFCNUfSrQJLbxhoQk/TE1r6MjHo3sFF2tlJCwMjhkBVq3/ahUisj7+EpRSz0/+8+9A== + +"@esbuild/freebsd-arm64@0.17.18": + version "0.17.18" + resolved "https://registry.yarnpkg.com/@esbuild/freebsd-arm64/-/freebsd-arm64-0.17.18.tgz#b83122bb468889399d0d63475d5aea8d6829c2c2" + integrity sha512-fw/ZfxfAzuHfaQeMDhbzxp9mc+mHn1Y94VDHFHjGvt2Uxl10mT4CDavHm+/L9KG441t1QdABqkVYwakMUeyLRA== + +"@esbuild/freebsd-x64@0.17.18": + version "0.17.18" + resolved "https://registry.yarnpkg.com/@esbuild/freebsd-x64/-/freebsd-x64-0.17.18.tgz#af59e0e03fcf7f221b34d4c5ab14094862c9c864" + integrity sha512-FQFbRtTaEi8ZBi/A6kxOC0V0E9B/97vPdYjY9NdawyLd4Qk5VD5g2pbWN2VR1c0xhzcJm74HWpObPszWC+qTew== + +"@esbuild/linux-arm64@0.17.18": + version "0.17.18" + resolved "https://registry.yarnpkg.com/@esbuild/linux-arm64/-/linux-arm64-0.17.18.tgz#8551d72ba540c5bce4bab274a81c14ed01eafdcf" + integrity sha512-R7pZvQZFOY2sxUG8P6A21eq6q+eBv7JPQYIybHVf1XkQYC+lT7nDBdC7wWKTrbvMXKRaGudp/dzZCwL/863mZQ== + +"@esbuild/linux-arm@0.17.18": + version "0.17.18" + resolved "https://registry.yarnpkg.com/@esbuild/linux-arm/-/linux-arm-0.17.18.tgz#e09e76e526df4f665d4d2720d28ff87d15cdf639" + integrity sha512-jW+UCM40LzHcouIaqv3e/oRs0JM76JfhHjCavPxMUti7VAPh8CaGSlS7cmyrdpzSk7A+8f0hiedHqr/LMnfijg== + +"@esbuild/linux-ia32@0.17.18": + version "0.17.18" + resolved "https://registry.yarnpkg.com/@esbuild/linux-ia32/-/linux-ia32-0.17.18.tgz#47878860ce4fe73a36fd8627f5647bcbbef38ba4" + integrity sha512-ygIMc3I7wxgXIxk6j3V00VlABIjq260i967Cp9BNAk5pOOpIXmd1RFQJQX9Io7KRsthDrQYrtcx7QCof4o3ZoQ== + "@esbuild/linux-loong64@0.15.18": version "0.15.18" resolved "https://registry.yarnpkg.com/@esbuild/linux-loong64/-/linux-loong64-0.15.18.tgz#128b76ecb9be48b60cf5cfc1c63a4f00691a3239" integrity sha512-L4jVKS82XVhw2nvzLg/19ClLWg0y27ulRwuP7lcyL6AbUWB5aPglXY3M21mauDQMDfRLs8cQmeT03r/+X3cZYQ== +"@esbuild/linux-loong64@0.17.18": + version "0.17.18" + resolved "https://registry.yarnpkg.com/@esbuild/linux-loong64/-/linux-loong64-0.17.18.tgz#3f8fbf5267556fc387d20b2e708ce115de5c967a" + integrity sha512-bvPG+MyFs5ZlwYclCG1D744oHk1Pv7j8psF5TfYx7otCVmcJsEXgFEhQkbhNW8otDHL1a2KDINW20cfCgnzgMQ== + +"@esbuild/linux-mips64el@0.17.18": + version "0.17.18" + resolved "https://registry.yarnpkg.com/@esbuild/linux-mips64el/-/linux-mips64el-0.17.18.tgz#9d896d8f3c75f6c226cbeb840127462e37738226" + integrity sha512-oVqckATOAGuiUOa6wr8TXaVPSa+6IwVJrGidmNZS1cZVx0HqkTMkqFGD2HIx9H1RvOwFeWYdaYbdY6B89KUMxA== + +"@esbuild/linux-ppc64@0.17.18": + version "0.17.18" + resolved "https://registry.yarnpkg.com/@esbuild/linux-ppc64/-/linux-ppc64-0.17.18.tgz#3d9deb60b2d32c9985bdc3e3be090d30b7472783" + integrity sha512-3dLlQO+b/LnQNxgH4l9rqa2/IwRJVN9u/bK63FhOPB4xqiRqlQAU0qDU3JJuf0BmaH0yytTBdoSBHrb2jqc5qQ== + +"@esbuild/linux-riscv64@0.17.18": + version "0.17.18" + resolved "https://registry.yarnpkg.com/@esbuild/linux-riscv64/-/linux-riscv64-0.17.18.tgz#8a943cf13fd24ff7ed58aefb940ef178f93386bc" + integrity sha512-/x7leOyDPjZV3TcsdfrSI107zItVnsX1q2nho7hbbQoKnmoeUWjs+08rKKt4AUXju7+3aRZSsKrJtaRmsdL1xA== + +"@esbuild/linux-s390x@0.17.18": + version "0.17.18" + resolved "https://registry.yarnpkg.com/@esbuild/linux-s390x/-/linux-s390x-0.17.18.tgz#66cb01f4a06423e5496facabdce4f7cae7cb80e5" + integrity sha512-cX0I8Q9xQkL/6F5zWdYmVf5JSQt+ZfZD2bJudZrWD+4mnUvoZ3TDDXtDX2mUaq6upMFv9FlfIh4Gfun0tbGzuw== + +"@esbuild/linux-x64@0.17.18": + version "0.17.18" + resolved "https://registry.yarnpkg.com/@esbuild/linux-x64/-/linux-x64-0.17.18.tgz#23c26050c6c5d1359c7b774823adc32b3883b6c9" + integrity sha512-66RmRsPlYy4jFl0vG80GcNRdirx4nVWAzJmXkevgphP1qf4dsLQCpSKGM3DUQCojwU1hnepI63gNZdrr02wHUA== + +"@esbuild/netbsd-x64@0.17.18": + version "0.17.18" + resolved "https://registry.yarnpkg.com/@esbuild/netbsd-x64/-/netbsd-x64-0.17.18.tgz#789a203d3115a52633ff6504f8cbf757f15e703b" + integrity sha512-95IRY7mI2yrkLlTLb1gpDxdC5WLC5mZDi+kA9dmM5XAGxCME0F8i4bYH4jZreaJ6lIZ0B8hTrweqG1fUyW7jbg== + +"@esbuild/openbsd-x64@0.17.18": + version "0.17.18" + resolved "https://registry.yarnpkg.com/@esbuild/openbsd-x64/-/openbsd-x64-0.17.18.tgz#d7b998a30878f8da40617a10af423f56f12a5e90" + integrity sha512-WevVOgcng+8hSZ4Q3BKL3n1xTv5H6Nb53cBrtzzEjDbbnOmucEVcZeGCsCOi9bAOcDYEeBZbD2SJNBxlfP3qiA== + +"@esbuild/sunos-x64@0.17.18": + version "0.17.18" + resolved "https://registry.yarnpkg.com/@esbuild/sunos-x64/-/sunos-x64-0.17.18.tgz#ecad0736aa7dae07901ba273db9ef3d3e93df31f" + integrity sha512-Rzf4QfQagnwhQXVBS3BYUlxmEbcV7MY+BH5vfDZekU5eYpcffHSyjU8T0xucKVuOcdCsMo+Ur5wmgQJH2GfNrg== + +"@esbuild/win32-arm64@0.17.18": + version "0.17.18" + resolved "https://registry.yarnpkg.com/@esbuild/win32-arm64/-/win32-arm64-0.17.18.tgz#58dfc177da30acf956252d7c8ae9e54e424887c4" + integrity sha512-Kb3Ko/KKaWhjeAm2YoT/cNZaHaD1Yk/pa3FTsmqo9uFh1D1Rfco7BBLIPdDOozrObj2sahslFuAQGvWbgWldAg== + +"@esbuild/win32-ia32@0.17.18": + version "0.17.18" + resolved "https://registry.yarnpkg.com/@esbuild/win32-ia32/-/win32-ia32-0.17.18.tgz#340f6163172b5272b5ae60ec12c312485f69232b" + integrity sha512-0/xUMIdkVHwkvxfbd5+lfG7mHOf2FRrxNbPiKWg9C4fFrB8H0guClmaM3BFiRUYrznVoyxTIyC/Ou2B7QQSwmw== + +"@esbuild/win32-x64@0.17.18": + version "0.17.18" + resolved "https://registry.yarnpkg.com/@esbuild/win32-x64/-/win32-x64-0.17.18.tgz#3a8e57153905308db357fd02f57c180ee3a0a1fa" + integrity sha512-qU25Ma1I3NqTSHJUOKi9sAH1/Mzuvlke0ioMJRthLXKm7JiSKVwFghlGbDLOO2sARECGhja4xYfRAZNPAkooYg== + "@eslint/eslintrc@^1.4.1": version "1.4.1" resolved "https://registry.yarnpkg.com/@eslint/eslintrc/-/eslintrc-1.4.1.tgz#af58772019a2d271b7e2d4c23ff4ddcba3ccfb3e" @@ -725,6 +835,11 @@ resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz#b520529ec21d8e5945a1851dfd1c32e94e39ff45" integrity sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA== +"@improbable-eng/grpc-web-node-http-transport@^0.15.0": + version "0.15.0" + resolved "https://registry.yarnpkg.com/@improbable-eng/grpc-web-node-http-transport/-/grpc-web-node-http-transport-0.15.0.tgz#5a064472ef43489cbd075a91fb831c2abeb09d68" + integrity sha512-HLgJfVolGGpjc9DWPhmMmXJx8YGzkek7jcCFO1YYkSOoO81MWRZentPOd/JiKiZuU08wtc4BG+WNuGzsQB5jZA== + "@improbable-eng/grpc-web@^0.15.0": version "0.15.0" resolved "https://registry.yarnpkg.com/@improbable-eng/grpc-web/-/grpc-web-0.15.0.tgz#3e47e9fdd90381a74abd4b7d26e67422a2a04bef" @@ -780,40 +895,72 @@ "@jridgewell/resolve-uri" "3.1.0" "@jridgewell/sourcemap-codec" "1.4.14" -"@latticexyz/cli@https://gitpkg.now.sh/dk1a/mud/packages/cli?b102cd16ac81233df9c90e86797f551dae7ab2eb": - version "1.34.0" - resolved "https://gitpkg.now.sh/dk1a/mud/packages/cli?b102cd16ac81233df9c90e86797f551dae7ab2eb#349802207921c079412ae50a37c6d6c452e8813d" +"@latticexyz/cli@^1.41.0": + version "1.41.0" + resolved "https://registry.yarnpkg.com/@latticexyz/cli/-/cli-1.41.0.tgz#36e19f114117f8236f6579dede4404ee7c83109b" + integrity sha512-Ylot6B5S80ideixZI8eGfP2VtwmOI4MpbumsFsTVntJwT6gNsAQAwfONzLrVQO7AyV24ILfNZ8XnVhBTAkV6bQ== dependencies: - "@latticexyz/services" "^1.34.0" - "@latticexyz/solecs" "^1.34.0" - "@latticexyz/std-contracts" "^1.34.0" - "@latticexyz/utils" "^1.34.0" + "@improbable-eng/grpc-web" "^0.15.0" + "@improbable-eng/grpc-web-node-http-transport" "^0.15.0" + "@latticexyz/schema-type" "^1.41.0" + "@latticexyz/services" "^1.41.0" + "@latticexyz/solecs" "^1.41.0" + "@latticexyz/std-contracts" "^1.41.0" "@typechain/ethers-v5" "^10.1.1" chalk "^5.0.1" chokidar "^3.5.3" - clear "^0.1.0" - commander "^9.2.0" + dotenv "^16.0.3" ds-test "https://github.com/dapphub/ds-test.git#c9ce3f25bde29fc5eb9901842bf02850dfd2d084" ejs "^3.1.8" - esm "^3.2.25" ethers "^5.7.2" - execa "^6.1.0" - figlet "^1.5.2" - forge-std "https://github.com/foundry-rs/forge-std.git#f36dab24d63d1c1945a05ed375ce341d3c1a49ed" + execa "^7.0.0" + find-up "^6.3.0" + forge-std "https://github.com/foundry-rs/forge-std.git#b4f121555729b3afb3c5ffccb62ff4b6e2818fd3" glob "^8.0.3" - inquirer "^8.2.4" - inquirer-prompt-suggest "^0.1.0" - listr2 "^4.0.5" - netlify "^11.0.1" nice-grpc-web "^2.0.1" - node-fetch "^3.2.6" openurl "^1.1.1" path "^0.12.7" + prettier "^2.8.4" + prettier-plugin-solidity "^1.1.2" solmate "https://github.com/Rari-Capital/solmate.git#9cf1428245074e39090dceacb0c28b1f684f584c" table "^6.8.1" + ts-node "^10.9.1" typechain "^8.1.1" - uuid "^8.3.2" - yargs "^17.5.1" + typescript "^4.9.5" + yargs "^17.7.1" + zod "^3.20.6" + zod-validation-error "^0.3.2" + +"@latticexyz/common@2.0.0-alpha.1.33+ede54c31": + version "2.0.0-alpha.1.33" + resolved "https://registry.yarnpkg.com/@latticexyz/common/-/common-2.0.0-alpha.1.33.tgz#8a6e9c45bbc3db86327da41c4c922f7958741941" + integrity sha512-+CNyqOY9yXDJHirY/ryev9v3QFGeM1TkB2biUzLTqKVefvFMXE+ym6RGk/kjFgDFBd6chdsD3fpbeJcf4TdTRw== + dependencies: + "@latticexyz/config" "2.0.0-alpha.1.33+ede54c31" + "@latticexyz/schema-type" "2.0.0-alpha.1.33+ede54c31" + "@solidity-parser/parser" "^0.16.0" + chalk "^5.2.0" + execa "^7.0.0" + prettier "^2.8.4" + prettier-plugin-solidity "^1.1.2" + +"@latticexyz/config@2.0.0-alpha.1.33+ede54c31": + version "2.0.0-alpha.1.33" + resolved "https://registry.yarnpkg.com/@latticexyz/config/-/config-2.0.0-alpha.1.33.tgz#7597b2f9dba359d867f49ece96ad670d6f97e611" + integrity sha512-oauzvsqU3QOtutnol+72Xy2pvhdSOnzN/70+6w5K5Hzi5VKf+Lua2VGpppA2U5Bx1JPZiwg27H5gtCB8Q7dMtg== + dependencies: + "@latticexyz/schema-type" "2.0.0-alpha.1.33+ede54c31" + chalk "^5.2.0" + esbuild "^0.17.15" + ethers "^5.7.2" + find-up "^6.3.0" + zod "^3.21.4" + zod-validation-error "^1.3.0" + +"@latticexyz/config@^1.41.0": + version "1.41.0" + resolved "https://registry.yarnpkg.com/@latticexyz/config/-/config-1.41.0.tgz#3f208fd630691db424e5eaec1a5c3b7f1f301373" + integrity sha512-LCh2OyI16SzfGawIMet015bZRLhPe8P8hiEopK5J45DCbSD74sF3Gj7UyD+4hREyz1vE9GAM1YtA4lhDdYNMDA== "@latticexyz/ecs-browser@^1.39.0": version "1.39.0" @@ -842,10 +989,15 @@ resolved "https://registry.yarnpkg.com/@latticexyz/recs/-/recs-1.39.0.tgz#106f3a07bd529b0d201ae6d37211dd3987e48059" integrity sha512-9IPAlTjq5F4zODh6DDEaVtwu1D9PQIUjQ/nzBiix7tas56foc+RhNtTiDNncd7YN2ryUXWV3VEeCqpEjpGkrQA== -"@latticexyz/services@^1.34.0": - version "1.34.0" - resolved "https://registry.yarnpkg.com/@latticexyz/services/-/services-1.34.0.tgz#3085d391c54f845a7a17f78ba874592f5651d80d" - integrity sha512-0oqk9ys1JxnlKIbzp+zsdQ59p0CLWm4zRZsx83GjJKb/9XiiCo26/GDrV00ALHAEtRU4dCrP9mbmaY8zrCOc5w== +"@latticexyz/schema-type@2.0.0-alpha.1.33+ede54c31": + version "2.0.0-alpha.1.33" + resolved "https://registry.yarnpkg.com/@latticexyz/schema-type/-/schema-type-2.0.0-alpha.1.33.tgz#26094f1df5ff41c2c4ef1aea9087d3ec6efe761a" + integrity sha512-HnVj/4btBpTgrgKL5pt/heYusBruq0TmEJ9eJXHe7RSyFrQSfT+Aogl60WRpg1emPiHXwIxYzJktaGVqlh9+7A== + +"@latticexyz/schema-type@^1.41.0": + version "1.41.0" + resolved "https://registry.yarnpkg.com/@latticexyz/schema-type/-/schema-type-1.41.0.tgz#a3a3694489f481c4d60e854b9dfd80201ee22ea5" + integrity sha512-tyE7+HDDGMXn1SUY+VDAJ+xYAA6AYEL6hLobzxJiT1SVSFnahDoD8IvLwSskR7qbl4xM+BdrpnFzWML/26bfMw== "@latticexyz/services@^1.39.0": version "1.39.0" @@ -856,6 +1008,15 @@ nice-grpc-common "^2.0.0" protobufjs "^7.1.2" +"@latticexyz/services@^1.41.0": + version "1.41.0" + resolved "https://registry.yarnpkg.com/@latticexyz/services/-/services-1.41.0.tgz#cc181df6f8aafc5cab1a6fe5a291a6a8e6f3cd17" + integrity sha512-Fr3q4nRHWM4MJYZniYlxMTFF2D0ob9UqoOb8+dszny8p+TBjp2YF0c2dAs1pAeI96L7iVEmCrFDlevoWFxPfCA== + dependencies: + long "^5.2.1" + nice-grpc-common "^2.0.0" + protobufjs "^7.1.2" + "@latticexyz/solecs@^1.34.0", "@latticexyz/solecs@https://gitpkg.now.sh/dk1a/mud/packages/solecs?b102cd16ac81233df9c90e86797f551dae7ab2eb": version "1.34.0" resolved "https://gitpkg.now.sh/dk1a/mud/packages/solecs?b102cd16ac81233df9c90e86797f551dae7ab2eb#1a0ffc28a291d92b6ab693e575e7c6c91aea9a33" @@ -865,6 +1026,11 @@ resolved "https://registry.yarnpkg.com/@latticexyz/solecs/-/solecs-1.39.0.tgz#7ec86653cf4bce17499f7dcf896c765a1ea6abe4" integrity sha512-MojEtWHAUV2jnARReTWU8MRbv/BnpaTQjdL7ljf/UIwOuS2C05E4k22yvzn3gk/798dLNUag/sDS/ulcWDD3Fg== +"@latticexyz/solecs@^1.41.0": + version "1.41.0" + resolved "https://registry.yarnpkg.com/@latticexyz/solecs/-/solecs-1.41.0.tgz#e438c2cddff72a0f1864f3cfa2efb1cd634dd040" + integrity sha512-70ti6lU5HcAWMerAn/I//XQA4ZSxyES4wVLa3bxNvi9Oah3bPRy7QsgKLjesjRnxSIRyi1e0AbU0Hca3GzHulg== + "@latticexyz/std-client@^1.39.0": version "1.39.0" resolved "https://registry.yarnpkg.com/@latticexyz/std-client/-/std-client-1.39.0.tgz#9ee4b7aeae9b673f482d8d5c49769aee4fe5485e" @@ -880,12 +1046,22 @@ resolved "https://registry.yarnpkg.com/@latticexyz/std-contracts/-/std-contracts-1.39.0.tgz#9a5ccba9915887206d4d8274ee469b627c1e710c" integrity sha512-jaP/WKleCma4x1fEu9RuYIuHHZEcRtrGorfz9JnSxvK6AN9SpreuLVwNIR84MTaUallgEDSemHfazGGqXltLiw== -"@latticexyz/utils@^1.34.0": - version "1.34.0" - resolved "https://registry.yarnpkg.com/@latticexyz/utils/-/utils-1.34.0.tgz#90d98ac11eb3da8e9aa81af686f0f41151119d74" - integrity sha512-tr/LV4QfhV0XYjtrY8DHLYEI2EPHzVQXmK1JtjupstLvK31WpE9xvgIqMYTawxupC9xw2c5q6zxEs/JZtiUmSQ== +"@latticexyz/std-contracts@^1.41.0": + version "1.41.0" + resolved "https://registry.yarnpkg.com/@latticexyz/std-contracts/-/std-contracts-1.41.0.tgz#77cdffcf4d2a6ca84632debe0e15aa003b33899b" + integrity sha512-TxiN7mGag3hadziblOfQi9/IwP09ninnpf5jz36DCFjramweg5woEGcd+/y8d19jRk0iPD/TioeuzN+LhXNFVg== + +"@latticexyz/store@2.0.0-alpha.1.33": + version "2.0.0-alpha.1.33" + resolved "https://registry.yarnpkg.com/@latticexyz/store/-/store-2.0.0-alpha.1.33.tgz#84b7b945edd11a287241fdaf33ebea36c5a53f70" + integrity sha512-C/ILwxAD+/PD1H92mLanKLt6Gw/ie96wgM4TU5jkhTL/rbwK2eIkz8o4wixwg3bibhkcGaAawO2hYl1yVeyVJQ== dependencies: - typedoc-plugin-markdown "^3.13.6" + "@ethersproject/abi" "^5.7.0" + "@ethersproject/providers" "^5.7.2" + "@latticexyz/common" "2.0.0-alpha.1.33+ede54c31" + "@latticexyz/config" "2.0.0-alpha.1.33+ede54c31" + "@latticexyz/schema-type" "2.0.0-alpha.1.33+ede54c31" + ethers "^5.7.2" "@latticexyz/utils@^1.39.0": version "1.39.0" @@ -905,11 +1081,6 @@ tweetnacl "^1.0.3" tweetnacl-util "^0.15.1" -"@netlify/open-api@^2.11.0": - version "2.13.0" - resolved "https://registry.yarnpkg.com/@netlify/open-api/-/open-api-2.13.0.tgz#758864df7d0b26a87ee900e15b7d6913227f0fd1" - integrity sha512-RKImnmGwHtGH3ycQ9LnqOiyWOFmsQ+07cz8wOyOfRJzNZVOdUs5P6nu0GHed9lIsAOUs4bCCPrlB9OxwpUOCrA== - "@noble/hashes@1.2.0", "@noble/hashes@~1.2.0": version "1.2.0" resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.2.0.tgz#a3150eeb09cc7ab207ebf6d7b9ad311a9bdbed12" @@ -1336,6 +1507,13 @@ dependencies: antlr4ts "^0.5.0-alpha.4" +"@solidity-parser/parser@^0.16.0": + version "0.16.0" + resolved "https://registry.yarnpkg.com/@solidity-parser/parser/-/parser-0.16.0.tgz#1fb418c816ca1fc3a1e94b08bcfe623ec4e1add4" + integrity sha512-ESipEcHyRHg4Np4SqBCfcXwyxxna1DgFVz69bgpLV8vzl/NP1DtcKsJ4dJZXWQhY/Z4J2LeKBiOkOVZn9ct33Q== + dependencies: + antlr4ts "^0.5.0-alpha.4" + "@solidstate/contracts@^0.0.52": version "0.0.52" resolved "https://registry.yarnpkg.com/@solidstate/contracts/-/contracts-0.0.52.tgz#cfe7e2ef237421f6e150927d7338c1ef02daa7b8" @@ -1718,23 +1896,13 @@ ansi-colors@^4.1.1: resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.3.tgz#37611340eb2243e70cc604cad35d63270d48781b" integrity sha512-/6w/C21Pm1A7aZitlI5Ni/2J6FFQN8i1Cvz3kHABAAbw93v/NlvKdVOqz7CCWz/3iv/JplRSEEZ83XION15ovw== -ansi-escapes@^3.0.0: - version "3.2.0" - resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-3.2.0.tgz#8780b98ff9dbf5638152d1f1fe5c1d7b4442976b" - integrity sha512-cBhpre4ma+U0T1oM5fXg7Dy1Jw7zzwv7lt/GoCpr+hDQJoYnKVPLL4dCvSEFMmQurOQvSrwT7SL/DAlhBI97RQ== - -ansi-escapes@^4.2.1, ansi-escapes@^4.3.0: +ansi-escapes@^4.3.0: version "4.3.2" resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-4.3.2.tgz#6b2291d1db7d98b6521d5f1efa42d0f3a9feb65e" integrity sha512-gKXj5ALrKWQLsYG9jlTRmR/xKluxHV+Z9QEwNIgCfM1/uwPMCuzVVnh5mwTd+OuBZcwSIMbqssNWRm1lE51QaQ== dependencies: type-fest "^0.21.3" -ansi-regex@^3.0.0: - version "3.0.1" - resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-3.0.1.tgz#123d6479e92ad45ad897d4054e3c7ca7db4944e1" - integrity sha512-+O9Jct8wf++lXxxFc4hc8LsjaSq0HFzzL7cVsw8pRDIPdjKD2mT4ytDZlLuSBZ4cLKZFXIrMGO7DbQCtMJJMKw== - ansi-regex@^5.0.1: version "5.0.1" resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304" @@ -1935,15 +2103,6 @@ binary-extensions@^2.0.0: resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-2.2.0.tgz#75f502eeaf9ffde42fc98829645be4ea76bd9e2d" integrity sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA== -bl@^4.1.0: - version "4.1.0" - resolved "https://registry.yarnpkg.com/bl/-/bl-4.1.0.tgz#451535264182bec2fbbc83a62ab98cf11d9f7b3a" - integrity sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w== - dependencies: - buffer "^5.5.0" - inherits "^2.0.4" - readable-stream "^3.4.0" - blakejs@^1.1.0: version "1.2.1" resolved "https://registry.yarnpkg.com/blakejs/-/blakejs-1.2.1.tgz#5057e4206eadb4a97f7c0b6e197a505042fc3814" @@ -2054,14 +2213,6 @@ buffer-xor@^1.0.3: resolved "https://registry.yarnpkg.com/buffer-xor/-/buffer-xor-1.0.3.tgz#26e61ed1422fb70dd42e6e36729ed51d855fe8d9" integrity sha512-571s0T7nZWK6vB67HI5dyUF7wXiNcfaPPPTl6zYCNApANjIvYJTg7hlud/+cJpdAhS7dVzqMLmfhfHR3rAcOjQ== -buffer@^5.5.0: - version "5.7.1" - resolved "https://registry.yarnpkg.com/buffer/-/buffer-5.7.1.tgz#ba62e7c13133053582197160851a8f648e99eed0" - integrity sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ== - dependencies: - base64-js "^1.3.1" - ieee754 "^1.1.13" - buffer@^6.0.3: version "6.0.3" resolved "https://registry.yarnpkg.com/buffer/-/buffer-6.0.3.tgz#2ace578459cc8fbe2a70aaa8f52ee63b6a74c6c6" @@ -2115,7 +2266,7 @@ catering@^2.1.0, catering@^2.1.1: resolved "https://registry.yarnpkg.com/catering/-/catering-2.1.1.tgz#66acba06ed5ee28d5286133982a927de9a04b510" integrity sha512-K7Qy8O9p76sL3/3m7/zLKbRkyOlSZAgzEaLhyj2mXS8PsCud2Eo4hAb8aLtZqHh0QGqLcb9dlJSu6lHRVENm1w== -chalk@^2.0.0, chalk@^2.4.1, chalk@^2.4.2: +chalk@^2.0.0, chalk@^2.4.2: version "2.4.2" resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.4.2.tgz#cd42541677a54333cf541a49108c1432b44c9424" integrity sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ== @@ -2124,7 +2275,7 @@ chalk@^2.0.0, chalk@^2.4.1, chalk@^2.4.2: escape-string-regexp "^1.0.5" supports-color "^5.3.0" -chalk@^4.0.0, chalk@^4.0.2, chalk@^4.1.0, chalk@^4.1.1: +chalk@^4.0.0, chalk@^4.0.2, chalk@^4.1.0: version "4.1.2" resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01" integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA== @@ -2132,21 +2283,11 @@ chalk@^4.0.0, chalk@^4.0.2, chalk@^4.1.0, chalk@^4.1.1: ansi-styles "^4.1.0" supports-color "^7.1.0" -chalk@^5.0.1: +chalk@^5.0.1, chalk@^5.2.0: version "5.2.0" resolved "https://registry.yarnpkg.com/chalk/-/chalk-5.2.0.tgz#249623b7d66869c673699fb66d65723e54dfcfb3" integrity sha512-ree3Gqw/nazQAPuJJEy+avdl7QfZMcUvmHIKgEZkGL+xOBzRvup5Hxo6LHuMceSxOabuJLJm5Yp/92R9eMmMvA== -chardet@^0.4.0: - version "0.4.2" - resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.4.2.tgz#b5473b33dc97c424e5d98dc87d55d4d8a29c8bf2" - integrity sha512-j/Toj7f1z98Hh2cYo2BVr85EpIRWqUi7rtRSGxh/cqUjqrnJe9l9UE7IUGd2vQ2p+kSHLkSzObQPZPLUC6TQwg== - -chardet@^0.7.0: - version "0.7.0" - resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.7.0.tgz#90094849f0937f2eedc2425d0d28a9e5f0cbad9e" - integrity sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA== - chokidar@3.5.3, "chokidar@>=3.0.0 <4.0.0", chokidar@^3.4.0, chokidar@^3.5.3: version "3.5.3" resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-3.5.3.tgz#1cf37c8707b932bd1af1ae22c0432e2acd1903bd" @@ -2191,18 +2332,6 @@ clean-stack@^2.0.0: resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-2.2.0.tgz#ee8472dbb129e727b31e8a10a427dee9dfe4008b" integrity sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A== -clear@^0.1.0: - version "0.1.0" - resolved "https://registry.yarnpkg.com/clear/-/clear-0.1.0.tgz#b81b1e03437a716984fd7ac97c87d73bdfe7048a" - integrity sha512-qMjRnoL+JDPJHeLePZJuao6+8orzHMGP04A8CdwCNsKhRbOnKRjefxONR7bwILT3MHecxKBjHkKL/tkZ8r4Uzw== - -cli-cursor@^2.1.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-2.1.0.tgz#b35dac376479facc3e94747d41d0d0f5238ffcb5" - integrity sha512-8lgKz8LmCRYZZQDpRyT2m5rKJ08TnU4tR9FFFW2rxpxR1FzWi4PQ/NfyODchAatHaUgnSPVcx/R5w6NuTBzFiw== - dependencies: - restore-cursor "^2.0.0" - cli-cursor@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-3.1.0.tgz#264305a7ae490d1d03bf0c9ba7c925d1753af307" @@ -2210,11 +2339,6 @@ cli-cursor@^3.1.0: dependencies: restore-cursor "^3.1.0" -cli-spinners@^2.5.0: - version "2.7.0" - resolved "https://registry.yarnpkg.com/cli-spinners/-/cli-spinners-2.7.0.tgz#f815fd30b5f9eaac02db604c7a231ed7cb2f797a" - integrity sha512-qu3pN8Y3qHNgE2AFweciB1IfMnmZ/fsNTEE+NOFjmGB2F/7rLhnhzppvpCnN4FovtP26k8lHyy9ptEbNwWFLzw== - cli-truncate@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/cli-truncate/-/cli-truncate-2.1.0.tgz#c39e28bf05edcde5be3b98992a22deed5a2b93c7" @@ -2231,16 +2355,6 @@ cli-truncate@^3.1.0: slice-ansi "^5.0.0" string-width "^5.0.0" -cli-width@^2.0.0: - version "2.2.1" - resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-2.2.1.tgz#b0433d0b4e9c847ef18868a4ef16fd5fc8271c48" - integrity sha512-GRMWDxpOB6Dgk2E5Uo+3eEBvtOOlimMmpbFiKuLFnQzYDavtLFY3K5ona41jgN/WdRZtG7utuVSVTL4HbZHGkw== - -cli-width@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-3.0.0.tgz#a2f48437a2caa9a22436e794bf071ec9e61cedf6" - integrity sha512-FxqpkPPwu1HjuN93Omfm4h8uIanXofW0RxVEW3k5RKx+mJJYSthzNhp32Kzxxy3YAEZ/Dc/EWN1vZRY0+kOhbw== - cliui@^7.0.2: version "7.0.4" resolved "https://registry.yarnpkg.com/cliui/-/cliui-7.0.4.tgz#a0265ee655476fc807aea9df3df8df7783808b4f" @@ -2259,11 +2373,6 @@ cliui@^8.0.1: strip-ansi "^6.0.1" wrap-ansi "^7.0.0" -clone@^1.0.2: - version "1.0.4" - resolved "https://registry.yarnpkg.com/clone/-/clone-1.0.4.tgz#da309cc263df15994c688ca902179ca3c7cd7c7e" - integrity sha512-JQHZ2QMW6l3aH/j6xCqQThY/9OH4D/9ls34cgkUBiEeocRTU04tHfKPBsUK1PqZCUQM7GiA0IIXJSuXHI64Kbg== - clsx@^1.1.1: version "1.2.1" resolved "https://registry.yarnpkg.com/clsx/-/clsx-1.2.1.tgz#0ddc4a20a549b59c93a4116bb26f5294ca17dc12" @@ -2293,7 +2402,7 @@ color-name@^1.1.4, color-name@~1.1.4: resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.4.tgz#c2a09a87acbde69543de6f63fa3995c826c536a2" integrity sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== -colorette@^2.0.16, colorette@^2.0.19: +colorette@^2.0.19: version "2.0.19" resolved "https://registry.yarnpkg.com/colorette/-/colorette-2.0.19.tgz#cdf044f47ad41a0f4b56b3a0d5b4e6e1a2d5a798" integrity sha512-3tlv/dIP7FWvj3BsbHrGLJ6l/oKh1O3TcgBqMn+yyCagOxc23fyzDS6HypQbgxWbkpDnf52p1LuR4eWDQ/K9WQ== @@ -2328,7 +2437,7 @@ commander@3.0.2: resolved "https://registry.yarnpkg.com/commander/-/commander-3.0.2.tgz#6837c3fb677ad9933d1cfba42dd14d5117d6b39e" integrity sha512-Gar0ASD4BDyKC4hl4DwHqDrmvjoxWKZigVnAbn5H1owvm4CxCPdb0HQDehwNYMJpla5+M2tPmPARzhtYuwpHow== -commander@^9.2.0, commander@^9.4.1: +commander@^9.4.1: version "9.5.0" resolved "https://registry.yarnpkg.com/commander/-/commander-9.5.0.tgz#bc08d1eb5cedf7ccb797a96199d41c7bc3e60d30" integrity sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ== @@ -2418,11 +2527,6 @@ csstype@^3.0.2: resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.1.1.tgz#841b532c45c758ee546a11d5bd7b7b473c8c30b9" integrity sha512-DJR/VvkAvSZW9bTouZue2sSxDwdTN92uHjqeKVm+0dAqdfNykRzQ95tay8aXMBAAPpUiq4Qcug2L7neoRh2Egw== -data-uri-to-buffer@^4.0.0: - version "4.0.1" - resolved "https://registry.yarnpkg.com/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz#d8feb2b2881e6a4f58c2e08acfd0e2834e26222e" - integrity sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A== - debug@4, debug@4.3.4, debug@^4.1.0, debug@^4.1.1, debug@^4.2.0, debug@^4.3.1, debug@^4.3.2, debug@^4.3.3, debug@^4.3.4: version "4.3.4" resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865" @@ -2445,13 +2549,6 @@ deep-is@^0.1.3: resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.4.tgz#a6f2dce612fadd2ef1f519b73551f17e85199831" integrity sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ== -defaults@^1.0.3: - version "1.0.4" - resolved "https://registry.yarnpkg.com/defaults/-/defaults-1.0.4.tgz#b0b02062c1e2aa62ff5d9528f0f98baa90978d7a" - integrity sha512-eFuaLoy/Rxalv2kr+lqMlUnrDWV+3j4pljOIJgLIhI058IQfWJ7vXhyEIHu+HtC738klGALYxOKDO0bQP3tg8A== - dependencies: - clone "^1.0.2" - define-properties@^1.1.3, define-properties@^1.1.4: version "1.1.4" resolved "https://registry.yarnpkg.com/define-properties/-/define-properties-1.1.4.tgz#0b14d7bd7fbeb2f3572c3a7eda80ea5d57fb05b1" @@ -2528,6 +2625,11 @@ dom-helpers@^5.0.1: "@babel/runtime" "^7.8.7" csstype "^3.0.2" +dotenv@^16.0.3: + version "16.0.3" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.0.3.tgz#115aec42bac5053db3c456db30cc243a5a836a07" + integrity sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ== + "ds-test@https://github.com/dapphub/ds-test": version "1.0.0" resolved "https://github.com/dapphub/ds-test#cd98eff28324bfac652e63a239a60632a761790b" @@ -2792,6 +2894,34 @@ esbuild@^0.15.9: esbuild-windows-64 "0.15.18" esbuild-windows-arm64 "0.15.18" +esbuild@^0.17.15: + version "0.17.18" + resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.17.18.tgz#f4f8eb6d77384d68cd71c53eb6601c7efe05e746" + integrity sha512-z1lix43jBs6UKjcZVKOw2xx69ffE2aG0PygLL5qJ9OS/gy0Ewd1gW/PUQIOIQGXBHWNywSc0floSKoMFF8aK2w== + optionalDependencies: + "@esbuild/android-arm" "0.17.18" + "@esbuild/android-arm64" "0.17.18" + "@esbuild/android-x64" "0.17.18" + "@esbuild/darwin-arm64" "0.17.18" + "@esbuild/darwin-x64" "0.17.18" + "@esbuild/freebsd-arm64" "0.17.18" + "@esbuild/freebsd-x64" "0.17.18" + "@esbuild/linux-arm" "0.17.18" + "@esbuild/linux-arm64" "0.17.18" + "@esbuild/linux-ia32" "0.17.18" + "@esbuild/linux-loong64" "0.17.18" + "@esbuild/linux-mips64el" "0.17.18" + "@esbuild/linux-ppc64" "0.17.18" + "@esbuild/linux-riscv64" "0.17.18" + "@esbuild/linux-s390x" "0.17.18" + "@esbuild/linux-x64" "0.17.18" + "@esbuild/netbsd-x64" "0.17.18" + "@esbuild/openbsd-x64" "0.17.18" + "@esbuild/sunos-x64" "0.17.18" + "@esbuild/win32-arm64" "0.17.18" + "@esbuild/win32-ia32" "0.17.18" + "@esbuild/win32-x64" "0.17.18" + escalade@^3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.1.1.tgz#d8cfdc7000965c5a0174b4a82eaa5c0552742e40" @@ -3078,23 +3208,20 @@ execa@^6.1.0: signal-exit "^3.0.7" strip-final-newline "^3.0.0" -external-editor@^2.1.0: - version "2.2.0" - resolved "https://registry.yarnpkg.com/external-editor/-/external-editor-2.2.0.tgz#045511cfd8d133f3846673d1047c154e214ad3d5" - integrity sha512-bSn6gvGxKt+b7+6TKEv1ZycHleA7aHhRHyAqJyp5pbUFuYYNIzpZnQDk7AsYckyWdEnTeAnay0aCy2aV6iTk9A== - dependencies: - chardet "^0.4.0" - iconv-lite "^0.4.17" - tmp "^0.0.33" - -external-editor@^3.0.3: - version "3.1.0" - resolved "https://registry.yarnpkg.com/external-editor/-/external-editor-3.1.0.tgz#cb03f740befae03ea4d283caed2741a83f335495" - integrity sha512-hMQ4CX1p1izmuLYyZqLMO/qGNw10wSv9QDCPfzXfyFrOaCSSoRfqE1Kf1s5an66J5JZC62NewG+mK49jOCtQew== +execa@^7.0.0: + version "7.1.1" + resolved "https://registry.yarnpkg.com/execa/-/execa-7.1.1.tgz#3eb3c83d239488e7b409d48e8813b76bb55c9c43" + integrity sha512-wH0eMf/UXckdUYnO21+HDztteVv05rq2GXksxT4fCGeHkBhw1DROXh40wcjMcRqDOWE7iPJ4n3M7e2+YFP+76Q== dependencies: - chardet "^0.7.0" - iconv-lite "^0.4.24" - tmp "^0.0.33" + cross-spawn "^7.0.3" + get-stream "^6.0.1" + human-signals "^4.3.0" + is-stream "^3.0.0" + merge-stream "^2.0.0" + npm-run-path "^5.1.0" + onetime "^6.0.0" + signal-exit "^3.0.7" + strip-final-newline "^3.0.0" fast-deep-equal@^3.1.1, fast-deep-equal@^3.1.3: version "3.1.3" @@ -3129,33 +3256,6 @@ fastq@^1.6.0: dependencies: reusify "^1.0.4" -fetch-blob@^3.1.2, fetch-blob@^3.1.4: - version "3.2.0" - resolved "https://registry.yarnpkg.com/fetch-blob/-/fetch-blob-3.2.0.tgz#f09b8d4bbd45adc6f0c20b7e787e793e309dcce9" - integrity sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ== - dependencies: - node-domexception "^1.0.0" - web-streams-polyfill "^3.0.3" - -figlet@^1.5.2: - version "1.5.2" - resolved "https://registry.yarnpkg.com/figlet/-/figlet-1.5.2.tgz#dda34ff233c9a48e36fcff6741aeb5bafe49b634" - integrity sha512-WOn21V8AhyE1QqVfPIVxe3tupJacq1xGkPTB4iagT6o+P2cAgEOOwIxMftr4+ZCTI6d551ij9j61DFr0nsP2uQ== - -figures@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/figures/-/figures-2.0.0.tgz#3ab1a2d2a62c8bfb431a0c94cb797a2fce27c962" - integrity sha512-Oa2M9atig69ZkfwiApY8F2Yy+tzMbazyvqv21R0NsSC8floSOC09BbT1ITWAdoMGQvJ/aZnR1KMwdx9tvHnTNA== - dependencies: - escape-string-regexp "^1.0.5" - -figures@^3.0.0: - version "3.2.0" - resolved "https://registry.yarnpkg.com/figures/-/figures-3.2.0.tgz#625c18bd293c604dc4a8ddb2febf0c88341746af" - integrity sha512-yaduQFRKLXYOGgEn6AZau90j3ggSOyiqXU0F9JZfeXYhNa+Jk4X+s45A2zg5jns87GAFa34BBm2kXw4XpNcbdg== - dependencies: - escape-string-regexp "^1.0.5" - file-entry-cache@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/file-entry-cache/-/file-entry-cache-6.0.1.tgz#211b2dd9659cb0394b073e7323ac3c933d522027" @@ -3204,6 +3304,14 @@ find-up@^2.1.0: dependencies: locate-path "^2.0.0" +find-up@^6.3.0: + version "6.3.0" + resolved "https://registry.yarnpkg.com/find-up/-/find-up-6.3.0.tgz#2abab3d3280b2dc7ac10199ef324c4e002c8c790" + integrity sha512-v2ZsoEuVHYy8ZIlYqwPe/39Cy+cFDzp4dXPaxNvkEuouymu+2Jbz0PxpKarJHYJTmv2HWT3O382qY8l4jMWthw== + dependencies: + locate-path "^7.1.0" + path-exists "^5.0.0" + flat-cache@^3.0.4: version "3.0.4" resolved "https://registry.yarnpkg.com/flat-cache/-/flat-cache-3.0.4.tgz#61b0338302b2fe9f957dcc32fc2a87f1c3048b11" @@ -3245,16 +3353,9 @@ for-each@^0.3.3: version "1.2.0" resolved "https://codeload.github.com/foundry-rs/forge-std/tar.gz/eb980e1d4f0e8173ec27da77297ae411840c8ccb" -"forge-std@https://github.com/foundry-rs/forge-std.git#f36dab24d63d1c1945a05ed375ce341d3c1a49ed": - version "0.1.0" - resolved "https://github.com/foundry-rs/forge-std.git#f36dab24d63d1c1945a05ed375ce341d3c1a49ed" - -formdata-polyfill@^4.0.10: - version "4.0.10" - resolved "https://registry.yarnpkg.com/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz#24807c31c9d402e002ab3d8c720144ceb8848423" - integrity sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g== - dependencies: - fetch-blob "^3.1.2" +"forge-std@https://github.com/foundry-rs/forge-std.git#b4f121555729b3afb3c5ffccb62ff4b6e2818fd3": + version "1.2.0" + resolved "https://github.com/foundry-rs/forge-std.git#b4f121555729b3afb3c5ffccb62ff4b6e2818fd3" fp-ts@1.19.3: version "1.19.3" @@ -3664,19 +3765,24 @@ human-signals@^3.0.1: resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-3.0.1.tgz#c740920859dafa50e5a3222da9d3bf4bb0e5eef5" integrity sha512-rQLskxnM/5OCldHo+wNXbpVgDn5A17CUoKX+7Sokwaknlq7CdSnphy0W39GU8dw59XiCXmFXDg4fRuckQRKewQ== +human-signals@^4.3.0: + version "4.3.1" + resolved "https://registry.yarnpkg.com/human-signals/-/human-signals-4.3.1.tgz#ab7f811e851fca97ffbd2c1fe9a958964de321b2" + integrity sha512-nZXjEF2nbo7lIw3mgYjItAfgQXog3OjJogSbKa2CQIIvSGWcKgeJnQlNXip6NglNzYH45nSRiEVimMvYL8DDqQ== + husky@^8.0.3: version "8.0.3" resolved "https://registry.yarnpkg.com/husky/-/husky-8.0.3.tgz#4936d7212e46d1dea28fef29bb3a108872cd9184" integrity sha512-+dQSyqPh4x1hlO1swXBiNb2HzTDN1I2IGLQx1GrBuiqFJfoMrnZWwVmatvSiO+Iz8fBUnf+lekwNo4c2LlXItg== -iconv-lite@0.4.24, iconv-lite@^0.4.17, iconv-lite@^0.4.24: +iconv-lite@0.4.24: version "0.4.24" resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b" integrity sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA== dependencies: safer-buffer ">= 2.1.2 < 3" -ieee754@^1.1.13, ieee754@^1.2.1: +ieee754@^1.2.1: version "1.2.1" resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.2.1.tgz#8eb7a10a63fff25d15a57b001586d177d1b0d352" integrity sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA== @@ -3737,54 +3843,6 @@ inherits@2.0.3: resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" integrity sha512-x00IRNXNy63jwGkJmzPigoySHbaqpNuzKbBOmzK+g2OdZpQ9w+sxCN+VSB3ja7IAge2OP2qpfxTjeNcyjmW1uw== -inquirer-prompt-suggest@^0.1.0: - version "0.1.0" - resolved "https://registry.yarnpkg.com/inquirer-prompt-suggest/-/inquirer-prompt-suggest-0.1.0.tgz#2b5b4ca8e0d48261a4add75c91498afa6e530a24" - integrity sha512-RC5XKDeBSsf0nBOQ380NloJcI+WTbGNo049aJsXRZXxxnRDCL5PqvftIe81zUPSUqF8hI0UxR+v77L74xJB40w== - dependencies: - chalk "^2.4.1" - inquirer "^5.2.0" - -inquirer@^5.2.0: - version "5.2.0" - resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-5.2.0.tgz#db350c2b73daca77ff1243962e9f22f099685726" - integrity sha512-E9BmnJbAKLPGonz0HeWHtbKf+EeSP93paWO3ZYoUpq/aowXvYGjjCSuashhXPpzbArIjBbji39THkxTz9ZeEUQ== - dependencies: - ansi-escapes "^3.0.0" - chalk "^2.0.0" - cli-cursor "^2.1.0" - cli-width "^2.0.0" - external-editor "^2.1.0" - figures "^2.0.0" - lodash "^4.3.0" - mute-stream "0.0.7" - run-async "^2.2.0" - rxjs "^5.5.2" - string-width "^2.1.0" - strip-ansi "^4.0.0" - through "^2.3.6" - -inquirer@^8.2.4: - version "8.2.5" - resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-8.2.5.tgz#d8654a7542c35a9b9e069d27e2df4858784d54f8" - integrity sha512-QAgPDQMEgrDssk1XiwwHoOGYF9BAbUcc1+j+FhEvaOt8/cKRqyLn0U5qA6F74fGhTMGxf92pOvPBeh29jQJDTQ== - dependencies: - ansi-escapes "^4.2.1" - chalk "^4.1.1" - cli-cursor "^3.1.0" - cli-width "^3.0.0" - external-editor "^3.0.3" - figures "^3.0.0" - lodash "^4.17.21" - mute-stream "0.0.8" - ora "^5.4.1" - run-async "^2.4.0" - rxjs "^7.5.5" - string-width "^4.1.0" - strip-ansi "^6.0.0" - through "^2.3.6" - wrap-ansi "^7.0.0" - internal-slot@^1.0.3, internal-slot@^1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/internal-slot/-/internal-slot-1.0.4.tgz#8551e7baf74a7a6ba5f749cfb16aa60722f0d6f3" @@ -3866,11 +3924,6 @@ is-extglob@^2.1.1: resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-2.1.1.tgz#a88c02535791f02ed37c76a1b9ea9773c833f8c2" integrity sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ== -is-fullwidth-code-point@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz#a3b30a5c4f199183167aaab93beefae3ddfb654f" - integrity sha512-VHskAKYM8RfSFXwee5t5cbN5PZeq1Wrh6qd5bkyiXIf6UQcN6w/A0eXM9r6t8d+GYOh+o6ZhiEnb88LN/Y8m2w== - is-fullwidth-code-point@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz#f116f8064fe90b3f7844a38997c0b75051269f1d" @@ -3893,11 +3946,6 @@ is-hex-prefixed@1.0.0: resolved "https://registry.yarnpkg.com/is-hex-prefixed/-/is-hex-prefixed-1.0.0.tgz#7d8d37e6ad77e5d127148913c573e082d777f554" integrity sha512-WvtOiug1VFrE9v1Cydwm+FnXd3+w9GaeVUss5W4v/SLy3UW00vP+6iNF2SdnfiBoLy4bTqVdkftNGTUeOFVsbA== -is-interactive@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/is-interactive/-/is-interactive-1.0.0.tgz#cea6e6ae5c870a7b0a0004070b7b587e0252912e" - integrity sha512-2HvIEKRoqS62guEC+qBjpvRubdX910WCMuJTZ+I9yvqKU2/12eSL549HMwtabb4oupdj2sMP50k+XJfB/8JE6w== - is-negative-zero@^2.0.2: version "2.0.2" resolved "https://registry.yarnpkg.com/is-negative-zero/-/is-negative-zero-2.0.2.tgz#7bf6f03a28003b8b3965de3ac26f664d765f3150" @@ -4160,20 +4208,6 @@ lint-staged@^13.1.0: string-argv "^0.3.1" yaml "^2.1.3" -listr2@^4.0.5: - version "4.0.5" - resolved "https://registry.yarnpkg.com/listr2/-/listr2-4.0.5.tgz#9dcc50221583e8b4c71c43f9c7dfd0ef546b75d5" - integrity sha512-juGHV1doQdpNT3GSTs9IUN43QJb7KHdF9uqg7Vufs/tG9VTzpFphqF4pm/ICdAABGQxsyNn9CiYA3StkI6jpwA== - dependencies: - cli-truncate "^2.1.0" - colorette "^2.0.16" - log-update "^4.0.0" - p-map "^4.0.0" - rfdc "^1.3.0" - rxjs "^7.5.5" - through "^2.3.8" - wrap-ansi "^7.0.0" - listr2@^5.0.5: version "5.0.7" resolved "https://registry.yarnpkg.com/listr2/-/listr2-5.0.7.tgz#de69ccc4caf6bea7da03c74f7a2ffecf3904bd53" @@ -4203,6 +4237,13 @@ locate-path@^6.0.0: dependencies: p-locate "^5.0.0" +locate-path@^7.1.0: + version "7.2.0" + resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-7.2.0.tgz#69cb1779bd90b35ab1e771e1f2f89a202c2a8a8a" + integrity sha512-gvVijfZvn7R+2qyPX8mAuKcFGDf6Nc61GdvGafQsHL0sBIxfKzA+usWn4GFC/bk+QdwPUD4kWFJLhElipq+0VA== + dependencies: + p-locate "^6.0.0" + lodash.camelcase@^4.3.0: version "4.3.0" resolved "https://registry.yarnpkg.com/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz#b28aa6288a2b9fc651035c7711f65ab6190331a6" @@ -4218,12 +4259,12 @@ lodash.truncate@^4.4.2: resolved "https://registry.yarnpkg.com/lodash.truncate/-/lodash.truncate-4.4.2.tgz#5a350da0b1113b837ecfffd5812cbe58d6eae193" integrity sha512-jttmRe7bRse52OsWIMDLaXxWqRAmtIUccAQ3garviCqJjafXOfNMO0yMfNpdD6zbGaTU0P5Nz7e7gAT6cKmJRw== -lodash@^4.17.11, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.21, lodash@^4.3.0: +lodash@^4.17.11, lodash@^4.17.14, lodash@^4.17.15: version "4.17.21" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== -log-symbols@4.1.0, log-symbols@^4.1.0: +log-symbols@4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-4.1.0.tgz#3fbdbb95b4683ac9fc785111e792e558d4abd503" integrity sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg== @@ -4335,11 +4376,6 @@ merge2@^1.3.0, merge2@^1.4.1: resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.4.1.tgz#4368892f885e907455a6fd7dc55c0c9d404990ae" integrity sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg== -micro-api-client@^3.3.0: - version "3.3.0" - resolved "https://registry.yarnpkg.com/micro-api-client/-/micro-api-client-3.3.0.tgz#52dd567d322f10faffe63d19d4feeac4e4ffd215" - integrity sha512-y0y6CUB9RLVsy3kfgayU28746QrNMpSm9O/AYGNsBgOkJr/X/Jk0VLGoO8Ude7Bpa8adywzF+MzXNZRFRsNPhg== - micromatch@^4.0.4, micromatch@^4.0.5: version "4.0.5" resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.5.tgz#bc8999a7cbbf77cdc89f132f6e467051b49090c6" @@ -4348,11 +4384,6 @@ micromatch@^4.0.4, micromatch@^4.0.5: braces "^3.0.2" picomatch "^2.3.1" -mimic-fn@^1.0.0: - version "1.2.0" - resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.2.0.tgz#820c86a39334640e99516928bd03fca88057d022" - integrity sha512-jf84uxzwiuiIVKiOLpfYk7N46TSy8ubTonmneY9vrpHNAnp0QBt2BxWV9dO3/j+BoVAb+a5G6YDPW3M5HOdMWQ== - mimic-fn@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-2.1.0.tgz#7ed2c2ccccaf84d3ffcb7a69b57711fc2083401b" @@ -4472,16 +4503,6 @@ murmur-128@^0.2.1: fmix "^0.1.0" imul "^1.0.0" -mute-stream@0.0.7: - version "0.0.7" - resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.7.tgz#3075ce93bc21b8fab43e1bc4da7e8115ed1e7bab" - integrity sha512-r65nCZhrbXXb6dXOACihYApHw2Q6pV0M3V0PSxd74N0+D8nzAdEAITq2oAjA1jVnKI+tGvEBUpqiMh0+rW6zDQ== - -mute-stream@0.0.8: - version "0.0.8" - resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.8.tgz#1630c42b2251ff81e2a283de96a5497ea92e5e0d" - integrity sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA== - nan@^2.14.0: version "2.17.0" resolved "https://registry.yarnpkg.com/nan/-/nan-2.17.0.tgz#c0150a2368a182f033e9aa5195ec76ea41a199cb" @@ -4517,19 +4538,6 @@ neo-async@^2.6.0: resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.2.tgz#b4aafb93e3aeb2d8174ca53cf163ab7d7308305f" integrity sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw== -netlify@^11.0.1: - version "11.0.4" - resolved "https://registry.yarnpkg.com/netlify/-/netlify-11.0.4.tgz#f7de45a1432b90ff32e6143011121e65e12175a4" - integrity sha512-pvaFCKkc0pi4CYnM21pNTlQ79zxbnPi8saxT1aslc4zC7gG6A97iIfCQYF7bGWOQgLyaDbmv6A4AWQ7vncDjBg== - dependencies: - "@netlify/open-api" "^2.11.0" - lodash.camelcase "^4.3.0" - micro-api-client "^3.3.0" - node-fetch "^3.0.0" - omit.js "^2.0.2" - p-wait-for "^4.0.0" - qs "^6.9.6" - nice-grpc-common@^2.0.0, nice-grpc-common@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/nice-grpc-common/-/nice-grpc-common-2.0.1.tgz#2291d3d9c321eb9829a48d6e1c061b29363bc283" @@ -4552,20 +4560,6 @@ node-addon-api@^2.0.0: resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-2.0.2.tgz#432cfa82962ce494b132e9d72a15b29f71ff5d32" integrity sha512-Ntyt4AIXyaLIuMHF6IOoTakB3K+RWxwtsHNRxllEoA6vPwP9o4866g6YWDLUdnucilZhmkxiHwHr11gAENw+QA== -node-domexception@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/node-domexception/-/node-domexception-1.0.0.tgz#6888db46a1f71c0b76b3f7555016b63fe64766e5" - integrity sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ== - -node-fetch@^3.0.0, node-fetch@^3.2.6: - version "3.3.0" - resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-3.3.0.tgz#37e71db4ecc257057af828d523a7243d651d91e4" - integrity sha512-BKwRP/O0UvoMKp7GNdwPlObhYGB5DQqwhEDQlNKuoqwVYSxkSZCSbHjnFFmUEtwSKRPU4kNK8PbDYYitwaE3QA== - dependencies: - data-uri-to-buffer "^4.0.0" - fetch-blob "^3.1.4" - formdata-polyfill "^4.0.10" - node-gyp-build@^4.2.0, node-gyp-build@^4.3.0: version "4.6.0" resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.6.0.tgz#0c52e4cbf54bbd28b709820ef7b6a3c2d6209055" @@ -4687,11 +4681,6 @@ observable-webworker@^4.0.1: dependencies: tslib "^2.0.0" -omit.js@^2.0.2: - version "2.0.2" - resolved "https://registry.yarnpkg.com/omit.js/-/omit.js-2.0.2.tgz#dd9b8436fab947a5f3ff214cb2538631e313ec2f" - integrity sha512-hJmu9D+bNB40YpL9jYebQl4lsTW6yEHRTroJzNLqQJYHm7c+NQnJGfZmIWh8S3q3KoaxV1aLhV6B3+0N0/kyJg== - once@^1.3.0: version "1.4.0" resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" @@ -4699,13 +4688,6 @@ once@^1.3.0: dependencies: wrappy "1" -onetime@^2.0.0: - version "2.0.1" - resolved "https://registry.yarnpkg.com/onetime/-/onetime-2.0.1.tgz#067428230fd67443b2794b22bba528b6867962d4" - integrity sha512-oyyPpiMaKARvvcgip+JV+7zci5L8D1W9RZIz2l1o08AM3pfspitVWnPt3mzHcBPp12oYMTy0pqrFs/C+m3EwsQ== - dependencies: - mimic-fn "^1.0.0" - onetime@^5.1.0: version "5.1.2" resolved "https://registry.yarnpkg.com/onetime/-/onetime-5.1.2.tgz#d0e96ebb56b07476df1dd9c4806e5237985ca45e" @@ -4737,21 +4719,6 @@ optionator@^0.9.1: type-check "^0.4.0" word-wrap "^1.2.3" -ora@^5.4.1: - version "5.4.1" - resolved "https://registry.yarnpkg.com/ora/-/ora-5.4.1.tgz#1b2678426af4ac4a509008e5e4ac9e9959db9e18" - integrity sha512-5b6Y85tPxZZ7QytO+BQzysW31HJku27cRIlkbAXaNx+BdcVi+LlRFmVXzeF6a7JCwJpyw5c4b+YSVImQIrBpuQ== - dependencies: - bl "^4.1.0" - chalk "^4.1.0" - cli-cursor "^3.1.0" - cli-spinners "^2.5.0" - is-interactive "^1.0.0" - is-unicode-supported "^0.1.0" - log-symbols "^4.1.0" - strip-ansi "^6.0.0" - wcwidth "^1.0.1" - os-tmpdir@~1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274" @@ -4771,6 +4738,13 @@ p-limit@^3.0.2: dependencies: yocto-queue "^0.1.0" +p-limit@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-4.0.0.tgz#914af6544ed32bfa54670b061cafcbd04984b644" + integrity sha512-5b0R4txpzjPWVw/cXXUResoD4hb6U/x9BH08L7nw+GN1sezDzPdxeRvpc9c433fZhBan/wusjbCsqwqm4EIBIQ== + dependencies: + yocto-queue "^1.0.0" + p-locate@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-2.0.0.tgz#20a0103b222a70c8fd39cc2e580680f3dde5ec43" @@ -4785,6 +4759,13 @@ p-locate@^5.0.0: dependencies: p-limit "^3.0.2" +p-locate@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-6.0.0.tgz#3da9a49d4934b901089dca3302fa65dc5a05c04f" + integrity sha512-wPrq66Llhl7/4AGC6I+cqxT07LhXvWL08LNXz1fENOw0Ap4sRZZ/gZpTTJ5jpurzzzfS2W/Ge9BY3LgLjCShcw== + dependencies: + p-limit "^4.0.0" + p-map@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/p-map/-/p-map-4.0.0.tgz#bb2f95a5eda2ec168ec9274e06a747c3e2904d2b" @@ -4792,23 +4773,11 @@ p-map@^4.0.0: dependencies: aggregate-error "^3.0.0" -p-timeout@^5.0.0: - version "5.1.0" - resolved "https://registry.yarnpkg.com/p-timeout/-/p-timeout-5.1.0.tgz#b3c691cf4415138ce2d9cfe071dba11f0fee085b" - integrity sha512-auFDyzzzGZZZdHz3BtET9VEz0SE/uMEAx7uWfGPucfzEwwe/xH0iVeZibQmANYE/hp9T2+UUZT5m+BKyrDp3Ew== - p-try@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/p-try/-/p-try-1.0.0.tgz#cbc79cdbaf8fd4228e13f621f2b1a237c1b207b3" integrity sha512-U1etNYuMJoIz3ZXSrrySFjsXQTWOx2/jdi86L+2pRvph/qMKL6sbcCYdH23fqsbm8TH2Gn0OybpT4eSFlCVHww== -p-wait-for@^4.0.0: - version "4.1.0" - resolved "https://registry.yarnpkg.com/p-wait-for/-/p-wait-for-4.1.0.tgz#290f126f49bbd7c84e0cedccb342cd631aaa0f16" - integrity sha512-i8nE5q++9h8oaQHWltS1Tnnv4IoMDOlqN7C0KFG2OdbK0iFJIt6CROZ8wfBM+K4Pxqfnq4C4lkkpXqTEpB5DZw== - dependencies: - p-timeout "^5.0.0" - parent-module@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/parent-module/-/parent-module-1.0.1.tgz#691d2709e78c79fae3a156622452d00762caaaa2" @@ -4836,6 +4805,11 @@ path-exists@^4.0.0: resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-4.0.0.tgz#513bdbe2d3b95d7762e8c1137efa195c6c61b5b3" integrity sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w== +path-exists@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-5.0.0.tgz#a6aad9489200b21fab31e49cf09277e5116fb9e7" + integrity sha512-RjhtfwJOxzcFmNOi6ltcbcu4Iu+FL3zEj83dk4kAS+fVpTxXLO1b38RvJgT/0QwvV/L3aY9TAnyv0EOqW4GoMQ== + path-is-absolute@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" @@ -4982,6 +4956,11 @@ prettier@^2.8.3: resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.3.tgz#ab697b1d3dd46fb4626fbe2f543afe0cc98d8632" integrity sha512-tJ/oJ4amDihPoufT5sM0Z1SKEuKay8LfVAMlbbhnnkvt6BUserZylqo2PN+p9KeljLr0OHa2rXHU1T8reeoTrw== +prettier@^2.8.4: + version "2.8.5" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.5.tgz#3dd8ae1ebddc4f6aa419c9b64d8c8319a7e0d982" + integrity sha512-3gzuxrHbKUePRBB4ZeU08VNkUcqEHaUaouNt0m7LGP4Hti/NuB07C7PPTM/LkWqXoJYJn2McEo5+kxPNrtQkLQ== + process@^0.11.1: version "0.11.10" resolved "https://registry.yarnpkg.com/process/-/process-0.11.10.tgz#7332300e840161bda3e69a1d1d91a7d4bc16f182" @@ -5042,7 +5021,7 @@ punycode@^2.1.0: resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.3.0.tgz#f67fa67c94da8f4d0cfff981aee4118064199b8f" integrity sha512-rRV+zQD8tVFys26lAGR9WUuS4iUAngJScM+ZRSKtvl5tKeZ2t5bvdNFdNHBW9FWR4guGHlgmsZ1G7BSm2wTbuA== -qs@^6.7.0, qs@^6.9.6: +qs@^6.7.0: version "6.11.0" resolved "https://registry.yarnpkg.com/qs/-/qs-6.11.0.tgz#fd0d963446f7a65e1367e01abd85429453f0c37a" integrity sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q== @@ -5162,7 +5141,7 @@ read-cache@^1.0.0: dependencies: pify "^2.3.0" -readable-stream@^3.4.0, readable-stream@^3.6.0: +readable-stream@^3.6.0: version "3.6.0" resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-3.6.0.tgz#337bbda3adc0706bd3e024426a286d4b4b2c9198" integrity sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA== @@ -5242,14 +5221,6 @@ resolve@^2.0.0-next.4: path-parse "^1.0.7" supports-preserve-symlinks-flag "^1.0.0" -restore-cursor@^2.0.0: - version "2.0.0" - resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-2.0.0.tgz#9f7ee287f82fd326d4fd162923d62129eee0dfaf" - integrity sha512-6IzJLuGi4+R14vwagDHX+JrXmPVtPpn4mffDJ1UdR7/Edm87fl6yi8mMBIVvFtJaNTUvjughmW4hwLhRG7gC1Q== - dependencies: - onetime "^2.0.0" - signal-exit "^3.0.2" - restore-cursor@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-3.1.0.tgz#39f67c54b3a7a58cea5236d95cf0034239631f7e" @@ -5304,11 +5275,6 @@ rollup@^2.79.1: optionalDependencies: fsevents "~2.3.2" -run-async@^2.2.0, run-async@^2.4.0: - version "2.4.1" - resolved "https://registry.yarnpkg.com/run-async/-/run-async-2.4.1.tgz#8440eccf99ea3e70bd409d49aab88e10c189a455" - integrity sha512-tvVnVv01b8c1RrA6Ep7JkStj85Guv/YrMcwqYQnwjsAS2cTmmPGBBjAjpCW7RrSodNSoE2/qg9O4bceNvUuDgQ== - run-parallel-limit@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/run-parallel-limit/-/run-parallel-limit-1.1.0.tgz#be80e936f5768623a38a963262d6bef8ff11e7ba" @@ -5336,14 +5302,7 @@ rustbn.js@~0.2.0: resolved "https://registry.yarnpkg.com/rustbn.js/-/rustbn.js-0.2.0.tgz#8082cb886e707155fd1cb6f23bd591ab8d55d0ca" integrity sha512-4VlvkRUuCJvr2J6Y0ImW7NvTCriMi7ErOAqWk1y69vAdoNIzCF3yPmgeNzx+RQTLEDFq5sHfscn1MwHxP9hNfA== -rxjs@^5.5.2: - version "5.5.12" - resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-5.5.12.tgz#6fa61b8a77c3d793dbaf270bee2f43f652d741cc" - integrity sha512-xx2itnL5sBbqeeiVgNPVuQQ1nC8Jp2WfNJhXWHmElW9YmrpS9UVnNzhP3EH3HFqexO5Tlp8GhYY+WEcqcVMvGw== - dependencies: - symbol-observable "1.0.1" - -rxjs@^7.5.5, rxjs@^7.8.0: +rxjs@^7.8.0: version "7.8.0" resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-7.8.0.tgz#90a938862a82888ff4c7359811a595e14e1e09a4" integrity sha512-F2+gxDshqmIub1KdvZkaEfGDwLNpPvk9Fs6LD/MyQxNgMds/WH9OdDDXOmxUZpME+iSK3rQCctkL0DYyytUqMg== @@ -5581,14 +5540,6 @@ string-format@^2.0.0: resolved "https://registry.yarnpkg.com/string-format/-/string-format-2.0.0.tgz#f2df2e7097440d3b65de31b6d40d54c96eaffb9b" integrity sha512-bbEs3scLeYNXLecRRuk6uJxdXUSj6le/8rNPHChIJTn2V79aXVTR1EH2OH5zLKKoz0V02fOUKZZcw01pLUShZA== -string-width@^2.1.0: - version "2.1.1" - resolved "https://registry.yarnpkg.com/string-width/-/string-width-2.1.1.tgz#ab93f27a8dc13d28cac815c462143a6d9012ae9e" - integrity sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw== - dependencies: - is-fullwidth-code-point "^2.0.0" - strip-ansi "^4.0.0" - string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" @@ -5646,13 +5597,6 @@ string_decoder@^1.1.1: dependencies: safe-buffer "~5.2.0" -strip-ansi@^4.0.0: - version "4.0.0" - resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-4.0.0.tgz#a8479022eb1ac368a871389b635262c505ee368f" - integrity sha512-4XaJ2zQdCzROZDivEVIDPkcQn8LMFSa8kj8Gxb/Lnwzv9A8VctNZ+lfivC/sV3ivW8ElJTERXZoPBRrZKkNKow== - dependencies: - ansi-regex "^3.0.0" - strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" @@ -5715,11 +5659,6 @@ supports-preserve-symlinks-flag@^1.0.0: resolved "https://registry.yarnpkg.com/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz#6eda4bd344a3c94aea376d4cc31bc77311039e09" integrity sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w== -symbol-observable@1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/symbol-observable/-/symbol-observable-1.0.1.tgz#8340fc4702c3122df5d22288f88283f513d3fdd4" - integrity sha512-Kb3PrPYz4HanVF1LVGuAdW6LoVgIwjUYJGzFe7NDrBLCN4lsV/5J0MFurV+ygS4bRVwrCEt2c7MQ1R2a72oJDw== - table-layout@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/table-layout/-/table-layout-1.0.2.tgz#c4038a1853b0136d63365a734b6931cf4fad4a04" @@ -5792,7 +5731,7 @@ threads@^1.7.0: optionalDependencies: tiny-worker ">= 2" -through@^2.3.6, through@^2.3.8: +through@^2.3.8: version "2.3.8" resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5" integrity sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg== @@ -5816,7 +5755,7 @@ tippy.js@^6.3.1, tippy.js@^6.3.7: dependencies: "@popperjs/core" "^2.9.0" -tmp@0.0.33, tmp@^0.0.33: +tmp@0.0.33: version "0.0.33" resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9" integrity sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw== @@ -6081,18 +6020,6 @@ vscode-textmate@^6.0.0: resolved "https://registry.yarnpkg.com/vscode-textmate/-/vscode-textmate-6.0.0.tgz#a3777197235036814ac9a92451492f2748589210" integrity sha512-gu73tuZfJgu+mvCSy4UZwd2JXykjK9zAZsfmDeut5dx/1a7FeTk0XwJsSuqQn+cuMCGVbIBfl+s53X4T19DnzQ== -wcwidth@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/wcwidth/-/wcwidth-1.0.1.tgz#f0b0dcf915bc5ff1528afadb2c0e17b532da2fe8" - integrity sha512-XHPEwS0q6TaxcvG85+8EYkbiCux2XtWG2mkc47Ng2A77BQu9+DqIOJldST4HgPkuea7dvKSj5VgX3P1d4rW8Tg== - dependencies: - defaults "^1.0.3" - -web-streams-polyfill@^3.0.3: - version "3.2.1" - resolved "https://registry.yarnpkg.com/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz#71c2718c52b45fd49dbeee88634b3a60ceab42a6" - integrity sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q== - which-boxed-primitive@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz#13757bc89b209b049fe5d86430e21cf40a89a8e6" @@ -6247,10 +6174,10 @@ yargs@16.2.0: y18n "^5.0.5" yargs-parser "^20.2.2" -yargs@^17.5.1: - version "17.6.2" - resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.6.2.tgz#2e23f2944e976339a1ee00f18c77fedee8332541" - integrity sha512-1/9UrdHjDZc0eOU0HxOHoS78C69UD3JRMvzlJ7S79S2nTaWRA/whGCTV8o9e/N/1Va9YIV7Q4sOxD8VV4pCWOw== +yargs@^17.7.1: + version "17.7.1" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-17.7.1.tgz#34a77645201d1a8fc5213ace787c220eabbd0967" + integrity sha512-cwiTb08Xuv5fqF4AovYacTFNxk62th7LKJ6BL9IGUpTJrWoU7/7WdQGTP2SjKf1dUNBGzDd28p/Yfs/GI6JrLw== dependencies: cliui "^8.0.1" escalade "^3.1.1" @@ -6269,3 +6196,23 @@ yocto-queue@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-0.1.0.tgz#0294eb3dee05028d31ee1a5fa2c556a6aaf10a1b" integrity sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q== + +yocto-queue@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/yocto-queue/-/yocto-queue-1.0.0.tgz#7f816433fb2cbc511ec8bf7d263c3b58a1a3c251" + integrity sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g== + +zod-validation-error@^0.3.2: + version "0.3.2" + resolved "https://registry.yarnpkg.com/zod-validation-error/-/zod-validation-error-0.3.2.tgz#1f09877cd3d671a37d6c0e4e0b7ad42c24d5d8c2" + integrity sha512-pBXItXNDup6KF54fdnA+cmB/eEt65HlN5pmahfBTUhufWEnXs4ouU8lLXh01GoAksIR9K7iF7BxXxkKvct+r+A== + +zod-validation-error@^1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/zod-validation-error/-/zod-validation-error-1.3.0.tgz#6a37e8b1896e45362a4e4cf9506eca203fad3c6e" + integrity sha512-4WoQnuWnj06kwKR4A+cykRxFmy+CTvwMQO5ogTXLiVx1AuvYYmMjixh7sbkSsQTr1Fvtss6d5kVz8PGeMPUQjQ== + +zod@^3.20.6, zod@^3.21.4: + version "3.21.4" + resolved "https://registry.yarnpkg.com/zod/-/zod-3.21.4.tgz#10882231d992519f0a10b5dd58a38c9dabbb64db" + integrity sha512-m46AKbrzKVzOzs/DZgVnG5H55N1sv1M8qZU3A8RIKbs3mrACDNeIOeilDymVb2HdmP8uwshOCF4uJ8uM9rCqJw== From a980defb0264973020cd45215598b9096ff7bfbf Mon Sep 17 00:00:00 2001 From: rashid Date: Mon, 15 May 2023 11:38:10 +0300 Subject: [PATCH 2/6] add LibExperience --- packages/contracts/_old_src/BaseTest.ejs | 65 -- packages/contracts/_old_src/SingletonID.sol | 5 - packages/contracts/_old_src/Types.sol | 49 -- .../_old_src/Uint256SetComponent.sol | 151 ---- .../affix/AffixAvailabilityComponent.sol | 20 - .../_old_src/affix/AffixNamingComponent.sol | 29 - .../affix/AffixPrototypeComponent.sol | 55 -- .../affix/AffixPrototypeGroupComponent.sol | 18 - .../_old_src/affix/LibPickAffixes.sol | 158 ---- .../_old_src/charstat/ExperienceComponent.sol | 41 - .../_old_src/charstat/LibCharstat.sol | 162 ---- .../_old_src/charstat/LibExperience.sol | 139 ---- .../charstat/LifeCurrentComponent.sol | 11 - .../charstat/ManaCurrentComponent.sol | 11 - .../contracts/_old_src/charstat/Topics.sol | 55 -- .../_old_src/combat/ActiveCombatComponent.sol | 13 - .../_old_src/combat/CombatSubSystem.sol | 252 ------ .../_old_src/combat/LibActiveCombat.sol | 49 -- .../_old_src/combat/LibCombatAction.sol | 132 ---- .../combat/test/CombatSubsystem.t.sol | 203 ----- .../_old_src/common/ComponentDevSystem.sol | 12 - .../common/FromPrototypeComponent.sol | 11 - .../_old_src/common/NameComponent.sol | 11 - .../_old_src/common/OwnedByComponent.sol | 11 - .../common/ReverseHashNameComponent.sol | 11 - .../_old_src/common/ReverseHashNameSystem.sol | 40 - .../_old_src/cycle/ActiveCycleComponent.sol | 11 - .../cycle/ActiveCyclePreviousComponent.sol | 11 - .../_old_src/cycle/ClaimCycleTurnsSystem.sol | 37 - .../_old_src/cycle/CompleteCycleSystem.sol | 57 -- .../cycle/CycleActivateCombatSystem.sol | 86 -- .../cycle/CycleBossesDefeatedComponent.sol | 11 - .../CycleCombatRewardRequestComponent.sol | 64 -- .../cycle/CycleCombatRewardSystem.sol | 66 -- .../_old_src/cycle/CycleCombatSystem.sol | 52 -- .../_old_src/cycle/CycleEquipmentSystem.sol | 54 -- .../cycle/CycleToWandererComponent.sol | 11 - .../_old_src/cycle/CycleTurnsComponent.sol | 19 - .../cycle/CycleTurnsLastClaimedComponent.sol | 19 - .../_old_src/cycle/LearnCycleSkillSystem.sol | 60 -- .../contracts/_old_src/cycle/LibCycle.sol | 146 ---- .../cycle/LibCycleCombatRewardRequest.sol | 161 ---- .../_old_src/cycle/LibCycleTurns.sol | 87 --- .../_old_src/cycle/PassCycleTurnSystem.sol | 46 -- .../_old_src/cycle/StartCycleSystem.sol | 32 - .../cycle/test/CycleCombatSystem.t.sol | 76 -- .../cycle/test/CycleEquipmentSystem.t.sol | 26 - .../cycle/test/LearnCycleSkillSystem.t.sol | 51 -- .../_old_src/cycle/test/LibCycleTurns.t.sol | 84 -- .../cycle/test/PassCycleTurnSystem.t.sol | 48 -- .../cycle/test/StartCycleSystem.t.sol | 35 - .../duration/DurationOnEndComponent.sol | 40 - .../duration/DurationScopeComponent.sol | 11 - .../_old_src/duration/DurationSubSystem.sol | 30 - .../duration/DurationValueComponent.sol | 11 - .../effect/AppliedEffectComponent.sol | 19 - .../effect/EffectPrototypeComponent.sol | 53 -- .../_old_src/effect/EffectSubSystem.sol | 149 ---- .../_old_src/effect/LibEffectPrototype.sol | 42 - .../_old_src/effect/makeEffectPrototype.sol | 80 -- .../equipment/EquipmentPrototypeComponent.sol | 11 - .../equipment/EquipmentPrototypes.sol | 17 - .../EquipmentSlotAllowedComponent.sol | 14 - .../equipment/EquipmentSlotComponent.sol | 14 - .../_old_src/equipment/EquipmentSubSystem.sol | 137 ---- .../equipment/LibSpawnEquipmentSlots.sol | 70 -- .../equipment/test/EquipmentSubsystem.t.sol | 185 ----- .../_old_src/guise/ActiveGuiseComponent.sol | 11 - .../guise/GuisePrototypeComponent.sol | 47 -- .../_old_src/guise/GuiseSkillsComponent.sol | 11 - .../_old_src/guise/LibGuiseLevel.sol | 44 -- .../_old_src/init/LibBaseInitAffix.sol | 316 -------- .../_old_src/init/LibBaseInitSkill.sol | 59 -- .../init/LibInitAuthorizeSubsystems.sol | 118 --- .../_old_src/init/LibInitEquipmentAffix.sol | 738 ------------------ .../init/LibInitEquipmentPrototype.sol | 45 -- .../contracts/_old_src/init/LibInitGuise.sol | 60 -- .../_old_src/init/LibInitMapAffix.sol | 271 ------- .../_old_src/init/LibInitMapPrototype.sol | 35 - .../_old_src/init/LibInitMapsBoss.sol | 290 ------- .../_old_src/init/LibInitMapsGlobal.sol | 59 -- .../_old_src/init/LibInitReverseHashName.ejs | 18 - .../contracts/_old_src/init/LibInitSkill.sol | 259 ------ .../_old_src/init/LibInitStatmod.sol | 116 --- .../contracts/_old_src/init/LibInitWheel.sol | 42 - .../contracts/_old_src/libraries/LibArray.sol | 29 - .../_old_src/loot/LibLootEquipment.sol | 117 --- .../contracts/_old_src/loot/LibLootMap.sol | 40 - .../contracts/_old_src/loot/LibLootMint.sol | 71 -- .../contracts/_old_src/loot/LibLootOwner.sol | 37 - .../contracts/_old_src/loot/LootComponent.sol | 62 -- .../loot/RandomEquipmentSubSystem.sol | 49 -- .../_old_src/loot/RandomMapSubSystem.sol | 48 -- .../loot/test/RandomEquipmentSubsystem.t.sol | 99 --- .../_old_src/map/MapPrototypeComponent.sol | 11 - .../contracts/_old_src/map/MapPrototypes.sol | 11 - packages/contracts/_old_src/rng/LibRNG.sol | 94 --- .../_old_src/rng/RNGPrecommitComponent.sol | 11 - .../_old_src/rng/RNGRequestOwnerComponent.sol | 11 - .../contracts/_old_src/rng/test/LibRNG.t.sol | 109 --- .../_old_src/skill/LearnedSkillsComponent.sol | 11 - .../_old_src/skill/LibLearnedSkills.sol | 72 -- .../contracts/_old_src/skill/LibSkill.sol | 149 ---- .../_old_src/skill/NoncombatSkillSystem.sol | 44 -- .../skill/SkillDescriptionComponent.sol | 11 - .../skill/SkillPrototypeComponent.sol | 113 --- .../_old_src/skill/test/LibSkill.t.sol | 172 ---- .../skill/test/SkillPrototypeComponent.t.sol | 40 - .../contracts/_old_src/statmod/Statmod.sol | 192 ----- .../statmod/StatmodPrototypeComponent.sol | 70 -- .../statmod/StatmodScopeComponent.sol | 11 - .../statmod/StatmodValueComponent.sol | 11 - .../_old_src/statmod/statmodName.sol | 74 -- .../_old_src/statmod/test/Statmod.t.sol | 121 --- .../statmod/test/StatmodPrototype.t.sol | 26 - .../contracts/_old_src/token/LibToken.sol | 29 - .../contracts/_old_src/token/WFTSystem.sol | 19 - .../contracts/_old_src/token/WNFTSystem.sol | 60 -- packages/contracts/_old_src/uri/LibUri.sol | 25 - .../_old_src/uri/LibUriEquipment.sol | 128 --- .../contracts/_old_src/uri/LibUriMisc.sol | 30 - .../contracts/_old_src/uri/LibUriWanderer.sol | 125 --- packages/contracts/_old_src/uri/UriUtils.sol | 16 - .../_old_src/wanderer/IdentityComponent.sol | 11 - .../_old_src/wanderer/LibWanderer.sol | 57 -- .../_old_src/wanderer/PermSkillSystem.sol | 73 -- .../_old_src/wanderer/WandererComponent.sol | 12 - .../_old_src/wanderer/WandererSpawnSystem.sol | 51 -- .../wanderer/test/WandererSpawnSystem.t.sol | 94 --- .../_old_src/wheel/ActiveWheelComponent.sol | 11 - .../_old_src/wheel/DefaultWheelComponent.sol | 11 - .../_old_src/wheel/WheelComponent.sol | 40 - .../wheel/WheelsCompletedComponent.sol | 18 - .../src/charstat/ExperienceComponent.sol | 0 .../contracts/src/charstat/LibExperience.sol | 0 135 files changed, 9212 deletions(-) delete mode 100644 packages/contracts/_old_src/BaseTest.ejs delete mode 100644 packages/contracts/_old_src/SingletonID.sol delete mode 100644 packages/contracts/_old_src/Types.sol delete mode 100644 packages/contracts/_old_src/Uint256SetComponent.sol delete mode 100644 packages/contracts/_old_src/affix/AffixAvailabilityComponent.sol delete mode 100644 packages/contracts/_old_src/affix/AffixNamingComponent.sol delete mode 100644 packages/contracts/_old_src/affix/AffixPrototypeComponent.sol delete mode 100644 packages/contracts/_old_src/affix/AffixPrototypeGroupComponent.sol delete mode 100644 packages/contracts/_old_src/affix/LibPickAffixes.sol delete mode 100644 packages/contracts/_old_src/charstat/ExperienceComponent.sol delete mode 100644 packages/contracts/_old_src/charstat/LibCharstat.sol delete mode 100644 packages/contracts/_old_src/charstat/LibExperience.sol delete mode 100644 packages/contracts/_old_src/charstat/LifeCurrentComponent.sol delete mode 100644 packages/contracts/_old_src/charstat/ManaCurrentComponent.sol delete mode 100644 packages/contracts/_old_src/charstat/Topics.sol delete mode 100644 packages/contracts/_old_src/combat/ActiveCombatComponent.sol delete mode 100644 packages/contracts/_old_src/combat/CombatSubSystem.sol delete mode 100644 packages/contracts/_old_src/combat/LibActiveCombat.sol delete mode 100644 packages/contracts/_old_src/combat/LibCombatAction.sol delete mode 100644 packages/contracts/_old_src/combat/test/CombatSubsystem.t.sol delete mode 100644 packages/contracts/_old_src/common/ComponentDevSystem.sol delete mode 100644 packages/contracts/_old_src/common/FromPrototypeComponent.sol delete mode 100644 packages/contracts/_old_src/common/NameComponent.sol delete mode 100644 packages/contracts/_old_src/common/OwnedByComponent.sol delete mode 100644 packages/contracts/_old_src/common/ReverseHashNameComponent.sol delete mode 100644 packages/contracts/_old_src/common/ReverseHashNameSystem.sol delete mode 100644 packages/contracts/_old_src/cycle/ActiveCycleComponent.sol delete mode 100644 packages/contracts/_old_src/cycle/ActiveCyclePreviousComponent.sol delete mode 100644 packages/contracts/_old_src/cycle/ClaimCycleTurnsSystem.sol delete mode 100644 packages/contracts/_old_src/cycle/CompleteCycleSystem.sol delete mode 100644 packages/contracts/_old_src/cycle/CycleActivateCombatSystem.sol delete mode 100644 packages/contracts/_old_src/cycle/CycleBossesDefeatedComponent.sol delete mode 100644 packages/contracts/_old_src/cycle/CycleCombatRewardRequestComponent.sol delete mode 100644 packages/contracts/_old_src/cycle/CycleCombatRewardSystem.sol delete mode 100644 packages/contracts/_old_src/cycle/CycleCombatSystem.sol delete mode 100644 packages/contracts/_old_src/cycle/CycleEquipmentSystem.sol delete mode 100644 packages/contracts/_old_src/cycle/CycleToWandererComponent.sol delete mode 100644 packages/contracts/_old_src/cycle/CycleTurnsComponent.sol delete mode 100644 packages/contracts/_old_src/cycle/CycleTurnsLastClaimedComponent.sol delete mode 100644 packages/contracts/_old_src/cycle/LearnCycleSkillSystem.sol delete mode 100644 packages/contracts/_old_src/cycle/LibCycle.sol delete mode 100644 packages/contracts/_old_src/cycle/LibCycleCombatRewardRequest.sol delete mode 100644 packages/contracts/_old_src/cycle/LibCycleTurns.sol delete mode 100644 packages/contracts/_old_src/cycle/PassCycleTurnSystem.sol delete mode 100644 packages/contracts/_old_src/cycle/StartCycleSystem.sol delete mode 100644 packages/contracts/_old_src/cycle/test/CycleCombatSystem.t.sol delete mode 100644 packages/contracts/_old_src/cycle/test/CycleEquipmentSystem.t.sol delete mode 100644 packages/contracts/_old_src/cycle/test/LearnCycleSkillSystem.t.sol delete mode 100644 packages/contracts/_old_src/cycle/test/LibCycleTurns.t.sol delete mode 100644 packages/contracts/_old_src/cycle/test/PassCycleTurnSystem.t.sol delete mode 100644 packages/contracts/_old_src/cycle/test/StartCycleSystem.t.sol delete mode 100644 packages/contracts/_old_src/duration/DurationOnEndComponent.sol delete mode 100644 packages/contracts/_old_src/duration/DurationScopeComponent.sol delete mode 100644 packages/contracts/_old_src/duration/DurationSubSystem.sol delete mode 100644 packages/contracts/_old_src/duration/DurationValueComponent.sol delete mode 100644 packages/contracts/_old_src/effect/AppliedEffectComponent.sol delete mode 100644 packages/contracts/_old_src/effect/EffectPrototypeComponent.sol delete mode 100644 packages/contracts/_old_src/effect/EffectSubSystem.sol delete mode 100644 packages/contracts/_old_src/effect/LibEffectPrototype.sol delete mode 100644 packages/contracts/_old_src/effect/makeEffectPrototype.sol delete mode 100644 packages/contracts/_old_src/equipment/EquipmentPrototypeComponent.sol delete mode 100644 packages/contracts/_old_src/equipment/EquipmentPrototypes.sol delete mode 100644 packages/contracts/_old_src/equipment/EquipmentSlotAllowedComponent.sol delete mode 100644 packages/contracts/_old_src/equipment/EquipmentSlotComponent.sol delete mode 100644 packages/contracts/_old_src/equipment/EquipmentSubSystem.sol delete mode 100644 packages/contracts/_old_src/equipment/LibSpawnEquipmentSlots.sol delete mode 100644 packages/contracts/_old_src/equipment/test/EquipmentSubsystem.t.sol delete mode 100644 packages/contracts/_old_src/guise/ActiveGuiseComponent.sol delete mode 100644 packages/contracts/_old_src/guise/GuisePrototypeComponent.sol delete mode 100644 packages/contracts/_old_src/guise/GuiseSkillsComponent.sol delete mode 100644 packages/contracts/_old_src/guise/LibGuiseLevel.sol delete mode 100644 packages/contracts/_old_src/init/LibBaseInitAffix.sol delete mode 100644 packages/contracts/_old_src/init/LibBaseInitSkill.sol delete mode 100644 packages/contracts/_old_src/init/LibInitAuthorizeSubsystems.sol delete mode 100644 packages/contracts/_old_src/init/LibInitEquipmentAffix.sol delete mode 100644 packages/contracts/_old_src/init/LibInitEquipmentPrototype.sol delete mode 100644 packages/contracts/_old_src/init/LibInitGuise.sol delete mode 100644 packages/contracts/_old_src/init/LibInitMapAffix.sol delete mode 100644 packages/contracts/_old_src/init/LibInitMapPrototype.sol delete mode 100644 packages/contracts/_old_src/init/LibInitMapsBoss.sol delete mode 100644 packages/contracts/_old_src/init/LibInitMapsGlobal.sol delete mode 100644 packages/contracts/_old_src/init/LibInitReverseHashName.ejs delete mode 100644 packages/contracts/_old_src/init/LibInitSkill.sol delete mode 100644 packages/contracts/_old_src/init/LibInitStatmod.sol delete mode 100644 packages/contracts/_old_src/init/LibInitWheel.sol delete mode 100644 packages/contracts/_old_src/libraries/LibArray.sol delete mode 100644 packages/contracts/_old_src/loot/LibLootEquipment.sol delete mode 100644 packages/contracts/_old_src/loot/LibLootMap.sol delete mode 100644 packages/contracts/_old_src/loot/LibLootMint.sol delete mode 100644 packages/contracts/_old_src/loot/LibLootOwner.sol delete mode 100644 packages/contracts/_old_src/loot/LootComponent.sol delete mode 100644 packages/contracts/_old_src/loot/RandomEquipmentSubSystem.sol delete mode 100644 packages/contracts/_old_src/loot/RandomMapSubSystem.sol delete mode 100644 packages/contracts/_old_src/loot/test/RandomEquipmentSubsystem.t.sol delete mode 100644 packages/contracts/_old_src/map/MapPrototypeComponent.sol delete mode 100644 packages/contracts/_old_src/map/MapPrototypes.sol delete mode 100644 packages/contracts/_old_src/rng/LibRNG.sol delete mode 100644 packages/contracts/_old_src/rng/RNGPrecommitComponent.sol delete mode 100644 packages/contracts/_old_src/rng/RNGRequestOwnerComponent.sol delete mode 100644 packages/contracts/_old_src/rng/test/LibRNG.t.sol delete mode 100644 packages/contracts/_old_src/skill/LearnedSkillsComponent.sol delete mode 100644 packages/contracts/_old_src/skill/LibLearnedSkills.sol delete mode 100644 packages/contracts/_old_src/skill/LibSkill.sol delete mode 100644 packages/contracts/_old_src/skill/NoncombatSkillSystem.sol delete mode 100644 packages/contracts/_old_src/skill/SkillDescriptionComponent.sol delete mode 100644 packages/contracts/_old_src/skill/SkillPrototypeComponent.sol delete mode 100644 packages/contracts/_old_src/skill/test/LibSkill.t.sol delete mode 100644 packages/contracts/_old_src/skill/test/SkillPrototypeComponent.t.sol delete mode 100644 packages/contracts/_old_src/statmod/Statmod.sol delete mode 100644 packages/contracts/_old_src/statmod/StatmodPrototypeComponent.sol delete mode 100644 packages/contracts/_old_src/statmod/StatmodScopeComponent.sol delete mode 100644 packages/contracts/_old_src/statmod/StatmodValueComponent.sol delete mode 100644 packages/contracts/_old_src/statmod/statmodName.sol delete mode 100644 packages/contracts/_old_src/statmod/test/Statmod.t.sol delete mode 100644 packages/contracts/_old_src/statmod/test/StatmodPrototype.t.sol delete mode 100644 packages/contracts/_old_src/token/LibToken.sol delete mode 100644 packages/contracts/_old_src/token/WFTSystem.sol delete mode 100644 packages/contracts/_old_src/token/WNFTSystem.sol delete mode 100644 packages/contracts/_old_src/uri/LibUri.sol delete mode 100644 packages/contracts/_old_src/uri/LibUriEquipment.sol delete mode 100644 packages/contracts/_old_src/uri/LibUriMisc.sol delete mode 100644 packages/contracts/_old_src/uri/LibUriWanderer.sol delete mode 100644 packages/contracts/_old_src/uri/UriUtils.sol delete mode 100644 packages/contracts/_old_src/wanderer/IdentityComponent.sol delete mode 100644 packages/contracts/_old_src/wanderer/LibWanderer.sol delete mode 100644 packages/contracts/_old_src/wanderer/PermSkillSystem.sol delete mode 100644 packages/contracts/_old_src/wanderer/WandererComponent.sol delete mode 100644 packages/contracts/_old_src/wanderer/WandererSpawnSystem.sol delete mode 100644 packages/contracts/_old_src/wanderer/test/WandererSpawnSystem.t.sol delete mode 100644 packages/contracts/_old_src/wheel/ActiveWheelComponent.sol delete mode 100644 packages/contracts/_old_src/wheel/DefaultWheelComponent.sol delete mode 100644 packages/contracts/_old_src/wheel/WheelComponent.sol delete mode 100644 packages/contracts/_old_src/wheel/WheelsCompletedComponent.sol create mode 100644 packages/contracts/src/charstat/ExperienceComponent.sol create mode 100644 packages/contracts/src/charstat/LibExperience.sol diff --git a/packages/contracts/_old_src/BaseTest.ejs b/packages/contracts/_old_src/BaseTest.ejs deleted file mode 100644 index 802d8798..00000000 --- a/packages/contracts/_old_src/BaseTest.ejs +++ /dev/null @@ -1,65 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; -import { World } from "solecs/World.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { PRBTest } from "@prb/test/src/PRBTest.sol"; - -import { LibDeploy } from "../test/LibDeploy.sol"; - -// Components -<% components.forEach(({name, file}) => { -%> -import { <%= name %>, ID as <%= name %>ID } from "<%= file %>"; -<% }) -%> - -// Systems -<% systems.forEach(({name, file}) => { -%> -import { <%= name %>, ID as <%= name %>ID } from "<%= file %>"; -<% }) -%> - -abstract contract BaseTest is PRBTest { - World world; - - address internal alice; - address internal bob; - - IUint256Component components; - IUint256Component systems; - -<% const varName = (name) => name.charAt(0).toLowerCase() + name.slice(1); -%> - // Components -<% components.forEach(({name}) => { -%> - <%= name %> internal <%= varName(name) %>; -<% }) -%> - - // Systems -<% systems.forEach(({name}) => { -%> - <%= name %> internal <%= varName(name) %>; -<% }) -%> - - function setUp() public virtual { - alice = address(bytes20(keccak256("alice"))); - bob = address(bytes20(keccak256("bob"))); - - // deploy world - world = new World(); - world.init(); - - LibDeploy.deploy(address(this), address(world), false); - - // Assign all systems and components to storage vars for convenience - components = world.components(); - systems = world.systems(); - // Components -<% components.forEach(({name}) => { -%> - <%= varName(name) %> = <%= name %>(getAddressById(components, <%= name %>ID)); -<% }) -%> - // Systems -<% systems.forEach(({name}) => { -%> - <%= varName(name) %> = <%= name %>(getAddressById(systems, <%= name %>ID)); -<% }) -%> - } -} \ No newline at end of file diff --git a/packages/contracts/_old_src/SingletonID.sol b/packages/contracts/_old_src/SingletonID.sol deleted file mode 100644 index 88337433..00000000 --- a/packages/contracts/_old_src/SingletonID.sol +++ /dev/null @@ -1,5 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -uint256 constant SingletonID = 0x60D; diff --git a/packages/contracts/_old_src/Types.sol b/packages/contracts/_old_src/Types.sol deleted file mode 100644 index 81ea525d..00000000 --- a/packages/contracts/_old_src/Types.sol +++ /dev/null @@ -1,49 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity >=0.8.0; - -/* Autogenerated file. Do not edit manually. */ - -enum AffixPartId { - IMPLICIT, - PREFIX, - SUFFIX -} - -enum EffectRemovabilityId { - BUFF, - DEBUFF, - PERSISTENT -} - -enum PStat { - STRENGTH, - ARCANA, - DEXTERITY -} - -enum EleStat { - NONE, - PHYSICAL, - FIRE, - COLD, - POISON -} - -enum SkillType { - COMBAT, - NONCOMBAT, - PASSIVE -} - -enum TargetType { - SELF, - ENEMY, - ALLY, - SELF_OR_ALLY -} - -enum StatmodOp { - ADD, - MUL, - BADD -} diff --git a/packages/contracts/_old_src/Uint256SetComponent.sol b/packages/contracts/_old_src/Uint256SetComponent.sol deleted file mode 100644 index 6cff6b40..00000000 --- a/packages/contracts/_old_src/Uint256SetComponent.sol +++ /dev/null @@ -1,151 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { LibTypes } from "solecs/LibTypes.sol"; -import { MapSetBatchable } from "./MapSetBatchable.sol"; -import { AbstractComponent } from "./AbstractComponent.sol"; - -/** - * The main purpose of SetComponent is hasItem method, - * which allows to check existence in O(1) instead of reading the whole array. - * - * There's also addItem and removeItem, which don't write the whole array - * (though they still read it all for world value registration). - */ -contract Uint256SetComponent is AbstractComponent { - error BareComponent__NotImplemented(); - - MapSetBatchable internal entityToItemSet; - - constructor(address _world, uint256 _id) AbstractComponent(_world, _id) { - entityToItemSet = new MapSetBatchable(); - } - - // TODO override should be here if IComponent gets getSchema - function getSchema() public pure returns (string[] memory keys, LibTypes.SchemaValue[] memory values) { - keys = new string[](1); - values = new LibTypes.SchemaValue[](1); - - keys[0] = "value"; - values[0] = LibTypes.SchemaValue.UINT256_ARRAY; - } - - /** - * Avoid in favor of addItem when possible - */ - function set(uint256 entity, bytes memory value) public override { - set(entity, abi.decode(value, (uint256[]))); - } - - /** - * Avoid in favor of addItem when possible - */ - function set(uint256 entity, uint256[] memory value) public onlyWriter { - _set(entity, value); - } - - /** - * Avoid in favor of removeItem when possible - */ - function remove(uint256 entity) public override onlyWriter { - _remove(entity); - } - - function has(uint256 entity) public view virtual override returns (bool) { - return itemSetSize(entity) != 0; - } - - /** - * Get size of entity's item set - * Set-specific - */ - function itemSetSize(uint256 entity) public view virtual returns (uint256) { - return entityToItemSet.size(entity); - } - - function getRawValue(uint256 entity) public view virtual override returns (bytes memory) { - return abi.encode(getValue(entity)); - } - - function getValue(uint256 entity) public view virtual returns (uint256[] memory) { - return entityToItemSet.getItems(entity); - } - - /** - * Check if set has `item` in O(1) - * Set-specific - */ - function hasItem(uint256 entity, uint256 item) public view virtual returns (bool) { - return entityToItemSet.has(entity, item); - } - - /** - * Add an item without writing the whole array - * Set-specific - */ - function addItem(uint256 entity, uint256 item) public onlyWriter { - _addItem(entity, item); - } - - /** - * Remove an item without writing the whole array - * Set-specific - */ - function removeItem(uint256 entity, uint256 item) public onlyWriter { - _removeItem(entity, item); - } - - function _set(uint256 entity, uint256[] memory items) internal virtual { - entityToItemSet.replaceAll(entity, items); - - IWorld(world).registerComponentValueSet(entity, abi.encode(items)); - } - - function _remove(uint256 entity) internal virtual { - entityToItemSet.removeAll(entity); - - IWorld(world).registerComponentValueRemoved(entity); - } - - /** - * Add an item without writing the whole array - */ - function _addItem(uint256 entity, uint256 item) internal virtual { - if (hasItem(entity, item)) { - // item is already in set - return; - } - - entityToItemSet.add(entity, item); - - IWorld(world).registerComponentValueSet(entity, abi.encode(entityToItemSet.getItems(entity))); - } - - /** - * Remove an item without writing the whole array - */ - function _removeItem(uint256 entity, uint256 item) internal virtual { - if (!hasItem(entity, item)) { - // item is not in set - return; - } - - entityToItemSet.remove(entity, item); - - IWorld(world).registerComponentValueSet(entity, abi.encode(entityToItemSet.getItems(entity))); - } - - function getEntities() public view virtual override returns (uint256[] memory) { - revert BareComponent__NotImplemented(); - } - - function getEntitiesWithValue(bytes memory) public view virtual override returns (uint256[] memory) { - revert BareComponent__NotImplemented(); - } - - function registerIndexer(address) external virtual { - revert BareComponent__NotImplemented(); - } -} diff --git a/packages/contracts/_old_src/affix/AffixAvailabilityComponent.sol b/packages/contracts/_old_src/affix/AffixAvailabilityComponent.sol deleted file mode 100644 index 53ef7e37..00000000 --- a/packages/contracts/_old_src/affix/AffixAvailabilityComponent.sol +++ /dev/null @@ -1,20 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { Uint256SetComponent } from "../Uint256SetComponent.sol"; - -import { AffixPartId } from "./AffixNamingComponent.sol"; - -uint256 constant ID = uint256(keccak256("component.AffixAvailability")); - -/** - * @dev affixAvailabilityEntity = hashed(ID, ilvl, AffixPartId, targetEntity) - */ -function getAffixAvailabilityEntity(uint256 ilvl, AffixPartId partId, uint256 targetEntity) pure returns (uint256) { - return uint256(keccak256(abi.encode(ID, ilvl, partId, targetEntity))); -} - -contract AffixAvailabilityComponent is Uint256SetComponent { - constructor(address world) Uint256SetComponent(world, ID) {} -} diff --git a/packages/contracts/_old_src/affix/AffixNamingComponent.sol b/packages/contracts/_old_src/affix/AffixNamingComponent.sol deleted file mode 100644 index 39234149..00000000 --- a/packages/contracts/_old_src/affix/AffixNamingComponent.sol +++ /dev/null @@ -1,29 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { StringBareComponent } from "std-contracts/components/StringBareComponent.sol"; - -uint256 constant ID = uint256(keccak256("component.AffixNaming")); - -/** - * @dev affixNamingEntity = hashed(ID, AffixPartId, targetEntity, affixProtoEntity) - */ -function getAffixNamingEntity( - AffixPartId partId, - uint256 targetEntity, - uint256 affixProtoEntity -) pure returns (uint256) { - return uint256(keccak256(abi.encode(ID, partId, targetEntity, affixProtoEntity))); -} - -enum AffixPartId { - IMPLICIT, - PREFIX, - SUFFIX -} -uint256 constant AFFIX_PARTS_LENGTH = 3; - -contract AffixNamingComponent is StringBareComponent { - constructor(address world) StringBareComponent(world, ID) {} -} diff --git a/packages/contracts/_old_src/affix/AffixPrototypeComponent.sol b/packages/contracts/_old_src/affix/AffixPrototypeComponent.sol deleted file mode 100644 index 47f75dba..00000000 --- a/packages/contracts/_old_src/affix/AffixPrototypeComponent.sol +++ /dev/null @@ -1,55 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { LibTypes } from "solecs/LibTypes.sol"; -import { BareComponent } from "solecs/BareComponent.sol"; - -uint256 constant ID = uint256(keccak256("component.AffixPrototype")); - -/** - * @dev affixProtoEntity = hashed(ID, affixName, tier) - */ -function getAffixProtoEntity(string memory name, uint32 tier) pure returns (uint256) { - return uint256(keccak256(abi.encode(ID, name, tier))); -} - -struct AffixPrototype { - uint32 tier; - uint256 statmodProtoEntity; - uint32 requiredIlvl; - uint32 min; - uint32 max; -} - -contract AffixPrototypeComponent is BareComponent { - constructor(address world) BareComponent(world, ID) {} - - function getSchema() public pure override returns (string[] memory keys, LibTypes.SchemaValue[] memory values) { - keys = new string[](5); - values = new LibTypes.SchemaValue[](5); - - keys[0] = "tier"; - values[0] = LibTypes.SchemaValue.UINT32; - - keys[1] = "statmodProtoEntity"; - values[1] = LibTypes.SchemaValue.UINT256; - - keys[2] = "requiredIlvl"; - values[2] = LibTypes.SchemaValue.UINT32; - - keys[3] = "min"; - values[3] = LibTypes.SchemaValue.UINT32; - - keys[4] = "max"; - values[4] = LibTypes.SchemaValue.UINT32; - } - - function set(uint256 entity, AffixPrototype memory value) public { - set(entity, abi.encode(value)); - } - - function getValue(uint256 entity) public view returns (AffixPrototype memory) { - return abi.decode(getRawValue(entity), (AffixPrototype)); - } -} diff --git a/packages/contracts/_old_src/affix/AffixPrototypeGroupComponent.sol b/packages/contracts/_old_src/affix/AffixPrototypeGroupComponent.sol deleted file mode 100644 index 7711ce7b..00000000 --- a/packages/contracts/_old_src/affix/AffixPrototypeGroupComponent.sol +++ /dev/null @@ -1,18 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { Uint256Component } from "std-contracts/components/Uint256Component.sol"; - -uint256 constant ID = uint256(keccak256("component.AffixPrototypeGroup")); - -/** - * @dev affixProtoGroupEntity = hashed(ID, affixName) - */ -function getAffixProtoGroupEntity(string memory name) pure returns (uint256) { - return uint256(keccak256(abi.encode(ID, name))); -} - -contract AffixPrototypeGroupComponent is Uint256Component { - constructor(address world) Uint256Component(world, ID) {} -} diff --git a/packages/contracts/_old_src/affix/LibPickAffixes.sol b/packages/contracts/_old_src/affix/LibPickAffixes.sol deleted file mode 100644 index 748aaf9f..00000000 --- a/packages/contracts/_old_src/affix/LibPickAffixes.sol +++ /dev/null @@ -1,158 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { LibArray } from "../libraries/LibArray.sol"; - -import { getAffixAvailabilityEntity, AffixAvailabilityComponent, ID as AffixAvailabilityComponentID } from "./AffixAvailabilityComponent.sol"; -import { getAffixProtoEntity, AffixPrototype, AffixPrototypeComponent, ID as AffixPrototypeComponentID } from "./AffixPrototypeComponent.sol"; -import { AffixPrototypeGroupComponent, ID as AffixPrototypeGroupComponentID } from "./AffixPrototypeGroupComponent.sol"; -import { AffixPartId } from "./AffixNamingComponent.sol"; - -/// @title Randomly pick affixes. -library LibPickAffixes { - error LibPickAffixes__NoAvailableAffix(uint256 ilvl, AffixPartId affixPartId, uint256 protoEntity); - error LibPickAffixes__InvalidMinMax(); - error LibPickAffixes__InvalidIlvl(uint256 ilvl); - - struct Comps { - AffixPrototypeComponent affixProto; - AffixAvailabilityComponent availability; - AffixPrototypeGroupComponent group; - } - - function pickAffixes( - IUint256Component components, - AffixPartId[] memory affixPartIds, - uint256[] memory excludeAffixes, - uint256 targetEntity, - uint256 ilvl, - uint256 randomness - ) - internal - view - returns (uint256[] memory statmodProtoEntities, uint256[] memory affixProtoEntities, uint32[] memory affixValues) - { - Comps memory comps = Comps( - AffixPrototypeComponent(getAddressById(components, AffixPrototypeComponentID)), - AffixAvailabilityComponent(getAddressById(components, AffixAvailabilityComponentID)), - AffixPrototypeGroupComponent(getAddressById(components, AffixPrototypeGroupComponentID)) - ); - - statmodProtoEntities = new uint256[](affixPartIds.length); - affixProtoEntities = new uint256[](affixPartIds.length); - affixValues = new uint32[](affixPartIds.length); - - for (uint256 i; i < affixPartIds.length; i++) { - randomness = uint256(keccak256(abi.encode(i, randomness))); - // pick affix proto entity - uint256 affixProtoEntity = _pickAffixProtoEntity( - comps, - ilvl, - affixPartIds[i], - targetEntity, - excludeAffixes, - randomness - ); - AffixPrototype memory affixProto = comps.affixProto.getValue(affixProtoEntity); - // set the corresponding statmod - statmodProtoEntities[i] = affixProto.statmodProtoEntity; - - // pick its value - affixProtoEntities[i] = affixProtoEntity; - affixValues[i] = _pickAffixValue(affixProto, randomness); - - if (i != affixPartIds.length - 1) { - // exclude all affixes from the picked affix's group (skip for the last cycle) - uint256[] memory newExcludeAffixes = comps.group.getEntitiesWithValue(comps.group.getValue(affixProtoEntity)); - excludeAffixes = LibArray.concat(excludeAffixes, newExcludeAffixes); - } - } - } - - function manuallyPickAffixesMax( - IUint256Component components, - string[] memory names, - uint32[] memory tiers - ) - internal - view - returns (uint256[] memory statmodProtoEntities, uint256[] memory affixProtoEntities, uint32[] memory affixValues) - { - uint256 len = names.length; - statmodProtoEntities = new uint256[](len); - affixProtoEntities = new uint256[](len); - affixValues = new uint32[](len); - - for (uint256 i; i < names.length; i++) { - affixProtoEntities[i] = getAffixProtoEntity(names[i], tiers[i]); - - AffixPrototype memory affixProto = AffixPrototypeComponent(getAddressById(components, AffixPrototypeComponentID)) - .getValue(affixProtoEntities[i]); - statmodProtoEntities[i] = affixProto.statmodProtoEntity; - - affixValues[i] = affixProto.max; - } - } - - /// @dev Randomly pick an affix entity from the available set. - function _pickAffixProtoEntity( - Comps memory comps, - uint256 ilvl, - AffixPartId affixPartId, - uint256 targetEntity, - uint256[] memory excludeAffixes, - uint256 randomness - ) internal view returns (uint256) { - randomness = uint256(keccak256(abi.encode(keccak256("pickAffixEntity"), randomness))); - - // TODO this can be significantly optimized if you need it - uint256 availabilityEntity = getAffixAvailabilityEntity(ilvl, affixPartId, targetEntity); - uint256[] memory entities = _getAvailableEntities(comps, availabilityEntity, excludeAffixes); - if (entities.length == 0) revert LibPickAffixes__NoAvailableAffix(ilvl, affixPartId, targetEntity); - - uint256 index = randomness % entities.length; - return entities[index]; - } - - /// @dev Queries the default availability and removes `excludeEntities` from it. - function _getAvailableEntities( - Comps memory comps, - uint256 availabilityEntity, - uint256[] memory excludeEntities - ) private view returns (uint256[] memory availableEntities) { - // get default availability - availableEntities = comps.availability.getValue(availabilityEntity); - - for (uint256 i; i < availableEntities.length; i++) { - // exclude the specified entities - if (LibArray.isIn(availableEntities[i], excludeEntities)) { - uint256 len = availableEntities.length; - // swap and pop - availableEntities[i] = availableEntities[len - 1]; - /// @solidity memory-safe-assembly - assembly { - // shorten the array length - mstore(availableEntities, sub(len, 1)) - } - } - } - return availableEntities; - } - - /// @dev Randomly pick an affix value. - function _pickAffixValue(AffixPrototype memory affixProto, uint256 randomness) internal pure returns (uint32) { - randomness = uint256(keccak256(abi.encode(keccak256("_pickAffixValue"), randomness))); - - if (affixProto.max < affixProto.min) revert LibPickAffixes__InvalidMinMax(); - if (affixProto.max == affixProto.min) return affixProto.min; - - uint32 range = affixProto.max - affixProto.min; - uint32 result = uint32(randomness % uint256(range)); - return result + affixProto.min; - } -} diff --git a/packages/contracts/_old_src/charstat/ExperienceComponent.sol b/packages/contracts/_old_src/charstat/ExperienceComponent.sol deleted file mode 100644 index 46c06b5e..00000000 --- a/packages/contracts/_old_src/charstat/ExperienceComponent.sol +++ /dev/null @@ -1,41 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { LibTypes } from "solecs/LibTypes.sol"; -import { BareComponent } from "solecs/BareComponent.sol"; - -enum PStat { - STRENGTH, - ARCANA, - DEXTERITY -} -uint256 constant PS_L = 3; - -uint256 constant ID = uint256(keccak256("component.Experience")); - -contract ExperienceComponent is BareComponent { - constructor(address _world) BareComponent(_world, ID) {} - - function getSchema() public pure override returns (string[] memory keys, LibTypes.SchemaValue[] memory values) { - keys = new string[](PS_L); - values = new LibTypes.SchemaValue[](PS_L); - - keys[0] = "strength"; - values[0] = LibTypes.SchemaValue.UINT32; - - keys[1] = "arcana"; - values[1] = LibTypes.SchemaValue.UINT32; - - keys[2] = "dexterity"; - values[2] = LibTypes.SchemaValue.UINT32; - } - - function getValue(uint256 entity) public view returns (uint32[PS_L] memory result) { - return abi.decode(getRawValue(entity), (uint32[3])); /* 3 == PS_L */ - } - - function set(uint256 entity, uint32[PS_L] memory pstats) public { - set(entity, abi.encode(pstats)); - } -} diff --git a/packages/contracts/_old_src/charstat/LibCharstat.sol b/packages/contracts/_old_src/charstat/LibCharstat.sol deleted file mode 100644 index ec2efdb9..00000000 --- a/packages/contracts/_old_src/charstat/LibCharstat.sol +++ /dev/null @@ -1,162 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; -import { getAddressById } from "solecs/utils.sol"; -import { Statmod, Element, EL_L } from "../statmod/Statmod.sol"; -import { Topics } from "./Topics.sol"; -import { LibExperience, PStat, PS_L } from "./LibExperience.sol"; -import { LifeCurrentComponent, ID as LifeCurrentComponentID } from "./LifeCurrentComponent.sol"; -import { ManaCurrentComponent, ID as ManaCurrentComponentID } from "./ManaCurrentComponent.sol"; - -library LibCharstat { - using Statmod for Statmod.Self; - using LibExperience for LibExperience.Self; - - struct Self { - Statmod.Self statmod; - LibExperience.Self exp; - LifeCurrentComponent lifeCComp; - ManaCurrentComponent manaCComp; - uint256 targetEntity; - } - - function __construct(IUint256Component components, uint256 targetEntity) internal view returns (Self memory) { - return - Self({ - statmod: Statmod.__construct(components, targetEntity), - exp: LibExperience.__construct(components, targetEntity), - lifeCComp: LifeCurrentComponent(getAddressById(components, LifeCurrentComponentID)), - manaCComp: ManaCurrentComponent(getAddressById(components, ManaCurrentComponentID)), - targetEntity: targetEntity - }); - } - - // ========== PRIMARY STATS (strength, arcana, dexterity) ========== - function getBasePStat(Self memory __self, PStat pstatIndex) internal view returns (uint32) { - if (__self.exp.hasExp()) { - // if entity uses exp component, use that for primary stats - return __self.exp.getPStat(pstatIndex); - } else { - // otherwise try a special statmod - return __self.statmod.getValuesFinal(Topics.LEVEL.toEntity(), 0); - } - } - - function getPStat(Self memory __self, PStat pstatIndex) internal view returns (uint32) { - uint32 baseValue = getBasePStat(__self, pstatIndex); - - return __self.statmod.getValuesFinal(Topics.PSTAT()[uint256(pstatIndex)].toEntity(), baseValue); - } - - function getPStats(Self memory __self) internal view returns (uint32[PS_L] memory pstats) { - for (uint256 i; i < PS_L; i++) { - pstats[i] = getPStat(__self, PStat(i)); - } - return pstats; - } - - // ========== ATTRIBUTES ========== - function getLife(Self memory __self) internal view returns (uint32) { - uint32 strength = getPStat(__self, PStat.STRENGTH); - uint32 baseValue = 2 + 2 * strength; - - return __self.statmod.getValuesFinal(Topics.LIFE.toEntity(), baseValue); - } - - function getMana(Self memory __self) internal view returns (uint32) { - uint32 arcana = getPStat(__self, PStat.ARCANA); - uint32 baseValue = 4 * arcana; - - return __self.statmod.getValuesFinal(Topics.MANA.toEntity(), baseValue); - } - - function getFortune(Self memory __self) internal view returns (uint32) { - return __self.statmod.getValuesFinal(Topics.FORTUNE.toEntity(), 0); - } - - function getConnection(Self memory __self) internal view returns (uint32) { - return __self.statmod.getValuesFinal(Topics.CONNECTION.toEntity(), 0); - } - - function getLifeRegen(Self memory __self) internal view returns (uint32) { - return __self.statmod.getValuesFinal(Topics.LIFE_GAINED_PER_TURN.toEntity(), 0); - } - - function getManaRegen(Self memory __self) internal view returns (uint32) { - return __self.statmod.getValuesFinal(Topics.MANA_GAINED_PER_TURN.toEntity(), 0); - } - - // ========== ELEMENTAL ========== - function getAttack(Self memory __self) internal view returns (uint32[EL_L] memory) { - uint32 strength = getPStat(__self, PStat.STRENGTH); - // strength increases physical base attack damage - uint32[EL_L] memory baseValues = [uint32(0), strength / 2 + 1, 0, 0, 0]; - - return __self.statmod.getValuesElementalFinal(Topics.ATTACK.toEntity(), baseValues); - } - - function getSpell(Self memory __self, uint32[EL_L] memory baseValues) internal view returns (uint32[EL_L] memory) { - uint32 arcana = getPStat(__self, PStat.ARCANA); - // arcana increases non-zero base spell damage - for (uint256 i; i < EL_L; i++) { - if (baseValues[i] > 0) { - // TODO u sure it's fine to modify in-place like that? - baseValues[i] += arcana; - } - } - - return __self.statmod.getValuesElementalFinal(Topics.SPELL.toEntity(), baseValues); - } - - function getResistance(Self memory __self) internal view returns (uint32[EL_L] memory) { - uint32 dexterity = getPStat(__self, PStat.DEXTERITY); - // dexterity increases base physical resistance - uint32[EL_L] memory baseValues = [uint32((dexterity / 4) * 4), 0, 0, 0, 0]; - - return __self.statmod.getValuesElementalFinal(Topics.SPELL.toEntity(), baseValues); - } - - // ========== CURRENTS ========== - function getLifeCurrent(Self memory __self) internal view returns (uint32) { - uint32 lifeMax = getLife(__self); - uint32 lifeCurrent = __self.lifeCComp.getValue(__self.targetEntity); - if (lifeCurrent > lifeMax) { - return lifeMax; - } else { - return uint32(lifeCurrent); - } - } - - function setLifeCurrent(Self memory __self, uint32 value) internal { - __self.lifeCComp.set(__self.targetEntity, value); - } - - function getManaCurrent(Self memory __self) internal view returns (uint32) { - uint32 manaMax = getMana(__self); - uint32 manaCurrent = __self.manaCComp.getValue(__self.targetEntity); - if (manaCurrent > manaMax) { - return manaMax; - } else { - return uint32(manaCurrent); - } - } - - function setManaCurrent(Self memory __self, uint32 value) internal { - __self.manaCComp.set(__self.targetEntity, value); - } - - /** - * @dev Set currents to max values - */ - function setFullCurrents(Self memory __self) internal { - setLifeCurrent(__self, getLife(__self)); - setManaCurrent(__self, getMana(__self)); - } - - // ========== ROUND DAMAGE ========== - function getRoundDamage(Self memory __self) internal view returns (uint32[EL_L] memory) { - return __self.statmod.getValuesElementalFinal(Topics.SPELL.toEntity(), [uint32(0), 0, 0, 0, 0]); - } -} diff --git a/packages/contracts/_old_src/charstat/LibExperience.sol b/packages/contracts/_old_src/charstat/LibExperience.sol deleted file mode 100644 index c7b2bbb0..00000000 --- a/packages/contracts/_old_src/charstat/LibExperience.sol +++ /dev/null @@ -1,139 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; -import { getAddressById } from "solecs/utils.sol"; -import { PStat, PS_L, ExperienceComponent, ID as ExperienceComponentID } from "./ExperienceComponent.sol"; - -library LibExperience { - error LibExperience__InvalidLevel(); - error LibExperience__ExpNotInitialized(); - - uint32 constant MAX_LEVEL = 16; - - struct Self { - ExperienceComponent comp; - uint256 targetEntity; - } - - function __construct(IUint256Component components, uint256 targetEntity) internal view returns (Self memory) { - return - Self({ - comp: ExperienceComponent(getAddressById(components, ExperienceComponentID)), - targetEntity: targetEntity - }); - } - - function getPStats(Self memory __self) internal view returns (uint32[PS_L] memory result) { - result = __self.comp.getValue(__self.targetEntity); - for (uint256 i; i < result.length; i++) { - result[i] = _getLevel(result[i]); - } - } - - function getPStat(Self memory __self, PStat pstatIndex) internal view returns (uint32) { - uint32 exp = __self.comp.getValue(__self.targetEntity)[uint256(pstatIndex)]; - return _getLevel(exp); - } - - function hasExp(Self memory __self) internal view returns (bool) { - return __self.comp.has(__self.targetEntity); - } - - function getExp(Self memory __self) internal view returns (uint32[PS_L] memory) { - return __self.comp.getValue(__self.targetEntity); - } - - /** - * @dev Allow target to receive exp, set exp to 0s - */ - function initExp(Self memory __self) internal { - uint32[PS_L] memory exp; - __self.comp.set(__self.targetEntity, exp); - } - - /** - * @dev Increase target's experience - * Exp must be initialized - */ - function increaseExp(Self memory __self, uint32[PS_L] memory addExp) internal { - // get current exp, or revert if it doesn't exist - if (!__self.comp.has(__self.targetEntity)) { - revert LibExperience__ExpNotInitialized(); - } - uint32[PS_L] memory exp = __self.comp.getValue(__self.targetEntity); - - // increase - for (uint256 i; i < PS_L; i++) { - exp[i] += addExp[i]; - } - // set increased exp - __self.comp.set(__self.targetEntity, exp); - } - - /** - * @dev Calculate aggregate level based on weighted sum of pstat exp - */ - function getAggregateLevel(Self memory __self, uint32[PS_L] memory levelMul) internal view returns (uint32) { - uint32[PS_L] memory exp = getExp(__self); - uint256 expTotal; - uint256 mulTotal; - for (uint256 i; i < PS_L; i++) { - expTotal += exp[i] * levelMul[i]; - mulTotal += levelMul[i]; - } - - expTotal /= mulTotal; - - return _getLevel(expTotal); - } - - /** - * @dev Calculate level based on single exp value - */ - function _getLevel(uint256 expVal) private pure returns (uint32) { - // expVal per level rises exponentially with polynomial easing - // 1-0, 2-96, 3-312, 4-544, 5-804, 6-1121... - for (uint32 level = 1; level < MAX_LEVEL; level++) { - // (1< MAX_LEVEL) revert LibExperience__InvalidLevel(); - - // this formula starts from 0, so adjust the arg - if (level == 1) { - return 0; - } else { - level -= 1; - } - - return uint32(8 * (1 << level) - level ** 6 / 1024 + level * 200 - 120); - } - - /** - * @dev Get exp amount to get base primary to `pstats` (assuming 0 current exp). - * This is a utility for testing - */ - function getExpForPStats(uint32[PS_L] memory pstats) internal pure returns (uint32[PS_L] memory exp) { - for (uint256 i; i < PS_L; i++) { - exp[i] = _getExpForLevel(pstats[i]); - } - } - - /** - * @dev same as getExpForPStats but for 1 specific pstat - */ - function getExpForPStat(uint32 pstat) internal pure returns (uint32) { - return _getExpForLevel(pstat); - } -} diff --git a/packages/contracts/_old_src/charstat/LifeCurrentComponent.sol b/packages/contracts/_old_src/charstat/LifeCurrentComponent.sol deleted file mode 100644 index d0889b9d..00000000 --- a/packages/contracts/_old_src/charstat/LifeCurrentComponent.sol +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { Uint32BareComponent } from "std-contracts/components/Uint32BareComponent.sol"; - -uint256 constant ID = uint256(keccak256("component.LifeCurrent")); - -contract LifeCurrentComponent is Uint32BareComponent { - constructor(address world) Uint32BareComponent(world, ID) {} -} diff --git a/packages/contracts/_old_src/charstat/ManaCurrentComponent.sol b/packages/contracts/_old_src/charstat/ManaCurrentComponent.sol deleted file mode 100644 index e84bdfdf..00000000 --- a/packages/contracts/_old_src/charstat/ManaCurrentComponent.sol +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { Uint32BareComponent } from "std-contracts/components/Uint32BareComponent.sol"; - -uint256 constant ID = uint256(keccak256("component.ManaCurrent")); - -contract ManaCurrentComponent is Uint32BareComponent { - constructor(address world) Uint32BareComponent(world, ID) {} -} diff --git a/packages/contracts/_old_src/charstat/Topics.sol b/packages/contracts/_old_src/charstat/Topics.sol deleted file mode 100644 index e9f96d44..00000000 --- a/packages/contracts/_old_src/charstat/Topics.sol +++ /dev/null @@ -1,55 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IWorld } from "solecs/interfaces/IWorld.sol"; - -import { PS_L, PStat } from "./LibExperience.sol"; -import { statmodName } from "../statmod/statmodName.sol"; -import { Op, Element, StatmodPrototype, getStatmodProtoEntity } from "../statmod/StatmodPrototypeComponent.sol"; - -type Topic is uint256; - -library Topics { - Topic constant STRENGTH = Topic.wrap(uint256(keccak256("strength"))); - Topic constant ARCANA = Topic.wrap(uint256(keccak256("arcana"))); - Topic constant DEXTERITY = Topic.wrap(uint256(keccak256("dexterity"))); - - // pstat topics also come as an array since it's often useful to iterate them - function PSTAT() internal pure returns (Topic[PS_L] memory r) { - r[uint256(PStat.STRENGTH)] = STRENGTH; - r[uint256(PStat.ARCANA)] = ARCANA; - r[uint256(PStat.DEXTERITY)] = DEXTERITY; - } - - Topic constant LIFE = Topic.wrap(uint256(keccak256("life"))); - Topic constant MANA = Topic.wrap(uint256(keccak256("mana"))); - Topic constant FORTUNE = Topic.wrap(uint256(keccak256("fortune"))); - Topic constant CONNECTION = Topic.wrap(uint256(keccak256("connection"))); - Topic constant LIFE_GAINED_PER_TURN = Topic.wrap(uint256(keccak256("life gained per turn"))); - Topic constant MANA_GAINED_PER_TURN = Topic.wrap(uint256(keccak256("mana gained per turn"))); - - Topic constant ATTACK = Topic.wrap(uint256(keccak256("attack"))); - Topic constant SPELL = Topic.wrap(uint256(keccak256("spell"))); - Topic constant RESISTANCE = Topic.wrap(uint256(keccak256("resistance"))); - - Topic constant DAMAGE_TAKEN_PER_ROUND = Topic.wrap(uint256(keccak256("damage taken per round"))); - - Topic constant DAMAGE_TAKEN = Topic.wrap(uint256(keccak256("damage taken"))); - Topic constant REDUCED_DAMAGE_DONE = Topic.wrap(uint256(keccak256("reduced damage done"))); - Topic constant ROUNDS_STUNNED = Topic.wrap(uint256(keccak256("rounds stunned"))); - - Topic constant PERCENT_OF_MISSING_LIFE_TO_ATTACK = - Topic.wrap(uint256(keccak256("% of missing life to {element} attack"))); - Topic constant LEVEL = Topic.wrap(uint256(keccak256("level"))); -} - -using { toEntity, toStatmodEntity } for Topic global; - -function toEntity(Topic topic) pure returns (uint256) { - return Topic.unwrap(topic); -} - -function toStatmodEntity(Topic topic, Op op, Element element) pure returns (uint256) { - return getStatmodProtoEntity(StatmodPrototype({ topicEntity: topic.toEntity(), op: op, element: element })); -} diff --git a/packages/contracts/_old_src/combat/ActiveCombatComponent.sol b/packages/contracts/_old_src/combat/ActiveCombatComponent.sol deleted file mode 100644 index b45d06de..00000000 --- a/packages/contracts/_old_src/combat/ActiveCombatComponent.sol +++ /dev/null @@ -1,13 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { Uint256Component } from "std-contracts/components/Uint256Component.sol"; - -uint256 constant ID = uint256(keccak256("component.ActiveCombat")); - -/// @title initiatorEntity => retaliatorEntity -/// @dev An entity can initiate only 1 combat at a time -contract ActiveCombatComponent is Uint256Component { - constructor(address world) Uint256Component(world, ID) {} -} diff --git a/packages/contracts/_old_src/combat/CombatSubSystem.sol b/packages/contracts/_old_src/combat/CombatSubSystem.sol deleted file mode 100644 index 31f380ef..00000000 --- a/packages/contracts/_old_src/combat/CombatSubSystem.sol +++ /dev/null @@ -1,252 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { System } from "solecs/System.sol"; -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { getAddressById } from "solecs/utils.sol"; -import { Subsystem } from "@dk1a/solecslib/contracts/mud/Subsystem.sol"; - -import { ActiveCombatComponent, ID as ActiveCombatComponentID } from "./ActiveCombatComponent.sol"; -import { ScopedDuration, SystemCallback, DurationSubSystem, ID as DurationSubSystemID } from "../duration/DurationSubSystem.sol"; - -import { LibActiveCombat } from "./LibActiveCombat.sol"; -import { LibCharstat, EL_L } from "../charstat/LibCharstat.sol"; -import { LibCombatAction, Action, ActionType, ActorOpts } from "./LibCombatAction.sol"; - -/// @dev combatDurationEntity = hashed(salt, initiator) -function getCombatDurationEntity(uint256 initiatorEntity) pure returns (uint256) { - return uint256(keccak256(abi.encode(keccak256("getCombatDurationEntity"), initiatorEntity))); -} - -uint256 constant ID = uint256(keccak256("system.Combat")); - -/** - * @title Subsystem to execute 1 combat round between 2 actors; extensively uses charstats. - * @dev A combat may have multiple rounds, each executed separately. - * `Action[]` in args allows multiple actions in 1 round. (For another round call execute again). - * `CombatSubsystem` has multi-actor multi-action interactions logic, - * and uses `LibCombatAction` for reusable one-way action logic. - */ -contract CombatSubSystem is Subsystem { - using LibCharstat for LibCharstat.Self; - using LibCombatAction for LibCombatAction.Self; - - error CombatSubSystem__InvalidExecuteSelector(); - error CombatSubSystem__InvalidActionsLength(); - error CombatSubSystem__ResidualDuration(); - - struct CombatActor { - uint256 entity; - Action[] actions; - ActorOpts opts; - } - - // Result for initiator; it's based on who loses all life first. - // This just indicates how the combat concluded. - enum CombatResult { - NONE, - VICTORY, - DEFEAT - } - - constructor(IWorld _world, address _components) Subsystem(_world, _components) {} - - /** - * @notice Execute a combat round with default PVE options - * @dev Player must be the initiator - */ - function executePVERound( - uint256 initiatorEntity, - uint256 retaliatorEntity, - Action[] memory initiatorActions, - Action[] memory retaliatorActions - ) public returns (CombatResult) { - CombatActor memory initiator = CombatActor({ - entity: initiatorEntity, - actions: initiatorActions, - opts: ActorOpts({ maxResistance: 80 }) - }); - CombatActor memory retaliator = CombatActor({ - entity: retaliatorEntity, - actions: retaliatorActions, - opts: ActorOpts({ maxResistance: 99 }) - }); - - return executeCombatRound(initiator, retaliator); - } - - /** - * @notice Execute a combat round with generic actors - */ - function executeCombatRound( - CombatActor memory initiator, - CombatActor memory retaliator - ) public onlyWriter returns (CombatResult result) { - // TODO (maybe this check doesn't need to be here?) - // combat should be externally activated - LibActiveCombat.requireActiveCombat(components, initiator.entity, retaliator.entity); - - result = _bothActorsActions(initiator, retaliator); - - if (result != CombatResult.NONE) { - // combat ended - deactivate it - executeDeactivateCombat(initiator.entity); - } else { - // combat keeps going - decrement round durations - DurationSubSystem durationSubSystem = _durationSubSystem(); - durationSubSystem.executeDecreaseScope( - initiator.entity, - ScopedDuration({ - // TODO unhardcode durations in CombatSubSystem - timeScopeId: uint256(keccak256("round")), - timeValue: 1 - }) - ); - durationSubSystem.executeDecreaseScope( - initiator.entity, - ScopedDuration({ timeScopeId: uint256(keccak256("round_persistent")), timeValue: 1 }) - ); - // if combat duration ran out, initiator loses by default - uint256 durationEntity = getCombatDurationEntity(initiator.entity); - if (!durationSubSystem.has(initiator.entity, durationEntity)) { - executeDeactivateCombat(initiator.entity); - result = CombatResult.DEFEAT; - } - } - - return result; - } - - /** - * @notice Combat must be activated first, then `executeCombatRound` can be called until it's over - */ - function executeActivateCombat( - uint256 initiatorEntity, - uint256 retaliatorEntity, - uint256 maxRounds - ) public onlyWriter { - LibActiveCombat.requireNotActiveCombat(components, initiatorEntity); - - ActiveCombatComponent activeCombatComp = ActiveCombatComponent(getAddressById(components, ActiveCombatComponentID)); - activeCombatComp.set(initiatorEntity, retaliatorEntity); - - uint256 durationEntity = getCombatDurationEntity(initiatorEntity); - DurationSubSystem durationSubSystem = _durationSubSystem(); - if (durationSubSystem.has(initiatorEntity, durationEntity)) { - // helps catch weird bugs where combat isn't active, but duration still is - revert CombatSubSystem__ResidualDuration(); - } - durationSubSystem.executeIncrease( - initiatorEntity, - durationEntity, - ScopedDuration({ timeScopeId: uint256(keccak256("round")), timeValue: maxRounds }), - SystemCallback(0, "") - ); - } - - /** - * @notice Mostly for internal use, but it can also be called to prematurely deactivate combat - */ - function executeDeactivateCombat(uint256 initiatorEntity) public onlyWriter { - ActiveCombatComponent activeCombatComp = ActiveCombatComponent(getAddressById(components, ActiveCombatComponentID)); - activeCombatComp.remove(initiatorEntity); - - DurationSubSystem durationSubSystem = _durationSubSystem(); - durationSubSystem.executeDecreaseScope( - initiatorEntity, - ScopedDuration({ timeScopeId: uint256(keccak256("round")), timeValue: type(uint256).max }) - ); - durationSubSystem.executeDecreaseScope( - initiatorEntity, - ScopedDuration({ timeScopeId: uint256(keccak256("turn")), timeValue: 1 }) - ); - } - - /*////////////////////////////////////////////////////////////// - INTERNAL - //////////////////////////////////////////////////////////////*/ - - function _execute(bytes memory args) internal override returns (bytes memory) { - (bytes4 executeSelector, bytes memory innerArgs) = abi.decode(args, (bytes4, bytes)); - - if (executeSelector == this.executeCombatRound.selector) { - (CombatActor memory initiator, CombatActor memory retaliator) = abi.decode(innerArgs, (CombatActor, CombatActor)); - return abi.encode(executeCombatRound(initiator, retaliator)); - } else if (executeSelector == this.executeActivateCombat.selector) { - (uint256 initiatorEntity, uint256 retaliatorEntity, uint256 maxRounds) = abi.decode( - innerArgs, - (uint256, uint256, uint256) - ); - executeActivateCombat(initiatorEntity, retaliatorEntity, maxRounds); - return ""; - } else if (executeSelector == this.executeDeactivateCombat.selector) { - uint256 initiatorEntity = abi.decode(innerArgs, (uint256)); - executeDeactivateCombat(initiatorEntity); - return ""; - } else { - revert CombatSubSystem__InvalidExecuteSelector(); - } - } - - function _bothActorsActions( - CombatActor memory initiator, - CombatActor memory retaliator - ) internal returns (CombatResult) { - // TODO use some initiative method instead of initiator always being 1st? - LibCharstat.Self memory initiatorCharstat = LibCharstat.__construct(components, initiator.entity); - LibCharstat.Self memory retaliatorCharstat = LibCharstat.__construct(components, retaliator.entity); - - // instant loss if initiator somehow started with 0 life - if (initiatorCharstat.getLifeCurrent() == 0) return CombatResult.DEFEAT; - - // initiator's actions - _oneActorActions(initiator, initiatorCharstat, retaliator, retaliatorCharstat); - - // win if retaliator is dead; this interrupts retaliator's actions - if (retaliatorCharstat.getLifeCurrent() == 0) return CombatResult.VICTORY; - - // retaliator's actions - _oneActorActions(retaliator, retaliatorCharstat, initiator, initiatorCharstat); - - // loss if initiator is dead - if (initiatorCharstat.getLifeCurrent() == 0) return CombatResult.DEFEAT; - // win if retaliator somehow died in its own round - if (retaliatorCharstat.getLifeCurrent() == 0) return CombatResult.VICTORY; - // none otherwise - return CombatResult.NONE; - } - - function _oneActorActions( - CombatActor memory attacker, - LibCharstat.Self memory attackerCharstat, - CombatActor memory defender, - LibCharstat.Self memory defenderCharstat - ) internal { - _checkActionsLength(attacker); - - LibCombatAction.Self memory combatAction = LibCombatAction.__construct( - world, - attackerCharstat, - attacker.opts, - defenderCharstat, - defender.opts - ); - - for (uint256 i; i < attacker.actions.length; i++) { - combatAction.executeAction(attacker.actions[i]); - } - } - - function _checkActionsLength(CombatActor memory actor) internal pure { - if (actor.actions.length > 1) { - // TODO a way to do 2 actions in a round, like a special skill - // (limited by actionType, 2 attacks in a round is too OP) - revert CombatSubSystem__InvalidActionsLength(); - } - } - - function _durationSubSystem() internal view returns (DurationSubSystem) { - return DurationSubSystem(getAddressById(world.systems(), DurationSubSystemID)); - } -} diff --git a/packages/contracts/_old_src/combat/LibActiveCombat.sol b/packages/contracts/_old_src/combat/LibActiveCombat.sol deleted file mode 100644 index a5846a4c..00000000 --- a/packages/contracts/_old_src/combat/LibActiveCombat.sol +++ /dev/null @@ -1,49 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { ActiveCombatComponent, ID as ActiveCombatComponentID } from "./ActiveCombatComponent.sol"; - -library LibActiveCombat { - error LibActiveCombat__CombatActive(); - error LibActiveCombat__CombatNotActive(); - error LibActiveCombat__CombatActiveForDifferentRetaliator(); - - function getRetaliatorEntity( - IUint256Component components, - uint256 initiatorEntity - ) internal view returns (uint256 retaliatorEntity) { - ActiveCombatComponent activeCombatComp = _comp(components); - if (!activeCombatComp.has(initiatorEntity)) { - revert LibActiveCombat__CombatNotActive(); - } - return activeCombatComp.getValue(initiatorEntity); - } - - function requireActiveCombat( - IUint256Component components, - uint256 initiatorEntity, - uint256 retaliatorEntity - ) internal view { - ActiveCombatComponent activeCombatComp = _comp(components); - if (!activeCombatComp.has(initiatorEntity)) { - revert LibActiveCombat__CombatNotActive(); - } - if (activeCombatComp.getValue(initiatorEntity) != retaliatorEntity) { - revert LibActiveCombat__CombatActiveForDifferentRetaliator(); - } - } - - function requireNotActiveCombat(IUint256Component components, uint256 initiatorEntity) internal view { - if (_comp(components).has(initiatorEntity)) { - revert LibActiveCombat__CombatActive(); - } - } - - function _comp(IUint256Component components) internal view returns (ActiveCombatComponent) { - return ActiveCombatComponent(getAddressById(components, ActiveCombatComponentID)); - } -} diff --git a/packages/contracts/_old_src/combat/LibCombatAction.sol b/packages/contracts/_old_src/combat/LibCombatAction.sol deleted file mode 100644 index 8747a356..00000000 --- a/packages/contracts/_old_src/combat/LibCombatAction.sol +++ /dev/null @@ -1,132 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; - -import { LibSkill } from "../skill/LibSkill.sol"; -import { LibCharstat, EL_L } from "../charstat/LibCharstat.sol"; - -struct Action { - ActionType actionType; - uint256 actionEntity; -} - -enum ActionType { - ATTACK, - SKILL -} - -// TODO this may work better via a component -struct ActorOpts { - uint32 maxResistance; -} - -library LibCombatAction { - using LibCharstat for LibCharstat.Self; - using LibSkill for LibSkill.Self; - - error LibCombat__InvalidActionType(); - - struct Self { - IWorld world; - LibCharstat.Self attackerCharstat; - ActorOpts attackerOpts; - LibCharstat.Self defenderCharstat; - ActorOpts defenderOpts; - } - - function __construct( - IWorld world, - LibCharstat.Self memory attackerCharstat, - ActorOpts memory attackerOpts, - LibCharstat.Self memory defenderCharstat, - ActorOpts memory defenderOpts - ) internal pure returns (Self memory) { - return - Self({ - world: world, - attackerCharstat: attackerCharstat, - attackerOpts: attackerOpts, - defenderCharstat: defenderCharstat, - defenderOpts: defenderOpts - }); - } - - function executeAction(Self memory __self, Action memory action) internal { - if (action.actionType == ActionType.ATTACK) { - // deal damage to defender (updates currents) - _dealAttackDamage(__self); - } else if (action.actionType == ActionType.SKILL) { - _useSkill(__self, action.actionEntity); - } else { - revert LibCombat__InvalidActionType(); - } - } - - function _useSkill(Self memory __self, uint256 skillEntity) private { - LibSkill.Self memory libSkill = LibSkill.__construct( - __self.world, - __self.attackerCharstat.targetEntity, - skillEntity - ); - - libSkill.requireCombat(); - - // combat skills may target either self or enemy, depending on skill prototype - uint256 targetEntity = libSkill.chooseCombatTarget(__self.defenderCharstat.targetEntity); - // use skill - libSkill.useSkill(targetEntity); - - // skill may need a follow-up attack and/or spell - if (libSkill.skill.withAttack) { - _dealAttackDamage(__self); - } - if (libSkill.skill.withSpell) { - _dealSpellDamage(__self, libSkill.skill.spellDamage); - } - } - - function _dealAttackDamage(Self memory __self) private { - _dealDamage(__self, __self.attackerCharstat.getAttack()); - } - - function _dealSpellDamage(Self memory __self, uint32[EL_L] memory baseSpellDamage) private { - _dealDamage(__self, __self.attackerCharstat.getSpell(baseSpellDamage)); - } - - /** - * @dev Modifies LifeCurrent according to elemental damage and resistance - * Resistances are percentages (scaling of 1/100) - */ - function _dealDamage(Self memory __self, uint32[EL_L] memory elemDamage) private { - uint32 maxResistance = __self.defenderOpts.maxResistance; - assert(maxResistance <= 100); - - uint32[EL_L] memory resistance = __self.defenderCharstat.getResistance(); - - // calculate total damage (elemental, 0 index isn't used) - uint32 totalDamage = 0; - for (uint256 i = 1; i < EL_L; i++) { - uint32 elemResistance = resistance[i] < maxResistance ? resistance[i] : maxResistance; - uint32 adjustedDamage = (elemDamage[i] * (100 - elemResistance)) / 100; - totalDamage += adjustedDamage; - } - - // modify life only if resistances didn't fully negate damage - if (totalDamage == 0) return; - - // get life - uint32 lifeCurrent = __self.defenderCharstat.getLifeCurrent(); - // subtract damage - if (totalDamage >= lifeCurrent) { - // life can't be negative - lifeCurrent = 0; - } else { - lifeCurrent -= totalDamage; - } - // update life - __self.defenderCharstat.setLifeCurrent(lifeCurrent); - } -} diff --git a/packages/contracts/_old_src/combat/test/CombatSubsystem.t.sol b/packages/contracts/_old_src/combat/test/CombatSubsystem.t.sol deleted file mode 100644 index d74acad4..00000000 --- a/packages/contracts/_old_src/combat/test/CombatSubsystem.t.sol +++ /dev/null @@ -1,203 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { BaseTest } from "../../BaseTest.sol"; - -import { OwnableWritable } from "solecs/OwnableWritable.sol"; - -import { Topics } from "../../charstat/Topics.sol"; -import { LibCharstat, PStat } from "../../charstat/LibCharstat.sol"; -import { Statmod, Op, Element, EL_L } from "../../statmod/Statmod.sol"; -import { CombatSubSystem, Action, ActionType } from "../CombatSubSystem.sol"; -import { LibActiveCombat } from "../LibActiveCombat.sol"; - -contract CombatSubSystemTest is BaseTest { - using LibCharstat for LibCharstat.Self; - using Statmod for Statmod.Self; - - address writer = address(bytes20(keccak256('writer'))); - - uint256 playerEntity = uint256(keccak256('playerEntity')); - uint256 encounterEntity = uint256(keccak256('encounterEntity')); - - // libs - LibCharstat.Self playerCharstat; - LibCharstat.Self encounterCharstat; - - Action[] _noActions; - - // default data - uint32 constant initLevel = 2; - uint32 initLife; - uint32 initAttack; - uint256 maxRounds = 12; - - // statmod proto entities - uint256 levelPE = Topics.LEVEL.toStatmodEntity(Op.BADD, Element.ALL); - - function setUp() public virtual override { - super.setUp(); - - // authorize writer - combatSubSystem.authorizeWriter(writer); - - // init libs - playerCharstat = LibCharstat.__construct(world.components(), playerEntity); - encounterCharstat = LibCharstat.__construct(world.components(), encounterEntity); - - // give direct levels - // (note: don't change statmods directly outside of tests, use effects) - playerCharstat.statmod.increase(levelPE, initLevel); - encounterCharstat.statmod.increase(levelPE, initLevel); - - // initialize and fill up life, mana - playerCharstat.setFullCurrents(); - encounterCharstat.setFullCurrents(); - - // activate combat between player and encounter - combatSubSystem.executeActivateCombat(playerEntity, encounterEntity, maxRounds); - - initLife = playerCharstat.getLifeCurrent(); - initAttack = playerCharstat.getAttack()[uint256(Element.PHYSICAL)]; - } - - // ================ HELPERS ================ - - function _sumElements(uint32[EL_L] memory elemValues) internal pure returns (uint32 result) { - // TODO elemental values could use their own library, or at least some helpers - for (uint256 i = 1; i < EL_L; i++) { - result += elemValues[i]; - } - } - - function _actions1Attack() internal pure returns (Action[] memory result) { - result = new Action[](1); - result[0] = Action({ - actionType: ActionType.ATTACK, - actionEntity: 0 - }); - } - - function _actions2Attacks() internal pure returns (Action[] memory result) { - result = new Action[](2); - result[0] = Action({ - actionType: ActionType.ATTACK, - actionEntity: 0 - }); - result[1] = Action({ - actionType: ActionType.ATTACK, - actionEntity: 0 - }); - } - - // ================ TESTS ================ - - // this just shows the values I expect, and may need to change if LibCharstat config changes - function test_setUp() public { - assertEq(initLife, 2 + 2 * initLevel); - assertEq(playerCharstat.getLifeCurrent(), encounterCharstat.getLifeCurrent()); - - assertEq(initAttack, 1 + initLevel / 2); - assertEq(_sumElements(playerCharstat.getAttack()), initAttack); - assertEq(_sumElements(playerCharstat.getAttack()), _sumElements(encounterCharstat.getAttack())); - } - - function test_combatPVERound_notWriter() public { - vm.prank(address(bytes20(keccak256('notWriter')))); - vm.expectRevert(OwnableWritable.OwnableWritable__NotWriter.selector); - combatSubSystem.executePVERound( - playerEntity, encounterEntity, _noActions, _noActions - ); - } - - // skipping a round is fine - function test_combatPVERound_noActions() public { - vm.prank(writer); - CombatSubSystem.CombatResult result = combatSubSystem.executePVERound( - playerEntity, encounterEntity, _noActions, _noActions - ); - assertEq(uint8(result), uint8(CombatSubSystem.CombatResult.NONE)); - } - - // by default entities can only do 1 action per round - function test_combatPVERound_invalidActionsLength() public { - vm.prank(writer); - vm.expectRevert(CombatSubSystem.CombatSubSystem__InvalidActionsLength.selector); - combatSubSystem.executePVERound( - playerEntity, encounterEntity, _actions2Attacks(), _actions2Attacks() - ); - } - - // an unopposed single attack - function test_combatPVERound_playerAttacks_1() public { - vm.prank(writer); - - CombatSubSystem.CombatResult result = combatSubSystem.executePVERound( - playerEntity, encounterEntity, _actions1Attack(), _noActions - ); - assertEq(uint8(result), uint8(CombatSubSystem.CombatResult.NONE)); - assertEq(encounterCharstat.getLifeCurrent(), initLife - initAttack); - } - - // unopposed player attacks, enough to get victory - function test_combatPVERound_playerAttacks_victory() public { - vm.prank(writer); - - CombatSubSystem.CombatResult result; - // do enough attacks to defeat encounter - uint256 attacksNumber = initLife / initAttack; - for (uint256 i; i < attacksNumber; i++) { - result = combatSubSystem.executePVERound( - playerEntity, encounterEntity, _actions1Attack(), _noActions - ); - if (i != attacksNumber - 1) { - assertEq(uint8(result), uint8(CombatSubSystem.CombatResult.NONE)); - } - } - assertEq(uint8(result), uint8(CombatSubSystem.CombatResult.VICTORY)); - assertEq(encounterCharstat.getLifeCurrent(), 0); - } - - // unopposed encounter attacks, enough to get defeat - function test_combatPVERound_encounterAttacks_defeat() public { - vm.prank(writer); - - CombatSubSystem.CombatResult result; - // do enough attacks to defeat player - uint256 attacksNumber = initLife / initAttack; - for (uint256 i; i < attacksNumber; i++) { - result = combatSubSystem.executePVERound( - playerEntity, encounterEntity, _noActions, _actions1Attack() - ); - if (i != attacksNumber - 1) { - assertEq(uint8(result), uint8(CombatSubSystem.CombatResult.NONE)); - } - } - assertEq(uint8(result), uint8(CombatSubSystem.CombatResult.DEFEAT)); - assertEq(playerCharstat.getLifeCurrent(), 0); - } - - // player and encounter have the same stats and attacks, but player goes 1st and wins the last round - function test_combatPVERound_opposedAttacks_victoryByInitiative() public { - vm.prank(writer); - - CombatSubSystem.CombatResult result; - // do enough attacks to defeat encounter - uint256 attacksNumber = initLife / initAttack; - for (uint256 i; i < attacksNumber; i++) { - result = combatSubSystem.executePVERound( - playerEntity, encounterEntity, _actions1Attack(), _actions1Attack() - ); - if (i != attacksNumber - 1) { - assertEq(uint8(result), uint8(CombatSubSystem.CombatResult.NONE)); - } - } - assertEq(uint8(result), uint8(CombatSubSystem.CombatResult.VICTORY)); - // also check that the last encounter action didn't go through, since it lost - assertEq(playerCharstat.getLifeCurrent(), initLife - initAttack * (attacksNumber - 1)); - assertEq(encounterCharstat.getLifeCurrent(), 0); - } - - // TODO So far just basic physical attacks. More tests, with statmods and skills. -} \ No newline at end of file diff --git a/packages/contracts/_old_src/common/ComponentDevSystem.sol b/packages/contracts/_old_src/common/ComponentDevSystem.sol deleted file mode 100644 index 579c7488..00000000 --- a/packages/contracts/_old_src/common/ComponentDevSystem.sol +++ /dev/null @@ -1,12 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { ComponentDevSystem as _ComponentDevSystem } from "std-contracts/systems/ComponentDevSystem.sol"; - -uint256 constant ID = uint256(keccak256("system.ComponentDev")); - -contract ComponentDevSystem is _ComponentDevSystem { - constructor(IWorld _world, address _components) _ComponentDevSystem(_world, _components) {} -} diff --git a/packages/contracts/_old_src/common/FromPrototypeComponent.sol b/packages/contracts/_old_src/common/FromPrototypeComponent.sol deleted file mode 100644 index 906055ff..00000000 --- a/packages/contracts/_old_src/common/FromPrototypeComponent.sol +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { Uint256Component } from "std-contracts/components/Uint256Component.sol"; - -uint256 constant ID = uint256(keccak256("component.FromPrototype")); - -contract FromPrototypeComponent is Uint256Component { - constructor(address world) Uint256Component(world, ID) {} -} diff --git a/packages/contracts/_old_src/common/NameComponent.sol b/packages/contracts/_old_src/common/NameComponent.sol deleted file mode 100644 index 7255f672..00000000 --- a/packages/contracts/_old_src/common/NameComponent.sol +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { StringBareComponent } from "std-contracts/components/StringBareComponent.sol"; - -uint256 constant ID = uint256(keccak256("component.Name")); - -contract NameComponent is StringBareComponent { - constructor(address world) StringBareComponent(world, ID) {} -} diff --git a/packages/contracts/_old_src/common/OwnedByComponent.sol b/packages/contracts/_old_src/common/OwnedByComponent.sol deleted file mode 100644 index e10139bd..00000000 --- a/packages/contracts/_old_src/common/OwnedByComponent.sol +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { Uint256BareComponent } from "std-contracts/components/Uint256BareComponent.sol"; - -uint256 constant ID = uint256(keccak256("component.OwnedBy")); - -contract OwnedByComponent is Uint256BareComponent { - constructor(address world) Uint256BareComponent(world, ID) {} -} diff --git a/packages/contracts/_old_src/common/ReverseHashNameComponent.sol b/packages/contracts/_old_src/common/ReverseHashNameComponent.sol deleted file mode 100644 index 1171e38b..00000000 --- a/packages/contracts/_old_src/common/ReverseHashNameComponent.sol +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { StringBareComponent } from "std-contracts/components/StringBareComponent.sol"; - -uint256 constant ID = uint256(keccak256("component.ReverseHashName")); - -contract ReverseHashNameComponent is StringBareComponent { - constructor(address world) StringBareComponent(world, ID) {} -} diff --git a/packages/contracts/_old_src/common/ReverseHashNameSystem.sol b/packages/contracts/_old_src/common/ReverseHashNameSystem.sol deleted file mode 100644 index 967fa5b6..00000000 --- a/packages/contracts/_old_src/common/ReverseHashNameSystem.sol +++ /dev/null @@ -1,40 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { System } from "solecs/System.sol"; -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { StrSlice, toSlice } from "@dk1a/solidity-stringutils/src/StrSlice.sol"; - -import { ReverseHashNameComponent, ID as ReverseHashNameComponentID } from "./ReverseHashNameComponent.sol"; - -uint256 constant ID = uint256(keccak256("system.ReverseHashName")); - -contract ReverseHashNameSystem is System { - constructor(IWorld _world, address _components) System(_world, _components) {} - - function executeTyped(string memory name) public returns (uint256) { - return abi.decode(execute(abi.encode(name)), (uint256)); - } - - /** - * @dev Permissionlessly map a hashed entity to its string name. - * Reverts on invalid UTF-8. - * Returns the character count of the name. - */ - function execute(bytes memory args) public override returns (bytes memory) { - string memory name = abi.decode(args, (string)); - - ReverseHashNameComponent comp = ReverseHashNameComponent(getAddressById(components, ReverseHashNameComponentID)); - - // reverts if UTF-8 is invalid - uint256 charCount = toSlice(name).chars().count(); - - uint256 entity = uint256(keccak256(bytes(name))); - comp.set(entity, name); - - return abi.encode(charCount); - } -} diff --git a/packages/contracts/_old_src/cycle/ActiveCycleComponent.sol b/packages/contracts/_old_src/cycle/ActiveCycleComponent.sol deleted file mode 100644 index 139b0325..00000000 --- a/packages/contracts/_old_src/cycle/ActiveCycleComponent.sol +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { Uint256BareComponent } from "std-contracts/components/Uint256BareComponent.sol"; - -uint256 constant ID = uint256(keccak256("component.ActiveCycle")); - -contract ActiveCycleComponent is Uint256BareComponent { - constructor(address world) Uint256BareComponent(world, ID) {} -} diff --git a/packages/contracts/_old_src/cycle/ActiveCyclePreviousComponent.sol b/packages/contracts/_old_src/cycle/ActiveCyclePreviousComponent.sol deleted file mode 100644 index b7830490..00000000 --- a/packages/contracts/_old_src/cycle/ActiveCyclePreviousComponent.sol +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { Uint256BareComponent } from "std-contracts/components/Uint256BareComponent.sol"; - -uint256 constant ID = uint256(keccak256("component.ActiveCyclePrevious")); - -contract ActiveCyclePreviousComponent is Uint256BareComponent { - constructor(address world) Uint256BareComponent(world, ID) {} -} diff --git a/packages/contracts/_old_src/cycle/ClaimCycleTurnsSystem.sol b/packages/contracts/_old_src/cycle/ClaimCycleTurnsSystem.sol deleted file mode 100644 index f2f80895..00000000 --- a/packages/contracts/_old_src/cycle/ClaimCycleTurnsSystem.sol +++ /dev/null @@ -1,37 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { System } from "solecs/System.sol"; -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { ActiveCycleComponent, ID as ActiveCycleComponentID } from "./ActiveCycleComponent.sol"; - -import { LibCycleTurns } from "./LibCycleTurns.sol"; -import { LibToken } from "../token/LibToken.sol"; - -uint256 constant ID = uint256(keccak256("system.ClaimCycleTurns")); - -/// @title Claim accumulated cycle turns. -/// @dev Does nothing if claimable turns == 0. -contract ClaimCycleTurnsSystem is System { - constructor(IWorld _world, address _components) System(_world, _components) {} - - function executeTyped(uint256 wandererEntity) public { - execute(abi.encode(wandererEntity)); - } - - function execute(bytes memory args) public override returns (bytes memory) { - uint256 wandererEntity = abi.decode(args, (uint256)); - // check permission - LibToken.requireOwner(components, wandererEntity, msg.sender); - // get cycle entity - ActiveCycleComponent activeCycleComp = ActiveCycleComponent(getAddressById(components, ActiveCycleComponentID)); - uint256 cycleEntity = activeCycleComp.getValue(wandererEntity); - // claim - LibCycleTurns.claimTurns(components, cycleEntity); - - return ""; - } -} diff --git a/packages/contracts/_old_src/cycle/CompleteCycleSystem.sol b/packages/contracts/_old_src/cycle/CompleteCycleSystem.sol deleted file mode 100644 index a5b0caf2..00000000 --- a/packages/contracts/_old_src/cycle/CompleteCycleSystem.sol +++ /dev/null @@ -1,57 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { System } from "solecs/System.sol"; -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { CycleBossesDefeatedComponent, ID as CycleBossesDefeatedComponentID } from "./CycleBossesDefeatedComponent.sol"; - -import { LibCycle } from "./LibCycle.sol"; -import { LibToken } from "../token/LibToken.sol"; -import { LibGuiseLevel } from "../guise/LibGuiseLevel.sol"; -import { LibWanderer } from "../wanderer/LibWanderer.sol"; - -uint256 constant ID = uint256(keccak256("system.CompleteCycle")); - -/// @title Complete a cycle and gain rewards. -contract CompleteCycleSystem is System { - error CompleteCycleSystem__NotAllBossesDefeated(); - error CompleteCycleSystem__InsufficientLevel(); - - constructor(IWorld _world, address _components) System(_world, _components) {} - - function executeTyped(uint256 wandererEntity) public returns (uint256 cycleEntity) { - return abi.decode(execute(abi.encode(wandererEntity)), (uint256)); - } - - function execute(bytes memory args) public override returns (bytes memory) { - uint256 wandererEntity = abi.decode(args, (uint256)); - - // reverts if sender doesn't have permission - uint256 cycleEntity = LibCycle.getCycleEntityPermissioned(components, wandererEntity); - - // All bosses must be defeated - CycleBossesDefeatedComponent cycleBossesDefeated = CycleBossesDefeatedComponent( - getAddressById(components, CycleBossesDefeatedComponentID) - ); - // TODO requirement reduced for testing; remove hardcode - if (cycleBossesDefeated.itemSetSize(cycleEntity) < 0) { - revert CompleteCycleSystem__NotAllBossesDefeated(); - } - - // must be max level - // TODO requirement reduced for testing; also remove hardcode - uint32 level = LibGuiseLevel.getAggregateLevel(components, cycleEntity); - if (level < 1) { - revert CompleteCycleSystem__InsufficientLevel(); - } - - // complete cycle - LibCycle.endCycle(components, wandererEntity, cycleEntity); - LibWanderer.gainCycleRewards(components, wandererEntity); - - return abi.encode(cycleEntity); - } -} diff --git a/packages/contracts/_old_src/cycle/CycleActivateCombatSystem.sol b/packages/contracts/_old_src/cycle/CycleActivateCombatSystem.sol deleted file mode 100644 index 4f29af21..00000000 --- a/packages/contracts/_old_src/cycle/CycleActivateCombatSystem.sol +++ /dev/null @@ -1,86 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { System } from "solecs/System.sol"; -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { FromPrototypeComponent, ID as FromPrototypeComponentID } from "../common/FromPrototypeComponent.sol"; -import { CycleBossesDefeatedComponent, ID as CycleBossesDefeatedComponentID } from "./CycleBossesDefeatedComponent.sol"; -import { Action, ActionType, CombatSubSystem, ID as CombatSubSystemID } from "../combat/CombatSubSystem.sol"; -import { EffectSubSystem, ID as EffectSubSystemID } from "../effect/EffectSubSystem.sol"; - -import { MapPrototypes } from "../map/MapPrototypes.sol"; -import { LibCycle } from "./LibCycle.sol"; -import { LibCycleTurns } from "./LibCycleTurns.sol"; -import { LibActiveCombat } from "../combat/LibActiveCombat.sol"; -import { LibCharstat } from "../charstat/LibCharstat.sol"; - -uint256 constant ID = uint256(keccak256("system.CycleActivateCombat")); - -contract CycleActivateCombatSystem is System { - using LibCharstat for LibCharstat.Self; - - error CycleActivateCombatSystem__InvalidMapPrototype(); - error CycleActivateCombatSystem__BossMapAlreadyCleared(); - - uint32 constant TURNS_COST = 1; - uint256 constant MAX_ROUNDS = 12; - - constructor(IWorld _world, address _components) System(_world, _components) {} - - function executeTyped(uint256 wandererEntity, uint256 mapEntity) public { - execute(abi.encode(wandererEntity, mapEntity)); - } - - function execute(bytes memory args) public override returns (bytes memory) { - (uint256 wandererEntity, uint256 mapEntity) = abi.decode(args, (uint256, uint256)); - - FromPrototypeComponent fromProtoComp = FromPrototypeComponent(getAddressById(components, FromPrototypeComponentID)); - CycleBossesDefeatedComponent cycleBossesDefeated = CycleBossesDefeatedComponent( - getAddressById(components, CycleBossesDefeatedComponentID) - ); - EffectSubSystem effectSubSystem = EffectSubSystem(getAddressById(world.systems(), EffectSubSystemID)); - CombatSubSystem combatSubSystem = CombatSubSystem(getAddressById(world.systems(), CombatSubSystemID)); - - // reverts if sender doesn't have permission - uint256 cycleEntity = LibCycle.getCycleEntityPermissioned(components, wandererEntity); - // reverts if combat is active - LibActiveCombat.requireNotActiveCombat(components, cycleEntity); - // reverts if map isn't GLOBAL_ (they are ownerless and can be used by anyone) - uint256 mapProtoEntity = fromProtoComp.getValue(mapEntity); - if ( - mapProtoEntity != MapPrototypes.GLOBAL_BASIC && - mapProtoEntity != MapPrototypes.GLOBAL_RANDOM && - mapProtoEntity != MapPrototypes.GLOBAL_CYCLE_BOSS - ) { - revert CycleActivateCombatSystem__InvalidMapPrototype(); - } - // TODO level checks - // reverts if boss is already defeated - if (mapProtoEntity == MapPrototypes.GLOBAL_CYCLE_BOSS) { - if (cycleBossesDefeated.hasItem(cycleEntity, mapEntity)) { - revert CycleActivateCombatSystem__BossMapAlreadyCleared(); - } - } - // reverts if not enough turns - LibCycleTurns.decreaseTurns(components, cycleEntity, TURNS_COST); - - // spawn new entity for map - uint256 retaliatorEntity = world.getUniqueEntityId(); - // apply map effects (this affects values of charstats, so must happen 1st) - effectSubSystem.executeApply(retaliatorEntity, mapEntity); - // init currents - LibCharstat.Self memory charstat = LibCharstat.__construct(components, retaliatorEntity); - charstat.setFullCurrents(); - // TODO I think this should have its own component - // set map (not mapProto) as retaliator's prototype so it can be referenced later for rewards and stuff - fromProtoComp.set(retaliatorEntity, mapEntity); - - // activate combat - combatSubSystem.executeActivateCombat(cycleEntity, retaliatorEntity, MAX_ROUNDS); - - return ""; - } -} diff --git a/packages/contracts/_old_src/cycle/CycleBossesDefeatedComponent.sol b/packages/contracts/_old_src/cycle/CycleBossesDefeatedComponent.sol deleted file mode 100644 index 699d2936..00000000 --- a/packages/contracts/_old_src/cycle/CycleBossesDefeatedComponent.sol +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { Uint256SetComponent } from "../Uint256SetComponent.sol"; - -uint256 constant ID = uint256(keccak256("component.CycleBossesDefeated")); - -contract CycleBossesDefeatedComponent is Uint256SetComponent { - constructor(address world) Uint256SetComponent(world, ID) {} -} diff --git a/packages/contracts/_old_src/cycle/CycleCombatRewardRequestComponent.sol b/packages/contracts/_old_src/cycle/CycleCombatRewardRequestComponent.sol deleted file mode 100644 index 0e6f249f..00000000 --- a/packages/contracts/_old_src/cycle/CycleCombatRewardRequestComponent.sol +++ /dev/null @@ -1,64 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { LibTypes } from "solecs/LibTypes.sol"; -import { BareComponent } from "solecs/BareComponent.sol"; - -import { PS_L } from "../charstat/ExperienceComponent.sol"; - -uint256 constant ID = uint256(keccak256("component.CycleCombatRewardRequest")); - -struct CycleCombatRewardRequestData { - uint256 mapEntity; - uint32 connection; - uint32 fortune; - uint32[PS_L] winnerPstats; - uint32[PS_L] loserPstats; -} - -/// @dev requestId => cycleEntity -/// Use `getEntitiesWithValue` to get cycleEntity's unfulfilled reward requests -contract CycleCombatRewardRequestComponent is BareComponent { - constructor(address world) BareComponent(world, ID) {} - - function getSchema() public pure override returns (string[] memory keys, LibTypes.SchemaValue[] memory values) { - keys = new string[](3 + 2 * PS_L); - values = new LibTypes.SchemaValue[](3 + 2 * PS_L); - - keys[0] = "mapEntity"; - values[0] = LibTypes.SchemaValue.UINT256; - - keys[1] = "connection"; - values[1] = LibTypes.SchemaValue.UINT32; - - keys[2] = "fortune"; - values[2] = LibTypes.SchemaValue.UINT32; - - keys[3] = "winner_strength"; - values[3] = LibTypes.SchemaValue.UINT32; - - keys[4] = "winner_arcana"; - values[4] = LibTypes.SchemaValue.UINT32; - - keys[5] = "winner_dexterity"; - values[5] = LibTypes.SchemaValue.UINT32; - - keys[6] = "loser_strength"; - values[6] = LibTypes.SchemaValue.UINT32; - - keys[7] = "loser_arcana"; - values[7] = LibTypes.SchemaValue.UINT32; - - keys[8] = "loser_dexterity"; - values[8] = LibTypes.SchemaValue.UINT32; - } - - function getValue(uint256 entity) public view returns (CycleCombatRewardRequestData memory result) { - return abi.decode(getRawValue(entity), (CycleCombatRewardRequestData)); - } - - function set(uint256 entity, CycleCombatRewardRequestData memory data) public { - set(entity, abi.encode(data)); - } -} diff --git a/packages/contracts/_old_src/cycle/CycleCombatRewardSystem.sol b/packages/contracts/_old_src/cycle/CycleCombatRewardSystem.sol deleted file mode 100644 index 29e3c885..00000000 --- a/packages/contracts/_old_src/cycle/CycleCombatRewardSystem.sol +++ /dev/null @@ -1,66 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { System } from "solecs/System.sol"; -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { RandomEquipmentSubSystem, ID as RandomEquipmentSubSystemID } from "../loot/RandomEquipmentSubSystem.sol"; - -import { LibCycle } from "./LibCycle.sol"; -import { LibActiveCombat } from "../combat/LibActiveCombat.sol"; -import { LibCycleCombatRewardRequest } from "./LibCycleCombatRewardRequest.sol"; -import { LibExperience, PS_L } from "../charstat/LibExperience.sol"; -import { LibLootOwner } from "../loot/LibLootOwner.sol"; -import { LibGuiseLevel } from "../guise/LibGuiseLevel.sol"; -import { LibRNG } from "../rng/LibRNG.sol"; - -uint256 constant ID = uint256(keccak256("system.CycleCombatReward")); - -contract CycleCombatRewardSystem is System { - using LibExperience for LibExperience.Self; - - error CycleCombatRewardSystem__UnknownMapPrototype(); - - constructor(IWorld _world, address _components) System(_world, _components) {} - - function executeTyped(uint256 wandererEntity, uint256 requestId) public { - execute(abi.encode(wandererEntity, requestId)); - } - - function execute(bytes memory args) public override returns (bytes memory) { - (uint256 wandererEntity, uint256 requestId) = abi.decode(args, (uint256, uint256)); - // reverts if sender doesn't have permission - uint256 cycleEntity = LibCycle.getCycleEntityPermissioned(components, wandererEntity); - // TODO decide if claiming exp during combat is actually bad and why - LibActiveCombat.requireNotActiveCombat(components, cycleEntity); - - (uint256 randomness, uint32[PS_L] memory exp, uint32 lootIlvl, uint256 lootCount) = LibCycleCombatRewardRequest - .popReward(components, cycleEntity, requestId); - - // multiply awarded exp by guise's multiplier - exp = LibGuiseLevel.multiplyExperience(components, cycleEntity, exp); - - // give exp - LibExperience.__construct(components, cycleEntity).increaseExp(exp); - - // give loot - RandomEquipmentSubSystem randomEquipmentSubSystem = RandomEquipmentSubSystem( - getAddressById(world.systems(), RandomEquipmentSubSystemID) - ); - for (uint256 i; i < lootCount; i++) { - uint256 lootEntity = randomEquipmentSubSystem.executeTyped(lootIlvl, randomness); - LibLootOwner.setSimpleOwnership(components, lootEntity, cycleEntity); - } - - return ""; - } - - function cancelRequest(uint256 wandererEntity, uint256 requestId) public { - // reverts if sender doesn't have permission - uint256 cycleEntity = LibCycle.getCycleEntityPermissioned(components, wandererEntity); - // remove the reward without claiming it - LibRNG.removeRequest(components, cycleEntity, requestId); - } -} diff --git a/packages/contracts/_old_src/cycle/CycleCombatSystem.sol b/packages/contracts/_old_src/cycle/CycleCombatSystem.sol deleted file mode 100644 index 8abed985..00000000 --- a/packages/contracts/_old_src/cycle/CycleCombatSystem.sol +++ /dev/null @@ -1,52 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { System } from "solecs/System.sol"; -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { Action, ActionType, CombatSubSystem, ID as CombatSubSystemID } from "../combat/CombatSubSystem.sol"; - -import { LibActiveCombat } from "../combat/LibActiveCombat.sol"; -import { LibCycle } from "./LibCycle.sol"; -import { LibCycleCombatRewardRequest } from "./LibCycleCombatRewardRequest.sol"; - -uint256 constant ID = uint256(keccak256("system.CycleCombat")); - -contract CycleCombatSystem is System { - constructor(IWorld _world, address _components) System(_world, _components) {} - - function executeTyped( - uint256 wandererEntity, - Action[] memory initiatorActions - ) public returns (CombatSubSystem.CombatResult) { - return abi.decode(execute(abi.encode(wandererEntity, initiatorActions)), (CombatSubSystem.CombatResult)); - } - - function execute(bytes memory args) public override returns (bytes memory) { - (uint256 wandererEntity, Action[] memory initiatorActions) = abi.decode(args, (uint256, Action[])); - // reverts if sender doesn't have permission - uint256 cycleEntity = LibCycle.getCycleEntityPermissioned(components, wandererEntity); - // reverts if combat isn't active - uint256 retaliatorEntity = LibActiveCombat.getRetaliatorEntity(components, cycleEntity); - - // TODO other retaliator actions? - Action[] memory retaliatorActions = new Action[](1); - retaliatorActions[0] = Action({ actionType: ActionType.ATTACK, actionEntity: 0 }); - - CombatSubSystem combatSubSystem = CombatSubSystem(getAddressById(world.systems(), CombatSubSystemID)); - CombatSubSystem.CombatResult result = combatSubSystem.executePVERound( - cycleEntity, - retaliatorEntity, - initiatorActions, - retaliatorActions - ); - - if (result == CombatSubSystem.CombatResult.VICTORY) { - LibCycleCombatRewardRequest.requestReward(world, cycleEntity, retaliatorEntity); - } - - return abi.encode(result); - } -} diff --git a/packages/contracts/_old_src/cycle/CycleEquipmentSystem.sol b/packages/contracts/_old_src/cycle/CycleEquipmentSystem.sol deleted file mode 100644 index 59798852..00000000 --- a/packages/contracts/_old_src/cycle/CycleEquipmentSystem.sol +++ /dev/null @@ -1,54 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { System } from "solecs/System.sol"; -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { getAddressById, addressToEntity } from "solecs/utils.sol"; - -import { EquipmentSubSystem, ID as EquipmentSubSystemID, EquipmentAction } from "../equipment/EquipmentSubSystem.sol"; -import { OwnedByComponent, ID as OwnedByComponentID } from "../common/OwnedByComponent.sol"; -import { LibCycle } from "./LibCycle.sol"; -import { LibLootOwner } from "../loot/LibLootOwner.sol"; - -uint256 constant ID = uint256(keccak256("system.CycleEquipment")); - -contract CycleEquipmentSystem is System { - error CycleEquipmentSystem__NotSlotOwner(); - error CycleEquipmentSystem__NotEquipmentOwner(); - - constructor(IWorld _world, address _components) System(_world, _components) {} - - function executeTyped( - EquipmentAction equipmentAction, - uint256 wandererEntity, - uint256 equipmentSlot, - uint256 equipmentEntity - ) public { - execute(abi.encode(equipmentAction, wandererEntity, equipmentSlot, equipmentEntity)); - } - - function execute(bytes memory args) public override returns (bytes memory) { - (EquipmentAction equipmentAction, uint256 wandererEntity, uint256 equipmentSlot, uint256 equipmentEntity) = abi - .decode(args, (EquipmentAction, uint256, uint256, uint256)); - - // reverts if sender doesn't have permission - uint256 cycleEntity = LibCycle.getCycleEntityPermissioned(components, wandererEntity); - - // the caller must own the equipment slot - OwnedByComponent ownedByComponent = OwnedByComponent(getAddressById(components, OwnedByComponentID)); - if (cycleEntity != ownedByComponent.getValue(equipmentSlot)) { - revert CycleEquipmentSystem__NotSlotOwner(); - } - // and the equipment - // TODO allow the entity which has `equipmentEntity` equipped to unequip it without owning it - if (cycleEntity != LibLootOwner.ownerOf(components, equipmentEntity)) { - revert CycleEquipmentSystem__NotEquipmentOwner(); - } - - EquipmentSubSystem equipmentSubsystem = EquipmentSubSystem(getAddressById(world.systems(), EquipmentSubSystemID)); - equipmentSubsystem.executeTyped(equipmentAction, equipmentSlot, equipmentEntity); - - return ""; - } -} diff --git a/packages/contracts/_old_src/cycle/CycleToWandererComponent.sol b/packages/contracts/_old_src/cycle/CycleToWandererComponent.sol deleted file mode 100644 index 94d80daf..00000000 --- a/packages/contracts/_old_src/cycle/CycleToWandererComponent.sol +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { Uint256BareComponent } from "std-contracts/components/Uint256BareComponent.sol"; - -uint256 constant ID = uint256(keccak256("component.CycleToWanderer")); - -contract CycleToWandererComponent is Uint256BareComponent { - constructor(address world) Uint256BareComponent(world, ID) {} -} diff --git a/packages/contracts/_old_src/cycle/CycleTurnsComponent.sol b/packages/contracts/_old_src/cycle/CycleTurnsComponent.sol deleted file mode 100644 index 1c4768ce..00000000 --- a/packages/contracts/_old_src/cycle/CycleTurnsComponent.sol +++ /dev/null @@ -1,19 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { Uint32BareComponent } from "std-contracts/components/Uint32BareComponent.sol"; - -uint256 constant ID = uint256(keccak256("component.CycleTurns")); - -contract CycleTurnsComponent is Uint32BareComponent { - constructor(address world) Uint32BareComponent(world, ID) {} - - function getRawValue(uint256 entity) public view virtual override returns (bytes memory rawValue) { - rawValue = entityToValue[entity]; - // just return 0 for absent entities to avoid unnecessary `has` checks - if (rawValue.length == 0) { - return abi.encode(0); - } - } -} diff --git a/packages/contracts/_old_src/cycle/CycleTurnsLastClaimedComponent.sol b/packages/contracts/_old_src/cycle/CycleTurnsLastClaimedComponent.sol deleted file mode 100644 index 7e0f5c7b..00000000 --- a/packages/contracts/_old_src/cycle/CycleTurnsLastClaimedComponent.sol +++ /dev/null @@ -1,19 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { Uint256BareComponent } from "std-contracts/components/Uint256BareComponent.sol"; - -uint256 constant ID = uint256(keccak256("component.CycleTurnsLastClaimed")); - -contract CycleTurnsLastClaimedComponent is Uint256BareComponent { - constructor(address world) Uint256BareComponent(world, ID) {} - - function getRawValue(uint256 entity) public view virtual override returns (bytes memory rawValue) { - rawValue = entityToValue[entity]; - // just return 0 for absent entities to avoid unnecessary `has` checks - if (rawValue.length == 0) { - return abi.encode(0); - } - } -} diff --git a/packages/contracts/_old_src/cycle/LearnCycleSkillSystem.sol b/packages/contracts/_old_src/cycle/LearnCycleSkillSystem.sol deleted file mode 100644 index 25810b89..00000000 --- a/packages/contracts/_old_src/cycle/LearnCycleSkillSystem.sol +++ /dev/null @@ -1,60 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { System } from "solecs/System.sol"; -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { ActiveGuiseComponent, ID as ActiveGuiseComponentID } from "../guise/ActiveGuiseComponent.sol"; -import { GuiseSkillsComponent, ID as GuiseSkillsComponentID } from "../guise/GuiseSkillsComponent.sol"; -import { SkillPrototypeComponent, ID as SkillPrototypeComponentID } from "../skill/SkillPrototypeComponent.sol"; - -import { LibLearnedSkills } from "../skill/LibLearnedSkills.sol"; -import { LibCycle } from "./LibCycle.sol"; -import { LibGuiseLevel } from "../guise/LibGuiseLevel.sol"; - -uint256 constant ID = uint256(keccak256("system.LearnCycleSkill")); - -/// @title Learn a Skill from the current cycle Guise's set of available skills. -contract LearnCycleSkillSystem is System { - using LibLearnedSkills for LibLearnedSkills.Self; - - error LearnCycleSkillSystem__SkillNotInGuiseSkills(); - error LearnCycleSkillSystem__LevelIsTooLow(); - - constructor(IWorld _world, address _components) System(_world, _components) {} - - function executeTyped(uint256 wandererEntity, uint256 skillEntity) public { - execute(abi.encode(wandererEntity, skillEntity)); - } - - function execute(bytes memory args) public override returns (bytes memory) { - (uint256 wandererEntity, uint256 skillEntity) = abi.decode(args, (uint256, uint256)); - - ActiveGuiseComponent activeGuiseComp = ActiveGuiseComponent(getAddressById(components, ActiveGuiseComponentID)); - SkillPrototypeComponent skillProto = SkillPrototypeComponent(getAddressById(components, SkillPrototypeComponentID)); - GuiseSkillsComponent guiseSkillsComp = GuiseSkillsComponent(getAddressById(components, GuiseSkillsComponentID)); - - // get cycle entity if sender is allowed to use it - uint256 cycleEntity = LibCycle.getCycleEntityPermissioned(components, wandererEntity); - - // check skill's level requirements - uint32 currentLevel = LibGuiseLevel.getAggregateLevel(components, cycleEntity); - uint8 requiredLevel = skillProto.getValue(skillEntity).requiredLevel; - if (currentLevel < requiredLevel) { - revert LearnCycleSkillSystem__LevelIsTooLow(); - } - - // guise skills must include `skillEntity` - uint256 guiseProtoEntity = activeGuiseComp.getValue(cycleEntity); - if (!guiseSkillsComp.hasItem(guiseProtoEntity, skillEntity)) { - revert LearnCycleSkillSystem__SkillNotInGuiseSkills(); - } - - // learn the skill - LibLearnedSkills.__construct(world, cycleEntity).learnSkill(skillEntity); - - return ""; - } -} diff --git a/packages/contracts/_old_src/cycle/LibCycle.sol b/packages/contracts/_old_src/cycle/LibCycle.sol deleted file mode 100644 index f987ecb3..00000000 --- a/packages/contracts/_old_src/cycle/LibCycle.sol +++ /dev/null @@ -1,146 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { ActiveCycleComponent, ID as ActiveCycleComponentID } from "./ActiveCycleComponent.sol"; -import { ActiveCyclePreviousComponent, ID as ActiveCyclePreviousComponentID } from "./ActiveCyclePreviousComponent.sol"; -import { ActiveGuiseComponent, ID as ActiveGuiseComponentID } from "../guise/ActiveGuiseComponent.sol"; -import { CycleToWandererComponent, ID as CycleToWandererComponentID } from "./CycleToWandererComponent.sol"; -import { GuisePrototypeComponent, ID as GuisePrototypeComponentID } from "../guise/GuisePrototypeComponent.sol"; -import { ActiveWheelComponent, ID as ActiveWheelComponentID } from "../wheel/ActiveWheelComponent.sol"; -import { WheelComponent, ID as WheelComponentID } from "../wheel/WheelComponent.sol"; - -import { LibCharstat } from "../charstat/LibCharstat.sol"; -import { LibExperience } from "../charstat/LibExperience.sol"; -import { LibCycleTurns } from "./LibCycleTurns.sol"; -import { LibToken } from "../token/LibToken.sol"; -import { LibSpawnEquipmentSlots } from "../equipment/LibSpawnEquipmentSlots.sol"; -import { LibLearnedSkills } from "../skill/LibLearnedSkills.sol"; - -// TODO imports for testing stuff, remove later -import { RandomEquipmentSubSystem, ID as RandomEquipmentSubSystemID } from "../loot/RandomEquipmentSubSystem.sol"; -import { LibLootOwner } from "../loot/LibLootOwner.sol"; - -library LibCycle { - using LibCharstat for LibCharstat.Self; - using LibExperience for LibExperience.Self; - using LibLearnedSkills for LibLearnedSkills.Self; - - error LibCycle__CycleIsAlreadyActive(); - error LibCycle__CycleNotActive(); - error LibCycle__InvalidGuiseProtoEntity(); - error LibCycle__InvalidWheelEntity(); - - function initCycle( - IWorld world, - uint256 targetEntity, - uint256 guiseProtoEntity, - uint256 wheelEntity - ) internal returns (uint256 cycleEntity) { - // cycleEntity is for all the in-cycle components (everything except activeCycle) - cycleEntity = world.getUniqueEntityId(); - - IUint256Component components = world.components(); - ActiveCycleComponent activeCycleComp = ActiveCycleComponent(getAddressById(components, ActiveCycleComponentID)); - ActiveGuiseComponent activeGuiseComp = ActiveGuiseComponent(getAddressById(components, ActiveGuiseComponentID)); - CycleToWandererComponent cycleToWandererComp = CycleToWandererComponent( - getAddressById(components, CycleToWandererComponentID) - ); - ActiveWheelComponent activeWheelComp = ActiveWheelComponent(getAddressById(components, ActiveWheelComponentID)); - LibCharstat.Self memory charstat = LibCharstat.__construct(components, cycleEntity); - - // cycle must be inactive - if (activeCycleComp.has(targetEntity)) { - revert LibCycle__CycleIsAlreadyActive(); - } - // prototypes must exist - if (!GuisePrototypeComponent(getAddressById(components, GuisePrototypeComponentID)).has(guiseProtoEntity)) { - revert LibCycle__InvalidGuiseProtoEntity(); - } - if (!WheelComponent(getAddressById(components, WheelComponentID)).has(wheelEntity)) { - revert LibCycle__InvalidWheelEntity(); - } - - // TODO check wheel requirements - - // set active cycle - activeCycleComp.set(targetEntity, cycleEntity); - cycleToWandererComp.set(cycleEntity, targetEntity); - // set active guise - activeGuiseComp.set(cycleEntity, guiseProtoEntity); - // set active wheel - activeWheelComp.set(cycleEntity, wheelEntity); - // init exp - charstat.exp.initExp(); - // init currents - charstat.setFullCurrents(); - // claim initial cycle turns - LibCycleTurns.claimTurns(components, cycleEntity); - // spawn equipment slots - LibSpawnEquipmentSlots.spawnEquipmentSlots(world, cycleEntity); - // copy permanent skills - LibLearnedSkills.__construct(world, cycleEntity).copySkills(targetEntity); - - // TODO loot for testing, remove later - { - RandomEquipmentSubSystem randomEquipmentSubSystem = RandomEquipmentSubSystem( - getAddressById(world.systems(), RandomEquipmentSubSystemID) - ); - uint256 lootEntity; - for (uint256 i; i < 20; i++) { - lootEntity = randomEquipmentSubSystem.executeTyped(uint32((i % 12) + 1), i + 123123); - LibLootOwner.setSimpleOwnership(components, lootEntity, cycleEntity); - } - } - - return cycleEntity; - } - - function endCycle(IUint256Component components, uint256 wandererEntity, uint256 cycleEntity) internal { - // save the previous cycle entity - ActiveCyclePreviousComponent activeCyclePreviousComp = ActiveCyclePreviousComponent( - getAddressById(components, ActiveCyclePreviousComponentID) - ); - activeCyclePreviousComp.set(wandererEntity, cycleEntity); - // clear the current cycle - ActiveCycleComponent activeCycleComp = ActiveCycleComponent(getAddressById(components, ActiveCycleComponentID)); - CycleToWandererComponent cycleToWandererComp = CycleToWandererComponent( - getAddressById(components, CycleToWandererComponentID) - ); - activeCycleComp.remove(wandererEntity); - cycleToWandererComp.remove(cycleEntity); - } - - /// @dev Return `cycleEntity` if msg.sender is allowed to use it. - /// Revert otherwise. - /// - /// Note on why getCycleEntity and a permission check are 1 method: - /// Cycle systems take `wandererEntity` as the argument to simplify checking permissions, - /// and then convert it to `cycleEntity`. If you don't need permission checks, - /// you probably shouldn't need this method either, and should know cycle entities directly. - function getCycleEntityPermissioned( - IUint256Component components, - uint256 wandererEntity - ) internal view returns (uint256 cycleEntity) { - // check permission - LibToken.requireOwner(components, wandererEntity, msg.sender); - // get cycle entity - ActiveCycleComponent activeCycleComp = ActiveCycleComponent(getAddressById(components, ActiveCycleComponentID)); - if (!activeCycleComp.has(wandererEntity)) revert LibCycle__CycleNotActive(); - return activeCycleComp.getValue(wandererEntity); - } - - function requirePermission(IUint256Component components, uint256 cycleEntity) internal view { - // get wanderer entity - CycleToWandererComponent cycleToWandererComp = CycleToWandererComponent( - getAddressById(components, CycleToWandererComponentID) - ); - uint256 wandererEntity = cycleToWandererComp.getValue(cycleEntity); - // check permission - LibToken.requireOwner(components, wandererEntity, msg.sender); - } -} diff --git a/packages/contracts/_old_src/cycle/LibCycleCombatRewardRequest.sol b/packages/contracts/_old_src/cycle/LibCycleCombatRewardRequest.sol deleted file mode 100644 index 9084bfdf..00000000 --- a/packages/contracts/_old_src/cycle/LibCycleCombatRewardRequest.sol +++ /dev/null @@ -1,161 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { CycleCombatRewardRequestComponent, ID as CycleCombatRewardRequestComponentID, CycleCombatRewardRequestData } from "./CycleCombatRewardRequestComponent.sol"; -import { FromPrototypeComponent, ID as FromPrototypeComponentID } from "../common/FromPrototypeComponent.sol"; -import { Loot, LootComponent, ID as LootComponentID } from "../loot/LootComponent.sol"; -import { AffixPrototypeComponent, ID as AffixPrototypeComponentID } from "../affix/AffixPrototypeComponent.sol"; -import { CycleBossesDefeatedComponent, ID as CycleBossesDefeatedComponentID } from "./CycleBossesDefeatedComponent.sol"; - -import { LibCharstat } from "../charstat/LibCharstat.sol"; -import { LibRNG } from "../rng/LibRNG.sol"; -import { AffixPartId } from "../affix/LibPickAffixes.sol"; -import { PS_L } from "../charstat/ExperienceComponent.sol"; -import { MapPrototypes } from "../map/MapPrototypes.sol"; - -library LibCycleCombatRewardRequest { - using LibCharstat for LibCharstat.Self; - - error LibCycleCombatRewardRequest__EntityMismatch(); - error LibCycleCombatRewardRequest__UnknownMapPrototype(); - - /// @dev Creates a pending request - function requestReward(IWorld world, uint256 cycleEntity, uint256 retaliatorEntity) internal { - IUint256Component components = world.components(); - FromPrototypeComponent fromProtoComp = FromPrototypeComponent(getAddressById(components, FromPrototypeComponentID)); - // TODO see fromProto in `CycleActivateCombatSystem` - uint256 mapEntity = fromProtoComp.getValue(retaliatorEntity); - - LibCharstat.Self memory charstatInitiator = LibCharstat.__construct(components, cycleEntity); - LibCharstat.Self memory charstatRetaliator = LibCharstat.__construct(components, retaliatorEntity); - // Request a reward, after a few blocks it can be claimed via `CycleCombatRewardSystem` - uint256 requestId = LibRNG.requestRandomness(world, cycleEntity); - - _comp(components).set( - requestId, - CycleCombatRewardRequestData({ - mapEntity: mapEntity, - connection: charstatInitiator.getConnection(), - fortune: charstatInitiator.getFortune(), - winnerPstats: charstatInitiator.getPStats(), - loserPstats: charstatRetaliator.getPStats() - }) - ); - } - - /// @dev Verifies and removes the pending request, then returns the calculated reward - function popReward( - IUint256Component components, - uint256 cycleEntity, - uint256 requestId - ) internal returns (uint256 randomness, uint32[PS_L] memory exp, uint32 lootIlvl, uint256 lootCount) { - // reverts if getting randomness too early or too late - // TODO ability to cancel request that's too late so they don't endlessly accumulate? or remove the limit - randomness = LibRNG.getRandomness(components, cycleEntity, requestId); - LibRNG.removeRequest(components, cycleEntity, requestId); - - CycleCombatRewardRequestData memory req = _comp(components).getValue(requestId); - - FromPrototypeComponent fromProtoComp = FromPrototypeComponent(getAddressById(components, FromPrototypeComponentID)); - uint256 mapProtoEntity = fromProtoComp.getValue(req.mapEntity); - if ( - mapProtoEntity != MapPrototypes.GLOBAL_BASIC && - mapProtoEntity != MapPrototypes.GLOBAL_RANDOM && - mapProtoEntity != MapPrototypes.GLOBAL_CYCLE_BOSS - ) { - // TODO support for other map protos when they're added - revert LibCycleCombatRewardRequest__UnknownMapPrototype(); - } - - exp = _getExpReward(randomness, req); - (lootIlvl, lootCount) = _getLootReward(components, randomness, req); - - // extra boss rewards - if (mapProtoEntity == MapPrototypes.GLOBAL_CYCLE_BOSS) { - lootCount += 2; - - CycleBossesDefeatedComponent cycleBossesDefeated = CycleBossesDefeatedComponent( - getAddressById(components, CycleBossesDefeatedComponentID) - ); - cycleBossesDefeated.addItem(cycleEntity, req.mapEntity); - } - } - - function _getExpReward( - uint256 randomness, - CycleCombatRewardRequestData memory req - ) private pure returns (uint32[PS_L] memory exp) { - for (uint256 i; i < PS_L; i++) { - // initial exp is connection + loser's stats - exp[i] = req.connection + req.loserPstats[i]; - - if (req.winnerPstats[i] > req.loserPstats[i]) { - // easy win may reduce exp by up to stat diff - uint32 range = req.winnerPstats[i] - req.loserPstats[i]; - uint256 iterRandomness = uint256(keccak256(abi.encode("subExp", i, randomness))); - uint32 subExp = uint32(iterRandomness % range); - if (subExp > exp[i]) { - // exp reward can be 0, but not negative - exp[i] = 0; - } else { - exp[i] -= subExp; - } - } else if (req.winnerPstats[i] < req.loserPstats[i]) { - // hard win may increase exp by up to stat diff - uint32 range = req.loserPstats[i] - req.winnerPstats[i]; - uint256 iterRandomness = uint256(keccak256(abi.encode("addExp", i, randomness))); - uint32 addExp = uint32(iterRandomness % range); - exp[i] += addExp; - } - } - } - - function _getLootReward( - IUint256Component components, - uint256 randomness, - CycleCombatRewardRequestData memory req - ) private view returns (uint32 ilvl, uint256 count) { - randomness = uint256(keccak256(abi.encode(keccak256("_getLootIlvlReward"), randomness))); - - LootComponent lootComp = LootComponent(getAddressById(components, LootComponentID)); - AffixPrototypeComponent affixProtoComp = AffixPrototypeComponent( - getAddressById(components, AffixPrototypeComponentID) - ); - - // accumulatedFortune is fortune + affix tiers, it can improve the reward - uint256 accumulatedFortune = req.fortune; - - Loot memory loot = lootComp.getValue(req.mapEntity); - for (uint256 i; i < loot.affixPartIds.length; i++) { - if (loot.affixPartIds[i] == AffixPartId.IMPLICIT) { - ilvl += uint32(loot.affixValues[i]); - } else { - uint256 tier = affixProtoComp.getValue(loot.affixProtoEntities[i]).tier; - accumulatedFortune += tier; - } - } - - while (accumulatedFortune > 0) { - // TODO less hardcode, more generalization; and add comments, this looks confusing - if (randomness % accumulatedFortune < 8) { - count++; - } - - if (accumulatedFortune > 8) { - accumulatedFortune -= 8; - } else { - accumulatedFortune = 0; - } - } - return (ilvl, count); - } - - function _comp(IUint256Component components) internal view returns (CycleCombatRewardRequestComponent) { - return CycleCombatRewardRequestComponent(getAddressById(components, CycleCombatRewardRequestComponentID)); - } -} diff --git a/packages/contracts/_old_src/cycle/LibCycleTurns.sol b/packages/contracts/_old_src/cycle/LibCycleTurns.sol deleted file mode 100644 index e311f0d6..00000000 --- a/packages/contracts/_old_src/cycle/LibCycleTurns.sol +++ /dev/null @@ -1,87 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { CycleTurnsComponent, ID as CycleTurnsComponentID } from "./CycleTurnsComponent.sol"; -import { CycleTurnsLastClaimedComponent, ID as CycleTurnsLastClaimedComponentID } from "./CycleTurnsLastClaimedComponent.sol"; - -library LibCycleTurns { - error LibCycleTurns__NotEnoughTurns(); - - // TODO minutes is for testing, change to days - uint256 constant ACC_PERIOD = 1 minutes; - uint32 constant TURNS_PER_PERIOD = 10; - uint32 constant MAX_ACC_PERIODS = 2; - uint32 constant MAX_CURRENT_TURNS_FOR_CLAIM = 50; - - /// @dev Get the number of currently available cycle turns. - function getTurns(IUint256Component components, uint256 cycleEntity) internal view returns (uint256) { - return _turnsComp(components).getValue(cycleEntity); - } - - /// @dev Decrease entity's available turns by `subTurns`. - function decreaseTurns(IUint256Component components, uint256 cycleEntity, uint32 subTurns) internal { - CycleTurnsComponent turnsComp = _turnsComp(components); - uint32 currentTurns = turnsComp.getValue(cycleEntity); - if (subTurns > currentTurns) revert LibCycleTurns__NotEnoughTurns(); - turnsComp.set(cycleEntity, currentTurns - subTurns); - } - - /// @dev Claims all claimable turns. - function claimTurns(IUint256Component components, uint256 cycleEntity) internal { - uint32 claimableTurns = getClaimableTurns(components, cycleEntity); - if (claimableTurns == 0) return; - - CycleTurnsComponent turnsComp = _turnsComp(components); - turnsComp.set(cycleEntity, turnsComp.getValue(cycleEntity) + claimableTurns); - _lastClaimedComp(components).set(cycleEntity, block.timestamp); - } - - /// @dev Get accumulated turns that can be claimed (both accumulation and claim have a cap). - function getClaimableTurns(IUint256Component components, uint256 cycleEntity) internal view returns (uint32) { - // get accumulated turns - uint32 accumulatedTurns = TURNS_PER_PERIOD * _getAccPeriods(components, cycleEntity); - assert(accumulatedTurns <= TURNS_PER_PERIOD * MAX_ACC_PERIODS); - assert(TURNS_PER_PERIOD * MAX_ACC_PERIODS < type(uint256).max); - // make sure current turns aren't overcapped (gotta spend some before claiming more) - uint256 currentTurns = _turnsComp(components).getValue(cycleEntity); - if (currentTurns > MAX_CURRENT_TURNS_FOR_CLAIM) { - return 0; - } else { - return accumulatedTurns; - } - } - - /// @dev Can accumulate ACC_PERIODs up to MAX_ACC_PERIODS, claimTurns resets accumulation. - /// The accumulation moment is equal for everyone. - function _getAccPeriods(IUint256Component components, uint256 cycleEntity) private view returns (uint32) { - uint256 lastClaimedTimestamp = _lastClaimedComp(components).getValue(cycleEntity); - if (lastClaimedTimestamp == 0) { - // timestamp can be 0 for the first claim - return 1; - } - // lastClaimed timestamp in floored periods - uint256 periodsLast = lastClaimedTimestamp / ACC_PERIOD; - // current timestamp in floored periods - uint256 periodsCurrent = block.timestamp / ACC_PERIOD; - // number of periods since the last claim - uint256 accPeriods = periodsCurrent - periodsLast; - if (accPeriods > MAX_ACC_PERIODS) { - return MAX_ACC_PERIODS; - } else { - // typecast is safe because MAX_ACC_PERIODS is uint32 - return uint32(accPeriods); - } - } - - function _turnsComp(IUint256Component components) private view returns (CycleTurnsComponent) { - return CycleTurnsComponent(getAddressById(components, CycleTurnsComponentID)); - } - - function _lastClaimedComp(IUint256Component components) private view returns (CycleTurnsLastClaimedComponent) { - return CycleTurnsLastClaimedComponent(getAddressById(components, CycleTurnsLastClaimedComponentID)); - } -} diff --git a/packages/contracts/_old_src/cycle/PassCycleTurnSystem.sol b/packages/contracts/_old_src/cycle/PassCycleTurnSystem.sol deleted file mode 100644 index 40a70524..00000000 --- a/packages/contracts/_old_src/cycle/PassCycleTurnSystem.sol +++ /dev/null @@ -1,46 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { System } from "solecs/System.sol"; -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { ActiveCycleComponent, ID as ActiveCycleComponentID } from "./ActiveCycleComponent.sol"; -import { DurationSubSystem, ID as DurationSubSystemID, ScopedDuration } from "../duration/DurationSubSystem.sol"; - -import { LibCycle } from "./LibCycle.sol"; -import { LibCycleTurns } from "./LibCycleTurns.sol"; -import { LibCharstat } from "../charstat/LibCharstat.sol"; -import { LibActiveCombat } from "../combat/LibActiveCombat.sol"; - -uint256 constant ID = uint256(keccak256("system.PassCycleTurn")); - -contract PassCycleTurnSystem is System { - constructor(IWorld _world, address _components) System(_world, _components) {} - - function executeTyped(uint256 wandererEntity) public { - execute(abi.encode(wandererEntity)); - } - - function execute(bytes memory args) public override returns (bytes memory) { - uint256 wandererEntity = abi.decode(args, (uint256)); - // reverts if sender doesn't have permission - uint256 cycleEntity = LibCycle.getCycleEntityPermissioned(components, wandererEntity); - // not available during combat (since it fully heals) - LibActiveCombat.requireNotActiveCombat(components, cycleEntity); - - // subtract 1 turn - LibCycleTurns.decreaseTurns(components, cycleEntity, 1); - DurationSubSystem durationSubSystem = DurationSubSystem(getAddressById(world.systems(), DurationSubSystemID)); - durationSubSystem.executeDecreaseScope( - cycleEntity, - ScopedDuration({ timeScopeId: uint256(keccak256("turn")), timeValue: 1 }) - ); - // fill up currents - LibCharstat.Self memory charstat = LibCharstat.__construct(components, cycleEntity); - LibCharstat.setFullCurrents(charstat); - - return ""; - } -} diff --git a/packages/contracts/_old_src/cycle/StartCycleSystem.sol b/packages/contracts/_old_src/cycle/StartCycleSystem.sol deleted file mode 100644 index 159bd902..00000000 --- a/packages/contracts/_old_src/cycle/StartCycleSystem.sol +++ /dev/null @@ -1,32 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { System } from "solecs/System.sol"; -import { IWorld } from "solecs/interfaces/IWorld.sol"; - -import { LibCycle } from "./LibCycle.sol"; -import { LibToken } from "../token/LibToken.sol"; - -uint256 constant ID = uint256(keccak256("system.StartCycle")); - -/// @title Start a cycle. -/// @dev Very much like WandererSpawnSystem, but for an existing wandererEntity. -contract StartCycleSystem is System { - constructor(IWorld _world, address _components) System(_world, _components) {} - - function execute(bytes memory) public pure returns (bytes memory) { - return ""; - } - - function executeTyped( - uint256 wandererEntity, - uint256 guiseProtoEntity, - uint256 wheelEntity - ) public returns (uint256 cycleEntity) { - // reverts if sender doesn't have permission - LibToken.requireOwner(components, wandererEntity, msg.sender); - // init cycle (reverts if a cycle is already active) - cycleEntity = LibCycle.initCycle(world, wandererEntity, guiseProtoEntity, wheelEntity); - } -} diff --git a/packages/contracts/_old_src/cycle/test/CycleCombatSystem.t.sol b/packages/contracts/_old_src/cycle/test/CycleCombatSystem.t.sol deleted file mode 100644 index f45527f3..00000000 --- a/packages/contracts/_old_src/cycle/test/CycleCombatSystem.t.sol +++ /dev/null @@ -1,76 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { BaseTest } from "../../BaseTest.sol"; - -import { getGuiseProtoEntity } from "../../guise/GuisePrototypeComponent.sol"; -import { MapPrototypes } from "../../map/MapPrototypes.sol"; -import { Loot } from "../../loot/LootComponent.sol"; -import { AffixPartId } from "../../affix/LibPickAffixes.sol"; -import { Action, ActionType, CombatSubSystem } from "../../combat/CombatSubSystem.sol"; - -contract CycleCombatSystemTest is BaseTest { - // taken from InitGuiseSystem, initialized by LibDeploy - uint256 warriorGuiseProtoEntity = getGuiseProtoEntity("Warrior"); - - uint256 wandererEntity; - uint256 cycleEntity; - uint256 mapEntity; - - function setUp() public virtual override { - super.setUp(); - - vm.prank(alice); - wandererEntity = wandererSpawnSystem.executeTyped(warriorGuiseProtoEntity); - cycleEntity = activeCycleComponent.getValue(wandererEntity); - - // find a global basic level 1 map - uint256[] memory mapEntities = fromPrototypeComponent.getEntitiesWithValue(MapPrototypes.GLOBAL_BASIC); - if (mapEntities.length == 0) { - revert("No global basic maps are available for testing"); - } - for (uint256 i; i < mapEntities.length; i++) { - if (_getMapLevel(mapEntities[i]) == 1) { - mapEntity = mapEntities[i]; - } - } - } - - function _getMapLevel(uint256 mapEntity_) internal view returns (uint256) { - Loot memory loot = lootComponent.getValue(mapEntity_); - for (uint256 i; i < loot.affixPartIds.length; i++) { - if (loot.affixPartIds[i] == AffixPartId.IMPLICIT) { - return loot.affixValues[i]; - } - } - revert("_getMapLevel: no IMPLICIT"); - } - - function test_setUp() public { - assertNotEq(mapEntity, 0); - } - - function test_cycleCombat() public { - vm.startPrank(alice); - cycleActivateCombatSystem.executeTyped( - wandererEntity, - mapEntity - ); - - Action[] memory attackAction = new Action[](1); - attackAction[0] = Action({ - actionType: ActionType.ATTACK, - actionEntity: 0 - }); - - CombatSubSystem.CombatResult result = CombatSubSystem.CombatResult.NONE; - while (result == CombatSubSystem.CombatResult.NONE) { - result = cycleCombatSystem.executeTyped( - wandererEntity, - attackAction - ); - } - // TODO test combat results, atm this just makes sure it can start/finish at all - } -} \ No newline at end of file diff --git a/packages/contracts/_old_src/cycle/test/CycleEquipmentSystem.t.sol b/packages/contracts/_old_src/cycle/test/CycleEquipmentSystem.t.sol deleted file mode 100644 index eb8b64af..00000000 --- a/packages/contracts/_old_src/cycle/test/CycleEquipmentSystem.t.sol +++ /dev/null @@ -1,26 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { BaseTest } from "../../BaseTest.sol"; - -import { getGuiseProtoEntity } from "../../guise/GuisePrototypeComponent.sol"; - -// TODO base test for cycle things? -contract CycleEquipmentSystemTest is BaseTest { - // taken from InitGuiseSystem, initialized by LibDeploy - uint256 warriorGuiseProtoEntity = getGuiseProtoEntity("Warrior"); - - uint256 wandererEntity; - uint256 cycleEntity; - - function setUp() public virtual override { - super.setUp(); - - vm.prank(alice); - wandererEntity = wandererSpawnSystem.executeTyped(warriorGuiseProtoEntity); - cycleEntity = activeCycleComponent.getValue(wandererEntity); - - // TODO this (just permission tests, the base logic should is tested in EquipmentSubsystemTest) - } -} diff --git a/packages/contracts/_old_src/cycle/test/LearnCycleSkillSystem.t.sol b/packages/contracts/_old_src/cycle/test/LearnCycleSkillSystem.t.sol deleted file mode 100644 index b9d74c5e..00000000 --- a/packages/contracts/_old_src/cycle/test/LearnCycleSkillSystem.t.sol +++ /dev/null @@ -1,51 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { BaseTest } from "../../BaseTest.sol"; - -import { ERC721BaseInternal } from "@dk1a/solecslib/contracts/token/ERC721/logic/ERC721BaseInternal.sol"; - -import { getGuiseProtoEntity } from "../../guise/GuisePrototypeComponent.sol"; -import { getSkillProtoEntity } from "../../skill/SkillPrototypeComponent.sol"; -import { LibCycle } from "../LibCycle.sol"; -import { LibGuiseLevel } from "../../guise/LibGuiseLevel.sol"; -import { LibToken } from "../../token/LibToken.sol"; - -contract LearnCycleSkillSystemTest is BaseTest { - // taken from InitGuiseSystem, initialized by LibDeploy - uint256 warriorGuiseProtoEntity = getGuiseProtoEntity("Warrior"); - - // taken from InitSkillSystem, initialized by LibDeploy - uint256 skillEntity1 = getSkillProtoEntity("Cleave"); - uint256 skillEntity2 = getSkillProtoEntity("Charge"); - uint256 skillEntityInvalid = uint256(keccak256("skillEntityInvalid")); - - uint256 wandererEntity; - uint256 cycleEntity; - - function setUp() public virtual override { - super.setUp(); - - vm.prank(alice); - wandererEntity = wandererSpawnSystem.executeTyped(warriorGuiseProtoEntity); - cycleEntity = activeCycleComponent.getValue(wandererEntity); - } - - function test_setUp() public { - assertEq(LibGuiseLevel.getAggregateLevel(components, cycleEntity), 1); - } - - function test_learnSkill() public { - vm.prank(alice); - learnCycleSkillSystem.executeTyped(wandererEntity, skillEntity1); - assertTrue(learnedSkillsComponent.hasItem(cycleEntity, skillEntity1)); - assertFalse(learnedSkillsComponent.has(wandererEntity)); - } - - function test_learnSkill_notTokenOwner() public { - vm.prank(bob); - vm.expectRevert(LibToken.LibToken_MustBeTokenOwner.selector); - learnCycleSkillSystem.executeTyped(wandererEntity, skillEntity1); - } -} \ No newline at end of file diff --git a/packages/contracts/_old_src/cycle/test/LibCycleTurns.t.sol b/packages/contracts/_old_src/cycle/test/LibCycleTurns.t.sol deleted file mode 100644 index b3057ae2..00000000 --- a/packages/contracts/_old_src/cycle/test/LibCycleTurns.t.sol +++ /dev/null @@ -1,84 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { BaseTest } from "../../BaseTest.sol"; - -import { getGuiseProtoEntity } from "../../guise/GuisePrototypeComponent.sol"; -import { LibCycleTurns } from "../LibCycleTurns.sol"; - -contract LibCycleTurnsTest is BaseTest { - // taken from InitGuiseSystem, initialized by LibDeploy - uint256 warriorGuiseProtoEntity = getGuiseProtoEntity("Warrior"); - - uint256 cycleEntity; - uint256 initialTurns; - - function setUp() public virtual override { - super.setUp(); - - vm.prank(alice); - uint256 wandererEntity = wandererSpawnSystem.executeTyped(warriorGuiseProtoEntity); - cycleEntity = activeCycleComponent.getValue(wandererEntity); - initialTurns = cycleTurnsComponent.getValue(cycleEntity); - } - - function test_setUp() public { - // spawn should autoclaim the first turns batch - assertEq(initialTurns, LibCycleTurns.TURNS_PER_PERIOD); - } - - function test_claimTurns_premature() public { - LibCycleTurns.claimTurns(components, cycleEntity); - // trying to claim again prematurely should do nothing - LibCycleTurns.claimTurns(components, cycleEntity); - - uint256 turns = cycleTurnsComponent.getValue(cycleEntity); - assertEq(turns, initialTurns); - } - - function test_claimTurns_secondPeriod() public { - // after waiting for ACC_PERIOD, another batch should be claimable - vm.warp(block.timestamp + LibCycleTurns.ACC_PERIOD); - LibCycleTurns.claimTurns(components, cycleEntity); - uint256 turns = cycleTurnsComponent.getValue(cycleEntity); - assertEq(turns, initialTurns + LibCycleTurns.TURNS_PER_PERIOD); - } - - function test_claimTurns_twoPeriods() public { - // after waiting for 2 ACC_PERIODs, 2 batches should be claimable at once - vm.warp(block.timestamp + 2 * LibCycleTurns.ACC_PERIOD); - LibCycleTurns.claimTurns(components, cycleEntity); - uint256 turns = cycleTurnsComponent.getValue(cycleEntity); - assertEq(turns, initialTurns + 2 * LibCycleTurns.TURNS_PER_PERIOD); - } - - function test_claimTurns_atMaxCurrent() public { - vm.warp(block.timestamp + LibCycleTurns.ACC_PERIOD); - - uint32 maxCurrent = LibCycleTurns.MAX_CURRENT_TURNS_FOR_CLAIM; - cycleTurnsComponent.set(cycleEntity, maxCurrent); - // claim turns while at max, this should succeed - LibCycleTurns.claimTurns(components, cycleEntity); - uint256 turns = cycleTurnsComponent.getValue(cycleEntity); - assertEq(turns, maxCurrent + LibCycleTurns.TURNS_PER_PERIOD); - } - - function test_claimTurns_overMaxCurrent() public { - vm.warp(block.timestamp + LibCycleTurns.ACC_PERIOD); - - uint32 maxCurrent = LibCycleTurns.MAX_CURRENT_TURNS_FOR_CLAIM; - cycleTurnsComponent.set(cycleEntity, maxCurrent + 1); - // claim turns while over max, this should do nothing (same as premature) - LibCycleTurns.claimTurns(components, cycleEntity); - uint256 turns = cycleTurnsComponent.getValue(cycleEntity); - assertEq(turns, maxCurrent + 1); - - // reduce current turns to max - cycleTurnsComponent.set(cycleEntity, LibCycleTurns.MAX_CURRENT_TURNS_FOR_CLAIM); - // this should succeed (ensuring that the previous empty claim didn't remove potential claimable turns) - LibCycleTurns.claimTurns(components, cycleEntity); - turns = cycleTurnsComponent.getValue(cycleEntity); - assertEq(turns, maxCurrent + LibCycleTurns.TURNS_PER_PERIOD); - } -} \ No newline at end of file diff --git a/packages/contracts/_old_src/cycle/test/PassCycleTurnSystem.t.sol b/packages/contracts/_old_src/cycle/test/PassCycleTurnSystem.t.sol deleted file mode 100644 index 6345bb33..00000000 --- a/packages/contracts/_old_src/cycle/test/PassCycleTurnSystem.t.sol +++ /dev/null @@ -1,48 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { BaseTest } from "../../BaseTest.sol"; - -import { getGuiseProtoEntity } from "../../guise/GuisePrototypeComponent.sol"; -import { LibCycle } from "../LibCycle.sol"; -import { LibCycleTurns } from "../LibCycleTurns.sol"; - -contract PassCycleTurnSystemTest is BaseTest { - // taken from InitGuiseSystem, initialized by LibDeploy - uint256 warriorGuiseProtoEntity = getGuiseProtoEntity("Warrior"); - - uint256 wandererEntity; - uint256 cycleEntity; - - function setUp() public virtual override { - super.setUp(); - - vm.prank(alice); - wandererEntity = wandererSpawnSystem.executeTyped(warriorGuiseProtoEntity); - cycleEntity = activeCycleComponent.getValue(wandererEntity); - } - - function test_passTurn() public { - vm.startPrank(alice); - uint256 turns = cycleTurnsComponent.getValue(cycleEntity); - passCycleTurnSystem.executeTyped(wandererEntity); - uint256 decrementedTurns = cycleTurnsComponent.getValue(cycleEntity); - assertEq(decrementedTurns, turns - 1); - } - - function test_passAllTurns() public { - vm.startPrank(alice); - uint256 turns = cycleTurnsComponent.getValue(cycleEntity); - for (uint256 i; i < turns; i++) { - passCycleTurnSystem.executeTyped(wandererEntity); - } - uint256 decrementedTurns = cycleTurnsComponent.getValue(cycleEntity); - assertEq(decrementedTurns, 0); - - vm.expectRevert(LibCycleTurns.LibCycleTurns__NotEnoughTurns.selector); - passCycleTurnSystem.executeTyped(wandererEntity); - } - - // TODO test that it can't be used during combat -} diff --git a/packages/contracts/_old_src/cycle/test/StartCycleSystem.t.sol b/packages/contracts/_old_src/cycle/test/StartCycleSystem.t.sol deleted file mode 100644 index 3ca10d83..00000000 --- a/packages/contracts/_old_src/cycle/test/StartCycleSystem.t.sol +++ /dev/null @@ -1,35 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { BaseTest } from "../../BaseTest.sol"; - -import { getGuiseProtoEntity } from "../../guise/GuisePrototypeComponent.sol"; -import { LibCycle } from "../LibCycle.sol"; -import { SingletonID } from "../../SingletonID.sol"; - -contract StartCycleSystemTest is BaseTest { - // taken from InitGuiseSystem, initialized by LibDeploy - uint256 warriorGuiseProtoEntity = getGuiseProtoEntity("Warrior"); - - uint256 wandererEntity; - uint256 cycleEntity; - uint256 defaultWheelEntity; - - function setUp() public virtual override { - super.setUp(); - - vm.prank(alice); - wandererEntity = wandererSpawnSystem.executeTyped(warriorGuiseProtoEntity); - cycleEntity = activeCycleComponent.getValue(wandererEntity); - defaultWheelEntity = defaultWheelComponent.getValue(SingletonID); - } - - function test_startCycle_cycleIsAlreadyActive() public { - vm.prank(alice); - vm.expectRevert(LibCycle.LibCycle__CycleIsAlreadyActive.selector); - startCycleSystem.executeTyped(wandererEntity, warriorGuiseProtoEntity, defaultWheelEntity); - } - - // TODO this is a stub, requires endCycle etc for proper tests -} diff --git a/packages/contracts/_old_src/duration/DurationOnEndComponent.sol b/packages/contracts/_old_src/duration/DurationOnEndComponent.sol deleted file mode 100644 index 68584d1f..00000000 --- a/packages/contracts/_old_src/duration/DurationOnEndComponent.sol +++ /dev/null @@ -1,40 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -// imports for the component -import { LibTypes } from "solecs/LibTypes.sol"; -import { BareComponent } from "solecs/BareComponent.sol"; - -// imports for `executeSystemCallback` helper -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { ISystem } from "solecs/interfaces/ISystem.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { SystemCallback, executeSystemCallback } from "std-contracts/components/SystemCallbackBareComponent.sol"; - -uint256 constant ID = uint256(keccak256("component.DurationOnEnd")); - -contract DurationOnEndComponent is BareComponent { - constructor(address world) BareComponent(world, ID) {} - - function getSchema() public pure override returns (string[] memory keys, LibTypes.SchemaValue[] memory values) { - keys = new string[](2); - values = new LibTypes.SchemaValue[](2); - - keys[0] = "systemId"; - values[0] = LibTypes.SchemaValue.UINT256; - - keys[1] = "args"; - values[1] = LibTypes.SchemaValue.BYTES; - } - - function set(uint256 entity, SystemCallback memory value) public virtual { - set(entity, abi.encode(value.systemId, value.args)); - } - - function getValue(uint256 entity) public view virtual returns (SystemCallback memory) { - (uint256 systemId, bytes memory args) = abi.decode(getRawValue(entity), (uint256, bytes)); - return SystemCallback(systemId, args); - } -} diff --git a/packages/contracts/_old_src/duration/DurationScopeComponent.sol b/packages/contracts/_old_src/duration/DurationScopeComponent.sol deleted file mode 100644 index 05446f49..00000000 --- a/packages/contracts/_old_src/duration/DurationScopeComponent.sol +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { ScopeComponent } from "@dk1a/solecslib/contracts/scoped-value/ScopeComponent.sol"; - -uint256 constant ID = uint256(keccak256("component.DurationScope")); - -contract DurationScopeComponent is ScopeComponent { - constructor(address world) ScopeComponent(world, ID) {} -} diff --git a/packages/contracts/_old_src/duration/DurationSubSystem.sol b/packages/contracts/_old_src/duration/DurationSubSystem.sol deleted file mode 100644 index 769d1258..00000000 --- a/packages/contracts/_old_src/duration/DurationSubSystem.sol +++ /dev/null @@ -1,30 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { ScopedDurationSubsystem, ScopedDuration } from "@dk1a/solecslib/contracts/duration/ScopedDurationSubsystem.sol"; - -import { DurationScopeComponent, ID as DurationScopeComponentID } from "./DurationScopeComponent.sol"; -import { DurationValueComponent, ID as DurationValueComponentID } from "./DurationValueComponent.sol"; -import { DurationOnEndComponent, ID as DurationOnEndComponentID, SystemCallback } from "./DurationOnEndComponent.sol"; - -uint256 constant ID = uint256(keccak256("system.Duration")); - -/** - * @title Scoped duration time manager. - */ -contract DurationSubSystem is ScopedDurationSubsystem { - constructor( - IWorld _world, - address _components - ) - ScopedDurationSubsystem( - _world, - _components, - DurationScopeComponentID, - DurationValueComponentID, - DurationOnEndComponentID - ) - {} -} diff --git a/packages/contracts/_old_src/duration/DurationValueComponent.sol b/packages/contracts/_old_src/duration/DurationValueComponent.sol deleted file mode 100644 index f70844a7..00000000 --- a/packages/contracts/_old_src/duration/DurationValueComponent.sol +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { ValueComponent } from "@dk1a/solecslib/contracts/scoped-value/ValueComponent.sol"; - -uint256 constant ID = uint256(keccak256("component.DurationValue")); - -contract DurationValueComponent is ValueComponent { - constructor(address world) ValueComponent(world, ID) {} -} diff --git a/packages/contracts/_old_src/effect/AppliedEffectComponent.sol b/packages/contracts/_old_src/effect/AppliedEffectComponent.sol deleted file mode 100644 index 7d20c3ee..00000000 --- a/packages/contracts/_old_src/effect/AppliedEffectComponent.sol +++ /dev/null @@ -1,19 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { LibTypes } from "solecs/LibTypes.sol"; -import { BareComponent } from "solecs/BareComponent.sol"; - -import { AbstractEffectComponent } from "./EffectPrototypeComponent.sol"; - -uint256 constant ID = uint256(keccak256("component.AppliedEffect")); - -/** - * @title Copy of EffectPrototype created during application. - * @dev If EffectPrototype changes, any applied effects will hold the old value until reapplied - * (this avoids statmod leaks) - */ -contract AppliedEffectComponent is AbstractEffectComponent { - constructor(address world) AbstractEffectComponent(world, ID) {} -} diff --git a/packages/contracts/_old_src/effect/EffectPrototypeComponent.sol b/packages/contracts/_old_src/effect/EffectPrototypeComponent.sol deleted file mode 100644 index 654e960c..00000000 --- a/packages/contracts/_old_src/effect/EffectPrototypeComponent.sol +++ /dev/null @@ -1,53 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { LibTypes } from "solecs/LibTypes.sol"; -import { BareComponent } from "solecs/BareComponent.sol"; - -uint256 constant ID = uint256(keccak256("component.EffectPrototype")); - -enum EffectRemovability { - BUFF, - DEBUFF, - PERSISTENT -} - -struct EffectPrototype { - EffectRemovability removability; - uint256[] statmodProtoEntities; - uint32[] statmodValues; -} - -abstract contract AbstractEffectComponent is BareComponent { - constructor(address world, uint256 id) BareComponent(world, id) {} - - function getSchema() public pure override returns (string[] memory keys, LibTypes.SchemaValue[] memory values) { - keys = new string[](3); - values = new LibTypes.SchemaValue[](3); - - keys[0] = "removability"; - values[0] = LibTypes.SchemaValue.UINT8; - - keys[1] = "statmodProtoEntities"; - values[1] = LibTypes.SchemaValue.UINT256_ARRAY; - - keys[2] = "statmodValues"; - values[2] = LibTypes.SchemaValue.UINT32_ARRAY; - } - - function set(uint256 entity, EffectPrototype memory value) public { - set(entity, abi.encode(value.removability, value.statmodProtoEntities, value.statmodValues)); - } - - function getValue(uint256 entity) public view returns (EffectPrototype memory) { - (EffectRemovability removability, uint256[] memory statmodProtoEntities, uint32[] memory statmodValues) = abi - .decode(getRawValue(entity), (EffectRemovability, uint256[], uint32[])); - - return EffectPrototype(removability, statmodProtoEntities, statmodValues); - } -} - -contract EffectPrototypeComponent is AbstractEffectComponent { - constructor(address world) AbstractEffectComponent(world, ID) {} -} diff --git a/packages/contracts/_old_src/effect/EffectSubSystem.sol b/packages/contracts/_old_src/effect/EffectSubSystem.sol deleted file mode 100644 index d71792e7..00000000 --- a/packages/contracts/_old_src/effect/EffectSubSystem.sol +++ /dev/null @@ -1,149 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; -import { getAddressById } from "solecs/utils.sol"; -import { Subsystem } from "@dk1a/solecslib/contracts/mud/Subsystem.sol"; - -import { EffectRemovability, EffectPrototype, EffectPrototypeComponent, ID as EffectPrototypeComponentID } from "./EffectPrototypeComponent.sol"; -import { AppliedEffectComponent, ID as AppliedEffectComponentID } from "./AppliedEffectComponent.sol"; -import { Statmod } from "../statmod/Statmod.sol"; -// duration -import { SystemCallback, ScopedDuration, DurationSubSystem, ID as DurationSubSystemID } from "../duration/DurationSubSystem.sol"; - -/// @dev effectEntity = hashed(ID, target, prototype) -function getEffectEntity(uint256 targetEntity, uint256 protoEntity) pure returns (uint256) { - return uint256(keccak256(abi.encode(ID, targetEntity, protoEntity))); -} - -uint256 constant ID = uint256(keccak256("system.Effect")); - -contract EffectSubSystem is Subsystem { - error EffectSubSystem__InvalidProtoEntity(); - error EffectSubSystem__InvalidExecuteSelector(); - - constructor(IWorld _world, address _components) Subsystem(_world, _components) {} - - function executeApplyTimed( - uint256 targetEntity, - uint256 protoEntity, - ScopedDuration memory duration - ) public onlyWriter { - executeApply(targetEntity, protoEntity); - - // callback to remove the effect on duration end - // TODO I think callbacks shouldn't be managed by DurationSubSystem after all - // (it can lead to dangling callbacks, though it isn't critical cause there's no async) - SystemCallback memory onEnd = SystemCallback({ - systemId: ID, - args: abi.encode(this.executeRemove.selector, abi.encode(targetEntity, protoEntity)) - }); - - // effect prototypes may be global, so applied entity is target-specific - uint256 appliedEntity = getEffectEntity(targetEntity, protoEntity); - - DurationSubSystem durationSubSystem = DurationSubSystem(getAddressById(world.systems(), DurationSubSystemID)); - durationSubSystem.executeIncrease(targetEntity, appliedEntity, duration, onEnd); - } - - function executeApply(uint256 targetEntity, uint256 protoEntity) public onlyWriter { - EffectPrototypeComponent protoComp = _protoComp(); - AppliedEffectComponent comp = _comp(); - // valid effect prototype required - if (!protoComp.has(protoEntity)) { - revert EffectSubSystem__InvalidProtoEntity(); - } - - EffectPrototype memory effect = protoComp.getValue(protoEntity); - // effect prototypes may be global, so applied entity is target-specific - uint256 appliedEntity = getEffectEntity(targetEntity, protoEntity); - - Statmod.Self memory statmod = Statmod.__construct(components, targetEntity); - if (!comp.has(appliedEntity)) { - // set applied effect data - // (this is to avoid statmod leaks on effect removal, in case prototype changes) - comp.set(appliedEntity, effect); - // increase statmods - // TODO figure out what to do if statmods are empty - for (uint256 i; i < effect.statmodProtoEntities.length; i++) { - Statmod.increase(statmod, effect.statmodProtoEntities[i], effect.statmodValues[i]); - } - } - // TODO extend/refresh existing effect by applying it again - } - - function executeRemove(uint256 targetEntity, uint256 protoEntity) public onlyWriter { - AppliedEffectComponent comp = _comp(); - uint256 appliedEntity = getEffectEntity(targetEntity, protoEntity); - if (!comp.has(appliedEntity)) { - // nothing to remove - return; - } - // get and remove applied effect data - // (prototype isn't used in removal, so its statmods can change without leaking) - EffectPrototype memory effect = comp.getValue(appliedEntity); - comp.remove(appliedEntity); - // subtract statmods - Statmod.Self memory statmod = Statmod.__construct(components, targetEntity); - for (uint256 i; i < effect.statmodProtoEntities.length; i++) { - Statmod.decrease(statmod, effect.statmodProtoEntities[i], effect.statmodValues[i]); - } - } - - /*////////////////////////////////////////////////////////////// - READ - //////////////////////////////////////////////////////////////*/ - - /** - * @dev Returns true if `protoEntity` is an effect prototype - */ - function isEffectPrototype(uint256 protoEntity) public view returns (bool) { - return _protoComp().has(protoEntity); - } - - /** - * @dev Returns true if `targetEntity` has an ongoing effect for `protoEntity`. - */ - function has(uint256 targetEntity, uint256 protoEntity) public view returns (bool) { - return _comp().has(getEffectEntity(targetEntity, protoEntity)); - } - - /*////////////////////////////////////////////////////////////// - INTERNAL - //////////////////////////////////////////////////////////////*/ - - function _execute(bytes memory args) internal override returns (bytes memory) { - (bytes4 executeSelector, bytes memory innerArgs) = abi.decode(args, (bytes4, bytes)); - - if (executeSelector == this.executeRemove.selector) { - (uint256 targetEntity, uint256 protoEntity) = abi.decode(innerArgs, (uint256, uint256)); - executeRemove(targetEntity, protoEntity); - return ""; - } else if (executeSelector == this.executeApply.selector) { - (uint256 targetEntity, uint256 protoEntity) = abi.decode(innerArgs, (uint256, uint256)); - executeApply(targetEntity, protoEntity); - return ""; - } else if (executeSelector == this.executeApplyTimed.selector) { - (uint256 targetEntity, uint256 protoEntity, ScopedDuration memory duration) = abi.decode( - innerArgs, - (uint256, uint256, ScopedDuration) - ); - executeApplyTimed(targetEntity, protoEntity, duration); - return ""; - } else { - revert EffectSubSystem__InvalidExecuteSelector(); - } - } - - /// @dev Get the prototype component. - function _protoComp() internal view returns (EffectPrototypeComponent) { - return EffectPrototypeComponent(getAddressById(components, EffectPrototypeComponentID)); - } - - /// @dev Get the applied component. - function _comp() internal view returns (AppliedEffectComponent) { - return AppliedEffectComponent(getAddressById(components, AppliedEffectComponentID)); - } -} diff --git a/packages/contracts/_old_src/effect/LibEffectPrototype.sol b/packages/contracts/_old_src/effect/LibEffectPrototype.sol deleted file mode 100644 index c28e444f..00000000 --- a/packages/contracts/_old_src/effect/LibEffectPrototype.sol +++ /dev/null @@ -1,42 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; -import { getAddressById } from "solecs/utils.sol"; -import { EffectRemovability, EffectPrototype, EffectPrototypeComponent, ID as EffectPrototypeComponentID } from "./EffectPrototypeComponent.sol"; -import { StatmodPrototypeComponent, ID as StatmodPrototypeComponentID } from "../statmod/StatmodPrototypeComponent.sol"; - -library LibEffectPrototype { - error LibEffectPrototype__LengthMismatch(); - error LibEffectPrototype__InvalidStatmod(); - - /** - * @dev Check data validity before setting effect prototype - */ - function verifiedSet( - IUint256Component components, - uint256 effectProtoEntity, - EffectPrototype memory effectProto - ) internal { - StatmodPrototypeComponent statmodComp = StatmodPrototypeComponent( - getAddressById(components, StatmodPrototypeComponentID) - ); - EffectPrototypeComponent effectProtoComp = EffectPrototypeComponent( - getAddressById(components, EffectPrototypeComponentID) - ); - - // verify lengths - if (effectProto.statmodProtoEntities.length != effectProto.statmodValues.length) { - revert LibEffectPrototype__LengthMismatch(); - } - // verify statmods existence - for (uint256 i; i < effectProto.statmodProtoEntities.length; i++) { - if (!statmodComp.has(effectProto.statmodProtoEntities[i])) { - revert LibEffectPrototype__InvalidStatmod(); - } - } - // set - effectProtoComp.set(effectProtoEntity, effectProto); - } -} diff --git a/packages/contracts/_old_src/effect/makeEffectPrototype.sol b/packages/contracts/_old_src/effect/makeEffectPrototype.sol deleted file mode 100644 index 67184b23..00000000 --- a/packages/contracts/_old_src/effect/makeEffectPrototype.sol +++ /dev/null @@ -1,80 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { EffectRemovability, EffectPrototype } from "./EffectPrototypeComponent.sol"; -import { Topic, Op, Element } from "../charstat/Topics.sol"; - -// utils to make hardcoded `EffectPrototype` structs with less hassle and visual overhead - -function makeEffectPrototype() pure returns (EffectPrototype memory result) {} - -function makeEffectPrototype( - EffectRemovability removability, - Topic topic0, Op op0, Element element0, uint32 value0 -) pure returns (EffectPrototype memory result) { - result.removability = removability; - - result.statmodProtoEntities = new uint256[](1); - result.statmodProtoEntities[0] = topic0.toStatmodEntity(op0, element0); - - result.statmodValues = new uint32[](1); - result.statmodValues[0] = value0; -} - -function makeEffectPrototype( - EffectRemovability removability, - Topic topic0, Op op0, Element element0, uint32 value0, - Topic topic1, Op op1, Element element1, uint32 value1 -) pure returns (EffectPrototype memory result) { - result.removability = removability; - - result.statmodProtoEntities = new uint256[](2); - result.statmodProtoEntities[0] = topic0.toStatmodEntity(op0, element0); - result.statmodProtoEntities[1] = topic1.toStatmodEntity(op1, element1); - - result.statmodValues = new uint32[](2); - result.statmodValues[0] = value0; - result.statmodValues[1] = value1; -} - -function makeEffectPrototype( - EffectRemovability removability, - Topic topic0, Op op0, Element element0, uint32 value0, - Topic topic1, Op op1, Element element1, uint32 value1, - Topic topic2, Op op2, Element element2, uint32 value2 -) pure returns (EffectPrototype memory result) { - result.removability = removability; - - result.statmodProtoEntities = new uint256[](3); - result.statmodProtoEntities[0] = topic0.toStatmodEntity(op0, element0); - result.statmodProtoEntities[1] = topic1.toStatmodEntity(op1, element1); - result.statmodProtoEntities[2] = topic2.toStatmodEntity(op2, element2); - - result.statmodValues = new uint32[](3); - result.statmodValues[0] = value0; - result.statmodValues[1] = value1; - result.statmodValues[2] = value2; -} - -function makeEffectPrototype( - EffectRemovability removability, - Topic topic0, Op op0, Element element0, uint32 value0, - Topic topic1, Op op1, Element element1, uint32 value1, - Topic topic2, Op op2, Element element2, uint32 value2, - Topic topic3, Op op3, Element element3, uint32 value3 -) pure returns (EffectPrototype memory result) { - result.removability = removability; - - result.statmodProtoEntities = new uint256[](4); - result.statmodProtoEntities[0] = topic0.toStatmodEntity(op0, element0); - result.statmodProtoEntities[1] = topic1.toStatmodEntity(op1, element1); - result.statmodProtoEntities[2] = topic2.toStatmodEntity(op2, element2); - result.statmodProtoEntities[3] = topic3.toStatmodEntity(op3, element3); - - result.statmodValues = new uint32[](4); - result.statmodValues[0] = value0; - result.statmodValues[1] = value1; - result.statmodValues[2] = value2; - result.statmodValues[3] = value3; -} diff --git a/packages/contracts/_old_src/equipment/EquipmentPrototypeComponent.sol b/packages/contracts/_old_src/equipment/EquipmentPrototypeComponent.sol deleted file mode 100644 index a7fa4b62..00000000 --- a/packages/contracts/_old_src/equipment/EquipmentPrototypeComponent.sol +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { BoolBareComponent } from "std-contracts/components/BoolBareComponent.sol"; - -uint256 constant ID = uint256(keccak256("component.EquipmentPrototype")); - -contract EquipmentPrototypeComponent is BoolBareComponent { - constructor(address world) BoolBareComponent(world, ID) {} -} diff --git a/packages/contracts/_old_src/equipment/EquipmentPrototypes.sol b/packages/contracts/_old_src/equipment/EquipmentPrototypes.sol deleted file mode 100644 index 18bd0e35..00000000 --- a/packages/contracts/_old_src/equipment/EquipmentPrototypes.sol +++ /dev/null @@ -1,17 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { ID } from "./EquipmentPrototypeComponent.sol"; - -library EquipmentPrototypes { - uint256 constant WEAPON = uint256(keccak256(abi.encode(ID, "Weapon"))); - uint256 constant SHIELD = uint256(keccak256(abi.encode(ID, "Shield"))); - uint256 constant HAT = uint256(keccak256(abi.encode(ID, "Hat"))); - uint256 constant CLOTHING = uint256(keccak256(abi.encode(ID, "Clothing"))); - uint256 constant GLOVES = uint256(keccak256(abi.encode(ID, "Gloves"))); - uint256 constant PANTS = uint256(keccak256(abi.encode(ID, "Pants"))); - uint256 constant BOOTS = uint256(keccak256(abi.encode(ID, "Boots"))); - uint256 constant AMULET = uint256(keccak256(abi.encode(ID, "Amulet"))); - uint256 constant RING = uint256(keccak256(abi.encode(ID, "Ring"))); -} diff --git a/packages/contracts/_old_src/equipment/EquipmentSlotAllowedComponent.sol b/packages/contracts/_old_src/equipment/EquipmentSlotAllowedComponent.sol deleted file mode 100644 index 9911b8a3..00000000 --- a/packages/contracts/_old_src/equipment/EquipmentSlotAllowedComponent.sol +++ /dev/null @@ -1,14 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { Uint256SetComponent } from "../Uint256SetComponent.sol"; - -uint256 constant ID = uint256(keccak256("component.EquipmentSlotAllowed")); - -/** - * @title Set of equipment prototypes (value) that can be equipped per slot (key) - */ -contract EquipmentSlotAllowedComponent is Uint256SetComponent { - constructor(address world) Uint256SetComponent(world, ID) {} -} diff --git a/packages/contracts/_old_src/equipment/EquipmentSlotComponent.sol b/packages/contracts/_old_src/equipment/EquipmentSlotComponent.sol deleted file mode 100644 index 97b57ddc..00000000 --- a/packages/contracts/_old_src/equipment/EquipmentSlotComponent.sol +++ /dev/null @@ -1,14 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { Uint256Component } from "std-contracts/components/Uint256Component.sol"; - -uint256 constant ID = uint256(keccak256("component.EquipmentSlot")); - -/** - * @title Mapping of equipment slots to equipped entities. - */ -contract EquipmentSlotComponent is Uint256Component { - constructor(address world) Uint256Component(world, ID) {} -} diff --git a/packages/contracts/_old_src/equipment/EquipmentSubSystem.sol b/packages/contracts/_old_src/equipment/EquipmentSubSystem.sol deleted file mode 100644 index 6ff378ee..00000000 --- a/packages/contracts/_old_src/equipment/EquipmentSubSystem.sol +++ /dev/null @@ -1,137 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { System } from "solecs/System.sol"; -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { getAddressById } from "solecs/utils.sol"; -import { Subsystem } from "@dk1a/solecslib/contracts/mud/Subsystem.sol"; - -import { EquipmentSlotComponent, ID as EquipmentSlotComponentID } from "./EquipmentSlotComponent.sol"; -import { EquipmentSlotAllowedComponent, ID as EquipmentSlotAllowedComponentID } from "./EquipmentSlotAllowedComponent.sol"; -import { EquipmentPrototypeComponent, ID as EquipmentPrototypeComponentID } from "./EquipmentPrototypeComponent.sol"; -import { FromPrototypeComponent, ID as FromPrototypeComponentID } from "../common/FromPrototypeComponent.sol"; -import { OwnedByComponent, ID as OwnedByComponentID } from "../common/OwnedByComponent.sol"; - -import { EffectSubSystem, ID as EffectSubSystemID } from "../effect/EffectSubSystem.sol"; - -uint256 constant ID = uint256(keccak256("system.Equipment")); - -enum EquipmentAction { - UNEQUIP, - EQUIP -} - -/** - * @title Subsystem to equip stuff to slots based on slot to prototype allowances. - * @dev Equipment prototypes are a few entities (like `Clothing` or `Boots`) in `EquipmentPrototypeComponent`. - * Slots are entities defined only by allowed equipment prototypes via `EquipmentSlotAllowedComponent`. - * (Fun fact: this allows characters to have different/dynamic sets of limbs). - * Actual equipment entities are anything that uses `FromPrototypeComponent` to link to an equipment prototype. - * Currently equipped slot=>entity mapping is in `EquipmentSlotComponent`. - */ -contract EquipmentSubSystem is Subsystem { - error EquipmentSubSystem__InvalidEquipmentAction(); - error EquipmentSubSystem__InvalidEquipmentPrototype(); - error EquipmentSubSystem__SlotNotAllowedForPrototype(); - error EquipmentSubSystem__EquipmentEntityAlreadyEquipped(); - error EquipmentSubSystem__SlotNotOwned(); - - constructor(IWorld _world, address _components) Subsystem(_world, _components) {} - - function executeTyped(EquipmentAction equipmentAction, uint256 equipmentSlot, uint256 equipmentEntity) public { - execute(abi.encode(equipmentAction, equipmentSlot, equipmentEntity)); - } - - /** - * @notice UNEQUIP/EQUIP target's slot with entity - * @dev For UNEQUIP equipmentEntity is irrelevant and can just be 0 - */ - function _execute(bytes memory arguments) internal override returns (bytes memory) { - (EquipmentAction equipmentAction, uint256 equipmentSlot, uint256 equipmentEntity) = abi.decode( - arguments, - (EquipmentAction, uint256, uint256) - ); - - EquipmentSlotComponent slotComp = EquipmentSlotComponent(getAddressById(components, EquipmentSlotComponentID)); - EffectSubSystem effectSubSystem = EffectSubSystem(getAddressById(world.systems(), EffectSubSystemID)); - - uint256 targetEntity = _getTargetEntity(equipmentSlot); - - if (equipmentAction == EquipmentAction.UNEQUIP) { - _unequip(slotComp, effectSubSystem, targetEntity, equipmentSlot); - } else if (equipmentAction == EquipmentAction.EQUIP) { - _equip(slotComp, effectSubSystem, targetEntity, equipmentSlot, equipmentEntity); - } else { - revert EquipmentSubSystem__InvalidEquipmentAction(); - } - - return ""; - } - - function _unequip( - EquipmentSlotComponent slotComp, - EffectSubSystem effectSubSystem, - uint256 targetEntity, - uint256 equipmentSlot - ) internal { - uint256 equipmentEntity = slotComp.getValue(equipmentSlot); - slotComp.remove(equipmentSlot); - - effectSubSystem.executeRemove(targetEntity, equipmentEntity); - } - - function _equip( - EquipmentSlotComponent slotComp, - EffectSubSystem effectSubSystem, - uint256 targetEntity, - uint256 equipmentSlot, - uint256 equipmentEntity - ) internal { - // unequip first if slot is occupied (otherwise effects will leak) - if (slotComp.has(equipmentSlot)) { - _unequip(slotComp, effectSubSystem, targetEntity, equipmentSlot); - } - - // equipmentEntity must have equipment prototype - // TODO this looks dubious, and also very long - FromPrototypeComponent fromProtoComp = FromPrototypeComponent(getAddressById(components, FromPrototypeComponentID)); - EquipmentPrototypeComponent protoComp = EquipmentPrototypeComponent( - getAddressById(components, EquipmentPrototypeComponentID) - ); - uint256 protoEntity = fromProtoComp.getValue(equipmentEntity); - if (!protoComp.has(protoEntity)) { - revert EquipmentSubSystem__InvalidEquipmentPrototype(); - } - - // the slot must allow the equipment prototype - EquipmentSlotAllowedComponent slotAllowedComp = EquipmentSlotAllowedComponent( - getAddressById(components, EquipmentSlotAllowedComponentID) - ); - bool isAllowed = slotAllowedComp.hasItem(equipmentSlot, protoEntity); - if (!isAllowed) { - revert EquipmentSubSystem__SlotNotAllowedForPrototype(); - } - - // entity may not be equipped in 2 slots - uint256[] memory slotsWithEquipmentEntity = slotComp.getEntitiesWithValue(equipmentEntity); - if (slotsWithEquipmentEntity.length > 0) { - revert EquipmentSubSystem__EquipmentEntityAlreadyEquipped(); - } - - slotComp.set(equipmentSlot, equipmentEntity); - - // reverts if equipmentEntity isn't a valid effectProtoEntity - // TODO that's good atm because equipment only does effects. But it could do more. - effectSubSystem.executeApply(targetEntity, equipmentEntity); - } - - // Get the slot's owner, who will receive the equipment's benefits - function _getTargetEntity(uint256 equipmentSlot) internal view returns (uint256) { - OwnedByComponent ownedByComp = OwnedByComponent(getAddressById(components, OwnedByComponentID)); - if (!ownedByComp.has(equipmentSlot)) { - revert EquipmentSubSystem__SlotNotOwned(); - } - return ownedByComp.getValue(equipmentSlot); - } -} diff --git a/packages/contracts/_old_src/equipment/LibSpawnEquipmentSlots.sol b/packages/contracts/_old_src/equipment/LibSpawnEquipmentSlots.sol deleted file mode 100644 index 7fdd4622..00000000 --- a/packages/contracts/_old_src/equipment/LibSpawnEquipmentSlots.sol +++ /dev/null @@ -1,70 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { NameComponent, ID as NameComponentID } from "../common/NameComponent.sol"; -import { OwnedByComponent, ID as OwnedByComponentID } from "../common/OwnedByComponent.sol"; -import { EquipmentSlotAllowedComponent, ID as EquipmentSlotAllowedComponentID } from "./EquipmentSlotAllowedComponent.sol"; - -import { EquipmentPrototypes } from "./EquipmentPrototypes.sol"; - -library LibSpawnEquipmentSlots { - struct Self { - IWorld world; - NameComponent name; - OwnedByComponent ownedBy; - EquipmentSlotAllowedComponent slotAllowed; - uint256 ownerEntity; - } - - function spawnEquipmentSlots(IWorld world, uint256 ownerEntity) internal { - IUint256Component components = world.components(); - Self memory self = Self({ - world: world, - name: NameComponent(getAddressById(components, NameComponentID)), - ownedBy: OwnedByComponent(getAddressById(components, OwnedByComponentID)), - slotAllowed: EquipmentSlotAllowedComponent(getAddressById(components, EquipmentSlotAllowedComponentID)), - ownerEntity: ownerEntity - }); - - _newSlotEntity(self, "R Hand", EquipmentPrototypes.WEAPON, EquipmentPrototypes.SHIELD); - // TODO dual wielding to conditionally let L Hand use weapon too - _newSlotEntity(self, "L Hand", EquipmentPrototypes.SHIELD); - _newSlotEntity(self, "Head", EquipmentPrototypes.HAT); - _newSlotEntity(self, "Body", EquipmentPrototypes.CLOTHING); - _newSlotEntity(self, "Hands", EquipmentPrototypes.GLOVES); - _newSlotEntity(self, "Legs", EquipmentPrototypes.PANTS); - _newSlotEntity(self, "Feet", EquipmentPrototypes.BOOTS); - _newSlotEntity(self, "Neck", EquipmentPrototypes.AMULET); - _newSlotEntity(self, "R Ring", EquipmentPrototypes.RING); - _newSlotEntity(self, "L Ring", EquipmentPrototypes.RING); - } - - function _newSlotEntity( - Self memory self, - string memory name, - uint256 equipmentProtoEntity0 - ) private returns (uint256 slotEntity) { - slotEntity = self.world.getUniqueEntityId(); - self.name.set(slotEntity, name); - self.ownedBy.set(slotEntity, self.ownerEntity); - self.slotAllowed.addItem(slotEntity, equipmentProtoEntity0); - } - - function _newSlotEntity( - Self memory self, - string memory name, - uint256 equipmentProtoEntity0, - uint256 equipmentProtoEntity1 - ) private returns (uint256 slotEntity) { - slotEntity = self.world.getUniqueEntityId(); - self.name.set(slotEntity, name); - self.ownedBy.set(slotEntity, self.ownerEntity); - self.slotAllowed.addItem(slotEntity, equipmentProtoEntity0); - self.slotAllowed.addItem(slotEntity, equipmentProtoEntity1); - } -} diff --git a/packages/contracts/_old_src/equipment/test/EquipmentSubsystem.t.sol b/packages/contracts/_old_src/equipment/test/EquipmentSubsystem.t.sol deleted file mode 100644 index 3c77e665..00000000 --- a/packages/contracts/_old_src/equipment/test/EquipmentSubsystem.t.sol +++ /dev/null @@ -1,185 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { BaseTest } from "../../BaseTest.sol"; - -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; - -import { EquipmentSubSystem, EquipmentAction } from "../EquipmentSubSystem.sol"; -import { LibEffectPrototype } from "../../effect/LibEffectPrototype.sol"; -import { EffectPrototype, EffectRemovability } from "../../effect/EffectPrototypeComponent.sol"; -import { EquipmentPrototypes } from "../EquipmentPrototypes.sol"; -import { Topics, Op, Element } from "../../charstat/Topics.sol"; -import { makeEffectPrototype } from "../../effect/makeEffectPrototype.sol"; - -contract EquipmentSubSystemTest is BaseTest { - uint256 playerEntity = uint256(keccak256("playerEntity")); - - // equipment entities - uint256 armor = uint256(keccak256("armor")); - uint256 sword1 = uint256(keccak256("sword1")); - uint256 sword2 = uint256(keccak256("sword2")); - uint256 shield = uint256(keccak256("shield")); - uint256 miscThing = uint256(keccak256("miscThing")); - // equipment prototypes - uint256 clothingProtoEntity = EquipmentPrototypes.CLOTHING; - uint256 weaponProtoEntity = EquipmentPrototypes.WEAPON; - uint256 shieldProtoEntity = EquipmentPrototypes.SHIELD; - // equipment slots - uint256 armorSlot = uint256(keccak256("armorSlot")); - uint256 mainHandSlot = uint256(keccak256("mainHandSlot")); - uint256 offHandSlot = uint256(keccak256("offHandSlot")); - - function setUp() public virtual override { - super.setUp(); - - IUint256Component components = world.components(); - - // make player own the slots - ownedByComponent.set(armorSlot, playerEntity); - ownedByComponent.set(mainHandSlot, playerEntity); - ownedByComponent.set(offHandSlot, playerEntity); - - // allow prototypes for slots - equipmentSlotAllowedComponent.addItem(armorSlot, clothingProtoEntity); - equipmentSlotAllowedComponent.addItem(mainHandSlot, weaponProtoEntity); - equipmentSlotAllowedComponent.addItem(offHandSlot, weaponProtoEntity); - equipmentSlotAllowedComponent.addItem(offHandSlot, shieldProtoEntity); - - // init equipment - fromPrototypeComponent.set(armor, clothingProtoEntity); - LibEffectPrototype.verifiedSet( - components, - armor, - makeEffectPrototype(EffectRemovability.PERSISTENT, Topics.RESISTANCE, Op.ADD, Element.PHYSICAL, 40) - ); - - fromPrototypeComponent.set(sword1, weaponProtoEntity); - LibEffectPrototype.verifiedSet( - components, - sword1, - makeEffectPrototype(EffectRemovability.PERSISTENT, Topics.ATTACK, Op.MUL, Element.ALL, 100) - ); - - fromPrototypeComponent.set(sword2, weaponProtoEntity); - LibEffectPrototype.verifiedSet( - components, - sword2, - makeEffectPrototype( - EffectRemovability.PERSISTENT, - Topics.ATTACK, - Op.ADD, - Element.FIRE, - 100, - Topics.ATTACK, - Op.MUL, - Element.FIRE, - 100 - ) - ); - - fromPrototypeComponent.set(shield, shieldProtoEntity); - LibEffectPrototype.verifiedSet( - components, - shield, - makeEffectPrototype( - EffectRemovability.PERSISTENT, - Topics.RESISTANCE, - Op.ADD, - Element.PHYSICAL, - 40, - Topics.RESISTANCE, - Op.ADD, - Element.FIRE, - 40 - ) - ); - - // non-equipment prototype - fromPrototypeComponent.set(miscThing, miscThing); - } - - // TODO test that effects are applied/removed correctly - - function test_equip_revert_InvalidEquipmentPrototype() public { - vm.expectRevert(EquipmentSubSystem.EquipmentSubSystem__InvalidEquipmentPrototype.selector); - equipmentSubSystem.executeTyped(EquipmentAction.EQUIP, armorSlot, miscThing); - } - - function test_equip_revert_SlotNotAllowedForPrototype() public { - vm.expectRevert(EquipmentSubSystem.EquipmentSubSystem__SlotNotAllowedForPrototype.selector); - equipmentSubSystem.executeTyped(EquipmentAction.EQUIP, armorSlot, sword1); - } - - function test_equip_revert_EquipmentEntityAlreadyEquipped() public { - equipmentSubSystem.executeTyped(EquipmentAction.EQUIP, mainHandSlot, sword1); - - vm.expectRevert(EquipmentSubSystem.EquipmentSubSystem__EquipmentEntityAlreadyEquipped.selector); - equipmentSubSystem.executeTyped(EquipmentAction.EQUIP, offHandSlot, sword1); - } - - function test_equipUnequip() public { - equipmentSubSystem.executeTyped(EquipmentAction.EQUIP, armorSlot, armor); - assertEq(equipmentSlotComponent.getValue(armorSlot), armor); - - equipmentSubSystem.executeTyped(EquipmentAction.UNEQUIP, armorSlot, 0); - assertFalse(equipmentSlotComponent.has(armorSlot)); - } - - function test_equipUnequip_severalSlots() public { - equipmentSubSystem.executeTyped(EquipmentAction.EQUIP, armorSlot, armor); - equipmentSubSystem.executeTyped(EquipmentAction.EQUIP, mainHandSlot, sword1); - equipmentSubSystem.executeTyped(EquipmentAction.EQUIP, offHandSlot, sword2); - - assertEq(equipmentSlotComponent.getValue(armorSlot), armor); - assertEq(equipmentSlotComponent.getValue(mainHandSlot), sword1); - assertEq(equipmentSlotComponent.getValue(offHandSlot), sword2); - - equipmentSubSystem.executeTyped(EquipmentAction.UNEQUIP, armorSlot, 0); - - assertFalse(equipmentSlotComponent.has(armorSlot)); - assertEq(equipmentSlotComponent.getValue(mainHandSlot), sword1); - assertEq(equipmentSlotComponent.getValue(offHandSlot), sword2); - - equipmentSubSystem.executeTyped(EquipmentAction.UNEQUIP, offHandSlot, 0); - - assertFalse(equipmentSlotComponent.has(armorSlot)); - assertEq(equipmentSlotComponent.getValue(mainHandSlot), sword1); - assertFalse(equipmentSlotComponent.has(offHandSlot)); - - equipmentSubSystem.executeTyped(EquipmentAction.UNEQUIP, mainHandSlot, 0); - - assertFalse(equipmentSlotComponent.has(armorSlot)); - assertFalse(equipmentSlotComponent.has(mainHandSlot)); - assertFalse(equipmentSlotComponent.has(offHandSlot)); - } - - function test_reequip_sameSlot_sameEntity() public { - equipmentSubSystem.executeTyped(EquipmentAction.EQUIP, mainHandSlot, sword1); - assertEq(equipmentSlotComponent.getValue(mainHandSlot), sword1); - equipmentSubSystem.executeTyped(EquipmentAction.EQUIP, mainHandSlot, sword1); - assertEq(equipmentSlotComponent.getValue(mainHandSlot), sword1); - } - - function test_reequip_sameSlot_differentEntities() public { - equipmentSubSystem.executeTyped(EquipmentAction.EQUIP, offHandSlot, sword1); - assertEq(equipmentSlotComponent.getValue(offHandSlot), sword1); - equipmentSubSystem.executeTyped(EquipmentAction.EQUIP, offHandSlot, shield); - assertEq(equipmentSlotComponent.getValue(offHandSlot), shield); - equipmentSubSystem.executeTyped(EquipmentAction.EQUIP, offHandSlot, sword2); - assertEq(equipmentSlotComponent.getValue(offHandSlot), sword2); - } - - function test_reequip_differentSlots_sameEntity() public { - equipmentSubSystem.executeTyped(EquipmentAction.EQUIP, mainHandSlot, sword1); - assertEq(equipmentSlotComponent.getValue(mainHandSlot), sword1); - assertFalse(equipmentSlotComponent.has(offHandSlot)); - - equipmentSubSystem.executeTyped(EquipmentAction.UNEQUIP, mainHandSlot, 0); - - equipmentSubSystem.executeTyped(EquipmentAction.EQUIP, offHandSlot, sword1); - assertFalse(equipmentSlotComponent.has(mainHandSlot)); - assertEq(equipmentSlotComponent.getValue(offHandSlot), sword1); - } -} diff --git a/packages/contracts/_old_src/guise/ActiveGuiseComponent.sol b/packages/contracts/_old_src/guise/ActiveGuiseComponent.sol deleted file mode 100644 index bcb6b38d..00000000 --- a/packages/contracts/_old_src/guise/ActiveGuiseComponent.sol +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { Uint256BareComponent } from "std-contracts/components/Uint256BareComponent.sol"; - -uint256 constant ID = uint256(keccak256("component.ActiveGuise")); - -contract ActiveGuiseComponent is Uint256BareComponent { - constructor(address world) Uint256BareComponent(world, ID) {} -} diff --git a/packages/contracts/_old_src/guise/GuisePrototypeComponent.sol b/packages/contracts/_old_src/guise/GuisePrototypeComponent.sol deleted file mode 100644 index 89193d60..00000000 --- a/packages/contracts/_old_src/guise/GuisePrototypeComponent.sol +++ /dev/null @@ -1,47 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { LibTypes } from "solecs/LibTypes.sol"; -import { BareComponent } from "solecs/BareComponent.sol"; - -import { PS_L } from "../charstat/ExperienceComponent.sol"; - -uint256 constant ID = uint256(keccak256("component.GuisePrototype")); - -struct GuisePrototype { - uint32[PS_L] levelMul; -} - -/** - * @dev Guise protoEntity = hashed(ID, name) - */ -function getGuiseProtoEntity(string memory name) pure returns (uint256) { - return uint256(keccak256(abi.encode(ID, name))); -} - -contract GuisePrototypeComponent is BareComponent { - constructor(address world) BareComponent(world, ID) {} - - function getSchema() public pure override returns (string[] memory keys, LibTypes.SchemaValue[] memory values) { - keys = new string[](PS_L); - values = new LibTypes.SchemaValue[](PS_L); - - keys[0] = "levelMul_strength"; - values[0] = LibTypes.SchemaValue.UINT32; - - keys[1] = "levelMul_arcana"; - values[1] = LibTypes.SchemaValue.UINT32; - - keys[2] = "levelMul_dexterity"; - values[2] = LibTypes.SchemaValue.UINT32; - } - - function set(uint256 entity, GuisePrototype memory value) public { - set(entity, abi.encode(value)); - } - - function getValue(uint256 entity) public view returns (GuisePrototype memory) { - return abi.decode(getRawValue(entity), (GuisePrototype)); - } -} diff --git a/packages/contracts/_old_src/guise/GuiseSkillsComponent.sol b/packages/contracts/_old_src/guise/GuiseSkillsComponent.sol deleted file mode 100644 index 7dcc56ad..00000000 --- a/packages/contracts/_old_src/guise/GuiseSkillsComponent.sol +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { Uint256SetComponent } from "../Uint256SetComponent.sol"; - -uint256 constant ID = uint256(keccak256("component.GuiseSkills")); - -contract GuiseSkillsComponent is Uint256SetComponent { - constructor(address world) Uint256SetComponent(world, ID) {} -} diff --git a/packages/contracts/_old_src/guise/LibGuiseLevel.sol b/packages/contracts/_old_src/guise/LibGuiseLevel.sol deleted file mode 100644 index cc586aee..00000000 --- a/packages/contracts/_old_src/guise/LibGuiseLevel.sol +++ /dev/null @@ -1,44 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { ActiveGuiseComponent, ID as ActiveGuiseComponentID } from "./ActiveGuiseComponent.sol"; -import { GuisePrototypeComponent, ID as GuisePrototypeComponentID } from "./GuisePrototypeComponent.sol"; - -import { LibExperience, PS_L } from "../charstat/LibExperience.sol"; - -library LibGuiseLevel { - using LibExperience for LibExperience.Self; - - /// @dev Get target's aggregate level using its guise's level multipliers. - /// (aggregate level means all primary stats aggregated together) - function getAggregateLevel(IUint256Component components, uint256 targetEntity) internal view returns (uint32) { - ActiveGuiseComponent activeGuiseComp = ActiveGuiseComponent(getAddressById(components, ActiveGuiseComponentID)); - GuisePrototypeComponent guiseProto = GuisePrototypeComponent(getAddressById(components, GuisePrototypeComponentID)); - LibExperience.Self memory exp = LibExperience.__construct(components, targetEntity); - - uint256 guiseProtoEntity = activeGuiseComp.getValue(targetEntity); - uint32[PS_L] memory levelMul = guiseProto.getValue(guiseProtoEntity).levelMul; - return exp.getAggregateLevel(levelMul); - } - - /// @dev Multiply gained experience by guise's level multiplier - function multiplyExperience( - IUint256Component components, - uint256 targetEntity, - uint32[PS_L] memory exp - ) internal view returns (uint32[PS_L] memory expMultiplied) { - ActiveGuiseComponent activeGuiseComp = ActiveGuiseComponent(getAddressById(components, ActiveGuiseComponentID)); - GuisePrototypeComponent guiseProto = GuisePrototypeComponent(getAddressById(components, GuisePrototypeComponentID)); - - uint256 guiseProtoEntity = activeGuiseComp.getValue(targetEntity); - uint32[PS_L] memory levelMul = guiseProto.getValue(guiseProtoEntity).levelMul; - for (uint256 i; i < PS_L; i++) { - expMultiplied[i] = exp[i] * levelMul[i]; - } - return expMultiplied; - } -} diff --git a/packages/contracts/_old_src/init/LibBaseInitAffix.sol b/packages/contracts/_old_src/init/LibBaseInitAffix.sol deleted file mode 100644 index 439a0bac..00000000 --- a/packages/contracts/_old_src/init/LibBaseInitAffix.sol +++ /dev/null @@ -1,316 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { StatmodPrototypeComponent, ID as StatmodPrototypeComponentID } from "../statmod/StatmodPrototypeComponent.sol"; -import { NameComponent, ID as NameComponentID } from "../common/NameComponent.sol"; - -import { - getAffixProtoEntity, - AffixPrototype, - AffixPrototypeComponent, - ID as AffixPrototypeComponentID -} from "../affix/AffixPrototypeComponent.sol"; -import { - getAffixNamingEntity, - AffixPartId, - AffixNamingComponent, - ID as AffixNamingComponentID -} from "../affix/AffixNamingComponent.sol"; -import { - getAffixAvailabilityEntity, - AffixAvailabilityComponent, - ID as AffixAvailabilityComponentID -} from "../affix/AffixAvailabilityComponent.sol"; -import { - getAffixProtoGroupEntity, - AffixPrototypeGroupComponent, - ID as AffixPrototypeGroupComponentID -} from "../affix/AffixPrototypeGroupComponent.sol"; - -struct AffixPart { - AffixPartId partId; - uint256 targetEntity; - string label; -} - -/// @dev affix value range -struct Range { - uint32 min; - uint32 max; -} - -/// @dev target label -struct TargetLabel { - uint256 targetEntity; - string label; -} - -/// @dev number of usually expected tiers (some affixes may have non-standard tiers) -uint256 constant DEFAULT_TIERS = 4; -/// @dev number of currently expected ilvls -uint256 constant MAX_ILVL = 16; - -/// @dev Default ilvl requirement based on affix tier. -/// (affixes with non-standard tiers shouldn't use this function) -function tierToDefaultRequiredIlvl(uint256 tier) pure returns (uint32 requiredIlvl) { - // `tier` is not user-submitted, the asserts should never fail - assert(tier > 0); - assert(tier <= type(uint32).max); - - return (uint32(tier) - 1) * 4 + 1; -} - -/// @dev Affixes have a complex structure, however most complexity is shoved into this BaseInit, -/// so the child inits and affix components are relatively simple. -/// -/// Each affix has: name, associated statmod, tier. -/// Affixes with the same name (but different tiers) are grouped together via `AffixPrototypeGroupComponent`. -/// -/// Tiers are 1,2,3,4..., higher means better affixes (tiers can be skipped). -/// Each affix's tier has 1 min-max range and a set of affix parts. -/// Each set of affix parts has: -/// 2 explicits: prefix, suffix -/// 1 implicit -/// Parts have labels. Explicits' labels don't depend on targets. Implicits' label do. -/// affix => tier => {prefixLabel, suffixLabel} -/// affix => tier => targetEntity => implicitLabel -/// (targetEntity is e.g. equipmentProtoEntity) -library LibBaseInitAffix { - error LibBaseInitAffix__MalformedInput(string affixName, uint256 maxIlvl); - error LibBaseInitAffix__InvalidStatmodPrototype(); - - struct Comps { - // read - StatmodPrototypeComponent statmodProto; - // write - AffixPrototypeComponent proto; - AffixNamingComponent naming; - AffixAvailabilityComponent availability; - AffixPrototypeGroupComponent group; - NameComponent name; - } - - function getComps(IUint256Component components) internal view returns (Comps memory result) { - // read - result.statmodProto = StatmodPrototypeComponent(getAddressById(components, StatmodPrototypeComponentID)); - // write - result.proto = AffixPrototypeComponent(getAddressById(components, AffixPrototypeComponentID)); - result.naming = AffixNamingComponent(getAddressById(components, AffixNamingComponentID)); - result.availability = AffixAvailabilityComponent(getAddressById(components, AffixAvailabilityComponentID)); - result.group = AffixPrototypeGroupComponent(getAddressById(components, AffixPrototypeGroupComponentID)); - result.name = NameComponent(getAddressById(components, NameComponentID)); - } - - /// @dev Add `DEFAULT_TIERS` tiers of an affix - /// (for affixes with non-standard tiers use `addOne` directly) - function add( - Comps memory comps, - string memory affixName, - uint256 statmodProtoEntity, - Range[DEFAULT_TIERS] memory ranges, - AffixPart[][DEFAULT_TIERS] memory tieredAffixParts - ) internal { - for (uint32 i; i < tieredAffixParts.length; i++) { - uint32 tier = i + 1; - - AffixPart[] memory affixParts = tieredAffixParts[i]; - if (affixParts.length == 0) continue; - Range memory range = ranges[i]; - - AffixPrototype memory proto = AffixPrototype({ - tier: tier, - statmodProtoEntity: statmodProtoEntity, - requiredIlvl: tierToDefaultRequiredIlvl(tier), - min: range.min, - max: range.max - }); - - addOne( - comps, - affixName, - proto, - affixParts - ); - } - } - - /// @dev Add a single affix tier with *default* maxIlvl - function addOne( - Comps memory comps, - string memory affixName, - AffixPrototype memory proto, - AffixPart[] memory affixParts - ) internal { - addOne(comps, affixName, proto, affixParts, MAX_ILVL); - } - - /// @dev Add a single affix tier with *custom* maxIlvl - function addOne( - Comps memory comps, - string memory affixName, - AffixPrototype memory proto, - AffixPart[] memory affixParts, - uint256 maxIlvl - ) internal { - if (maxIlvl == 0 || proto.requiredIlvl > maxIlvl) { - revert LibBaseInitAffix__MalformedInput(affixName, maxIlvl); - } - if (!comps.statmodProto.has(proto.statmodProtoEntity)) { - revert LibBaseInitAffix__InvalidStatmodPrototype(); - } - - uint256 protoEntity = getAffixProtoEntity(affixName, proto.tier); - comps.proto.set(protoEntity, proto); - comps.name.set(protoEntity, affixName); - comps.group.set(protoEntity, getAffixProtoGroupEntity(affixName)); - - for (uint256 i; i < affixParts.length; i++) { - AffixPartId partId = affixParts[i].partId; - uint256 targetEntity = affixParts[i].targetEntity; - string memory label = affixParts[i].label; - - // which (partId+target) the affix is available for. - // affixProto => target => AffixPartId => label - uint256 namingEntity = getAffixNamingEntity(partId, targetEntity, protoEntity); - comps.naming.set(namingEntity, label); - - // availability component is basically a cache, - // all its data is technically redundant, but greatly simplifies and speeds up queries. - // target => partId => range(requiredIlvl, maxIlvl) => Set(affixProtos) - for (uint256 ilvl = proto.requiredIlvl; ilvl <= maxIlvl; ilvl++) { - uint256 availabilityEntity = getAffixAvailabilityEntity(ilvl, partId, targetEntity); - comps.availability.addItem(availabilityEntity, protoEntity); - } - } - } - - /*////////////////////////////////////////////////////////////////////////// - AFFIX PARTS OPTIONS - //////////////////////////////////////////////////////////////////////////*/ - - // explicits + implicits - function _affixes( - string memory prefixLabel, - string memory suffixLabel, - uint256[] memory explicits_targetEntities, - TargetLabel[] memory implicits_targetLabels - ) internal pure returns (AffixPart[] memory) { - AffixPart[][] memory separateParts = new AffixPart[][](3); - // prefix - separateParts[0] = _commonLabel( - AffixPartId.PREFIX, - explicits_targetEntities, - prefixLabel - ); - // suffix - separateParts[1] = _commonLabel( - AffixPartId.SUFFIX, - explicits_targetEntities, - suffixLabel - ); - // implicit - separateParts[2] = _individualLabels( - AffixPartId.IMPLICIT, - implicits_targetLabels - ); - - return _flatten(separateParts); - } - - // explicits - function _explicits( - string memory prefixLabel, - string memory suffixLabel, - uint256[] memory explicits_targetEntities - ) internal pure returns (AffixPart[] memory) { - AffixPart[][] memory separateParts = new AffixPart[][](2); - // prefix - separateParts[0] = _commonLabel( - AffixPartId.PREFIX, - explicits_targetEntities, - prefixLabel - ); - // suffix - separateParts[1] = _commonLabel( - AffixPartId.SUFFIX, - explicits_targetEntities, - suffixLabel - ); - - return _flatten(separateParts); - } - - // implicits - function _implicits( - TargetLabel[] memory implicits_targetLabels - ) internal pure returns (AffixPart[] memory) { - return _individualLabels( - AffixPartId.IMPLICIT, - implicits_targetLabels - ); - } - - // nothing - function _none() internal pure returns (AffixPart[] memory) { - return new AffixPart[](0); - } - - // combine several arrays of affix parts into one - function _flatten( - AffixPart[][] memory separateParts - ) private pure returns (AffixPart[] memory combinedParts) { - uint256 combinedLen; - for (uint256 i; i < separateParts.length; i++) { - combinedLen += separateParts[i].length; - } - - combinedParts = new AffixPart[](combinedLen); - - uint256 totalIndex; - for (uint256 i; i < separateParts.length; i++) { - AffixPart[] memory separatePart = separateParts[i]; - for (uint256 j; j < separatePart.length; j++) { - combinedParts[totalIndex] = separatePart[j]; - totalIndex++; - } - } - return combinedParts; - } - - // 1 label for multiple target entities - function _commonLabel( - AffixPartId partId, - uint256[] memory targetEntities, - string memory label - ) private pure returns (AffixPart[] memory affixParts) { - affixParts = new AffixPart[](targetEntities.length); - - for (uint256 i; i < targetEntities.length; i++) { - affixParts[i] = AffixPart({ - partId: partId, - targetEntity: targetEntities[i], - label: label - }); - } - } - - // 1 label per each target entity - function _individualLabels( - AffixPartId partId, - TargetLabel[] memory targetLabels - ) private pure returns (AffixPart[] memory affixParts) { - affixParts = new AffixPart[](targetLabels.length); - - for (uint256 i; i < targetLabels.length; i++) { - affixParts[i] = AffixPart({ - partId: partId, - targetEntity: targetLabels[i].targetEntity, - label: targetLabels[i].label - }); - } - } -} \ No newline at end of file diff --git a/packages/contracts/_old_src/init/LibBaseInitSkill.sol b/packages/contracts/_old_src/init/LibBaseInitSkill.sol deleted file mode 100644 index ad35a574..00000000 --- a/packages/contracts/_old_src/init/LibBaseInitSkill.sol +++ /dev/null @@ -1,59 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { ScopedDuration, EL_L, getSkillProtoEntity, SkillPrototype, SkillPrototypeComponent, ID as SkillPrototypeComponentID } from "../skill/SkillPrototypeComponent.sol"; -import { SkillDescriptionComponent, ID as SkillDescriptionComponentID } from "../skill/SkillDescriptionComponent.sol"; -import { LibEffectPrototype } from "../effect/LibEffectPrototype.sol"; -import { EffectPrototype } from "../effect/EffectPrototypeComponent.sol"; -import { NameComponent, ID as NameComponentID } from "../common/NameComponent.sol"; - -library LibBaseInitSkill { - struct Comps { - IUint256Component components; - SkillPrototypeComponent protoComp; - SkillDescriptionComponent descComp; - NameComponent nameComp; - } - - function getComps(IUint256Component components) internal view returns (Comps memory result) { - result.components = components; - result.protoComp = SkillPrototypeComponent(getAddressById(components, SkillPrototypeComponentID)); - result.descComp = SkillDescriptionComponent(getAddressById(components, SkillDescriptionComponentID)); - result.nameComp = NameComponent(getAddressById(components, NameComponentID)); - } - - function add( - Comps memory comps, - string memory name, - string memory description, - SkillPrototype memory prototype, - EffectPrototype memory effectProto - ) internal { - uint256 entity = getSkillProtoEntity(name); - - comps.protoComp.set(entity, prototype); - comps.descComp.set(entity, description); - comps.nameComp.set(entity, name); - - // Given statmods, a skill will have an on-use effect prototype - if (effectProto.statmodProtoEntities.length > 0) { - LibEffectPrototype.verifiedSet(comps.components, entity, effectProto); - } - } - - function _duration(string memory timeScope, uint256 timeValue) internal pure returns (ScopedDuration memory) { - return ScopedDuration({ timeScopeId: uint256(keccak256(bytes(timeScope))), timeValue: timeValue }); - } - - function _noDuration() internal pure returns (ScopedDuration memory) { - return _duration("", 0); - } - - function _emptyElemental() internal pure returns (uint32[EL_L] memory) { - return [uint32(0), 0, 0, 0, 0]; - } -} diff --git a/packages/contracts/_old_src/init/LibInitAuthorizeSubsystems.sol b/packages/contracts/_old_src/init/LibInitAuthorizeSubsystems.sol deleted file mode 100644 index c60d769d..00000000 --- a/packages/contracts/_old_src/init/LibInitAuthorizeSubsystems.sol +++ /dev/null @@ -1,118 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; -import { IOwnableWritable } from "solecs/interfaces/IOwnableWritable.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { ID as DurationSubSystemID } from "../duration/DurationSubSystem.sol"; -import { ID as EffectSubSystemID } from "../effect/EffectSubSystem.sol"; -import { ID as EquipmentSubSystemID } from "../equipment/EquipmentSubSystem.sol"; -import { ID as CombatSubSystemID } from "../combat/CombatSubSystem.sol"; -import { ID as WNFTSystemID } from "../token/WNFTSystem.sol"; -import { ID as CycleCombatSystemID } from "../cycle/CycleCombatSystem.sol"; -import { ID as PassCycleTurnSystemID } from "../cycle/PassCycleTurnSystem.sol"; -import { ID as LearnCycleSkillSystemID } from "../cycle/LearnCycleSkillSystem.sol"; -import { ID as PermSkillSystemID } from "../wanderer/PermSkillSystem.sol"; -import { ID as RandomEquipmentSubSystemID } from "../loot/RandomEquipmentSubSystem.sol"; -import { ID as NoncombatSkillSystemID } from "../skill/NoncombatSkillSystem.sol"; - -import { ID as WandererSpawnSystemID } from "../wanderer/WandererSpawnSystem.sol"; -import { ID as StartCycleSystemID } from "../cycle/StartCycleSystem.sol"; -import { ID as CycleActivateCombatSystemID } from "../cycle/CycleActivateCombatSystem.sol"; -import { ID as CycleCombatRewardSystemID } from "../cycle/CycleCombatRewardSystem.sol"; -import { ID as CycleEquipmentSystemID } from "../cycle/CycleEquipmentSystem.sol"; - -library LibInitAuthorizeSubsystems { - function init(IWorld world) internal { - IUint256Component systems = world.systems(); - IOwnableWritable subsystem; - address writer; - - // Duration -> Effect - writer = getAddressById(systems, DurationSubSystemID); - subsystem = IOwnableWritable(getAddressById(systems, EffectSubSystemID)); - subsystem.authorizeWriter(writer); - - // Effect -> Duration - writer = getAddressById(systems, EffectSubSystemID); - subsystem = IOwnableWritable(getAddressById(systems, DurationSubSystemID)); - subsystem.authorizeWriter(writer); - - // Equipment -> Effect - writer = getAddressById(systems, EquipmentSubSystemID); - subsystem = IOwnableWritable(getAddressById(systems, EffectSubSystemID)); - subsystem.authorizeWriter(writer); - - // Combat -> Duration, Effect - writer = getAddressById(systems, CombatSubSystemID); - subsystem = IOwnableWritable(getAddressById(systems, DurationSubSystemID)); - subsystem.authorizeWriter(writer); - subsystem = IOwnableWritable(getAddressById(systems, EffectSubSystemID)); - subsystem.authorizeWriter(writer); - - // NoncombatSkill -> Duration, Effect - writer = getAddressById(systems, NoncombatSkillSystemID); - subsystem = IOwnableWritable(getAddressById(systems, DurationSubSystemID)); - subsystem.authorizeWriter(writer); - subsystem = IOwnableWritable(getAddressById(systems, EffectSubSystemID)); - subsystem.authorizeWriter(writer); - - // WandererSpawn -> WNFT, Effect - writer = getAddressById(systems, WandererSpawnSystemID); - subsystem = IOwnableWritable(getAddressById(systems, WNFTSystemID)); - subsystem.authorizeWriter(writer); - subsystem = IOwnableWritable(getAddressById(systems, EffectSubSystemID)); - subsystem.authorizeWriter(writer); - // TODO for testing, remove later (see LibCycle) - subsystem = IOwnableWritable(getAddressById(systems, RandomEquipmentSubSystemID)); - subsystem.authorizeWriter(writer); - - // StartCycle -> Effect - writer = getAddressById(systems, StartCycleSystemID); - subsystem = IOwnableWritable(getAddressById(systems, EffectSubSystemID)); - subsystem.authorizeWriter(writer); - // TODO for testing, remove later (see LibCycle) - subsystem = IOwnableWritable(getAddressById(systems, RandomEquipmentSubSystemID)); - subsystem.authorizeWriter(writer); - - // CycleActivateCombat -> Effect, Combat - writer = getAddressById(systems, CycleActivateCombatSystemID); - subsystem = IOwnableWritable(getAddressById(systems, EffectSubSystemID)); - subsystem.authorizeWriter(writer); - subsystem = IOwnableWritable(getAddressById(systems, CombatSubSystemID)); - subsystem.authorizeWriter(writer); - - // CycleCombat -> Combat - writer = getAddressById(systems, CycleCombatSystemID); - subsystem = IOwnableWritable(getAddressById(systems, CombatSubSystemID)); - subsystem.authorizeWriter(writer); - - // CycleCombatReward -> RandomEquipment - writer = getAddressById(systems, CycleCombatRewardSystemID); - subsystem = IOwnableWritable(getAddressById(systems, RandomEquipmentSubSystemID)); - subsystem.authorizeWriter(writer); - - // CycleEquipment -> Equipment - writer = getAddressById(systems, CycleEquipmentSystemID); - subsystem = IOwnableWritable(getAddressById(systems, EquipmentSubSystemID)); - subsystem.authorizeWriter(writer); - - // PassCycleTurn -> Duration - writer = getAddressById(systems, PassCycleTurnSystemID); - subsystem = IOwnableWritable(getAddressById(systems, DurationSubSystemID)); - subsystem.authorizeWriter(writer); - - // LearnCycleSkill -> Effect - writer = getAddressById(systems, LearnCycleSkillSystemID); - subsystem = IOwnableWritable(getAddressById(systems, EffectSubSystemID)); - subsystem.authorizeWriter(writer); - - // PermSkill -> Effect - writer = getAddressById(systems, PermSkillSystemID); - subsystem = IOwnableWritable(getAddressById(systems, EffectSubSystemID)); - subsystem.authorizeWriter(writer); - } -} diff --git a/packages/contracts/_old_src/init/LibInitEquipmentAffix.sol b/packages/contracts/_old_src/init/LibInitEquipmentAffix.sol deleted file mode 100644 index 4b11f518..00000000 --- a/packages/contracts/_old_src/init/LibInitEquipmentAffix.sol +++ /dev/null @@ -1,738 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IWorld } from "solecs/interfaces/IWorld.sol"; - -import { LibBaseInitAffix as b, Range, TargetLabel, DEFAULT_TIERS } from "./LibBaseInitAffix.sol"; - -import { Topics, Op, Element } from "../charstat/Topics.sol"; -import { EquipmentPrototypes } from "../equipment/EquipmentPrototypes.sol"; - -library LibInitEquipmentAffix { - function init(IWorld world) internal { - b.Comps memory comps = b.getComps(world.components()); - - /*////////////////////////////////////////////////////////////////////////// - RESOURCES - //////////////////////////////////////////////////////////////////////////*/ - - Range[DEFAULT_TIERS] memory resourceRanges = [ - Range(1, 4), - Range(5, 6), - Range(7, 9), - Range(10, 12) - ]; - - b.add( - comps, - "life", - Topics.LIFE.toStatmodEntity(Op.ADD, Element.ALL), - resourceRanges, - [ - b._affixes( - "Hale", "of Haleness", - _allEquipment(), - _equipment([ - "", - "Brawler's Shield", - "Brawler's Headband", - "Brawler's Vest", - "Brawler's Bracers", - "Brawler's Pants", - "Brawler's Boots", - "Brawler's Necklace", - "Brawler's Ring" - ]) - ), - b._affixes( - "Healthful", "of Health", - _allEquipment(), - _equipment([ - "", - "Infantry Shield", - "Infantry Helmet", - "Infantry Brigandine", - "Infantry Gloves", - "Infantry Trousers", - "Infantry Boots", - "Infantry Pendant", - "Infantry Ring" - ]) - ), - b._affixes( - "Robust", "of Robustness", - _allEquipment(), - _equipment([ - "", - "Warrior Shield", - "Warrior Helmet", - "Warrior Armor", - "Warrior Gauntlets", - "Warrior Legguards", - "Warrior Greaves", - "Warrior Amulet", - "Warrior Ring" - ]) - ), - b._affixes( - "Stalwart", "of Stalwart Body", - _allEquipment(), - _equipment([ - "", - "Crusader Shield", - "Crusader Helmet", - "Crusader Plate", - "Crusader Gauntlets", - "Crusader Legguards", - "Crusader Greaves", - "Crusader Amulet", - "Crusader Signet" - ]) - ) - ] - ); - - b.add( - comps, - "life regen", - Topics.LIFE_GAINED_PER_TURN.toStatmodEntity(Op.ADD, Element.ALL), - resourceRanges, - [ - b._explicits( - "Salubrious", "of Salubrity", - _jewellery() - ), - b._explicits( - "Recuperative", "of Recuperation", - _jewellery() - ), - b._explicits( - "Restorative", "of Restoration", - _jewellery() - ), - b._explicits( - "Rejuvenating", "of Rejuvenation", - _jewellery() - ) - ] - ); - - b.add( - comps, - "mana", - Topics.MANA.toStatmodEntity(Op.ADD, Element.ALL), - resourceRanges, - [ - b._affixes( - "Calm", "of Calm", - _allEquipment(), - _equipment([ - "", - "Student's Shield", - "Student's Cap", - "Student's Robe", - "Student's Gloves", - "Student's Pants", - "Student's Boots", - "Student's Necklace", - "Student's Ring" - ]) - ), - b._affixes( - "Serene", "of Serenity", - _allEquipment(), - _equipment([ - "", - "Scholar's Shield", - "Scholar's Cap", - "Scholar's Robe", - "Scholar's Gloves", - "Scholar's Pants", - "Scholar's Boots", - "Scholar's Pendant", - "Scholar's Ring" - ]) - ), - b._affixes( - "Tranquil", "of Tranquility", - _allEquipment(), - _equipment([ - "", - "Mage Shield", - "Mage Hat", - "Mage Vestment", - "Mage Gloves", - "Mage Pants", - "Mage Boots", - "Mage Amulet", - "Mage Ring" - ]) - ), - b._affixes( - "Halcyon", "of Halcyon Mind", - _allEquipment(), - _equipment([ - "", - "Sage Shield", - "Sage Circlet", - "Sage Vestment", - "Sage Gloves", - "Sage Pants", - "Sage Boots", - "Sage Amulet", - "Sage Signet" - ]) - ) - ] - ); - - b.add( - comps, - "mana regen", - Topics.MANA_GAINED_PER_TURN.toStatmodEntity(Op.ADD, Element.ALL), - resourceRanges, - [ - b._explicits( - "Drowsy", "of Drowsiness", - _jewellery() - ), - b._explicits( - "Sleepy", "of Sleepiness", - _jewellery() - ), - b._explicits( - "Slumberous", "of Slumber", - _jewellery() - ), - b._explicits( - "Somnolent", "of Somnolence", - _jewellery() - ) - ] - ); - - /*////////////////////////////////////////////////////////////////////////// - PSTATS - //////////////////////////////////////////////////////////////////////////*/ - - Range[DEFAULT_TIERS] memory pstatRanges = [ - Range(1, 1), - Range(1, 2), - Range(2, 3), - Range(3, 4) - ]; - - b.add( - comps, - "strength", - Topics.STRENGTH.toStatmodEntity(Op.ADD, Element.ALL), - pstatRanges, - [ - b._affixes( - "Brutish", "of the Brute", - _attrEquipment(), - _equipment([ - "Wooden Club", - "", - "Headband", - "", - "", - "", - "", - "Knucklebone Pendant", - "" - ]) - ), - b._affixes( - "Canine", "of the Wolf", - _attrEquipment(), - _equipment([ - "Bronze Mace", - "", - "Wolf Pelt", - "", - "", - "", - "", - "Wolfclaw Talisman", - "" - ]) - ), - b._affixes( - "Bearish", "of the Bear", - _attrEquipment(), - _equipment([ - "Iron Mace", - "", - "Ursine Pelt", - "", - "", - "", - "", - "Bearclaw Talisman", - "" - ]) - ), - b._affixes( - "Lionheart", "of the Lion", - _attrEquipment(), - _equipment([ - "Steel Mace", - "", - "Lion Pelt", - "", - "", - "", - "", - "Lionclaw Talisman", - "" - ]) - ) - ] - ); - - b.add( - comps, - "arcana", - Topics.ARCANA.toStatmodEntity(Op.ADD, Element.ALL), - pstatRanges, - [ - b._affixes( - "Studious", "of the Student", - _attrEquipment(), - _equipment([ - "Carved Wand", - "", - "Carved Circlet", - "", - "", - "", - "", - "Carved Pendant", - "" - ]) - ), - b._affixes( - "Observant", "of the Goat", - _attrEquipment(), - _equipment([ - "Goat's Horn", - "", - "Goat Skull Mask", - "", - "", - "", - "", - "Goat Eye Talisman", - "" - ]) - ), - b._affixes( - "Seercraft", "of the Seer", - _attrEquipment(), - _equipment([ - "Bone Wand", - "", - "Bone Circlet", - "", - "", - "", - "", - "Bone Necklace", - "" - ]) - ), - b._affixes( - "Mystical", "of Mysticism", - _attrEquipment(), - _equipment([ - "Mystic Wand", - "", - "Mystic Circlet", - "", - "", - "", - "", - "Mystic Amulet", - "" - ]) - ) - ] - ); - - b.add( - comps, - "dexterity", - Topics.DEXTERITY.toStatmodEntity(Op.ADD, Element.ALL), - pstatRanges, - [ - b._affixes( - "Slick", "of the Mongoose", - _attrEquipment(), - _equipment([ - "Skinning Knife", - "", - "Skinning Cap", - "", - "", - "", - "", - "Rabbit's Foot", - "" - ]) - ), - b._affixes( - "Sly", "of the Fox", - _attrEquipment(), - _equipment([ - "Bronze Dagger", - "", - "Fox Pelt", - "", - "", - "", - "", - "Fox Paw Talisman", - "" - ]) - ), - b._affixes( - "Swift", "of the Falcon", - _attrEquipment(), - _equipment([ - "Iron Dagger", - "", - "Hunting Hood", - "", - "", - "", - "", - "Feather Talisman", - "" - ]) - ), - b._affixes( - "Agile", "of the Panther", - _attrEquipment(), - _equipment([ - "Steel Dagger", - "", - "Panther Pelt", - "", - "", - "", - "", - "Pantherclaw Talisman", - "" - ]) - ) - ] - ); - - /*////////////////////////////////////////////////////////////////////////// - ATTACK - //////////////////////////////////////////////////////////////////////////*/ - - Range[DEFAULT_TIERS] memory weaponAttackRanges = [ - Range(1, 4), - Range(5, 6), - Range(7, 9), - Range(10, 12) - ]; - - b.add( - comps, - "weapon base attack", - Topics.ATTACK.toStatmodEntity(Op.BADD, Element.PHYSICAL), - weaponAttackRanges, - [ - b._affixes( - "Burnished", "of Bruising", - _weapon(), - _equipment(["Bronze Shortsword", "", "", "", "", "", "", "", ""]) - ), - b._affixes( - "Polished", "of Striking", - _weapon(), - _equipment(["Bronze Falchion", "", "", "", "", "", "", "", ""]) - ), - b._affixes( - "Honed", "of Harm", - _weapon(), - _equipment(["Iron Sword", "", "", "", "", "", "", "", ""]) - ), - b._affixes( - "Tempered", "of Assault", - _weapon(), - _equipment(["Steel Sword", "", "", "", "", "", "", "", ""]) - ) - ] - ); - - b.add( - comps, - "weapon physical attack", - Topics.ATTACK.toStatmodEntity(Op.ADD, Element.PHYSICAL), - weaponAttackRanges, - [ - b._affixes( - "Irate", "of Ire", - _weapon(), - _equipment(["Bronze Hatchet", "", "", "", "", "", "", "", ""]) - ), - b._affixes( - "Bullish", "of the Bull", - _weapon(), - _equipment(["Bronze Axe", "", "", "", "", "", "", "", ""]) - ), - b._affixes( - "Raging", "of Rage", - _weapon(), - _equipment(["Iron Battleaxe", "", "", "", "", "", "", "", ""]) - ), - b._affixes( - "Furious", "of Fury", - _weapon(), - _equipment(["Steel Battlexe", "", "", "", "", "", "", "", ""]) - ) - ] - ); - - b.add( - comps, - "weapon fire attack", - Topics.ATTACK.toStatmodEntity(Op.ADD, Element.FIRE), - weaponAttackRanges, - [ - b._affixes( - "Heated", "of Heat", - _weapon(), - _equipment(["", "", "", "", "", "", "", "", ""]) - ), - b._affixes( - "Smouldering", "of Coals", - _weapon(), - _equipment(["", "", "", "", "", "", "", "", ""]) - ), - b._affixes( - "Fiery", "of Fire", - _weapon(), - _equipment(["", "", "", "", "", "", "", "", ""]) - ), - b._affixes( - "Flaming", "of Flames", - _weapon(), - _equipment(["", "", "", "", "", "", "", "", ""]) - ) - ] - ); - - b.add( - comps, - "weapon cold attack", - Topics.ATTACK.toStatmodEntity(Op.ADD, Element.COLD), - weaponAttackRanges, - [ - b._affixes( - "Chilled", "of Chills", - _weapon(), - _equipment(["", "", "", "", "", "", "", "", ""]) - ), - b._affixes( - "Icy", "of Ice", - _weapon(), - _equipment(["", "", "", "", "", "", "", "", ""]) - ), - b._affixes( - "Cold", "of Cold", - _weapon(), - _equipment(["", "", "", "", "", "", "", "", ""]) - ), - b._affixes( - "Frosted", "of Frost", - _weapon(), - _equipment(["", "", "", "", "", "", "", "", ""]) - ) - ] - ); - - b.add( - comps, - "weapon poison attack", - Topics.ATTACK.toStatmodEntity(Op.ADD, Element.POISON), - weaponAttackRanges, - [ - b._affixes( - "Sickly", "of Sickness", - _weapon(), - _equipment(["", "", "", "", "", "", "", "", ""]) - ), - b._affixes( - "Poisonous", "of Poison", - _weapon(), - _equipment(["", "", "", "", "", "", "", "", ""]) - ), - b._affixes( - "Venomous", "of Venom", - _weapon(), - _equipment(["", "", "", "", "", "", "", "", ""]) - ), - b._affixes( - "Malignant", "of Malignancy", - _weapon(), - _equipment(["", "", "", "", "", "", "", "", ""]) - ) - ] - ); - - /*////////////////////////////////////////////////////////////////////////// - RESISTANCE - //////////////////////////////////////////////////////////////////////////*/ - - Range[DEFAULT_TIERS] memory resistanceMinorRanges = [ - Range(1, 3), - Range(3, 5), - Range(5, 6), - Range(6, 7) - ]; - - b.add( - comps, - "physical resistance", - Topics.RESISTANCE.toStatmodEntity(Op.ADD, Element.PHYSICAL), - resistanceMinorRanges, - [ - b._affixes( - "Toughened", "of the Oyster", - _resEquipment(), - _equipment([ - "", - "Banded Shield", - "Battered Helmet", - "Rusted Armor", - "Rusted Bracers", - "Rusted Legguard", - "Rusted Boots", - "", - "" - ]) - ), - b._affixes( - "Sturdy", "of the Lobster", - _resEquipment(), - _equipment([ - "", - "Bronze Shield", - "Bronze Helmet", - "Bronze Vest", - "Bronze Bracers", - "Bronze Legguards", - "Bronze Boots", - "", - "" - ]) - ), - b._affixes( - "Reinforced", "of the Nautilus", - _resEquipment(), - _equipment([ - "", - "Iron Shield", - "Iron Helmet", - "Iron Plate", - "Iron Gauntlets", - "Iron Legguards", - "Iron Greaves", - "", - "" - ]) - ), - b._affixes( - "Fortified", "of the Tortoise", - _resEquipment(), - _equipment([ - "", - "Steel Shield", - "Steel Helmet", - "Steel Plate", - "Steel Gauntlets", - "Steel Legguards", - "Steel Greaves", - "", - "" - ]) - ) - ] - ); - } - - /*////////////////////////////////////////////////////////////////////////// - EQUIPMENT PROTOTYPES - //////////////////////////////////////////////////////////////////////////*/ - - function _allEquipment() internal pure returns (uint256[] memory r) { - r = new uint256[](9); - r[0] = EquipmentPrototypes.WEAPON; - r[1] = EquipmentPrototypes.SHIELD; - r[2] = EquipmentPrototypes.HAT; - r[3] = EquipmentPrototypes.CLOTHING; - r[4] = EquipmentPrototypes.GLOVES; - r[5] = EquipmentPrototypes.PANTS; - r[6] = EquipmentPrototypes.BOOTS; - r[7] = EquipmentPrototypes.AMULET; - r[8] = EquipmentPrototypes.RING; - } - - function _jewellery() internal pure returns (uint256[] memory r) { - r = new uint256[](2); - r[0] = EquipmentPrototypes.AMULET; - r[1] = EquipmentPrototypes.RING; - } - - function _attrEquipment() internal pure returns (uint256[] memory r) { - r = new uint256[](4); - r[0] = EquipmentPrototypes.WEAPON; - r[1] = EquipmentPrototypes.SHIELD; - r[2] = EquipmentPrototypes.HAT; - r[3] = EquipmentPrototypes.AMULET; - } - - function _weapon() internal pure returns (uint256[] memory r) { - r = new uint256[](1); - r[0] = EquipmentPrototypes.WEAPON; - } - - function _resEquipment() internal pure returns (uint256[] memory r) { - r = new uint256[](6); - r[0] = EquipmentPrototypes.SHIELD; - r[1] = EquipmentPrototypes.HAT; - r[2] = EquipmentPrototypes.CLOTHING; - r[3] = EquipmentPrototypes.GLOVES; - r[4] = EquipmentPrototypes.PANTS; - r[5] = EquipmentPrototypes.BOOTS; - } - - function _equipment(string[9] memory _labels) internal pure returns (TargetLabel[] memory _dynamic) { - uint256[] memory allEquipment = _allEquipment(); - - _dynamic = new TargetLabel[](_labels.length); - uint256 j; - for (uint256 i; i < _labels.length; i++) { - if (bytes(_labels[i]).length > 0) { - _dynamic[j] = TargetLabel({ - targetEntity: allEquipment[i], - label: _labels[i] - }); - j++; - } - } - // shorten dynamic length if necessary - if (_labels.length != j) { - /// @solidity memory-safe-assembly - assembly { - mstore(_dynamic, j) - } - } - } -} \ No newline at end of file diff --git a/packages/contracts/_old_src/init/LibInitEquipmentPrototype.sol b/packages/contracts/_old_src/init/LibInitEquipmentPrototype.sol deleted file mode 100644 index 533a02e5..00000000 --- a/packages/contracts/_old_src/init/LibInitEquipmentPrototype.sol +++ /dev/null @@ -1,45 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { EquipmentPrototypeComponent, ID as EquipmentPrototypeComponentID } from "../equipment/EquipmentPrototypeComponent.sol"; -import { NameComponent, ID as NameComponentID } from "../common/NameComponent.sol"; - -import { EquipmentPrototypes } from "../equipment/EquipmentPrototypes.sol"; - -// Inititalize equipment prototypes -// Sets of equipment protoEntities are used to determine what can be equipped in slots -library LibInitEquipmentPrototype { - function init(IWorld world) internal { - IUint256Component components = world.components(); - - EquipmentPrototypeComponent protoComp = EquipmentPrototypeComponent( - getAddressById(components, EquipmentPrototypeComponentID) - ); - NameComponent nameComp = NameComponent(getAddressById(components, NameComponentID)); - - _set(protoComp, nameComp, EquipmentPrototypes.WEAPON, "Weapon"); - _set(protoComp, nameComp, EquipmentPrototypes.SHIELD, "Shield"); - _set(protoComp, nameComp, EquipmentPrototypes.HAT, "Hat"); - _set(protoComp, nameComp, EquipmentPrototypes.CLOTHING, "Clothing"); - _set(protoComp, nameComp, EquipmentPrototypes.GLOVES, "Gloves"); - _set(protoComp, nameComp, EquipmentPrototypes.PANTS, "Pants"); - _set(protoComp, nameComp, EquipmentPrototypes.BOOTS, "Boots"); - _set(protoComp, nameComp, EquipmentPrototypes.AMULET, "Amulet"); - _set(protoComp, nameComp, EquipmentPrototypes.RING, "Ring"); - } - - function _set( - EquipmentPrototypeComponent protoComp, - NameComponent nameComp, - uint256 protoEntity, - string memory name - ) internal { - protoComp.set(protoEntity); - nameComp.set(protoEntity, name); - } -} diff --git a/packages/contracts/_old_src/init/LibInitGuise.sol b/packages/contracts/_old_src/init/LibInitGuise.sol deleted file mode 100644 index e3024440..00000000 --- a/packages/contracts/_old_src/init/LibInitGuise.sol +++ /dev/null @@ -1,60 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { getGuiseProtoEntity, GuisePrototype, GuisePrototypeComponent, ID as GuisePrototypeComponentID } from "../guise/GuisePrototypeComponent.sol"; -import { GuiseSkillsComponent, ID as GuiseSkillsComponentID } from "../guise/GuiseSkillsComponent.sol"; -import { getSkillProtoEntity as spe, SkillPrototypeComponent, ID as SkillPrototypeComponentID } from "../skill/SkillPrototypeComponent.sol"; -import { NameComponent, ID as NameComponentID } from "../common/NameComponent.sol"; - -library LibInitGuise { - error GuisePrototypeInitSystem__InvalidSkill(); - - function init(IWorld world) internal { - IUint256Component components = world.components(); - - // TODO maybe move guise skills init to LibInitSkill and have it depend on guise instead? - uint256[] memory guiseSkills = new uint256[](11); - guiseSkills[0] = spe("Cleave"); - guiseSkills[1] = spe("Charge"); - guiseSkills[2] = spe("Parry"); - guiseSkills[3] = spe("Onslaught"); - guiseSkills[4] = spe("Toughness"); - guiseSkills[5] = spe("Thunder Clap"); - guiseSkills[6] = spe("Precise Strikes"); - guiseSkills[7] = spe("Blood Rage"); - guiseSkills[8] = spe("Retaliation"); - guiseSkills[9] = spe("Last Stand"); - guiseSkills[10] = spe("Weapon Mastery"); - - add(components, "Warrior", GuisePrototype({ levelMul: [uint32(16), 8, 8] }), guiseSkills); - } - - function add( - IUint256Component components, - string memory name, - GuisePrototype memory prototype, - uint256[] memory guiseSkills - ) internal { - GuisePrototypeComponent proto = GuisePrototypeComponent(getAddressById(components, GuisePrototypeComponentID)); - GuiseSkillsComponent guiseSkillsComp = GuiseSkillsComponent(getAddressById(components, GuiseSkillsComponentID)); - SkillPrototypeComponent skillComp = SkillPrototypeComponent(getAddressById(components, SkillPrototypeComponentID)); - NameComponent nameComp = NameComponent(getAddressById(components, NameComponentID)); - - uint256 entity = getGuiseProtoEntity(name); - - for (uint256 i; i < guiseSkills.length; i++) { - if (!skillComp.has(guiseSkills[i])) { - revert GuisePrototypeInitSystem__InvalidSkill(); - } - } - - proto.set(entity, prototype); - guiseSkillsComp.set(entity, guiseSkills); - nameComp.set(entity, name); - } -} diff --git a/packages/contracts/_old_src/init/LibInitMapAffix.sol b/packages/contracts/_old_src/init/LibInitMapAffix.sol deleted file mode 100644 index 031e26c1..00000000 --- a/packages/contracts/_old_src/init/LibInitMapAffix.sol +++ /dev/null @@ -1,271 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IWorld } from "solecs/interfaces/IWorld.sol"; - -import { LibBaseInitAffix as b, Range, TargetLabel, DEFAULT_TIERS, AffixPrototype } from "./LibBaseInitAffix.sol"; - -import { Topics, Op, Element } from "../charstat/Topics.sol"; -import { MapPrototypes } from "../map/MapPrototypes.sol"; - -library LibInitMapAffix { - function init(IWorld world) internal { - b.Comps memory comps = b.getComps(world.components()); - - // TODO balance map ranges, they're even worse than equipment ranges - - Range[DEFAULT_TIERS] memory resourceRanges = [ - Range(4, 8), - Range(12, 18), - Range(24, 32), - Range(40, 50) - ]; - - Range[DEFAULT_TIERS] memory attrRanges = [ - Range(1, 1), - Range(2, 2), - Range(3, 3), - Range(4, 4) - ]; - - Range[DEFAULT_TIERS] memory attackRanges = [ - Range(2, 3), - Range(6, 8), - Range(10, 13), - Range(14, 18) - ]; - - Range[DEFAULT_TIERS] memory resistanceRanges = [ - Range(20, 30), - Range(40, 50), - Range(60, 70), - Range(80, 90) - ]; - - // LEVEL - - addMapLevel(comps, "map level 1", "Meadows", 1); - addMapLevel(comps, "map level 2", "Plains", 2); - addMapLevel(comps, "map level 3", "Valley", 3); - addMapLevel(comps, "map level 4", "Hills", 4); - addMapLevel(comps, "map level 5", "Woods", 5); - addMapLevel(comps, "map level 6", "Thicket", 6); - addMapLevel(comps, "map level 7", "Wetlands", 7); - addMapLevel(comps, "map level 8", "Swamp", 8); - addMapLevel(comps, "map level 9", "Wastes", 9); - addMapLevel(comps, "map level 10", "Mountains", 10); - addMapLevel(comps, "map level 11", "Caves", 11); - addMapLevel(comps, "map level 12", "Ruins", 12); - - // TODO customize map affix labels, atm they're just copypasted from equipment - - // RESOURCES - - b.add( - comps, - "map life", - Topics.LIFE.toStatmodEntity(Op.ADD, Element.ALL), - resourceRanges, - [ - b._explicits("Hale", "of Haleness", _globalMaps()), - b._explicits("Healthful", "of Health", _globalMaps()), - b._explicits("Robust", "of Robustness", _globalMaps()), - b._explicits("Stalwart", "of Stalwart Body", _globalMaps()) - ] - ); - - // ATTRIBUTES - - b.add( - comps, - "map strength", - Topics.STRENGTH.toStatmodEntity(Op.ADD, Element.ALL), - attrRanges, - [ - b._explicits("Brutish", "of the Brute", _globalMaps()), - b._explicits("Canine", "of the Wolf", _globalMaps()), - b._explicits("Bearish", "of the Bear", _globalMaps()), - b._explicits("Lionheart", "of the Lion", _globalMaps()) - ] - ); - - b.add( - comps, - "map arcana", - Topics.ARCANA.toStatmodEntity(Op.ADD, Element.ALL), - attrRanges, - [ - b._explicits("Studious", "of the Student", _globalMaps()), - b._explicits("Observant", "of the Goat", _globalMaps()), - b._explicits("Seercraft", "of the Seer", _globalMaps()), - b._explicits("Mystical", "of Mysticism", _globalMaps()) - ] - ); - - b.add( - comps, - "map dexterity", - Topics.DEXTERITY.toStatmodEntity(Op.ADD, Element.ALL), - attrRanges, - [ - b._explicits("Slick", "of the Mongoose", _globalMaps()), - b._explicits("Sly", "of the Fox", _globalMaps()), - b._explicits("Swift", "of the Falcon", _globalMaps()), - b._explicits("Agile", "of the Panther", _globalMaps()) - ] - ); - - // ATTACK - - b.add( - comps, - "map physical attack", - Topics.ATTACK.toStatmodEntity(Op.ADD, Element.PHYSICAL), - attackRanges, - [ - b._explicits("Irate", "of Ire", _globalMaps()), - b._explicits("Bullish", "of the Bull", _globalMaps()), - b._explicits("Raging", "of Rage", _globalMaps()), - b._explicits("Furious", "of Fury", _globalMaps()) - ] - ); - - b.add( - comps, - "map fire attack", - Topics.ATTACK.toStatmodEntity(Op.ADD, Element.FIRE), - attackRanges, - [ - b._explicits("Heated", "of Heat", _globalMaps()), - b._explicits("Smouldering", "of Coals", _globalMaps()), - b._explicits("Fiery", "of Fire", _globalMaps()), - b._explicits("Flaming", "of Flames", _globalMaps()) - ] - ); - - b.add( - comps, - "map cold attack", - Topics.ATTACK.toStatmodEntity(Op.ADD, Element.COLD), - attackRanges, - [ - b._explicits("Chilled", "of Chills", _globalMaps()), - b._explicits("Icy", "of Ice", _globalMaps()), - b._explicits("Cold", "of Cold", _globalMaps()), - b._explicits("Frosted", "of Frost", _globalMaps()) - ] - ); - - b.add( - comps, - "map poison attack", - Topics.ATTACK.toStatmodEntity(Op.ADD, Element.POISON), - attackRanges, - [ - b._explicits("Sickly", "of Sickness", _globalMaps()), - b._explicits("Poisonous", "of Poison", _globalMaps()), - b._explicits("Venomous", "of Venom", _globalMaps()), - b._explicits("Malignant", "of Malignancy", _globalMaps()) - ] - ); - - // RESISTANCE - - b.add( - comps, - "map physical resistance", - Topics.RESISTANCE.toStatmodEntity(Op.ADD, Element.PHYSICAL), - resistanceRanges, - [ - b._explicits("Toughened", "of the Oyster", _globalMaps()), - b._explicits("Sturdy", "of the Lobster", _globalMaps()), - b._explicits("Reinforced", "of the Nautilus", _globalMaps()), - b._explicits("Fortified", "of the Tortoise", _globalMaps()) - ] - ); - - b.add( - comps, - "map fire resistance", - Topics.RESISTANCE.toStatmodEntity(Op.ADD, Element.FIRE), - resistanceRanges, - [ - b._explicits("Heatproof", "of the Whelpling", _globalMaps()), - b._explicits("Dousing", "of the Salamander", _globalMaps()), - b._explicits("Fireproof", "of Fire Warding", _globalMaps()), - b._explicits("Flamewarded", "of Flame Warding", _globalMaps()) - ] - ); - - b.add( - comps, - "map cold resistance", - Topics.RESISTANCE.toStatmodEntity(Op.ADD, Element.COLD), - resistanceRanges, - [ - b._explicits("Insulating", "of the Penguin", _globalMaps()), - b._explicits("Warming", "of the Walrus", _globalMaps()), - b._explicits("Coldproof", "of Cold Warding", _globalMaps()), - b._explicits("Frostwarded", "of Frost Warding", _globalMaps()) - ] - ); - - b.add( - comps, - "map poison resistance", - Topics.RESISTANCE.toStatmodEntity(Op.ADD, Element.POISON), - resistanceRanges, - [ - b._explicits("Wholesome", "of the Opossum", _globalMaps()), - b._explicits("Inoculative", "of the Snake", _globalMaps()), - b._explicits("Poisonward", "of Poison Warding", _globalMaps()), - b._explicits("Venomward", "of Venom Warding", _globalMaps()) - ] - ); - } - - function _globalMaps() internal pure returns (uint256[] memory r) { - r = new uint256[](3); - r[0] = MapPrototypes.GLOBAL_BASIC; - r[1] = MapPrototypes.GLOBAL_RANDOM; - r[2] = MapPrototypes.GLOBAL_CYCLE_BOSS; - } - - /// @dev Add a map-specific implicit affix. - /// Non-standard affix tiers: tier == map level == affix value == requiredIlvl == maxIlvl - function addMapLevel( - b.Comps memory comps, - string memory name, - string memory label, - uint32 level - ) internal { - TargetLabel[] memory mapLabels = new TargetLabel[](3); - mapLabels[0] = TargetLabel({ - targetEntity: MapPrototypes.GLOBAL_BASIC, - label: label - }); - mapLabels[1] = TargetLabel({ - targetEntity: MapPrototypes.GLOBAL_RANDOM, - label: label - }); - mapLabels[2] = TargetLabel({ - targetEntity: MapPrototypes.GLOBAL_CYCLE_BOSS, - label: label - }); - - b.addOne( - comps, - name, - AffixPrototype({ - tier: level, - statmodProtoEntity: Topics.LEVEL.toStatmodEntity(Op.BADD, Element.ALL), - requiredIlvl: level, - min: level, - max: level - }), - b._implicits(mapLabels), - level - ); - } -} diff --git a/packages/contracts/_old_src/init/LibInitMapPrototype.sol b/packages/contracts/_old_src/init/LibInitMapPrototype.sol deleted file mode 100644 index cb17bcfd..00000000 --- a/packages/contracts/_old_src/init/LibInitMapPrototype.sol +++ /dev/null @@ -1,35 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { MapPrototypeComponent, ID as MapPrototypeComponentID } from "../map/MapPrototypeComponent.sol"; -import { NameComponent, ID as NameComponentID } from "../common/NameComponent.sol"; - -import { MapPrototypes } from "../map/MapPrototypes.sol"; - -library LibInitMapPrototype { - function init(IWorld world) internal { - IUint256Component components = world.components(); - - MapPrototypeComponent protoComp = MapPrototypeComponent(getAddressById(components, MapPrototypeComponentID)); - NameComponent nameComp = NameComponent(getAddressById(components, NameComponentID)); - - _set(protoComp, nameComp, MapPrototypes.GLOBAL_BASIC, "Global Basic"); - _set(protoComp, nameComp, MapPrototypes.GLOBAL_RANDOM, "Global Random"); - _set(protoComp, nameComp, MapPrototypes.GLOBAL_CYCLE_BOSS, "Global Cycle Boss"); - } - - function _set( - MapPrototypeComponent protoComp, - NameComponent nameComp, - uint256 protoEntity, - string memory name - ) internal { - protoComp.set(protoEntity); - nameComp.set(protoEntity, name); - } -} diff --git a/packages/contracts/_old_src/init/LibInitMapsBoss.sol b/packages/contracts/_old_src/init/LibInitMapsBoss.sol deleted file mode 100644 index eee83f74..00000000 --- a/packages/contracts/_old_src/init/LibInitMapsBoss.sol +++ /dev/null @@ -1,290 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { FromPrototypeComponent, ID as FromPrototypeComponentID } from "../common/FromPrototypeComponent.sol"; -import { NameComponent, ID as NameComponentID } from "../common/NameComponent.sol"; - -import { LibLootMint } from "../loot/LibLootMint.sol"; -import { LibPickAffixes } from "../affix/LibPickAffixes.sol"; -import { AffixPartId } from "../affix/AffixNamingComponent.sol"; - -import { MapPrototypes } from "../map/MapPrototypes.sol"; - -library LibInitMapsBoss { - struct ManualAffix { - AffixPartId affixPart; - string name; - uint32 tier; - } - - function init(IWorld world) internal { - IUint256Component components = world.components(); - - // 1 - _setBoss( - world, - components, - "Dire Rabbit", - 1, - [ - ManualAffix(AffixPartId.IMPLICIT, "map level 1", 1), - ManualAffix(AffixPartId.PREFIX, "map life", 1), - ManualAffix(AffixPartId.PREFIX, "map strength", 1), - ManualAffix(AffixPartId.SUFFIX, "map physical resistance", 1), - ManualAffix(AffixPartId.SUFFIX, "map dexterity", 1) - ] - ); - // 2 - _setBoss( - world, - components, - "Cultist Invoker", - 2, - [ - ManualAffix(AffixPartId.IMPLICIT, "map level 2", 2), - ManualAffix(AffixPartId.PREFIX, "map life", 1), - ManualAffix(AffixPartId.PREFIX, "map fire attack", 1), - ManualAffix(AffixPartId.SUFFIX, "map fire resistance", 1), - ManualAffix(AffixPartId.SUFFIX, "map dexterity", 1) - ] - ); - // 3 - _setBoss( - world, - components, - "Goblin Wolfrider", - 3, - [ - ManualAffix(AffixPartId.IMPLICIT, "map level 3", 3), - ManualAffix(AffixPartId.PREFIX, "map life", 1), - ManualAffix(AffixPartId.PREFIX, "map physical attack", 1), - ManualAffix(AffixPartId.SUFFIX, "map dexterity", 4), - ManualAffix(AffixPartId.SUFFIX, "map poison attack", 1) - ] - ); - // 4 - _setBoss( - world, - components, - "Hill Giant", - 4, - [ - ManualAffix(AffixPartId.IMPLICIT, "map level 4", 4), - ManualAffix(AffixPartId.PREFIX, "map life", 3), - ManualAffix(AffixPartId.PREFIX, "map strength", 3), - ManualAffix(AffixPartId.SUFFIX, "map physical attack", 2), - ManualAffix(AffixPartId.SUFFIX, "map physical resistance", 1) - ] - ); - // 5 - _setBoss( - world, - components, - "Goblin Shaman", - 5, - [ - ManualAffix(AffixPartId.IMPLICIT, "map level 5", 5), - ManualAffix(AffixPartId.PREFIX, "map life", 3), - ManualAffix(AffixPartId.PREFIX, "map arcana", 4), - ManualAffix(AffixPartId.SUFFIX, "map fire attack", 1), - ManualAffix(AffixPartId.SUFFIX, "map dexterity", 3) - ] - ); - // 6 - _setBoss( - world, - components, - "Vilewood Treant", - 6, - [ - ManualAffix(AffixPartId.IMPLICIT, "map level 6", 6), - ManualAffix(AffixPartId.PREFIX, "map strength", 3), - ManualAffix(AffixPartId.PREFIX, "map poison attack", 2), - ManualAffix(AffixPartId.PREFIX, "map physical resistance", 2), - ManualAffix(AffixPartId.SUFFIX, "map poison resistance", 3), - ManualAffix(AffixPartId.SUFFIX, "map fire resistance", 1), - ManualAffix(AffixPartId.SUFFIX, "map cold resistance", 2) - ] - ); - // 7 - _setBoss( - world, - components, - "Orc Warlord", - 7, - [ - ManualAffix(AffixPartId.IMPLICIT, "map level 7", 7), - ManualAffix(AffixPartId.PREFIX, "map strength", 4), - ManualAffix(AffixPartId.PREFIX, "map physical attack", 4), - ManualAffix(AffixPartId.SUFFIX, "map physical resistance", 3), - ManualAffix(AffixPartId.SUFFIX, "map poison resistance", 1) - ] - ); - // 8 - _setBoss( - world, - components, - "Grand Toad", - 8, - [ - ManualAffix(AffixPartId.IMPLICIT, "map level 8", 8), - ManualAffix(AffixPartId.PREFIX, "map life", 4), - ManualAffix(AffixPartId.PREFIX, "map strength", 3), - ManualAffix(AffixPartId.SUFFIX, "map poison attack", 3), - ManualAffix(AffixPartId.SUFFIX, "map dexterity", 3) - ] - ); - // 9 - _setBoss( - world, - components, - "Chimera", - 9, - [ - ManualAffix(AffixPartId.IMPLICIT, "map level 9", 9), - ManualAffix(AffixPartId.PREFIX, "map life", 4), - ManualAffix(AffixPartId.PREFIX, "map dexterity", 4), - ManualAffix(AffixPartId.SUFFIX, "map poison attack", 4), - ManualAffix(AffixPartId.SUFFIX, "map strength", 3) - ] - ); - // 10 - _setBoss( - world, - components, - "Ice Giant", - 10, - [ - ManualAffix(AffixPartId.IMPLICIT, "map level 10", 10), - ManualAffix(AffixPartId.PREFIX, "map life", 4), - ManualAffix(AffixPartId.PREFIX, "map strength", 4), - ManualAffix(AffixPartId.PREFIX, "map physical attack", 3), - ManualAffix(AffixPartId.SUFFIX, "map cold attack", 2), - ManualAffix(AffixPartId.SUFFIX, "map physical resistance", 2), - ManualAffix(AffixPartId.SUFFIX, "map cold resistance", 3) - ] - ); - // 11 - _setBoss( - world, - components, - "Fire Drake", - 11, - [ - ManualAffix(AffixPartId.IMPLICIT, "map level 11", 11), - ManualAffix(AffixPartId.PREFIX, "map life", 4), - ManualAffix(AffixPartId.PREFIX, "map strength", 4), - ManualAffix(AffixPartId.PREFIX, "map dexterity", 2), - ManualAffix(AffixPartId.SUFFIX, "map fire attack", 4), - ManualAffix(AffixPartId.SUFFIX, "map fire resistance", 4), - ManualAffix(AffixPartId.SUFFIX, "map physical resistance", 2) - ] - ); - // 12 - _setBoss( - world, - components, - "The Shadow", - 12, - [ - ManualAffix(AffixPartId.IMPLICIT, "map level 12", 12), - ManualAffix(AffixPartId.PREFIX, "map cold resistance", 4), - ManualAffix(AffixPartId.PREFIX, "map poison resistance", 4), - ManualAffix(AffixPartId.PREFIX, "map physical resistance", 3), - ManualAffix(AffixPartId.PREFIX, "map fire resistance", 3), - ManualAffix(AffixPartId.SUFFIX, "map poison attack", 4), - ManualAffix(AffixPartId.SUFFIX, "map arcana", 4), - ManualAffix(AffixPartId.SUFFIX, "map dexterity", 4), - ManualAffix(AffixPartId.SUFFIX, "map life", 3) - ] - ); - } - - function _setBoss( - IWorld world, - IUint256Component components, - string memory name, - uint32 ilvl, - ManualAffix[5] memory manualAffixesStatic - ) private { - ManualAffix[] memory manualAffixes = new ManualAffix[](manualAffixesStatic.length); - for (uint256 i; i < manualAffixesStatic.length; i++) { - manualAffixes[i] = manualAffixesStatic[i]; - } - _setBoss(world, components, name, ilvl, manualAffixes); - } - - function _setBoss( - IWorld world, - IUint256Component components, - string memory name, - uint32 ilvl, - ManualAffix[7] memory manualAffixesStatic - ) private { - ManualAffix[] memory manualAffixes = new ManualAffix[](manualAffixesStatic.length); - for (uint256 i; i < manualAffixesStatic.length; i++) { - manualAffixes[i] = manualAffixesStatic[i]; - } - _setBoss(world, components, name, ilvl, manualAffixes); - } - - function _setBoss( - IWorld world, - IUint256Component components, - string memory name, - uint32 ilvl, - ManualAffix[9] memory manualAffixesStatic - ) private { - ManualAffix[] memory manualAffixes = new ManualAffix[](manualAffixesStatic.length); - for (uint256 i; i < manualAffixesStatic.length; i++) { - manualAffixes[i] = manualAffixesStatic[i]; - } - _setBoss(world, components, name, ilvl, manualAffixes); - } - - function _setBoss( - IWorld world, - IUint256Component components, - string memory name, - uint32 ilvl, - ManualAffix[] memory manualAffixes - ) private { - AffixPartId[] memory affixParts = new AffixPartId[](manualAffixes.length); - string[] memory names = new string[](manualAffixes.length); - uint32[] memory tiers = new uint32[](manualAffixes.length); - - for (uint256 i; i < manualAffixes.length; i++) { - affixParts[i] = manualAffixes[i].affixPart; - names[i] = manualAffixes[i].name; - tiers[i] = manualAffixes[i].tier; - } - - ( - uint256[] memory statmodProtoEntities, - uint256[] memory affixProtoEntities, - uint32[] memory affixValues - ) = LibPickAffixes.manuallyPickAffixesMax(components, names, tiers); - - // get a new unique id - uint256 lootEntity = world.getUniqueEntityId(); - LibLootMint.lootMint( - components, - lootEntity, - ilvl, - affixParts, - statmodProtoEntities, - affixProtoEntities, - affixValues - ); - // set loot's map prototype - FromPrototypeComponent fromProtoComp = FromPrototypeComponent(getAddressById(components, FromPrototypeComponentID)); - fromProtoComp.set(lootEntity, MapPrototypes.GLOBAL_CYCLE_BOSS); - // set name - NameComponent(getAddressById(components, NameComponentID)).set(lootEntity, name); - } -} diff --git a/packages/contracts/_old_src/init/LibInitMapsGlobal.sol b/packages/contracts/_old_src/init/LibInitMapsGlobal.sol deleted file mode 100644 index 5fb71dfd..00000000 --- a/packages/contracts/_old_src/init/LibInitMapsGlobal.sol +++ /dev/null @@ -1,59 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { FromPrototypeComponent, ID as FromPrototypeComponentID } from "../common/FromPrototypeComponent.sol"; - -import { LibLootMint } from "../loot/LibLootMint.sol"; -import { AffixPartId } from "../affix/AffixNamingComponent.sol"; - -import { MapPrototypes } from "../map/MapPrototypes.sol"; - -library LibInitMapsGlobal { - function init(IWorld world) internal { - IUint256Component components = world.components(); - - // Hardcoded map level range - // TODO this should be in a constant somewhere, when you do cycles you'll need this value too - for (uint32 ilvl = 1; ilvl <= 12; ilvl++) { - _setBasic(world, components, ilvl); - } - // TODO put this into a system to generate new ones each day - for (uint32 ilvl = 2; ilvl <= 10; ilvl += 4) { - uint256 randomness = uint256(keccak256(abi.encode("global random map", ilvl, blockhash(block.number)))); - _setRandom(world, components, ilvl, randomness); - } - } - - function _setBasic(IWorld world, IUint256Component components, uint32 ilvl) private { - // global basic maps only have the implicit affix - AffixPartId[] memory affixParts = new AffixPartId[](1); - affixParts[0] = AffixPartId.IMPLICIT; - - // get a new unique id - uint256 lootEntity = world.getUniqueEntityId(); - // not really random, there's only 1 implicit per ilvl, it's just easier to reuse this function - LibLootMint.randomLootMint(components, affixParts, lootEntity, MapPrototypes.GLOBAL_BASIC, ilvl, 0); - // set loot's map prototype - FromPrototypeComponent fromProtoComp = FromPrototypeComponent(getAddressById(components, FromPrototypeComponentID)); - fromProtoComp.set(lootEntity, MapPrototypes.GLOBAL_BASIC); - } - - function _setRandom(IWorld world, IUint256Component components, uint32 ilvl, uint256 randomness) private { - AffixPartId[] memory affixParts = new AffixPartId[](3); - affixParts[0] = AffixPartId.IMPLICIT; - affixParts[1] = AffixPartId.SUFFIX; - affixParts[2] = AffixPartId.PREFIX; - - // get a new unique id - uint256 lootEntity = world.getUniqueEntityId(); - LibLootMint.randomLootMint(components, affixParts, lootEntity, MapPrototypes.GLOBAL_RANDOM, ilvl, randomness); - // set loot's map prototype - FromPrototypeComponent fromProtoComp = FromPrototypeComponent(getAddressById(components, FromPrototypeComponentID)); - fromProtoComp.set(lootEntity, MapPrototypes.GLOBAL_RANDOM); - } -} diff --git a/packages/contracts/_old_src/init/LibInitReverseHashName.ejs b/packages/contracts/_old_src/init/LibInitReverseHashName.ejs deleted file mode 100644 index f40a6747..00000000 --- a/packages/contracts/_old_src/init/LibInitReverseHashName.ejs +++ /dev/null @@ -1,18 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { ReverseHashNameSystem, ID as ReverseHashNameSystemID } from "../common/ReverseHashNameSystem.sol"; - -library LibInitReverseHashName { - function init(IWorld world) internal { - ReverseHashNameSystem system = ReverseHashNameSystem(getAddressById(world.systems(), ReverseHashNameSystemID)); - -<% names.forEach(name => { -%> - system.executeTyped("<%= name %>"); -<% }) -%> - } -} \ No newline at end of file diff --git a/packages/contracts/_old_src/init/LibInitSkill.sol b/packages/contracts/_old_src/init/LibInitSkill.sol deleted file mode 100644 index 0ad23897..00000000 --- a/packages/contracts/_old_src/init/LibInitSkill.sol +++ /dev/null @@ -1,259 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IWorld } from "solecs/interfaces/IWorld.sol"; - -import { LibBaseInitSkill as b } from "./LibBaseInitSkill.sol"; -import { SkillType, TargetType, SkillPrototype } from "../skill/SkillPrototypeComponent.sol"; -import { Topics, Op, Element } from "../charstat/Topics.sol"; -import { makeEffectPrototype, EffectRemovability } from "../effect/makeEffectPrototype.sol"; - -library LibInitSkill { - function init(IWorld world) internal { - b.Comps memory comps = b.getComps(world.components()); - - // 1 - b.add( - comps, - "Cleave", - "Attack with increased damage", - SkillPrototype({ - requiredLevel: 1, - skillType: SkillType.COMBAT, - withAttack: true, - withSpell: false, - cost: 1, - duration: b._duration("round", 1), - cooldown: b._duration("round", 1), - effectTarget: TargetType.SELF, - spellDamage: b._emptyElemental() - }), - makeEffectPrototype( - EffectRemovability.BUFF, - Topics.ATTACK, Op.MUL, Element.ALL, 16, - Topics.ATTACK, Op.ADD, Element.PHYSICAL, 2 - ) - ); - - // 2 - b.add( - comps, - "Charge", - "Greatly increase attack damage for the next combat round", - SkillPrototype({ - requiredLevel: 2, - skillType: SkillType.NONCOMBAT, - withAttack: false, - withSpell: false, - cost: 1, - duration: b._duration("round_persistent", 1), - cooldown: b._duration("turn", 3), - effectTarget: TargetType.SELF, - spellDamage: b._emptyElemental() - }), - makeEffectPrototype( - EffectRemovability.BUFF, - Topics.ATTACK, Op.MUL, Element.ALL, 64 - ) - ); - - // 3 - b.add( - comps, - "Parry", - "Increase physical resistance", - SkillPrototype({ - requiredLevel: 3, - skillType: SkillType.PASSIVE, - withAttack: false, - withSpell: false, - cost: 0, - duration: b._noDuration(), - cooldown: b._noDuration(), - effectTarget: TargetType.SELF, - spellDamage: b._emptyElemental() - }), - makeEffectPrototype( - EffectRemovability.PERSISTENT, - Topics.RESISTANCE, Op.ADD, Element.PHYSICAL, 8 - ) - ); - - // 4 - b.add( - comps, - "Onslaught", - "Increase attack damage and recover some life per round", - SkillPrototype({ - requiredLevel: 4, - skillType: SkillType.NONCOMBAT, - withAttack: false, - withSpell: false, - cost: 1, - duration: b._duration("turn", 2), - cooldown: b._duration("turn", 8), - effectTarget: TargetType.SELF, - spellDamage: b._emptyElemental() - }), - makeEffectPrototype( - EffectRemovability.BUFF, - Topics.ATTACK, Op.MUL, Element.ALL, 32, - Topics.LIFE_GAINED_PER_TURN, Op.ADD, Element.ALL, 2 - ) - ); - - // 5 - b.add( - comps, - "Toughness", - "Increase life", - SkillPrototype({ - requiredLevel: 5, - skillType: SkillType.PASSIVE, - withAttack: false, - withSpell: false, - cost: 0, - duration: b._noDuration(), - cooldown: b._noDuration(), - effectTarget: TargetType.SELF, - spellDamage: b._emptyElemental() - }), - makeEffectPrototype( - EffectRemovability.PERSISTENT, - Topics.LIFE, Op.MUL, Element.ALL, 8 - ) - ); - - // 6 - b.add( - comps, - "Thunder Clap", - "Attack and deal physical spell damage", - SkillPrototype({ - requiredLevel: 6, - skillType: SkillType.COMBAT, - withAttack: true, - withSpell: true, - cost: 4, - duration: b._noDuration(), - cooldown: b._duration("round", 4), - effectTarget: TargetType.SELF, - spellDamage: [uint32(0), 8, 0, 0, 0] - }), - makeEffectPrototype() - ); - - // 7 - b.add( - comps, - "Precise Strikes", - "Increase attack damage", - SkillPrototype({ - requiredLevel: 7, - skillType: SkillType.PASSIVE, - withAttack: false, - withSpell: false, - cost: 0, - duration: b._noDuration(), - cooldown: b._noDuration(), - effectTarget: TargetType.SELF, - spellDamage: b._emptyElemental() - }), - makeEffectPrototype( - EffectRemovability.PERSISTENT, - Topics.ATTACK, Op.MUL, Element.ALL, 8 - ) - ); - - // 8 - b.add( - comps, - "Blood Rage", - "Gain an extra turn after a kill, once per day", - SkillPrototype({ - requiredLevel: 8, - skillType: SkillType.PASSIVE, - withAttack: false, - withSpell: false, - cost: 0, - duration: b._noDuration(), - // TODO this should have a day(?) cooldown somehow, maybe not here though - cooldown: b._noDuration(), - effectTarget: TargetType.SELF, - spellDamage: b._emptyElemental() - }), - makeEffectPrototype() - ); - - // 9 - b.add( - comps, - "Retaliation", - "Increases physical resistance\nIncreases physical attack damage proportional to missing life", - SkillPrototype({ - requiredLevel: 9, - skillType: SkillType.NONCOMBAT, - withAttack: false, - withSpell: false, - cost: 0, - duration: b._duration("turn", 1), - cooldown: b._duration("turn", 16), - effectTarget: TargetType.SELF, - spellDamage: b._emptyElemental() - }), - makeEffectPrototype( - EffectRemovability.BUFF, - Topics.RESISTANCE, Op.ADD, Element.PHYSICAL, 8, - Topics.PERCENT_OF_MISSING_LIFE_TO_ATTACK, Op.ADD, Element.PHYSICAL, 400 - ) - ); - - // 10 - b.add( - comps, - "Last Stand", - "Gain temporary life for 4 rounds", - SkillPrototype({ - requiredLevel: 10, - skillType: SkillType.COMBAT, - withAttack: true, - withSpell: false, - cost: 1, - duration: b._duration("round", 4), - cooldown: b._duration("turn", 8), - effectTarget: TargetType.SELF, - spellDamage: b._emptyElemental() - }), - makeEffectPrototype( - EffectRemovability.BUFF, - Topics.LIFE, Op.MUL, Element.ALL, 32 - // TODO should this even be a modifier? - //'recover #% of base life', 32 - ) - ); - - // 11 - b.add( - comps, - "Weapon Mastery", - // TODO this dual-wielding thing - "Allows dual wielding one-handed weapons\nIncreases base attack", - SkillPrototype({ - requiredLevel: 11, - skillType: SkillType.PASSIVE, - withAttack: false, - withSpell: false, - cost: 0, - duration: b._noDuration(), - cooldown: b._noDuration(), - effectTarget: TargetType.SELF, - spellDamage: b._emptyElemental() - }), - makeEffectPrototype( - EffectRemovability.PERSISTENT, - Topics.ATTACK, Op.BADD, Element.PHYSICAL, 1 - ) - ); - } -} diff --git a/packages/contracts/_old_src/init/LibInitStatmod.sol b/packages/contracts/_old_src/init/LibInitStatmod.sol deleted file mode 100644 index 814f2635..00000000 --- a/packages/contracts/_old_src/init/LibInitStatmod.sol +++ /dev/null @@ -1,116 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { Topics, Topic } from "../charstat/Topics.sol"; -import { statmodName } from "../statmod/statmodName.sol"; -import { getStatmodProtoEntity, Op, Element, StatmodPrototype, StatmodPrototypeComponent, ID as StatmodPrototypeComponentID } from "../statmod/StatmodPrototypeComponent.sol"; -import { NameComponent, ID as NameComponentID } from "../common/NameComponent.sol"; -import { ReverseHashNameComponent, ID as ReverseHashNameComponentID } from "../common/ReverseHashNameComponent.sol"; - -library LibInitStatmod { - struct Comps { - StatmodPrototypeComponent proto; - NameComponent name; - ReverseHashNameComponent rhName; - } - - function getComps(IUint256Component components) internal view returns (Comps memory result) { - result.proto = StatmodPrototypeComponent(getAddressById(components, StatmodPrototypeComponentID)); - result.name = NameComponent(getAddressById(components, NameComponentID)); - result.rhName = ReverseHashNameComponent(getAddressById(components, ReverseHashNameComponentID)); - } - - function init(IWorld world) internal { - Comps memory comps = getComps(world.components()); - - // primary stats - for (uint256 i; i < Topics.PSTAT().length; i++) { - add(comps, Topics.PSTAT()[i], Op.MUL); - add(comps, Topics.PSTAT()[i], Op.ADD); - } - - // secondary stats - add(comps, Topics.FORTUNE, Op.MUL); - add(comps, Topics.FORTUNE, Op.ADD); - - add(comps, Topics.CONNECTION, Op.MUL); - add(comps, Topics.CONNECTION, Op.ADD); - - // currents - add(comps, Topics.LIFE, Op.MUL); - add(comps, Topics.LIFE, Op.ADD); - add(comps, Topics.LIFE, Op.BADD); - - add(comps, Topics.MANA, Op.MUL); - add(comps, Topics.MANA, Op.ADD); - add(comps, Topics.MANA, Op.BADD); - - // currents gained per turn - add(comps, Topics.LIFE_GAINED_PER_TURN, Op.ADD); - add(comps, Topics.MANA_GAINED_PER_TURN, Op.ADD); - - // attack - add(comps, Topics.ATTACK, Op.BADD, Element.PHYSICAL); - - add(comps, Topics.ATTACK, Op.MUL); - - add(comps, Topics.ATTACK, Op.MUL, Element.FIRE); - add(comps, Topics.ATTACK, Op.MUL, Element.COLD); - - add(comps, Topics.ATTACK, Op.ADD, Element.PHYSICAL); - add(comps, Topics.ATTACK, Op.ADD, Element.FIRE); - add(comps, Topics.ATTACK, Op.ADD, Element.COLD); - add(comps, Topics.ATTACK, Op.ADD, Element.POISON); - - // attack special - add(comps, Topics.PERCENT_OF_MISSING_LIFE_TO_ATTACK, Op.ADD, Element.PHYSICAL); - - // spell - add(comps, Topics.SPELL, Op.MUL); - - add(comps, Topics.SPELL, Op.ADD, Element.PHYSICAL); - add(comps, Topics.SPELL, Op.ADD, Element.FIRE); - add(comps, Topics.SPELL, Op.ADD, Element.COLD); - - // resistance - add(comps, Topics.RESISTANCE, Op.ADD, Element.PHYSICAL); - add(comps, Topics.RESISTANCE, Op.ADD, Element.FIRE); - add(comps, Topics.RESISTANCE, Op.ADD, Element.COLD); - add(comps, Topics.RESISTANCE, Op.ADD, Element.POISON); - - // damage taken per round - add(comps, Topics.DAMAGE_TAKEN_PER_ROUND, Op.ADD, Element.PHYSICAL); - add(comps, Topics.DAMAGE_TAKEN_PER_ROUND, Op.ADD, Element.FIRE); - add(comps, Topics.DAMAGE_TAKEN_PER_ROUND, Op.ADD, Element.COLD); - add(comps, Topics.DAMAGE_TAKEN_PER_ROUND, Op.ADD, Element.POISON); - - // debuffs - add(comps, Topics.DAMAGE_TAKEN, Op.MUL); - add(comps, Topics.REDUCED_DAMAGE_DONE, Op.ADD); - add(comps, Topics.ROUNDS_STUNNED, Op.ADD); - - // level - add(comps, Topics.LEVEL, Op.BADD); - } - - function add(Comps memory comps, Topic topic, Op op) internal { - add(comps, topic, op, Element.ALL); - } - - function add(Comps memory comps, Topic topic, Op op, Element element) internal { - add(comps, StatmodPrototype({ topicEntity: topic.toEntity(), op: op, element: element })); - } - - function add(Comps memory comps, StatmodPrototype memory prototype) internal { - uint256 protoEntity = getStatmodProtoEntity(prototype); - comps.proto.set(protoEntity, prototype); - - string memory name = statmodName(comps.rhName, prototype.topicEntity, prototype.op, prototype.element); - comps.name.set(protoEntity, name); - } -} diff --git a/packages/contracts/_old_src/init/LibInitWheel.sol b/packages/contracts/_old_src/init/LibInitWheel.sol deleted file mode 100644 index a1390895..00000000 --- a/packages/contracts/_old_src/init/LibInitWheel.sol +++ /dev/null @@ -1,42 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; -import { getAddressById } from "solecs/utils.sol"; -import { SingletonID } from "../SingletonID.sol"; - -import { WheelComponent, ID as WheelComponentID, WheelData } from "../wheel/WheelComponent.sol"; -import { DefaultWheelComponent, ID as DefaultWheelComponentID } from "../wheel/DefaultWheelComponent.sol"; -import { NameComponent, ID as NameComponentID } from "../common/NameComponent.sol"; - -library LibInitWheel { - error GuisePrototypeInitSystem__InvalidSkill(); - - function init(IWorld world) internal { - uint256 wheelEntity = add( - world, - "Wheel of Attainment", - WheelData({ totalIdentityRequired: 0, charges: 3, isIsolated: false }) - ); - - DefaultWheelComponent defaultWheel = DefaultWheelComponent( - getAddressById(world.components(), DefaultWheelComponentID) - ); - defaultWheel.set(SingletonID, wheelEntity); - - add(world, "Wheel of Isolation", WheelData({ totalIdentityRequired: 128, charges: 4, isIsolated: true })); - } - - function add(IWorld world, string memory name, WheelData memory wheelData) internal returns (uint256 entity) { - IUint256Component components = world.components(); - WheelComponent wheelComp = WheelComponent(getAddressById(components, WheelComponentID)); - NameComponent nameComp = NameComponent(getAddressById(components, NameComponentID)); - - entity = world.getUniqueEntityId(); - - wheelComp.set(entity, wheelData); - nameComp.set(entity, name); - } -} diff --git a/packages/contracts/_old_src/libraries/LibArray.sol b/packages/contracts/_old_src/libraries/LibArray.sol deleted file mode 100644 index 3050e1aa..00000000 --- a/packages/contracts/_old_src/libraries/LibArray.sol +++ /dev/null @@ -1,29 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -library LibArray { - function isIn(uint256 entity, uint256[] memory array) internal pure returns (bool) { - for (uint256 i; i < array.length; i++) { - if (array[i] == entity) return true; - } - return false; - } - - function concat(uint256[] memory array1, uint256[] memory array2) internal pure returns (uint256[] memory result) { - if (array1.length == 0) return array2; - if (array2.length == 0) return array1; - - uint256 totalIndex; - result = new uint256[](array1.length + array2.length); - for (uint256 i; i < array1.length; i++) { - result[totalIndex] = array1[i]; - totalIndex++; - } - for (uint256 i; i < array2.length; i++) { - result[totalIndex] = array2[i]; - totalIndex++; - } - return result; - } -} diff --git a/packages/contracts/_old_src/loot/LibLootEquipment.sol b/packages/contracts/_old_src/loot/LibLootEquipment.sol deleted file mode 100644 index 0a959d43..00000000 --- a/packages/contracts/_old_src/loot/LibLootEquipment.sol +++ /dev/null @@ -1,117 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { EquipmentPrototypes } from "../equipment/EquipmentPrototypes.sol"; -import { AffixPartId } from "../affix/AffixNamingComponent.sol"; - -library LibLootEquipment { - error LibLootEquipment__InvalidIlvl(); - error LibLootEquipment__InvalidWeights(); - - /// @dev Hardcoded ilvl => AffixPartsIds mapping - function getAffixPartIds(uint256 ilvl) internal pure returns (AffixPartId[] memory result) { - if (ilvl == 0) { - revert LibLootEquipment__InvalidIlvl(); - } else if (ilvl <= 4) { - result = new AffixPartId[](1); - result[0] = AffixPartId.IMPLICIT; - } else if (ilvl <= 8) { - result = new AffixPartId[](2); - result[0] = AffixPartId.IMPLICIT; - result[1] = AffixPartId.PREFIX; - } else if (ilvl <= 12) { - result = new AffixPartId[](3); - result[0] = AffixPartId.IMPLICIT; - result[1] = AffixPartId.PREFIX; - result[2] = AffixPartId.SUFFIX; - } else { - revert LibLootEquipment__InvalidIlvl(); - } - } - - /// @dev Randomly pick an equipment prototype. - /// (Hardcoded ilvl => EquipmentPrototype) - function pickEquipmentPrototype(uint256 ilvl, uint256 randomness) internal pure returns (uint256) { - randomness = uint256(keccak256(abi.encode(keccak256("pickEquipmentPrototype"), randomness))); - - uint256[] memory b; - uint256[] memory w; - - if (ilvl == 0) { - revert LibLootEquipment__InvalidIlvl(); - } else if (ilvl <= 4) { - b = new uint256[](5); - w = new uint256[](5); - b[0] = EquipmentPrototypes.WEAPON; - w[0] = 32; - b[1] = EquipmentPrototypes.SHIELD; - w[1] = 16; - b[2] = EquipmentPrototypes.CLOTHING; - w[2] = 32; - b[3] = EquipmentPrototypes.PANTS; - w[3] = 16; - b[4] = EquipmentPrototypes.BOOTS; - w[4] = 16; - } else if (ilvl <= 8) { - b = new uint256[](7); - w = new uint256[](7); - b[0] = EquipmentPrototypes.WEAPON; - w[0] = 32; - b[1] = EquipmentPrototypes.SHIELD; - w[1] = 32; - b[2] = EquipmentPrototypes.CLOTHING; - w[2] = 32; - b[3] = EquipmentPrototypes.GLOVES; - w[3] = 16; - b[4] = EquipmentPrototypes.PANTS; - w[4] = 32; - b[5] = EquipmentPrototypes.BOOTS; - w[5] = 32; - b[6] = EquipmentPrototypes.RING; - w[6] = 4; - } else if (ilvl <= 16) { - b = new uint256[](9); - w = new uint256[](9); - b[0] = EquipmentPrototypes.WEAPON; - w[0] = 32; - b[1] = EquipmentPrototypes.SHIELD; - w[1] = 32; - b[2] = EquipmentPrototypes.HAT; - w[2] = 16; - b[3] = EquipmentPrototypes.CLOTHING; - w[3] = 32; - b[4] = EquipmentPrototypes.GLOVES; - w[4] = 32; - b[5] = EquipmentPrototypes.PANTS; - w[5] = 32; - b[6] = EquipmentPrototypes.BOOTS; - w[6] = 32; - b[7] = EquipmentPrototypes.AMULET; - w[7] = 4; - b[8] = EquipmentPrototypes.RING; - w[8] = 8; - } else { - revert LibLootEquipment__InvalidIlvl(); - } - - uint256 index = _sampleIndex(randomness, w); - return b[index]; - } - - /// @dev Weighted sample. - function _sampleIndex(uint256 randomness, uint256[] memory weights) private pure returns (uint256) { - uint256 totalWeight; - for (uint256 i; i < weights.length; i++) { - totalWeight += weights[i]; - } - uint256 roll = randomness % totalWeight; - for (uint256 i; i < weights.length; i++) { - totalWeight -= weights[i]; - if (roll >= totalWeight) { - return i; - } - } - revert LibLootEquipment__InvalidWeights(); - } -} diff --git a/packages/contracts/_old_src/loot/LibLootMap.sol b/packages/contracts/_old_src/loot/LibLootMap.sol deleted file mode 100644 index 5df9913b..00000000 --- a/packages/contracts/_old_src/loot/LibLootMap.sol +++ /dev/null @@ -1,40 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { AffixPartId } from "../affix/AffixNamingComponent.sol"; - -library LibLootMap { - error LibLootMap__InvalidIlvl(); - - /// @dev Hardcoded ilvl => AffixPartsIds mapping - function getAffixPartIds(uint256 ilvl) internal pure returns (AffixPartId[] memory result) { - if (ilvl == 0) { - revert LibLootMap__InvalidIlvl(); - } else if (ilvl <= 4) { - result = new AffixPartId[](2); - result[0] = AffixPartId.IMPLICIT; - result[1] = AffixPartId.PREFIX; - } else if (ilvl <= 8) { - result = new AffixPartId[](3); - result[0] = AffixPartId.IMPLICIT; - result[1] = AffixPartId.PREFIX; - result[2] = AffixPartId.SUFFIX; - } else if (ilvl <= 12) { - result = new AffixPartId[](4); - result[0] = AffixPartId.IMPLICIT; - result[1] = AffixPartId.PREFIX; - result[2] = AffixPartId.SUFFIX; - result[3] = AffixPartId.PREFIX; - } else if (ilvl <= 16) { - result = new AffixPartId[](5); - result[0] = AffixPartId.IMPLICIT; - result[1] = AffixPartId.PREFIX; - result[2] = AffixPartId.SUFFIX; - result[3] = AffixPartId.PREFIX; - result[4] = AffixPartId.SUFFIX; - } else { - revert LibLootMap__InvalidIlvl(); - } - } -} diff --git a/packages/contracts/_old_src/loot/LibLootMint.sol b/packages/contracts/_old_src/loot/LibLootMint.sol deleted file mode 100644 index 39111c37..00000000 --- a/packages/contracts/_old_src/loot/LibLootMint.sol +++ /dev/null @@ -1,71 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { LibPickAffixes, AffixPartId } from "../affix/LibPickAffixes.sol"; - -import { Loot, LootComponent, ID as LootComponentID } from "./LootComponent.sol"; -import { EffectRemovability, EffectPrototype, LibEffectPrototype } from "../effect/LibEffectPrototype.sol"; - -library LibLootMint { - function randomLootMint( - IUint256Component components, - AffixPartId[] memory affixPartIds, - uint256 lootEntity, - uint256 targetEntity, - uint32 ilvl, - uint256 randomness - ) internal { - uint256[] memory excludeAffixes; - randomLootMint(components, affixPartIds, excludeAffixes, lootEntity, targetEntity, ilvl, randomness); - } - - function randomLootMint( - IUint256Component components, - AffixPartId[] memory affixPartIds, - uint256[] memory excludeAffixes, - uint256 lootEntity, - uint256 targetEntity, - uint32 ilvl, - uint256 randomness - ) internal { - // pick affixes - ( - uint256[] memory statmodProtoEntities, - uint256[] memory affixProtoEntities, - uint32[] memory affixValues - ) = LibPickAffixes.pickAffixes(components, affixPartIds, excludeAffixes, targetEntity, ilvl, randomness); - // mint picked affixes - lootMint(components, lootEntity, ilvl, affixPartIds, statmodProtoEntities, affixProtoEntities, affixValues); - } - - function lootMint( - IUint256Component components, - uint256 lootEntity, - uint32 ilvl, - AffixPartId[] memory affixPartIds, - uint256[] memory statmodProtoEntities, - uint256[] memory affixProtoEntities, - uint32[] memory affixValues - ) internal { - // save loot-specific data - LootComponent lootComp = LootComponent(getAddressById(components, LootComponentID)); - lootComp.set( - lootEntity, - Loot({ ilvl: ilvl, affixPartIds: affixPartIds, affixProtoEntities: affixProtoEntities, affixValues: affixValues }) - ); - // save loot as an effect prototype (the effect triggers on-equip) - LibEffectPrototype.verifiedSet( - components, - lootEntity, - EffectPrototype({ - removability: EffectRemovability.PERSISTENT, - statmodProtoEntities: statmodProtoEntities, - statmodValues: affixValues - }) - ); - } -} diff --git a/packages/contracts/_old_src/loot/LibLootOwner.sol b/packages/contracts/_old_src/loot/LibLootOwner.sol deleted file mode 100644 index 1da4a16d..00000000 --- a/packages/contracts/_old_src/loot/LibLootOwner.sol +++ /dev/null @@ -1,37 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; -import { getAddressById, addressToEntity } from "solecs/utils.sol"; - -import { OwnedByComponent, ID as OwnedByComponentID } from "../common/OwnedByComponent.sol"; -import { WNFTSystem, ID as WNFTSystemID } from "../token/WNFTSystem.sol"; - -import { LibToken } from "../token/LibToken.sol"; - -library LibLootOwner { - /// @dev Sets OwnedByComponent. - /// (any entity can be the owner, no default user-facing transfer functions) - function setSimpleOwnership(IUint256Component components, uint256 lootEntity, uint256 ownerEntity) internal { - OwnedByComponent ownedByComp = OwnedByComponent(getAddressById(components, OwnedByComponentID)); - ownedByComp.set(lootEntity, ownerEntity); - } - - /// @dev Mints an ERC721 token with `lootEntity` as the id. - /// (only an address can be the owner, full ERC721 interface by default) - function setTradeableOwnership(IUint256Component systems, uint256 lootEntity, address ownerAccount) internal { - WNFTSystem wnftSystem = WNFTSystem(getAddressById(systems, WNFTSystemID)); - wnftSystem.executeSafeMint(ownerAccount, lootEntity, ""); - } - - function ownerOf(IUint256Component components, uint256 lootEntity) internal view returns (uint256) { - address ownerAccount = LibToken.ownerOf(components, lootEntity); - if (ownerAccount != address(0)) { - return addressToEntity(ownerAccount); - } else { - OwnedByComponent ownedByComp = OwnedByComponent(getAddressById(components, OwnedByComponentID)); - return ownedByComp.getValue(lootEntity); - } - } -} diff --git a/packages/contracts/_old_src/loot/LootComponent.sol b/packages/contracts/_old_src/loot/LootComponent.sol deleted file mode 100644 index 459381ee..00000000 --- a/packages/contracts/_old_src/loot/LootComponent.sol +++ /dev/null @@ -1,62 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { LibTypes } from "solecs/LibTypes.sol"; -import { Component } from "solecs/Component.sol"; - -import { AffixPartId } from "../affix/LibPickAffixes.sol"; - -uint256 constant ID = uint256(keccak256("component.Loot")); - -struct Loot { - uint32 ilvl; - AffixPartId[] affixPartIds; - uint256[] affixProtoEntities; - uint32[] affixValues; -} - -contract LootComponent is Component { - constructor(address world) Component(world, ID) {} - - function getSchema() public pure override returns (string[] memory keys, LibTypes.SchemaValue[] memory values) { - keys = new string[](4); - values = new LibTypes.SchemaValue[](4); - - keys[0] = "ilvl"; - values[0] = LibTypes.SchemaValue.UINT32; - - // TODO I don't really like this enum array - keys[1] = "affixPartIds"; - values[1] = LibTypes.SchemaValue.UINT8_ARRAY; - - keys[2] = "affixProtoEntities"; - values[2] = LibTypes.SchemaValue.UINT256_ARRAY; - - keys[3] = "affixValues"; - values[3] = LibTypes.SchemaValue.UINT32_ARRAY; - } - - function set(uint256 entity, Loot memory value) public { - set(entity, _encode(value)); - } - - function getValue(uint256 entity) public view returns (Loot memory) { - ( - uint32 ilvl, - AffixPartId[] memory affixPartIds, - uint256[] memory affixProtoEntities, - uint32[] memory affixValues - ) = abi.decode(getRawValue(entity), (uint32, AffixPartId[], uint256[], uint32[])); - - return Loot(ilvl, affixPartIds, affixProtoEntities, affixValues); - } - - function getEntitiesWithValue(Loot memory value) public view returns (uint256[] memory) { - return getEntitiesWithValue(_encode(value)); - } - - function _encode(Loot memory value) internal pure returns (bytes memory) { - return abi.encode(value.ilvl, value.affixPartIds, value.affixProtoEntities, value.affixValues); - } -} diff --git a/packages/contracts/_old_src/loot/RandomEquipmentSubSystem.sol b/packages/contracts/_old_src/loot/RandomEquipmentSubSystem.sol deleted file mode 100644 index ec2503c4..00000000 --- a/packages/contracts/_old_src/loot/RandomEquipmentSubSystem.sol +++ /dev/null @@ -1,49 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { getAddressById } from "solecs/utils.sol"; -import { Subsystem } from "@dk1a/solecslib/contracts/mud/Subsystem.sol"; - -import { FromPrototypeComponent, ID as FromPrototypeComponentID } from "../common/FromPrototypeComponent.sol"; - -import { LibLootEquipment } from "./LibLootEquipment.sol"; -import { LibLootMint } from "./LibLootMint.sol"; - -uint256 constant ID = uint256(keccak256("system.RandomEquipment")); - -/// @title Mint a random equippable loot entity. -contract RandomEquipmentSubSystem is Subsystem { - constructor(IWorld _world, address _components) Subsystem(_world, _components) {} - - /// @param ilvl higher ilvl increases the pool of affixes for random generation (higher is better). - /// @param randomness used to randomly pick equipment prototype and affixes. - /// @return lootEntity a new entity. - function executeTyped(uint32 ilvl, uint256 randomness) public returns (uint256 lootEntity) { - return abi.decode(execute(abi.encode(ilvl, randomness)), (uint256)); - } - - function _execute(bytes memory args) internal override returns (bytes memory) { - (uint32 ilvl, uint256 randomness) = abi.decode(args, (uint32, uint256)); - - // pick equipment prototype (it's the targetEntity when getting affix availability) - uint256 equipmentProtoEntity = LibLootEquipment.pickEquipmentPrototype(ilvl, randomness); - // get a new unique id - uint256 lootEntity = world.getUniqueEntityId(); - // make random loot (affixes and effect) - LibLootMint.randomLootMint( - components, - LibLootEquipment.getAffixPartIds(ilvl), - lootEntity, - equipmentProtoEntity, - ilvl, - randomness - ); - // set loot's equipment prototype (to make it equippable) - FromPrototypeComponent fromProtoComp = FromPrototypeComponent(getAddressById(components, FromPrototypeComponentID)); - fromProtoComp.set(lootEntity, equipmentProtoEntity); - - return abi.encode(lootEntity); - } -} diff --git a/packages/contracts/_old_src/loot/RandomMapSubSystem.sol b/packages/contracts/_old_src/loot/RandomMapSubSystem.sol deleted file mode 100644 index e50e6d77..00000000 --- a/packages/contracts/_old_src/loot/RandomMapSubSystem.sol +++ /dev/null @@ -1,48 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { getAddressById } from "solecs/utils.sol"; -import { Subsystem } from "@dk1a/solecslib/contracts/mud/Subsystem.sol"; - -import { FromPrototypeComponent, ID as FromPrototypeComponentID } from "../common/FromPrototypeComponent.sol"; - -import { LibLootMap } from "./LibLootMap.sol"; -import { LibLootMint } from "./LibLootMint.sol"; - -uint256 constant ID = uint256(keccak256("system.RandomMap")); - -/// @title Mint a random map entity. -contract RandomMapSubSystem is Subsystem { - constructor(IWorld _world, address _components) Subsystem(_world, _components) {} - - /// @param ilvl higher ilvl increases the pool of affixes for random generation (higher is better). - /// @param mapProtoEntity map prototype. - /// @param randomness used to randomly pick equipment prototype and affixes. - /// @return lootEntity a new entity. - function executeTyped(uint32 ilvl, uint256 mapProtoEntity, uint256 randomness) public returns (uint256 lootEntity) { - return abi.decode(execute(abi.encode(ilvl, mapProtoEntity, randomness)), (uint256)); - } - - function _execute(bytes memory args) internal override returns (bytes memory) { - (uint32 ilvl, uint256 mapProtoEntity, uint256 randomness) = abi.decode(args, (uint32, uint256, uint256)); - - // get a new unique id - uint256 lootEntity = world.getUniqueEntityId(); - // make random loot (affixes and effect) - LibLootMint.randomLootMint( - components, - LibLootMap.getAffixPartIds(ilvl), - lootEntity, - mapProtoEntity, - ilvl, - randomness - ); - // set loot's map prototype - FromPrototypeComponent fromProtoComp = FromPrototypeComponent(getAddressById(components, FromPrototypeComponentID)); - fromProtoComp.set(lootEntity, mapProtoEntity); - - return abi.encode(lootEntity); - } -} diff --git a/packages/contracts/_old_src/loot/test/RandomEquipmentSubsystem.t.sol b/packages/contracts/_old_src/loot/test/RandomEquipmentSubsystem.t.sol deleted file mode 100644 index e7aa551b..00000000 --- a/packages/contracts/_old_src/loot/test/RandomEquipmentSubsystem.t.sol +++ /dev/null @@ -1,99 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { BaseTest } from "../../BaseTest.sol"; - -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; - -import { Loot } from "../LootComponent.sol"; -import { EffectPrototype, EffectRemovability } from "../../effect/EffectPrototypeComponent.sol"; -import { MAX_ILVL } from "../../init/LibBaseInitAffix.sol"; - -contract RandomEquipmentSubSystemTest is BaseTest { - function setUp() public virtual override { - super.setUp(); - } - - // tests basic assumptions, and that 2 mints don't break each other - function test_randomEquipment_2(uint256 seed1, uint256 seed2) public { - vm.assume(seed1 != seed2); - - uint32 ilvl1 = 1; - uint32 ilvl2 = 5; - - uint256 lootEntity1 = randomEquipmentSubSystem.executeTyped(ilvl1, seed1); - uint256 lootEntity2 = randomEquipmentSubSystem.executeTyped(ilvl2, seed2); - - // check entities - assertNotEq(lootEntity1, lootEntity2); - assertNotEq(lootEntity1, 0); - assertNotEq(lootEntity2, 0); - // check loot-specific data - Loot memory loot1 = lootComponent.getValue(lootEntity1); - Loot memory loot2 = lootComponent.getValue(lootEntity2); - assertEq(loot1.ilvl, ilvl1); - assertEq(loot2.ilvl, ilvl2); - assertEq(loot1.affixProtoEntities.length, 1, "1: affixProtoEntities.length"); - assertEq(loot2.affixProtoEntities.length, 2, "2: affixProtoEntities.length"); - assertEq(loot1.affixValues.length, 1, "1: affixValues.length"); - assertEq(loot2.affixValues.length, 2, "2: affixValues.length"); - // check equipment prototype - uint256 protoEntity1 = fromPrototypeComponent.getValue(lootEntity1); - uint256 protoEntity2 = fromPrototypeComponent.getValue(lootEntity2); - assertTrue(equipmentPrototypeComponent.has(protoEntity1)); - assertTrue(equipmentPrototypeComponent.has(protoEntity2)); - // check effect prototype - EffectPrototype memory effectProto1 = effectPrototypeComponent.getValue(lootEntity1); - EffectPrototype memory effectProto2 = effectPrototypeComponent.getValue(lootEntity2); - assertEq(uint256(effectProto1.removability), uint256(EffectRemovability.PERSISTENT)); - assertEq(uint256(effectProto2.removability), uint256(EffectRemovability.PERSISTENT)); - assertEq(effectProto1.statmodProtoEntities.length, 1, "1: statmodProtoEntities.length"); - assertEq(effectProto2.statmodProtoEntities.length, 2, "2: statmodProtoEntities.length"); - assertEq(abi.encode(effectProto1.statmodValues), abi.encode(loot1.affixValues), "1: statmod values != affix values"); - assertEq(abi.encode(effectProto2.statmodValues), abi.encode(loot2.affixValues), "2: statmod values != affix values"); - } - - // affixes and equipment proto should be identical, but otherwise these should be 2 different entities - function test_randomEquipment_sameSeed(uint256 seed) public { - uint256 lootEntity1 = randomEquipmentSubSystem.executeTyped(1, seed); - uint256 lootEntity2 = randomEquipmentSubSystem.executeTyped(1, seed); - assertNotEq(lootEntity1, lootEntity2); - assertEq(fromPrototypeComponent.getValue(lootEntity1), fromPrototypeComponent.getValue(lootEntity2)); - assertEq( - keccak256(abi.encode(effectPrototypeComponent.getValue(lootEntity1))), - keccak256(abi.encode(effectPrototypeComponent.getValue(lootEntity2))) - ); - } - - // ensure that mint can actually produce different affixes - function test_randomEquipment_differentAffixes() public { - uint256 inequalityCount; - for (uint256 i; i < 1000; i++) { - uint256 seed1 = 1000000 + i; - uint256 seed2 = 2000000 + i; - - uint256 lootEntity1 = randomEquipmentSubSystem.executeTyped(1, seed1); - uint256 lootEntity2 = randomEquipmentSubSystem.executeTyped(1, seed2); - assertNotEq(lootEntity1, lootEntity2); - uint256[] memory affixProtoEntities1 = lootComponent.getValue(lootEntity1).affixProtoEntities; - uint256[] memory affixProtoEntities2 = lootComponent.getValue(lootEntity2).affixProtoEntities; - - bool inequality = keccak256(abi.encode(affixProtoEntities1)) != keccak256(abi.encode(affixProtoEntities2)); - if (inequality) { - inequalityCount++; - } - } - - // at least 45% should be different - // (this does NOT test the actual distribution, which is complicated and dynamic) - assertGt(inequalityCount, 450); - } - - // make sure there're enough affixes to mint the highest ilvl loot - function test_randomEquipment_maxIlvl(uint256 seed) public { - // TODO more affixes, this fails at 13 - uint256 lootEntity = randomEquipmentSubSystem.executeTyped(12 /* should be MAX_ILVL */, seed); - assertEq(lootComponent.getValue(lootEntity).ilvl, 12 /* should be MAX_ILVL */); - } -} \ No newline at end of file diff --git a/packages/contracts/_old_src/map/MapPrototypeComponent.sol b/packages/contracts/_old_src/map/MapPrototypeComponent.sol deleted file mode 100644 index 8396f00b..00000000 --- a/packages/contracts/_old_src/map/MapPrototypeComponent.sol +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { BoolBareComponent } from "std-contracts/components/BoolBareComponent.sol"; - -uint256 constant ID = uint256(keccak256("component.MapPrototype")); - -contract MapPrototypeComponent is BoolBareComponent { - constructor(address world) BoolBareComponent(world, ID) {} -} diff --git a/packages/contracts/_old_src/map/MapPrototypes.sol b/packages/contracts/_old_src/map/MapPrototypes.sol deleted file mode 100644 index 46a849a1..00000000 --- a/packages/contracts/_old_src/map/MapPrototypes.sol +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { ID } from "./MapPrototypeComponent.sol"; - -library MapPrototypes { - uint256 constant GLOBAL_BASIC = uint256(keccak256(abi.encode(ID, "Global Basic"))); - uint256 constant GLOBAL_RANDOM = uint256(keccak256(abi.encode(ID, "Global Random"))); - uint256 constant GLOBAL_CYCLE_BOSS = uint256(keccak256(abi.encode(ID, "Global Cycle Boss"))); -} diff --git a/packages/contracts/_old_src/rng/LibRNG.sol b/packages/contracts/_old_src/rng/LibRNG.sol deleted file mode 100644 index b8be21b4..00000000 --- a/packages/contracts/_old_src/rng/LibRNG.sol +++ /dev/null @@ -1,94 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { RNGPrecommitComponent, ID as RNGPrecommitComponentID } from "./RNGPrecommitComponent.sol"; -import { RNGRequestOwnerComponent, ID as RNGRequestOwnerComponentID } from "./RNGRequestOwnerComponent.sol"; - -/// @dev Simple blockhash rng. -/// Get requestId from `requestRandomness`, then after `WAIT_BLOCKS` call `getRandomness` with that requestId. -/// Do not reuse the same requestId, otherwise it can be predictable. -/// -/// on-chain try+discard - solved with precommits to future block numbers. -/// 256 past blocks limit - ignored. Build UX around it. -/// MEV - ignored. Don't use this for high stakes. -/// -/// TODO consider prevrandao, VRF, eip-2935 -library LibRNG { - error LibRNG__InvalidPrecommit(); - error LibRNG__NotRequestOwner(); - - // TODO 0 wait allows 2 txs in a row really fast and is great during local dev, but not exactly safe - // (note that this does not allow same-block retrieval - you can't get current blockhash) - uint256 constant WAIT_BLOCKS = 0; - - function requestRandomness(IWorld world, uint256 requestOwnerEntity) internal returns (uint256 requestId) { - requestId = world.getUniqueEntityId(); - - RNGPrecommitComponent(getAddressById(world.components(), RNGPrecommitComponentID)).set( - requestId, - block.number + WAIT_BLOCKS - ); - - RNGRequestOwnerComponent(getAddressById(world.components(), RNGRequestOwnerComponentID)).set( - requestId, - requestOwnerEntity - ); - - return requestId; - } - - function getRandomness( - IUint256Component components, - uint256 requestOwnerEntity, - uint256 requestId - ) internal view returns (uint256 randomness) { - if (requestOwnerEntity != getRequestOwner(components, requestId)) { - revert LibRNG__NotRequestOwner(); - } - - uint256 precommit = getPrecommit(components, requestId); - - if (!isValid(precommit)) revert LibRNG__InvalidPrecommit(); - - return uint256(blockhash(precommit)); - } - - /** Check permission and remove the request */ - function removeRequest(IUint256Component components, uint256 requestOwnerEntity, uint256 requestId) internal { - if (requestOwnerEntity != getRequestOwner(components, requestId)) { - revert LibRNG__NotRequestOwner(); - } - RNGPrecommitComponent(getAddressById(components, RNGPrecommitComponentID)).remove(requestId); - RNGRequestOwnerComponent(getAddressById(components, RNGRequestOwnerComponentID)).remove(requestId); - } - - function getPrecommit(IUint256Component components, uint256 requestId) internal view returns (uint256 precommit) { - return RNGPrecommitComponent(getAddressById(components, RNGPrecommitComponentID)).getValue(requestId); - } - - function getRequestOwner( - IUint256Component components, - uint256 requestId - ) internal view returns (uint256 requestOwnerEntity) { - return RNGRequestOwnerComponent(getAddressById(components, RNGRequestOwnerComponentID)).getValue(requestId); - } - - function isValid(uint256 precommit) internal view returns (bool) { - return - // must be initialized - precommit != 0 && - // and past the precommitted-to-block - precommit < block.number && - // and not too far past it because blockhash only works for 256 most recent blocks - !isOverBlockLimit(precommit); - } - - function isOverBlockLimit(uint256 precommit) internal view returns (bool) { - return block.number > precommit + 256; - } -} diff --git a/packages/contracts/_old_src/rng/RNGPrecommitComponent.sol b/packages/contracts/_old_src/rng/RNGPrecommitComponent.sol deleted file mode 100644 index 1a76640a..00000000 --- a/packages/contracts/_old_src/rng/RNGPrecommitComponent.sol +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { Uint256Component } from "std-contracts/components/Uint256Component.sol"; - -uint256 constant ID = uint256(keccak256("component.RNGPrecommit")); - -contract RNGPrecommitComponent is Uint256Component { - constructor(address world) Uint256Component(world, ID) {} -} diff --git a/packages/contracts/_old_src/rng/RNGRequestOwnerComponent.sol b/packages/contracts/_old_src/rng/RNGRequestOwnerComponent.sol deleted file mode 100644 index 41318d47..00000000 --- a/packages/contracts/_old_src/rng/RNGRequestOwnerComponent.sol +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { Uint256Component } from "std-contracts/components/Uint256Component.sol"; - -uint256 constant ID = uint256(keccak256("component.RNGRequestOwner")); - -contract RNGRequestOwnerComponent is Uint256Component { - constructor(address world) Uint256Component(world, ID) {} -} diff --git a/packages/contracts/_old_src/rng/test/LibRNG.t.sol b/packages/contracts/_old_src/rng/test/LibRNG.t.sol deleted file mode 100644 index 374d7e95..00000000 --- a/packages/contracts/_old_src/rng/test/LibRNG.t.sol +++ /dev/null @@ -1,109 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; - -import { BaseTest } from "../../BaseTest.sol"; - -import { LibRNG } from "../LibRNG.sol"; - -contract GetRandomnessRevertHelper { - function getRandomness(IUint256Component components, uint256 requestOwner, uint256 requestId) public view { - LibRNG.getRandomness(components, requestOwner, requestId); - } -} - -contract LibRNGTest is BaseTest { - GetRandomnessRevertHelper revertHelper; - uint256 internal constant requestOwner = 123; - - function setUp() public virtual override { - super.setUp(); - - revertHelper = new GetRandomnessRevertHelper(); - } - - function test_getRandomness() public { - uint256 requestId = LibRNG.requestRandomness(world, requestOwner); - vm.roll(block.number + LibRNG.WAIT_BLOCKS + 1); - uint256 randomness = LibRNG.getRandomness(components, requestOwner, requestId); - assertGt(randomness, 0); - assertEq(LibRNG.getRequestOwner(components, requestId), requestOwner); - } - - function test_getRandomness_revert_NotRequestOwner() public { - uint256 requestId = LibRNG.requestRandomness(world, requestOwner); - uint256 notOwner = 987; - - vm.expectRevert(LibRNG.LibRNG__NotRequestOwner.selector); - revertHelper.getRandomness(components, notOwner, requestId); - } - - function test_getRandomness_revert_sameBlock() public { - uint256 requestId = LibRNG.requestRandomness(world, requestOwner); - - vm.expectRevert(LibRNG.LibRNG__InvalidPrecommit.selector); - revertHelper.getRandomness(components, requestOwner, requestId); - } - - /* TODO not relevant while WAIT_BLOCKS = 0 - function test_getRandomness_revert_tooEarly() public { - uint256 requestId = LibRNG.requestRandomness(world, ''); - - vm.roll(block.number + 1); - vm.expectRevert(LibRNG.LibRNG__InvalidPrecommit.selector); - revertHelper.getRandomness(components, requestId); - }*/ - - function test_getRandomness_revert_tooLate() public { - uint256 requestId = LibRNG.requestRandomness(world, requestOwner); - - vm.roll(block.number + LibRNG.WAIT_BLOCKS + 256 + 1); - vm.expectRevert(LibRNG.LibRNG__InvalidPrecommit.selector); - revertHelper.getRandomness(components, requestOwner, requestId); - } - - // basic test for different base blocknumbers - function test_requestRandomness_blocknumbers(uint32 blocknumber) public { - vm.assume(blocknumber != 0); - vm.roll(blocknumber); - uint256 requestId = LibRNG.requestRandomness(world, requestOwner); - - uint256 precommit = LibRNG.getPrecommit(components, requestId); - assertEq(precommit, blocknumber + LibRNG.WAIT_BLOCKS); - assertEq(LibRNG.getRequestOwner(components, requestId), requestOwner); - - uint256 newBlocknumber = uint256(blocknumber) + 10; - vm.roll(newBlocknumber); - precommit = LibRNG.getPrecommit(components, requestId); - assertLt(precommit, newBlocknumber); - assertEq(LibRNG.getRequestOwner(components, requestId), requestOwner); - assertTrue(LibRNG.isValid(precommit)); - } - - // thorough validity test for the possible offsets - function test_requestRandomness_validity() public { - uint256 initBlock = 1; - vm.roll(initBlock); - - uint256 requestId = LibRNG.requestRandomness(world, requestOwner); - uint256 precommit = LibRNG.getPrecommit(components, requestId); - - for (uint256 i = initBlock; i < initBlock + 270; i++) { - vm.roll(i); - if (i <= initBlock + LibRNG.WAIT_BLOCKS) { - assertFalse(LibRNG.isValid(precommit)); - assertEq(uint256(blockhash(precommit)), 0); - } else if (i <= initBlock + LibRNG.WAIT_BLOCKS + 256) { - assertTrue(LibRNG.isValid(precommit)); - assertFalse(LibRNG.isOverBlockLimit(precommit)); - assertNotEq(uint256(blockhash(precommit)), 0); - } else { - assertFalse(LibRNG.isValid(precommit)); - assertTrue(LibRNG.isOverBlockLimit(precommit)); - assertEq(uint256(blockhash(precommit)), 0); - } - } - } -} diff --git a/packages/contracts/_old_src/skill/LearnedSkillsComponent.sol b/packages/contracts/_old_src/skill/LearnedSkillsComponent.sol deleted file mode 100644 index d3a23c8a..00000000 --- a/packages/contracts/_old_src/skill/LearnedSkillsComponent.sol +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { Uint256SetComponent } from "../Uint256SetComponent.sol"; - -uint256 constant ID = uint256(keccak256("component.LearnedSkills")); - -contract LearnedSkillsComponent is Uint256SetComponent { - constructor(address world) Uint256SetComponent(world, ID) {} -} diff --git a/packages/contracts/_old_src/skill/LibLearnedSkills.sol b/packages/contracts/_old_src/skill/LibLearnedSkills.sol deleted file mode 100644 index aef3a39e..00000000 --- a/packages/contracts/_old_src/skill/LibLearnedSkills.sol +++ /dev/null @@ -1,72 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { LearnedSkillsComponent, ID as LearnedSkillsComponentID } from "./LearnedSkillsComponent.sol"; - -import { SkillType } from "./SkillPrototypeComponent.sol"; -import { LibSkill } from "./LibSkill.sol"; - -library LibLearnedSkills { - using LibSkill for LibSkill.Self; - - error LibLearnedSkills__LearnSkillDuplicate(); - - struct Self { - IWorld world; - LearnedSkillsComponent comp; - uint256 userEntity; - } - - function __construct(IWorld world, uint256 userEntity) internal view returns (Self memory) { - IUint256Component components = world.components(); - return - Self({ - world: world, - comp: LearnedSkillsComponent(getAddressById(components, LearnedSkillsComponentID)), - userEntity: userEntity - }); - } - - function hasSkill(Self memory __self, uint256 skillEntity) internal view returns (bool) { - return __self.comp.hasItem(__self.userEntity, skillEntity); - } - - /** - * @dev Add `skillEntity` to set of learned skills, revert if it's already learned - */ - function learnSkill(Self memory __self, uint256 skillEntity) internal { - if (__self.comp.hasItem(__self.userEntity, skillEntity)) { - revert LibLearnedSkills__LearnSkillDuplicate(); - } - - __self.comp.addItem(__self.userEntity, skillEntity); - - _autotoggleIfPassive(__self, skillEntity); - } - - /** - * @dev Copy skills from source to target. Overwrites target's existing skills - */ - function copySkills(Self memory __self, uint256 sourceEntity) internal { - if (__self.comp.has(sourceEntity)) { - uint256[] memory skillEntities = __self.comp.getValue(sourceEntity); - __self.comp.set(__self.userEntity, skillEntities); - - for (uint256 i; i < skillEntities.length; i++) { - _autotoggleIfPassive(__self, skillEntities[i]); - } - } - } - - function _autotoggleIfPassive(Self memory __self, uint256 skillEntity) private { - LibSkill.Self memory libSkill = LibSkill.__construct(__self.world, __self.userEntity, skillEntity); - if (libSkill.skill.skillType == SkillType.PASSIVE) { - libSkill.useSkill(__self.userEntity); - } - } -} diff --git a/packages/contracts/_old_src/skill/LibSkill.sol b/packages/contracts/_old_src/skill/LibSkill.sol deleted file mode 100644 index c0efa8e7..00000000 --- a/packages/contracts/_old_src/skill/LibSkill.sol +++ /dev/null @@ -1,149 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { DurationSubSystem, ID as DurationSubSystemID, ScopedDuration, SystemCallback } from "../duration/DurationSubSystem.sol"; -import { EffectSubSystem, ID as EffectSubSystemID } from "../effect/EffectSubSystem.sol"; -import { EffectPrototypeComponent, ID as EffectPrototypeComponentID } from "../effect/EffectPrototypeComponent.sol"; -import { LearnedSkillsComponent, ID as LearnedSkillsComponentID } from "./LearnedSkillsComponent.sol"; -import { LibLearnedSkills } from "./LibLearnedSkills.sol"; -import { LibCharstat } from "../charstat/LibCharstat.sol"; -import { SkillType, TargetType, SkillPrototype, SkillPrototypeComponent, ID as SkillPrototypeComponentID } from "./SkillPrototypeComponent.sol"; - -library LibSkill { - using LibCharstat for LibCharstat.Self; - using LibLearnedSkills for LibLearnedSkills.Self; - - error LibSkill__SkillMustBeLearned(); - error LibSkill__SkillOnCooldown(); - error LibSkill__NotEnoughMana(); - error LibSkill__InvalidSkillTarget(); - error LibSkill__RequiredCombat(); - error LibSkill__RequiredNonCombat(); - - struct Self { - IWorld world; - SkillPrototypeComponent protoComp; - LibCharstat.Self charstat; - LibLearnedSkills.Self learnedSkills; - uint256 userEntity; - uint256 skillEntity; - SkillPrototype skill; - } - - function __construct(IWorld world, uint256 userEntity, uint256 skillEntity) internal view returns (Self memory) { - IUint256Component components = world.components(); - SkillPrototypeComponent protoComp = SkillPrototypeComponent(getAddressById(components, SkillPrototypeComponentID)); - - return - Self({ - world: world, - protoComp: protoComp, - charstat: LibCharstat.__construct(components, userEntity), - learnedSkills: LibLearnedSkills.__construct(world, userEntity), - userEntity: userEntity, - skillEntity: skillEntity, - skill: protoComp.getValue(skillEntity) - }); - } - - /** - * @dev Change Self to use a different skill prototype - */ - function switchSkill(Self memory __self, uint256 skillEntity) internal view returns (Self memory) { - __self.skillEntity = skillEntity; - __self.skill = __self.protoComp.getValue(skillEntity); - return __self; - } - - function requireCombat(Self memory __self) internal pure { - if (__self.skill.skillType != SkillType.COMBAT) { - revert LibSkill__RequiredCombat(); - } - } - - function requireNonCombat(Self memory __self) internal pure { - if (__self.skill.skillType == SkillType.COMBAT) { - revert LibSkill__RequiredNonCombat(); - } - } - - /** - * @dev Combat skills may target either self or enemy, depending on skill prototype - */ - function chooseCombatTarget(Self memory __self, uint256 enemyEntity) internal pure returns (uint256) { - if (__self.skill.effectTarget == TargetType.SELF || __self.skill.effectTarget == TargetType.SELF_OR_ALLY) { - // self - return __self.userEntity; - } else if (__self.skill.effectTarget == TargetType.ENEMY) { - // enemy - return enemyEntity; - } else { - revert LibSkill__InvalidSkillTarget(); - } - } - - /** - * @dev Check some requirements, subtract cost, start cooldown, apply effect. - * However this method is NOT combat aware and doesn't do attack/spell damage - */ - function useSkill(Self memory __self, uint256 targetEntity) internal { - // must be learned - if (!__self.learnedSkills.hasSkill(__self.skillEntity)) { - revert LibSkill__SkillMustBeLearned(); - } - // must be off cooldown - DurationSubSystem durationSubSystem = DurationSubSystem( - getAddressById(__self.world.systems(), DurationSubSystemID) - ); - if (durationSubSystem.has(targetEntity, __self.skillEntity)) { - revert LibSkill__SkillOnCooldown(); - } - // verify self-only skill - if (__self.skill.effectTarget == TargetType.SELF && __self.userEntity != targetEntity) { - revert LibSkill__InvalidSkillTarget(); - } - // TODO verify other target types? - - // start cooldown - // (doesn't clash with skill effect duration, which has its own entity) - if (__self.skill.cooldown.timeValue > 0) { - durationSubSystem.executeIncrease(targetEntity, __self.skillEntity, __self.skill.cooldown, SystemCallback(0, "")); - } - - // check and subtract skill cost - uint32 manaCurrent = __self.charstat.getManaCurrent(); - if (__self.skill.cost > manaCurrent) { - revert LibSkill__NotEnoughMana(); - } else if (__self.skill.cost > 0) { - __self.charstat.setManaCurrent(manaCurrent - __self.skill.cost); - } - - _applySkillEffect(__self, targetEntity); - } - - function _applySkillEffect(Self memory __self, uint256 targetEntity) private { - EffectSubSystem effectSubSystem = EffectSubSystem(getAddressById(__self.world.systems(), EffectSubSystemID)); - - if (!effectSubSystem.isEffectPrototype(__self.skillEntity)) { - // skip if skill has no effect - return; - } - - if (__self.skill.skillType == SkillType.PASSIVE) { - // toggle passive skill - if (effectSubSystem.has(targetEntity, __self.skillEntity)) { - effectSubSystem.executeRemove(targetEntity, __self.skillEntity); - } else { - effectSubSystem.executeApply(targetEntity, __self.skillEntity); - } - } else { - // apply active skill - effectSubSystem.executeApplyTimed(targetEntity, __self.skillEntity, __self.skill.duration); - } - } -} diff --git a/packages/contracts/_old_src/skill/NoncombatSkillSystem.sol b/packages/contracts/_old_src/skill/NoncombatSkillSystem.sol deleted file mode 100644 index f08b7484..00000000 --- a/packages/contracts/_old_src/skill/NoncombatSkillSystem.sol +++ /dev/null @@ -1,44 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { System } from "solecs/System.sol"; -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { FromPrototypeComponent, ID as FromPrototypeComponentID } from "../common/FromPrototypeComponent.sol"; -import { Action, ActionType, CombatSubSystem, ID as CombatSubSystemID } from "../combat/CombatSubSystem.sol"; -import { EffectSubSystem, ID as EffectSubSystemID } from "../effect/EffectSubSystem.sol"; - -import { MapPrototypes } from "../map/MapPrototypes.sol"; -import { LibActiveCombat } from "../combat/LibActiveCombat.sol"; -import { LibCharstat } from "../charstat/LibCharstat.sol"; -import { LibSkill } from "../skill/LibSkill.sol"; -import { LibCycle } from "../cycle/LibCycle.sol"; - -uint256 constant ID = uint256(keccak256("system.NoncombatSkill")); - -contract NoncombatSkillSystem is System { - using LibSkill for LibSkill.Self; - - error NoncombatSkillSystem__Asd(); - - constructor(IWorld _world, address _components) System(_world, _components) {} - - function executeTyped(uint256 cycleEntity, uint256 skillEntity) public { - execute(abi.encode(cycleEntity, skillEntity)); - } - - function execute(bytes memory args) public override returns (bytes memory) { - (uint256 cycleEntity, uint256 skillEntity) = abi.decode(args, (uint256, uint256)); - - LibCycle.requirePermission(components, cycleEntity); - - LibSkill.Self memory libSkill = LibSkill.__construct(world, cycleEntity, skillEntity); - libSkill.requireNonCombat(); - - libSkill.useSkill(cycleEntity); - - return ""; - } -} diff --git a/packages/contracts/_old_src/skill/SkillDescriptionComponent.sol b/packages/contracts/_old_src/skill/SkillDescriptionComponent.sol deleted file mode 100644 index 53154447..00000000 --- a/packages/contracts/_old_src/skill/SkillDescriptionComponent.sol +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { StringBareComponent } from "std-contracts/components/StringBareComponent.sol"; - -uint256 constant ID = uint256(keccak256("component.SkillDescription")); - -contract SkillDescriptionComponent is StringBareComponent { - constructor(address world) StringBareComponent(world, ID) {} -} diff --git a/packages/contracts/_old_src/skill/SkillPrototypeComponent.sol b/packages/contracts/_old_src/skill/SkillPrototypeComponent.sol deleted file mode 100644 index 5b606c4e..00000000 --- a/packages/contracts/_old_src/skill/SkillPrototypeComponent.sol +++ /dev/null @@ -1,113 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { LibTypes } from "solecs/LibTypes.sol"; -import { BareComponent } from "solecs/BareComponent.sol"; - -import { EL_L } from "../statmod/StatmodPrototypeComponent.sol"; -import { ScopedDuration } from "../duration/DurationSubSystem.sol"; - -uint256 constant ID = uint256(keccak256("component.SkillPrototype")); - -/** - * @dev Skill protoEntity = hashed(ID, name) - */ -function getSkillProtoEntity(string memory name) pure returns (uint256) { - return uint256(keccak256(abi.encode(ID, name))); -} - -enum SkillType { - COMBAT, - NONCOMBAT, - PASSIVE -} -enum TargetType { - SELF, - ENEMY, - ALLY, - SELF_OR_ALLY -} -struct SkillPrototype { - // level required to learn it - uint8 requiredLevel; - // when/how can it be used - SkillType skillType; - // by default a skill only applies effects - // flag to also trigger an attack afterwards (base attack damage is not based on the skill) - bool withAttack; - // flag to also trigger a spell afterwards (base spell damage is the skill's `spellDamage`) - bool withSpell; - // mana cost to be subtracted on use - uint32 cost; - // duration of effect (important only if modifiers are present) - ScopedDuration duration; - // cooldown of skill - ScopedDuration cooldown; - // who can it be used on (also affects resulting effect's removability) - TargetType effectTarget; - // used only if withSpell == true - uint32[EL_L] spellDamage; -} - -contract SkillPrototypeComponent is BareComponent { - constructor(address world) BareComponent(world, ID) {} - - function getSchema() public pure override returns (string[] memory keys, LibTypes.SchemaValue[] memory values) { - keys = new string[](5 + 2 + 2 + 1 + EL_L); - values = new LibTypes.SchemaValue[](5 + 2 + 2 + 1 + EL_L); - - keys[0] = "requiredLevel"; - values[0] = LibTypes.SchemaValue.UINT8; - - keys[1] = "skillType"; - values[1] = LibTypes.SchemaValue.UINT8; - - keys[2] = "withAttack"; - values[2] = LibTypes.SchemaValue.BOOL; - - keys[3] = "withSpell"; - values[3] = LibTypes.SchemaValue.BOOL; - - keys[4] = "cost"; - values[4] = LibTypes.SchemaValue.UINT32; - - keys[5] = "duration_timeScopeId"; - values[5] = LibTypes.SchemaValue.UINT256; - - keys[6] = "duration_timeValue"; - values[6] = LibTypes.SchemaValue.UINT256; - - keys[7] = "cooldown_timeScopeId"; - values[7] = LibTypes.SchemaValue.UINT256; - - keys[8] = "cooldown_timeValue"; - values[8] = LibTypes.SchemaValue.UINT256; - - keys[9] = "effectTarget"; - values[9] = LibTypes.SchemaValue.UINT8; - - keys[10] = "spellDamage_all"; - values[10] = LibTypes.SchemaValue.UINT32; - - keys[11] = "spellDamage_physical"; - values[11] = LibTypes.SchemaValue.UINT32; - - keys[12] = "spellDamage_fire"; - values[12] = LibTypes.SchemaValue.UINT32; - - keys[13] = "spellDamage_cold"; - values[13] = LibTypes.SchemaValue.UINT32; - - keys[14] = "spellDamage_poison"; - values[14] = LibTypes.SchemaValue.UINT32; - } - - function set(uint256 entity, SkillPrototype memory value) public { - set(entity, abi.encode(value)); - } - - function getValue(uint256 entity) public view returns (SkillPrototype memory) { - return abi.decode(getRawValue(entity), (SkillPrototype)); - } -} diff --git a/packages/contracts/_old_src/skill/test/LibSkill.t.sol b/packages/contracts/_old_src/skill/test/LibSkill.t.sol deleted file mode 100644 index a5455fb3..00000000 --- a/packages/contracts/_old_src/skill/test/LibSkill.t.sol +++ /dev/null @@ -1,172 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { BaseTest } from "../../BaseTest.sol"; - -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; - -import { ScopedDuration } from "../../duration/DurationSubSystem.sol"; -import { getSkillProtoEntity } from "../SkillPrototypeComponent.sol"; -import { getEffectEntity } from "../../effect/EffectSubSystem.sol"; - -import { LibSkill } from "../LibSkill.sol"; -import { LibLearnedSkills } from "../LibLearnedSkills.sol"; -import { LibCharstat, Element } from "../../charstat/LibCharstat.sol"; -import { LibExperience, PStat, PS_L } from "../../charstat/LibExperience.sol"; - -// can't expectRevert internal calls, so this is an external wrapper -contract LibSkillRevertHelper { - using LibSkill for LibSkill.Self; - - function useSkill(LibSkill.Self memory libSkill, uint256 targetEntity) public { - libSkill.useSkill(targetEntity); - } -} - -contract LibSkillTest is BaseTest { - using LibSkill for LibSkill.Self; - using LibLearnedSkills for LibLearnedSkills.Self; - using LibCharstat for LibCharstat.Self; - - // helpers - LibSkillRevertHelper revertHelper; - - // libs - LibCharstat.Self charstat; - LibLearnedSkills.Self learnedSkills; - - uint256 userEntity = uint256(keccak256("userEntity")); - uint256 otherEntity = uint256(keccak256("otherEntity")); - - // sample skill entities - uint256 cleavePE = getSkillProtoEntity("Cleave"); - uint256 chargePE = getSkillProtoEntity("Charge"); - uint256 parryPE = getSkillProtoEntity("Parry"); - uint256 someInvalidSkillPE = getSkillProtoEntity("someInvalidSkill"); - - function setUp() public virtual override { - super.setUp(); - - IUint256Component components = world.components(); - // init helpers and libs - revertHelper = new LibSkillRevertHelper(); - charstat = LibCharstat.__construct(components, userEntity); - learnedSkills = LibLearnedSkills.__construct(world, userEntity); - - // give user some mana - charstat.setManaCurrent(4); - // allow user to receive experience - LibExperience.initExp(charstat.exp); - - // learn sample skills - learnedSkills.learnSkill(cleavePE); - learnedSkills.learnSkill(chargePE); - learnedSkills.learnSkill(parryPE); - } - - function _libSkill(uint256 skillEntity) internal view returns (LibSkill.Self memory) { - return LibSkill.__construct(world, userEntity, skillEntity); - } - - function test_setUp() public { - assertTrue(learnedSkills.hasSkill(cleavePE)); - assertTrue(learnedSkills.hasSkill(chargePE)); - assertTrue(learnedSkills.hasSkill(parryPE)); - - assertEq(charstat.getMana(), 4); - } - - function test_hasSkill_invalidSkill() public { - assertFalse(learnedSkills.hasSkill(someInvalidSkillPE)); - } - - function test_useSkill_invalidTarget() public { - // user is the only valid target for charge - LibSkill.Self memory libSkill = _libSkill(chargePE); - vm.expectRevert(LibSkill.LibSkill__InvalidSkillTarget.selector); - revertHelper.useSkill(libSkill, otherEntity); - } - - // TODO mana stuff isn't very skill-related? - function test_setManaCurrent_capped() public { - charstat.setManaCurrent(100); - assertEq(charstat.getMana(), 4); - } - - function test_useSkill_Charge() public { - _libSkill(chargePE).useSkill(userEntity); - - assertEq(charstat.getManaCurrent(), 4 - 1, "Invalid mana remainder"); - assertTrue(durationSubSystem.has(userEntity, chargePE), "No ongoing cooldown"); - - assertTrue(effectSubSystem.has(userEntity, chargePE), "No ongoing effect"); - } - - function test_useSkill_Cleave_effect() public { - _libSkill(cleavePE).useSkill(userEntity); - assertEq(charstat.getAttack()[uint256(Element.PHYSICAL)], 3); - } - - // str and the 2 skills should all modify physical attack, - // test that it all stacks correctly - function test_useSkill_CleaveAndCharge_strengthStacking() public { - // add exp to get 2 str (which should increase base physical attack to 2) - uint32[PS_L] memory addExp; - addExp[uint256(PStat.STRENGTH)] = LibExperience.getExpForPStat(2); - LibExperience.increaseExp(charstat.exp, addExp); - - // 16%, +2 - LibSkill.Self memory libSkill = _libSkill(cleavePE); - libSkill.useSkill(userEntity); - // 64% - libSkill.switchSkill(chargePE); - libSkill.useSkill(userEntity); - // 2 * 1.8 + 2 - assertEq(charstat.getAttack()[uint256(Element.PHYSICAL)], 5); - } - - // this tests durations, especially DurationSubSystem's effect removal callback - // TODO a lot of this can be removed if effects get their own tests, - // atm the many assertions help tell apart bugs in effectSubSystem and durationSubSystem - function test_useSkill_CleaveAndCharge_onDurationEnd() public { - // add exp to get 2 str (which should increase base physical attack to 2) - uint32[PS_L] memory addExp; - addExp[uint256(PStat.STRENGTH)] = LibExperience.getExpForPStat(2); - LibExperience.increaseExp(charstat.exp, addExp); - - assertEq(charstat.getAttack()[uint256(Element.PHYSICAL)], 2); - - LibSkill.Self memory libSkill = _libSkill(cleavePE); - libSkill.useSkill(userEntity); - libSkill = libSkill.switchSkill(chargePE); - libSkill.useSkill(userEntity); - - assertTrue(durationSubSystem.has(userEntity, getEffectEntity(userEntity, cleavePE))); - assertTrue(durationSubSystem.has(userEntity, getEffectEntity(userEntity, chargePE))); - assertEq(charstat.getAttack()[uint256(Element.PHYSICAL)], 5); - - // decrease cleave duration and cooldown - durationSubSystem.executeDecreaseScope( - userEntity, - ScopedDuration({ timeScopeId: uint256(keccak256("round")), timeValue: 1 }) - ); - - // cooldown - assertFalse(durationSubSystem.has(userEntity, cleavePE)); - // effect - assertFalse(durationSubSystem.has(userEntity, getEffectEntity(userEntity, cleavePE))); - assertTrue(durationSubSystem.has(userEntity, getEffectEntity(userEntity, chargePE))); - assertEq(charstat.getAttack()[uint256(Element.PHYSICAL)], 3); - - // decrease charge duration - durationSubSystem.executeDecreaseScope( - userEntity, - ScopedDuration({ timeScopeId: uint256(keccak256("round_persistent")), timeValue: 1 }) - ); - - assertFalse(durationSubSystem.has(userEntity, getEffectEntity(userEntity, cleavePE))); - assertFalse(durationSubSystem.has(userEntity, getEffectEntity(userEntity, chargePE))); - assertEq(charstat.getAttack()[uint256(Element.PHYSICAL)], 2); - } -} diff --git a/packages/contracts/_old_src/skill/test/SkillPrototypeComponent.t.sol b/packages/contracts/_old_src/skill/test/SkillPrototypeComponent.t.sol deleted file mode 100644 index 9e2e2293..00000000 --- a/packages/contracts/_old_src/skill/test/SkillPrototypeComponent.t.sol +++ /dev/null @@ -1,40 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { BaseTest } from "../../BaseTest.sol"; - -import { SkillType, TargetType, getSkillProtoEntity } from "../SkillPrototypeComponent.sol"; - -contract SkillPrototypeComponentTest is BaseTest { - // sample skill entities - uint256 chargePE = getSkillProtoEntity("Charge"); - uint256 parryPE = getSkillProtoEntity("Parry"); - uint256 cleavePE = getSkillProtoEntity("Cleave"); - - function setUp() public virtual override { - super.setUp(); - } - - // TODO this should be in effect tests (make those) - function test_sample_effectPrototype_statmodLengths() public { - assertEq(effectPrototypeComponent.getValue(chargePE).statmodProtoEntities.length, 1); - assertEq(effectPrototypeComponent.getValue(chargePE).statmodValues.length, 1); - } - - function test_sample_skillPrototype_name() public { - assertEq(nameComponent.getValue(chargePE), "Charge"); - } - - function test_sample_skillPrototype_targetTypes() public { - assertTrue(skillPrototypeComponent.getValue(chargePE).effectTarget == TargetType.SELF); - assertTrue(skillPrototypeComponent.getValue(parryPE).effectTarget == TargetType.SELF); - assertTrue(skillPrototypeComponent.getValue(cleavePE).effectTarget == TargetType.SELF); - } - - function test_sample_skillPrototype_skillTypes() public { - assertTrue(skillPrototypeComponent.getValue(chargePE).skillType == SkillType.NONCOMBAT); - assertTrue(skillPrototypeComponent.getValue(parryPE).skillType == SkillType.PASSIVE); - assertTrue(skillPrototypeComponent.getValue(cleavePE).skillType == SkillType.COMBAT); - } -} diff --git a/packages/contracts/_old_src/statmod/Statmod.sol b/packages/contracts/_old_src/statmod/Statmod.sol deleted file mode 100644 index b6038c65..00000000 --- a/packages/contracts/_old_src/statmod/Statmod.sol +++ /dev/null @@ -1,192 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; -import { getAddressById } from "solecs/utils.sol"; -import { StatmodPrototype, Op, OP_L, OP_FINAL, Element, EL_L, StatmodPrototypeComponent, ID as StatmodPrototypeComponentID } from "./StatmodPrototypeComponent.sol"; - -import { ScopedValue } from "@dk1a/solecslib/contracts/scoped-value/ScopedValue.sol"; -import { FromPrototype } from "@dk1a/solecslib/contracts/prototype/FromPrototype.sol"; -import { ScopedValueFromPrototype } from "@dk1a/solecslib/contracts/scoped-value/ScopedValueFromPrototype.sol"; -import { ID as StatmodScopeComponentID } from "./StatmodScopeComponent.sol"; -import { ID as StatmodValueComponentID } from "./StatmodValueComponent.sol"; -import { ID as FromPrototypeComponentID } from "../common/FromPrototypeComponent.sol"; - -/** - * @title Scoped statmod values with aggregation depending on prototype. - */ -library Statmod { - using ScopedValueFromPrototype for ScopedValueFromPrototype.Self; - - struct Self { - StatmodPrototypeComponent protoComp; - ScopedValueFromPrototype.Self sv; - uint256 targetEntity; - } - - /** - * @param components world.components() - * @param targetEntity context for instances of protoEntities. - * Modifying the same protoEntity with different targetEntities will not affect each other. - */ - function __construct(IUint256Component components, uint256 targetEntity) internal view returns (Self memory) { - return - Self({ - protoComp: StatmodPrototypeComponent(getAddressById(components, StatmodPrototypeComponentID)), - sv: ScopedValueFromPrototype.__construct( - ScopedValue.__construct(components, StatmodScopeComponentID, StatmodValueComponentID), - FromPrototype.__construct( - components, - FromPrototypeComponentID, - // instance context - abi.encode("Statmod", targetEntity) - ) - ), - targetEntity: targetEntity - }); - } - - function _scope(Self memory __self, uint256 topicEntity) private pure returns (string memory) { - return string(abi.encode(__self.targetEntity, topicEntity)); - } - - // ========== WRITE ========== - - /** - * @dev Increase statmod value for instantiated protoEntity. - */ - function increase(Self memory __self, uint256 protoEntity, uint256 value) internal returns (bool isUpdate) { - StatmodPrototype memory prototype = __self.protoComp.getValue(protoEntity); - - return __self.sv.increaseEntity(_scope(__self, prototype.topicEntity), protoEntity, value); - } - - /** - * @dev Decrease statmod value for instantiated protoEntity. - */ - function decrease(Self memory __self, uint256 protoEntity, uint256 value) internal returns (bool isUpdate) { - StatmodPrototype memory prototype = __self.protoComp.getValue(protoEntity); - - return __self.sv.decreaseEntity(_scope(__self, prototype.topicEntity), protoEntity, value); - } - - // ========== READ ========== - - /** - * @dev Sum all statmod values for `topicEntity` - * TODO is this even useful anywhere? - */ - function getTotal(Self memory __self, uint256 topicEntity) internal view returns (uint32 result) { - (, uint256[] memory values) = __self.sv.getEntitiesValues(_scope(__self, topicEntity)); - - for (uint256 i; i < values.length; i++) { - result += uint32(values[i]); - } - } - - /** - * @dev Sum statmod values for `topicEntity`, grouped by Op. - * This method shouldn't usually be needed externally, see getValues. - */ - function getOperands(Self memory __self, uint256 topicEntity) internal view returns (uint32[OP_L] memory result) { - (uint256[] memory protoEntities, uint256[] memory values) = __self.sv.getEntitiesValues( - _scope(__self, topicEntity) - ); - - for (uint256 i; i < protoEntities.length; i++) { - StatmodPrototype memory prototype = __self.protoComp.getValue(protoEntities[i]); - - result[uint256(prototype.op)] += uint32(values[i]); - } - } - - /** - * @dev Sum statmod values for `topicEntity`, grouped by Element and Op. - * This method shouldn't usually be needed externally, see getValuesElemental. - */ - function getOperandsElemental( - Self memory __self, - uint256 topicEntity - ) internal view returns (uint32[EL_L][OP_L] memory result) { - (uint256[] memory protoEntities, uint256[] memory values) = __self.sv.getEntitiesValues( - _scope(__self, topicEntity) - ); - - for (uint256 i; i < protoEntities.length; i++) { - StatmodPrototype memory prototype = __self.protoComp.getValue(protoEntities[i]); - - result[uint256(prototype.op)][uint256(prototype.element)] += uint32(values[i]); - } - - // Element.ALL applies to all other elements at the same time - for (uint256 el; el < EL_L; el++) { - if (el == uint256(Element.ALL)) continue; - - result[uint256(Op.ADD)][el] += result[uint256(Op.ADD)][uint256(Element.ALL)]; - result[uint256(Op.MUL)][el] += result[uint256(Op.MUL)][uint256(Element.ALL)]; - result[uint256(Op.BADD)][el] += result[uint256(Op.BADD)][uint256(Element.ALL)]; - } - } - - /** - * @dev Return statmod values grouped by results of operations. - * Usually you want OP_FINAL - the last operation in their sequence. - * The others give access to intermediate values like 'base life' - * @param baseValue inherent base, may be 0 - * @return result results of operations upon `baseValue` - */ - function getValues( - Self memory __self, - uint256 topicEntity, - uint32 baseValue - ) internal view returns (uint32[OP_L] memory result) { - uint32[OP_L] memory ops = getOperands(__self, topicEntity); - result[uint256(Op.BADD)] = baseValue + ops[uint256(Op.BADD)]; - result[uint256(Op.MUL)] = (result[uint256(Op.BADD)] * (100 + ops[uint256(Op.MUL)])) / 100; - result[uint256(Op.ADD)] = result[uint256(Op.MUL)] + ops[uint256(Op.ADD)]; - } - - /** - * @dev Result of all `topicEntity` operations upon `baseValue` - */ - function getValuesFinal(Self memory __self, uint256 topicEntity, uint32 baseValue) internal view returns (uint32) { - return getValues(__self, topicEntity, baseValue)[OP_FINAL]; - } - - /** - * @dev Return values grouped by Element and Op - * See getValues for details on Op grouping - */ - function getValuesElemental( - Self memory __self, - uint256 topicEntity, - uint32[EL_L] memory baseValues - ) internal view returns (uint32[EL_L][OP_L] memory result) { - uint32[EL_L][OP_L] memory ops = getOperandsElemental(__self, topicEntity); - // el is Element enum values - for (uint256 el; el < EL_L; el++) { - uint32 baseValue = baseValues[el]; - - // Element.ALL adds to all other elements at the same time - if (el != uint256(Element.ALL)) { - baseValue += baseValues[uint256(Element.ALL)]; - } - - result[uint256(Op.BADD)][el] = baseValue + ops[uint256(Op.BADD)][el]; - result[uint256(Op.MUL)][el] = (result[uint256(Op.BADD)][el] * (100 + ops[uint256(Op.MUL)][el])) / 100; - result[uint256(Op.ADD)][el] = result[uint256(Op.MUL)][el] + ops[uint256(Op.ADD)][el]; - } - } - - /** - * @dev Result of all `topicEntity` operations upon `baseValue` grouped by Element - */ - function getValuesElementalFinal( - Self memory __self, - uint256 topicEntity, - uint32[EL_L] memory baseValues - ) internal view returns (uint32[EL_L] memory) { - return getValuesElemental(__self, topicEntity, baseValues)[OP_FINAL]; - } -} diff --git a/packages/contracts/_old_src/statmod/StatmodPrototypeComponent.sol b/packages/contracts/_old_src/statmod/StatmodPrototypeComponent.sol deleted file mode 100644 index c17f5ba2..00000000 --- a/packages/contracts/_old_src/statmod/StatmodPrototypeComponent.sol +++ /dev/null @@ -1,70 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { LibTypes } from "solecs/LibTypes.sol"; -import { BareComponent } from "solecs/BareComponent.sol"; - -uint256 constant ID = uint256(keccak256("component.StatmodPrototype")); - -/** - * @dev Statmod protoEntity = hashed(ID, StatmodPrototype) - */ -function getStatmodProtoEntity(StatmodPrototype memory proto) pure returns (uint256) { - return uint256(keccak256(abi.encode(ID, proto))); -} - -enum Op { - ADD, - MUL, - BADD -} -uint256 constant OP_L = 3; -uint256 constant OP_FINAL = uint256(Op.ADD); - -enum Element { - ALL, - PHYSICAL, - FIRE, - COLD, - POISON -} -uint256 constant EL_L = 5; - -struct StatmodPrototype { - uint256 topicEntity; - Op op; - Element element; -} - -contract StatmodPrototypeComponent is BareComponent { - error StatmodPrototypeComponent__AbsentEntity(); - - constructor(address world) BareComponent(world, ID) {} - - function getSchema() public pure override returns (string[] memory keys, LibTypes.SchemaValue[] memory values) { - keys = new string[](3); - values = new LibTypes.SchemaValue[](3); - - keys[0] = "topicEntity"; - values[0] = LibTypes.SchemaValue.UINT256; - - keys[1] = "op"; - values[1] = LibTypes.SchemaValue.UINT8; - - keys[2] = "element"; - values[2] = LibTypes.SchemaValue.UINT8; - } - - function set(uint256 entity, StatmodPrototype memory value) public { - set(entity, abi.encode(value)); - } - - function getValue(uint256 entity) public view returns (StatmodPrototype memory) { - bytes memory rawValue = getRawValue(entity); - if (rawValue.length == 0) { - revert StatmodPrototypeComponent__AbsentEntity(); - } - return abi.decode(rawValue, (StatmodPrototype)); - } -} diff --git a/packages/contracts/_old_src/statmod/StatmodScopeComponent.sol b/packages/contracts/_old_src/statmod/StatmodScopeComponent.sol deleted file mode 100644 index 842cd1d3..00000000 --- a/packages/contracts/_old_src/statmod/StatmodScopeComponent.sol +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { ScopeComponent } from "@dk1a/solecslib/contracts/scoped-value/ScopeComponent.sol"; - -uint256 constant ID = uint256(keccak256("component.StatmodScope")); - -contract StatmodScopeComponent is ScopeComponent { - constructor(address _world) ScopeComponent(_world, ID) {} -} diff --git a/packages/contracts/_old_src/statmod/StatmodValueComponent.sol b/packages/contracts/_old_src/statmod/StatmodValueComponent.sol deleted file mode 100644 index 199be282..00000000 --- a/packages/contracts/_old_src/statmod/StatmodValueComponent.sol +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { ValueComponent } from "@dk1a/solecslib/contracts/scoped-value/ValueComponent.sol"; - -uint256 constant ID = uint256(keccak256("component.StatmodValue")); - -contract StatmodValueComponent is ValueComponent { - constructor(address _world) ValueComponent(_world, ID) {} -} diff --git a/packages/contracts/_old_src/statmod/statmodName.sol b/packages/contracts/_old_src/statmod/statmodName.sol deleted file mode 100644 index 97d13aeb..00000000 --- a/packages/contracts/_old_src/statmod/statmodName.sol +++ /dev/null @@ -1,74 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { StrSlice, toSlice } from "@dk1a/solidity-stringutils/src/StrSlice.sol"; - -import { ReverseHashNameComponent } from "../common/ReverseHashNameComponent.sol"; -import { Op, Element } from "./StatmodPrototypeComponent.sol"; - -using { toSlice } for string; - -// utils for autogenerating a name for a statmod prototype - -function statmodName(ReverseHashNameComponent rhNameComp, uint256 topicEntity, Op op) view returns (string memory) { - return statmodName(rhNameComp, topicEntity, op, Element.ALL); -} - -function statmodName( - ReverseHashNameComponent rhNameComp, - uint256 topicEntity, - Op op, - Element element -) view returns (string memory) { - StrSlice topicName = toSlice(rhNameComp.getValue(topicEntity)); - - StrSlice[] memory nameParts = new StrSlice[](2); - // prefix - if (op == Op.ADD) { - nameParts[0] = toSlice("+#"); - } else if (op == Op.MUL) { - nameParts[0] = toSlice("#% increased"); - } else if (op == Op.BADD) { - nameParts[0] = toSlice("+# base"); - } else { - revert("unknown op"); - } - // element + topic - if (element != Element.ALL) { - StrSlice elementName = _elementName(element); - // check if topicName has "{element}" placeholder - (bool found, StrSlice prefix, StrSlice suffix) = topicName.splitOnce(toSlice("{element}")); - - if (found) { - // replace {element} with the actual element name - nameParts[1] = prefix.add(elementName).toSlice().add(suffix).toSlice(); - } else { - // prepend element name to topicName - nameParts[1] = elementName.add(toSlice(" ")).toSlice().add(topicName).toSlice(); - } - } else if (element == Element.ALL) { - if (topicName.contains(toSlice("{element}"))) revert("invalid element placeholder"); - // just topicName, no element - nameParts[1] = topicName; - } - - return toSlice(" ").join(nameParts); -} - -function _elementName(Element element) pure returns (StrSlice) { - if (element == Element.PHYSICAL) { - return toSlice("physical"); - } else if (element == Element.FIRE) { - return toSlice("fire"); - } else if (element == Element.COLD) { - return toSlice("cold"); - } else if (element == Element.POISON) { - return toSlice("poison"); - } else { - revert("unknown element"); - } -} diff --git a/packages/contracts/_old_src/statmod/test/Statmod.t.sol b/packages/contracts/_old_src/statmod/test/Statmod.t.sol deleted file mode 100644 index 53038329..00000000 --- a/packages/contracts/_old_src/statmod/test/Statmod.t.sol +++ /dev/null @@ -1,121 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { BaseTest } from "../../BaseTest.sol"; - -import { Topics } from "../../charstat/Topics.sol"; -import { Statmod } from "../Statmod.sol"; -import { - Op, OP_L, OP_FINAL, - Element, EL_L, - getStatmodProtoEntity, - StatmodPrototype -} from "../StatmodPrototypeComponent.sol"; - -contract StatmodTest is BaseTest { - using Statmod for Statmod.Self; - - // this should normally be an in-memory object, it's in storage for testing convenience - Statmod.Self _statmod; - - // some statmod prototype entities and their topics - uint256 lifeTopic = Topics.LIFE.toEntity(); - uint256 addLifePE = Topics.LIFE.toStatmodEntity(Op.ADD, Element.ALL); - uint256 mulLifePE = Topics.LIFE.toStatmodEntity(Op.MUL, Element.ALL); - uint256 baddLifePE = Topics.LIFE.toStatmodEntity(Op.BADD, Element.ALL); - - uint256 attackTopic = Topics.ATTACK.toEntity(); - uint256 mulAttackPE = Topics.ATTACK.toStatmodEntity(Op.MUL, Element.ALL); - uint256 mulFireAttackPE = Topics.ATTACK.toStatmodEntity(Op.MUL, Element.FIRE); - uint256 addFireAttackPE = Topics.ATTACK.toStatmodEntity(Op.ADD, Element.FIRE); - uint256 addColdAttackPE = Topics.ATTACK.toStatmodEntity(Op.ADD, Element.COLD); - - function setUp() public override { - super.setUp(); - - // init library's object - _statmod = Statmod.__construct( - world.components(), - uint256(keccak256('mainEntity')) - ); - } - - function test_statmod_getValues_parallelChanges() public { - // a bunch of changes to make sure they don't interfere with each other - _statmod.increase(mulLifePE, 11); - - _statmod.increase(addLifePE, 80); - - _statmod.decrease(mulLifePE, 2); - - _statmod.decrease(addLifePE, 10); - - _statmod.increase(mulLifePE, 1); - - _statmod.increase(baddLifePE, 54); - _statmod.decrease(baddLifePE, 27); - - _statmod.increase(mulLifePE, 2); - _statmod.increase(mulLifePE, 5); - - // (10 + 27) * (100 + 17) / 100 + 70 - uint32[OP_L] memory result = _statmod.getValues(lifeTopic, 10); - assertEq(result[uint256(Op.BADD)], 37); - assertEq(result[uint256(Op.MUL)], 43); - assertEq(result[uint256(Op.ADD)], 113); - } - - function test_statmod_getValuesFinal() public { - _statmod.increase(baddLifePE, 27); - _statmod.increase(mulLifePE, 17); - _statmod.increase(addLifePE, 70); - - // (10 + 27) * (100 + 17) / 100 + 70 - uint32 result = _statmod.getValuesFinal(lifeTopic, 10); - assertEq(result, 113); - } - - function test_statmod_getValuesElementalFinal() public { - _statmod.increase(mulAttackPE, 40); - _statmod.increase(addFireAttackPE, 100); - _statmod.increase(mulFireAttackPE, 40); - _statmod.increase(addColdAttackPE, 50); - - uint32[EL_L] memory result - = _statmod.getValuesElementalFinal(attackTopic, [uint32(0), 200, 300, 400, 500]); - - uint32[EL_L] memory expected; - expected[uint256(Element.ALL)] = 0; - expected[uint256(Element.PHYSICAL)] = 280; - expected[uint256(Element.FIRE)] = 640; - expected[uint256(Element.COLD)] = 610; - expected[uint256(Element.POISON)] = 700; - - for (uint256 el; el < EL_L; el++) { - assertEq(result[el], expected[el]); - } - } - - // TODO Element.ALL is confusing and useless. You should replace it with NONE and make this test obsolete - function test_statmod_getValuesElemental_withBaseAll() public { - _statmod.increase(mulAttackPE, 40); - _statmod.increase(addFireAttackPE, 100); - _statmod.increase(mulFireAttackPE, 40); - _statmod.increase(addColdAttackPE, 50); - - uint32[EL_L] memory result - = _statmod.getValuesElementalFinal(attackTopic, [uint32(100), 200, 300, 400, 500]); - - uint32[EL_L] memory expected; - expected[uint256(Element.ALL)] = 140; - expected[uint256(Element.PHYSICAL)] = 420; - expected[uint256(Element.FIRE)] = 820; - expected[uint256(Element.COLD)] = 750; - expected[uint256(Element.POISON)] = 840; - - for (uint256 el; el < EL_L; el++) { - assertEq(result[el], expected[el]); - } - } -} \ No newline at end of file diff --git a/packages/contracts/_old_src/statmod/test/StatmodPrototype.t.sol b/packages/contracts/_old_src/statmod/test/StatmodPrototype.t.sol deleted file mode 100644 index db7a731d..00000000 --- a/packages/contracts/_old_src/statmod/test/StatmodPrototype.t.sol +++ /dev/null @@ -1,26 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { Assertions } from "@dk1a/solidity-stringutils/src/test/Assertions.sol"; - -import { BaseTest } from "../../BaseTest.sol"; - -import { Topics } from "../../charstat/Topics.sol"; -import { Op, Element } from "../StatmodPrototypeComponent.sol"; - -contract StatmodPrototypeTest is BaseTest, Assertions { - // some statmod prototype entities and their topics - uint256 lifeTopic = Topics.LIFE.toEntity(); - uint256 addLifePE = Topics.LIFE.toStatmodEntity(Op.ADD, Element.ALL); - - function setUp() public override { - super.setUp(); - } - - function test_statmodPrototype_name() public { - string memory topicName = reverseHashNameComponent.getValue(lifeTopic); - string memory name = nameComponent.getValue(addLifePE); - assertContains(name, topicName); - } -} \ No newline at end of file diff --git a/packages/contracts/_old_src/token/LibToken.sol b/packages/contracts/_old_src/token/LibToken.sol deleted file mode 100644 index 4dd36a16..00000000 --- a/packages/contracts/_old_src/token/LibToken.sol +++ /dev/null @@ -1,29 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; -import { IComponent } from "solecs/interfaces/IComponent.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { OwnershipComponent } from "@dk1a/solecslib/contracts/token/ERC721/components/OwnershipComponent.sol"; -import { ownershipComponentID } from "./WNFTSystem.sol"; - -library LibToken { - error LibToken_MustBeTokenOwner(); - - function ownerOf(IUint256Component components, uint256 tokenEntity) internal view returns (address) { - IComponent ownershipComp = IComponent(getAddressById(components, ownershipComponentID)); - bytes memory rawValue = ownershipComp.getRawValue(tokenEntity); - if (rawValue.length == 0) { - return address(0); - } - return abi.decode(rawValue, (address)); - } - - function requireOwner(IUint256Component components, uint256 tokenEntity, address account) internal view { - if (account != ownerOf(components, tokenEntity)) { - revert LibToken_MustBeTokenOwner(); - } - } -} diff --git a/packages/contracts/_old_src/token/WFTSystem.sol b/packages/contracts/_old_src/token/WFTSystem.sol deleted file mode 100644 index ecf1c29e..00000000 --- a/packages/contracts/_old_src/token/WFTSystem.sol +++ /dev/null @@ -1,19 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IWorld } from "solecs/interfaces/IWorld.sol"; - -import { ERC1155BaseSubsystem } from "@dk1a/solecslib/contracts/token/ERC1155/ERC1155BaseSubsystem.sol"; - -uint256 constant ID = uint256(keccak256("system.WFT")); - -uint256 constant balanceComponentID = uint256(keccak256("component.WFT_Balance")); -uint256 constant operatorApprovalComponentID = uint256(keccak256("component.WFT_OperatorApproval")); - -contract WFTSystem is ERC1155BaseSubsystem { - constructor( - IWorld _world, - address _components - ) ERC1155BaseSubsystem(_world, _components, balanceComponentID, operatorApprovalComponentID) {} -} diff --git a/packages/contracts/_old_src/token/WNFTSystem.sol b/packages/contracts/_old_src/token/WNFTSystem.sol deleted file mode 100644 index 1fd928e9..00000000 --- a/packages/contracts/_old_src/token/WNFTSystem.sol +++ /dev/null @@ -1,60 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IWorld } from "solecs/interfaces/IWorld.sol"; - -import { IERC721Metadata } from "@solidstate/contracts/token/ERC721/metadata/IERC721Metadata.sol"; -import { ERC721BaseSubsystem } from "@dk1a/solecslib/contracts/token/ERC721/ERC721BaseSubsystem.sol"; - -import { LibUri } from "../uri/LibUri.sol"; - -uint256 constant ID = uint256(keccak256("system.WNFT")); - -uint256 constant ownershipComponentID = uint256(keccak256("component.WNFT_Ownership")); -uint256 constant operatorApprovalComponentID = uint256(keccak256("component.WNFT_OperatorApproval")); -uint256 constant tokenApprovalComponentID = uint256(keccak256("component.WNFT_TokenApproval")); - -contract WNFTSystem is ERC721BaseSubsystem, IERC721Metadata { - constructor( - IWorld _world, - address _components - ) - ERC721BaseSubsystem( - _world, - _components, - ownershipComponentID, - operatorApprovalComponentID, - tokenApprovalComponentID - ) - { - // register interfaces - // IERC721Metadata - _setSupportsInterface(type(IERC721Metadata).interfaceId, true); - } - - /** - * @notice inheritdoc IERC721Metadata - */ - function name() external view virtual returns (string memory) { - return "wanderer-cycle non-fungible tokens"; - } - - /** - * @notice inheritdoc IERC721Metadata - */ - function symbol() external view virtual returns (string memory) { - return "WNFT"; - } - - /** - * @notice inheritdoc IERC721Metadata - */ - function tokenURI(uint256 tokenId) external view virtual returns (string memory) { - // TODO you need an _exists func in solecslib - address owner = _get_ownerOf(tokenId); - if (owner == address(0)) revert ERC721Base__NonExistentToken(); - - return LibUri.tokenURI(components, tokenId); - } -} diff --git a/packages/contracts/_old_src/uri/LibUri.sol b/packages/contracts/_old_src/uri/LibUri.sol deleted file mode 100644 index 7092dffc..00000000 --- a/packages/contracts/_old_src/uri/LibUri.sol +++ /dev/null @@ -1,25 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.16; - -import { Base64 } from "@openzeppelin/contracts/utils/Base64.sol"; -import { Strings } from "@openzeppelin/contracts/utils/Strings.sol"; - -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { WandererComponent, ID as WandererComponentID } from "../wanderer/WandererComponent.sol"; - -import { LibUriWanderer } from "./LibUriWanderer.sol"; -import { LibUriMisc } from "./LibUriMisc.sol"; - -library LibUri { - function tokenURI(IUint256Component components, uint256 tokenId) internal view returns (string memory) { - string memory json; - if (WandererComponent(getAddressById(components, WandererComponentID)).has(tokenId)) { - json = LibUriWanderer.json(components, tokenId); - } else { - json = LibUriMisc.json(tokenId); - } - return string.concat("data:application/json;base64,", json); - } -} diff --git a/packages/contracts/_old_src/uri/LibUriEquipment.sol b/packages/contracts/_old_src/uri/LibUriEquipment.sol deleted file mode 100644 index 27778731..00000000 --- a/packages/contracts/_old_src/uri/LibUriEquipment.sol +++ /dev/null @@ -1,128 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.16; - -import { Base64 } from "@openzeppelin/contracts/utils/Base64.sol"; -import { Strings } from "@openzeppelin/contracts/utils/Strings.sol"; -import { UriUtils as u } from "./UriUtils.sol"; - -/*library LibUriEquipment { - function json(uint256 id) internal view returns (string memory) { - AppliedAffix[] memory affixes = LootStorage.getAffixes(id); - require( - affixes.length > 0 && affixes.length <= 3, - 'LibNames: invalid loot affix count' - ); - uint128 tokenBase = LibSplitId.getTokenBase(id); - - // nameSplit is physical position of text, whereas nameParts are ordered by type - string[3] memory nameSplit; - // generic attributes for opensea etc - string memory affixesAttrsStr; - // non-standard array of affixes - // (generic attributes can't represent them well - affixes have 4 datums: type, name, modName and value) - string memory affixesCustomStr; - // affix mods as svg text - string memory modifiersUriStr; - - for (uint256 i; i < affixes.length; i++) { - AppliedAffix memory affix = affixes[i]; - - // npType is priority of existence (implicit can exist without prefix) - NamingPartType npType; - // placeIndex is placement in text (prefix goes before implicit) - uint256 placeIndex; - if (i == 0) { - npType = NamingPartType.IMPLICIT; - placeIndex = 1; - } else if (i == 1) { - npType = NamingPartType.PREFIX; - placeIndex = 0; - } else if (i == 2) { - npType = NamingPartType.SUFFIX; - placeIndex = 2; - } - - string memory npTypeName = AffixNamingStorage.getTypeName(npType); - - nameSplit[placeIndex] = AffixNamingStorage.getPartName( - affix.id, - affix.variantTier, - tokenBase, - npType - ); - - string memory affixValueStr = Strings.toString(affix.mod.modifierValue); - ModifierDataFull storage modData = ModifierStorage.modifierDataFull(affix.mod.modifierId); - - AffixData storage affixData = AffixStorage.getAffixData(affix.id); - affixesAttrsStr = string.concat(affixesAttrsStr, - '{' - '"trait_type": "', npTypeName, '",' - '"value": "', affixData.name, '"' - '},' - '{' - '"trait_type": "', modData.name, '",' - '"value": ', affixValueStr, - '},' - ); - - string memory lastComma = i == affixes.length - 1 ? '' : ','; - affixesCustomStr = string.concat(affixesCustomStr, - '{' - '"trait_type": "', npTypeName, '",' - '"name": "', affixData.name, '",' - '"modifier_id": "', Strings.toHexString(uint32(affix.mod.modifierId), 4), '",' - '"modifier_name": "', modData.name, '",' - '"value": ', affixValueStr, - '}', - lastComma - ); - - modifiersUriStr = string.concat(modifiersUriStr, - URI_TEXT_, 'x="10" y="', Strings.toString(40 * 4 + i * 30), '" ', - URI_STRING_FILL_, ' style="font-size: 20px;">', - modData.nameSplitForValue[0], - URI_TSPAN_NUM, - affixValueStr, - '', - modData.nameSplitForValue[1] - ); - } - - string memory output = string.concat( - URI_START, - URI_TEXT_INIT_, 'y="40">', - nameSplit[0], - '', - URI_TEXT_INIT_, 'y="80">', - nameSplit[1], - '', - URI_TEXT_INIT_, 'y="120">', - nameSplit[2], - modifiersUriStr, - URI_END - ); - - string memory name = string.concat( - nameSplit[0], (bytes(nameSplit[0]).length > 0 ? ' ' : ''), - nameSplit[1], (bytes(nameSplit[1]).length > 0 ? ' ' : ''), - nameSplit[2] - ); - // TODO better description? - return Base64.encode(abi.encodePacked( - '{"name": "', name, '",', - '"description": "Equipment NFT",', - '"attributes": [', - affixesAttrsStr, - '{' - '"trait_type": "Base",' - '"value": "Loot"' - '}' - '],' - '"affixes": [', - affixesCustomStr, - '],' - '"image": "data:image/svg+xml;base64,', Base64.encode(bytes(output)), '"}' - )); - } -}*/ diff --git a/packages/contracts/_old_src/uri/LibUriMisc.sol b/packages/contracts/_old_src/uri/LibUriMisc.sol deleted file mode 100644 index 010e6386..00000000 --- a/packages/contracts/_old_src/uri/LibUriMisc.sol +++ /dev/null @@ -1,30 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.16; - -import { Base64 } from "@openzeppelin/contracts/utils/Base64.sol"; -import { Strings } from "@openzeppelin/contracts/utils/Strings.sol"; -import { UriUtils as u } from "./UriUtils.sol"; - -library LibUriMisc { - /** - * @dev fallback, avoid using it for circulating tokens - */ - function json(uint256 tokenId) internal pure returns (string memory) { - string memory name = string.concat("Token ", Strings.toHexString( - uint128(bytes16(keccak256(abi.encode("Token", tokenId)))) - )); - string memory output = string.concat( - u.START, - '', - name, - '', - u.END - ); - - return Base64.encode(abi.encodePacked( - '{"name": "', name, '",', - '"description": "Miscellaneous token, undeserving of specialized metadata",', - '"image": "data:image/svg+xml;base64,', Base64.encode(bytes(output)), '"}' - )); - } -} diff --git a/packages/contracts/_old_src/uri/LibUriWanderer.sol b/packages/contracts/_old_src/uri/LibUriWanderer.sol deleted file mode 100644 index 0182419e..00000000 --- a/packages/contracts/_old_src/uri/LibUriWanderer.sol +++ /dev/null @@ -1,125 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.16; - -import { Base64 } from "@openzeppelin/contracts/utils/Base64.sol"; -import { Strings } from "@openzeppelin/contracts/utils/Strings.sol"; - -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { ActiveCycleComponent, ID as ActiveCycleComponentID } from "../cycle/ActiveCycleComponent.sol"; -import { ActiveGuiseComponent, ID as ActiveGuiseComponentID } from "../guise/ActiveGuiseComponent.sol"; -import { NameComponent, ID as NameComponentID } from "../common/NameComponent.sol"; -import { LibGuiseLevel } from "../guise/LibGuiseLevel.sol"; - -import { UriUtils as u } from './UriUtils.sol'; - -library LibUriWanderer { - // struct to avoid stack too deep error - struct Strs { - string[] cycles; - string totalIdentityGained; - string wandererNum; - string guise; - string level; - string svgGuiseLevel; - - string output; - } - - function json(IUint256Component components, uint256 tokenId) internal view returns (string memory) { - Strs memory _strs; - // TODO add real cycle stats - //uint256 completedCycles = 0; - //string memory strCyclesAll = Strings.toString(completedCycles); - uint256 totalIdentityGained = 0; - - // TODO add real cycle stats - uint256[] memory wheelEntities; - _strs.cycles = new string[](wheelEntities.length); - - for (uint256 i; i < wheelEntities.length; i++) { - // TODO add real cycle stats - uint256 wheelIdentityGained = 0; - - totalIdentityGained += wheelIdentityGained; - _strs.cycles[i] = Strings.toString( - // TODO wheelCompletedCycles - 0 - ); - } - _strs.totalIdentityGained = Strings.toString(totalIdentityGained); - - _strs.wandererNum = Strings.toHexString( - uint32(bytes4(keccak256(abi.encode("Wanderer", tokenId)))) - ); - - ActiveCycleComponent activeCycle = ActiveCycleComponent(getAddressById(components, ActiveCycleComponentID)); - if (activeCycle.has(tokenId)) { - uint256 cycleEntity = activeCycle.getValue(tokenId); - - ActiveGuiseComponent activeGuise = ActiveGuiseComponent(getAddressById(components, ActiveGuiseComponentID)); - - uint256 guiseEntity = activeGuise.getValue(cycleEntity); - - _strs.guise = NameComponent(getAddressById(components, NameComponentID)).getValue(guiseEntity); - _strs.level = Strings.toString(LibGuiseLevel.getAggregateLevel(components, cycleEntity)); - _strs.svgGuiseLevel = string.concat( - _strs.guise, ' ', - '', - _strs.level, - '' - ); - } else { - _strs.guise = 'none'; - _strs.level = '0'; - } - - _strs.output = string.concat( - u.START, - '', - 'Wanderer ', - '', - _strs.wandererNum, - '', - '', - '', - _strs.svgGuiseLevel, - '', - '', - 'Total Identity ', - '', - _strs.totalIdentityGained, - '', - '', - u.END - ); - - return Base64.encode(abi.encodePacked( - '{"name": "Wanderer ', _strs.wandererNum, '",' - '"description": "Wanderer of their namesake Cycle",' - '"attributes": [' - '{' - '"trait_type": "Base",' - '"value": "Wanderer"' - '},' - '{' - '"trait_type": "Guise",' - '"value": "', _strs.guise, '"' - '},' - '{' - '"trait_type": "Level",' - '"value": ', _strs.level, - '},' - '{' - '"trait_type": "Total Identity",' - '"value": ', _strs.totalIdentityGained, - '}' - '],' - //'"external_url": "",', - //'"background_color": "000000",', - '"image": "data:image/svg+xml;base64,', Base64.encode(bytes(_strs.output)), '"}' - //'"image_data": "data:image/svg+xml;base64,', Base64.encode(bytes(output)), '"}' - )); - } -} \ No newline at end of file diff --git a/packages/contracts/_old_src/uri/UriUtils.sol b/packages/contracts/_old_src/uri/UriUtils.sol deleted file mode 100644 index a79478fb..00000000 --- a/packages/contracts/_old_src/uri/UriUtils.sol +++ /dev/null @@ -1,16 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity ^0.8.16; - -library UriUtils { - string constant START = '' - '' - ''; - string constant END = ''; - - string constant ATTRS_HEADER_TYPE = ' x="50%" class="base" text-anchor="middle" fill="#4ec9b0" '; - string constant ATTRS_BASE = ' class="base" fill="#969696" '; - string constant ATTRS_NUM = ' class="base" fill="#b5cea8" '; - string constant ATTRS_STRING = ' class="base" fill="#ce9178" '; - string constant ATTRS_KEY = ' class="base" fill="#9cdcfe" '; - string constant ATTRS_TYPE = ' class="base" fill="#4ec9b0" '; -} diff --git a/packages/contracts/_old_src/wanderer/IdentityComponent.sol b/packages/contracts/_old_src/wanderer/IdentityComponent.sol deleted file mode 100644 index a2ed2812..00000000 --- a/packages/contracts/_old_src/wanderer/IdentityComponent.sol +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { Uint32BareComponent } from "std-contracts/components/Uint32BareComponent.sol"; - -uint256 constant ID = uint256(keccak256("component.Identity")); - -contract IdentityComponent is Uint32BareComponent { - constructor(address world) Uint32BareComponent(world, ID) {} -} diff --git a/packages/contracts/_old_src/wanderer/LibWanderer.sol b/packages/contracts/_old_src/wanderer/LibWanderer.sol deleted file mode 100644 index ff59a1af..00000000 --- a/packages/contracts/_old_src/wanderer/LibWanderer.sol +++ /dev/null @@ -1,57 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { ActiveCyclePreviousComponent, ID as ActiveCyclePreviousComponentID } from "../cycle/ActiveCyclePreviousComponent.sol"; -import { ActiveWheelComponent, ID as ActiveWheelComponentID } from "../wheel/ActiveWheelComponent.sol"; -import { WheelComponent, ID as WheelComponentID, WheelData } from "../wheel/WheelComponent.sol"; -import { WheelsCompletedComponent, ID as WheelsCompletedComponentID, getWheelsCompletedEntity } from "../wheel/WheelsCompletedComponent.sol"; -import { IdentityComponent, ID as IdentityComponentID } from "./IdentityComponent.sol"; - -library LibWanderer { - function gainCycleRewards(IUint256Component components, uint256 wandererEntity) internal { - ActiveCyclePreviousComponent activeCyclePreviousComp = ActiveCyclePreviousComponent( - getAddressById(components, ActiveCyclePreviousComponentID) - ); - uint256 prevCycleEntity = activeCyclePreviousComp.getValue(wandererEntity); - - // get last wheel entity - ActiveWheelComponent activeWheelComp = ActiveWheelComponent(getAddressById(components, ActiveWheelComponentID)); - uint256 wheelEntity = activeWheelComp.getValue(prevCycleEntity); - // and its data - WheelComponent wheelComp = WheelComponent(getAddressById(components, WheelComponentID)); - WheelData memory wheel = wheelComp.getValue(wheelEntity); - - // get number of completed wheels - uint256 wheelsCompletedEntity = getWheelsCompletedEntity(wandererEntity, wheelEntity); - WheelsCompletedComponent wheelsCompletedComp = WheelsCompletedComponent( - getAddressById(components, WheelsCompletedComponentID) - ); - uint32 wheelsCompleted = 0; - if (wheelsCompletedComp.has(wheelsCompletedEntity)) { - wheelsCompleted = wheelsCompletedComp.getValue(wheelsCompletedEntity); - } - - // reward identity if charges remain - if (wheelsCompleted < wheel.charges) { - _rewardIdentity(components, wandererEntity); - } - // increment completed count - wheelsCompletedComp.set(wheelsCompletedEntity, wheelsCompleted + 1); - } - - function _rewardIdentity(IUint256Component components, uint256 wandererEntity) private { - IdentityComponent identityComponent = IdentityComponent(getAddressById(components, IdentityComponentID)); - uint32 currentIdentity; - if (!identityComponent.has(wandererEntity)) { - currentIdentity = 0; - } else { - currentIdentity = identityComponent.getValue(wandererEntity); - } - identityComponent.set(wandererEntity, currentIdentity + 128); - } -} diff --git a/packages/contracts/_old_src/wanderer/PermSkillSystem.sol b/packages/contracts/_old_src/wanderer/PermSkillSystem.sol deleted file mode 100644 index 77155ca5..00000000 --- a/packages/contracts/_old_src/wanderer/PermSkillSystem.sol +++ /dev/null @@ -1,73 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { System } from "solecs/System.sol"; -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { getAddressById } from "solecs/utils.sol"; - -import { ActiveCycleComponent, ID as ActiveCycleComponentID } from "../cycle/ActiveCycleComponent.sol"; -import { ActiveCyclePreviousComponent, ID as ActiveCyclePreviousComponentID } from "../cycle/ActiveCyclePreviousComponent.sol"; -import { LearnedSkillsComponent, ID as LearnedSkillsComponentID } from "../skill/LearnedSkillsComponent.sol"; -import { IdentityComponent, ID as IdentityComponentID } from "./IdentityComponent.sol"; - -import { LibLearnedSkills } from "../skill/LibLearnedSkills.sol"; -import { LibToken } from "../token/LibToken.sol"; - -uint256 constant ID = uint256(keccak256("system.PermSkill")); - -/// @title Make a skill permanent -contract PermSkillSystem is System { - using LibLearnedSkills for LibLearnedSkills.Self; - - uint32 internal constant PERM_SKILL_IDENTITY_COST = 128; - - error PermSkillSystem__MustHaveNoActiveCycle(); - error PermSkillSystem__SkillNotLearnedInPreviousCycle(uint256 previousCycleEntity); - error PermSkillSystem__NotEnoughIdentity(); - - constructor(IWorld _world, address _components) System(_world, _components) {} - - function executeTyped(uint256 wandererEntity, uint256 skillEntity) public { - execute(abi.encode(wandererEntity, skillEntity)); - } - - function execute(bytes memory args) public override returns (bytes memory) { - (uint256 wandererEntity, uint256 skillEntity) = abi.decode(args, (uint256, uint256)); - - ActiveCycleComponent activeCycleComp = ActiveCycleComponent(getAddressById(components, ActiveCycleComponentID)); - ActiveCyclePreviousComponent activeCyclePreviousComp = ActiveCyclePreviousComponent( - getAddressById(components, ActiveCyclePreviousComponentID) - ); - LearnedSkillsComponent learnedSkillsComp = LearnedSkillsComponent( - getAddressById(components, LearnedSkillsComponentID) - ); - IdentityComponent identityComponent = IdentityComponent(getAddressById(components, IdentityComponentID)); - - // caller must own the wanderer - LibToken.requireOwner(components, wandererEntity, msg.sender); - - // must be called outside of a cycle - if (activeCycleComp.has(wandererEntity)) { - revert PermSkillSystem__MustHaveNoActiveCycle(); - } - - // must have learned the skill during the previous cycle - uint256 prevCycleEntity = activeCyclePreviousComp.getValue(wandererEntity); - if (!learnedSkillsComp.hasItem(prevCycleEntity, skillEntity)) { - revert PermSkillSystem__SkillNotLearnedInPreviousCycle(prevCycleEntity); - } - - // subtract identity cost - uint32 currentIdentity = identityComponent.getValue(wandererEntity); - if (currentIdentity < PERM_SKILL_IDENTITY_COST) { - revert PermSkillSystem__NotEnoughIdentity(); - } - identityComponent.set(wandererEntity, currentIdentity - PERM_SKILL_IDENTITY_COST); - - // learn the skill - LibLearnedSkills.__construct(world, wandererEntity).learnSkill(skillEntity); - - return ""; - } -} diff --git a/packages/contracts/_old_src/wanderer/WandererComponent.sol b/packages/contracts/_old_src/wanderer/WandererComponent.sol deleted file mode 100644 index 8022972f..00000000 --- a/packages/contracts/_old_src/wanderer/WandererComponent.sol +++ /dev/null @@ -1,12 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { BoolBareComponent } from "std-contracts/components/BoolBareComponent.sol"; - -uint256 constant ID = uint256(keccak256("component.Wanderer")); - -/// @title Flag entity as a wanderer -contract WandererComponent is BoolBareComponent { - constructor(address world) BoolBareComponent(world, ID) {} -} diff --git a/packages/contracts/_old_src/wanderer/WandererSpawnSystem.sol b/packages/contracts/_old_src/wanderer/WandererSpawnSystem.sol deleted file mode 100644 index 95bbdd8e..00000000 --- a/packages/contracts/_old_src/wanderer/WandererSpawnSystem.sol +++ /dev/null @@ -1,51 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { System } from "solecs/System.sol"; -import { IWorld } from "solecs/interfaces/IWorld.sol"; -import { getAddressById } from "solecs/utils.sol"; -import { SingletonID } from "../SingletonID.sol"; - -import { WNFTSystem, ID as WNFTSystemID } from "../token/WNFTSystem.sol"; -import { WandererComponent, ID as WandererComponentID } from "./WandererComponent.sol"; -import { GuisePrototypeComponent, ID as GuisePrototypeComponentID } from "../guise/GuisePrototypeComponent.sol"; -import { DefaultWheelComponent, ID as DefaultWheelComponentID } from "../wheel/DefaultWheelComponent.sol"; - -import { LibCycle } from "../cycle/LibCycle.sol"; - -uint256 constant ID = uint256(keccak256("system.WandererSpawn")); - -/// @title Spawn a wandererEntity and start a cycle for it. -/// @dev This is for new players, whereas StartCycleSystem is for existing ones. -contract WandererSpawnSystem is System { - error WandererSpawnSystem__InvalidGuise(); - - constructor(IWorld _world, address _components) System(_world, _components) {} - - function executeTyped(uint256 guiseProtoEntity) public returns (uint256 wandererEntity) { - return abi.decode(execute(abi.encode(guiseProtoEntity)), (uint256)); - } - - /// @notice Anyone can freely spawn wanderers, a wanderer is a tokenized game account - function execute(bytes memory args) public override returns (bytes memory) { - uint256 guiseProtoEntity = abi.decode(args, (uint256)); - - // mint nft - uint256 wandererEntity = world.getUniqueEntityId(); - WNFTSystem wnftSystem = WNFTSystem(getAddressById(world.systems(), WNFTSystemID)); - wnftSystem.executeSafeMint(msg.sender, wandererEntity, ""); - - // flag the entity as wanderer - WandererComponent wandererComp = WandererComponent(getAddressById(components, WandererComponentID)); - wandererComp.set(wandererEntity); - - DefaultWheelComponent defaultWheelComp = DefaultWheelComponent(getAddressById(components, DefaultWheelComponentID)); - uint256 defaultWheelEntity = defaultWheelComp.getValue(SingletonID); - - // init cycle - LibCycle.initCycle(world, wandererEntity, guiseProtoEntity, defaultWheelEntity); - - return abi.encode(wandererEntity); - } -} diff --git a/packages/contracts/_old_src/wanderer/test/WandererSpawnSystem.t.sol b/packages/contracts/_old_src/wanderer/test/WandererSpawnSystem.t.sol deleted file mode 100644 index db8476c4..00000000 --- a/packages/contracts/_old_src/wanderer/test/WandererSpawnSystem.t.sol +++ /dev/null @@ -1,94 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { BaseTest } from "../../BaseTest.sol"; - -import { IERC721BaseInternal } from "@dk1a/solecslib/contracts/token/ERC721/logic/ERC721BaseInternal.sol"; - -import { getGuiseProtoEntity } from "../../guise/GuisePrototypeComponent.sol"; -import { LibCycle } from "../../cycle/LibCycle.sol"; -import { SingletonID } from "../../SingletonID.sol"; - -contract WandererSpawnSystemTest is BaseTest { - // taken from InitGuiseSystem, initialized by LibDeploy - uint256 warriorGuiseProtoEntity = getGuiseProtoEntity("Warrior"); - - uint256 wandererEntity; - uint256 cycleEntity; - uint256 defaultWheelEntity; - - function setUp() public virtual override { - super.setUp(); - - vm.prank(alice); - wandererEntity = wandererSpawnSystem.executeTyped(warriorGuiseProtoEntity); - cycleEntity = activeCycleComponent.getValue(wandererEntity); - defaultWheelEntity = defaultWheelComponent.getValue(SingletonID); - } - - function test_setUp_invalidGuise() public { - vm.prank(alice); - vm.expectRevert(LibCycle.LibCycle__InvalidGuiseProtoEntity.selector); - wandererSpawnSystem.executeTyped(0); - } - - function test_initCycle_another() public { - // initializing a cycle for some unrelated entity should work fine and produce an unrelated cycleEntity - uint256 anotherCycleEntity = LibCycle.initCycle( - world, - world.getUniqueEntityId(), - warriorGuiseProtoEntity, - defaultWheelEntity - ); - assertNotEq(anotherCycleEntity, cycleEntity); - } - - function test_entities() public { - assertNotEq(cycleEntity, wandererEntity); - assertNotEq(cycleEntity, 0); - } - - // wandererEntity has all the components unrelated to cycles - - function test_wanderer() public { - assertTrue(wandererComponent.getValue(wandererEntity)); - } - - function test_tokenOwner() public { - assertEq(wNFTSystem.ownerOf(wandererEntity), alice); - } - - function test_tokenOwner_notForCycleEntity() public { - // cycleEntity shouldn't even be a token, this error refers to address(0) - vm.expectRevert(IERC721BaseInternal.ERC721Base__InvalidOwner.selector); - wNFTSystem.ownerOf(cycleEntity); - } - - // cycleEntity has all the in-cycle components - - function test_activeGuise() public { - assertEq(activeGuiseComponent.getValue(cycleEntity), warriorGuiseProtoEntity); - assertFalse(activeGuiseComponent.has(wandererEntity)); - } - - function test_experience() public { - assertTrue(experienceComponent.has(cycleEntity)); - // TODO wandererEntity could have exp for some non-cycle-related reasons, come back to this later - // TODO (same thing with currents, though less likely) - assertFalse(experienceComponent.has(wandererEntity)); - } - - function test_currents() public { - assertGt(lifeCurrentComponent.getValue(cycleEntity), 0); - assertFalse(lifeCurrentComponent.has(wandererEntity)); - - assertGt(manaCurrentComponent.getValue(cycleEntity), 0); - assertFalse(manaCurrentComponent.has(wandererEntity)); - } - - function test_cycleTurns() public { - assertGt(cycleTurnsComponent.getValue(cycleEntity), 0); - assertFalse(cycleTurnsComponent.has(wandererEntity)); - } -} diff --git a/packages/contracts/_old_src/wheel/ActiveWheelComponent.sol b/packages/contracts/_old_src/wheel/ActiveWheelComponent.sol deleted file mode 100644 index 30adb6e4..00000000 --- a/packages/contracts/_old_src/wheel/ActiveWheelComponent.sol +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { Uint256Component } from "std-contracts/components/Uint256Component.sol"; - -uint256 constant ID = uint256(keccak256("component.ActiveWheel")); - -contract ActiveWheelComponent is Uint256Component { - constructor(address world) Uint256Component(world, ID) {} -} diff --git a/packages/contracts/_old_src/wheel/DefaultWheelComponent.sol b/packages/contracts/_old_src/wheel/DefaultWheelComponent.sol deleted file mode 100644 index 14850896..00000000 --- a/packages/contracts/_old_src/wheel/DefaultWheelComponent.sol +++ /dev/null @@ -1,11 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { Uint256Component } from "std-contracts/components/Uint256Component.sol"; - -uint256 constant ID = uint256(keccak256("component.DefaultWheel")); - -contract DefaultWheelComponent is Uint256Component { - constructor(address world) Uint256Component(world, ID) {} -} diff --git a/packages/contracts/_old_src/wheel/WheelComponent.sol b/packages/contracts/_old_src/wheel/WheelComponent.sol deleted file mode 100644 index ccaf5a48..00000000 --- a/packages/contracts/_old_src/wheel/WheelComponent.sol +++ /dev/null @@ -1,40 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { LibTypes } from "solecs/LibTypes.sol"; -import { BareComponent } from "solecs/BareComponent.sol"; - -uint256 constant ID = uint256(keccak256("component.Wheel")); - -struct WheelData { - uint32 totalIdentityRequired; - uint32 charges; - bool isIsolated; -} - -contract WheelComponent is BareComponent { - constructor(address world) BareComponent(world, ID) {} - - function getSchema() public pure override returns (string[] memory keys, LibTypes.SchemaValue[] memory values) { - keys = new string[](3); - values = new LibTypes.SchemaValue[](3); - - keys[0] = "totalIdentityRequired"; - values[0] = LibTypes.SchemaValue.UINT32; - - keys[1] = "charges"; - values[1] = LibTypes.SchemaValue.UINT32; - - keys[2] = "isIsolated"; - values[2] = LibTypes.SchemaValue.BOOL; - } - - function set(uint256 entity, WheelData memory value) public { - set(entity, abi.encode(value)); - } - - function getValue(uint256 entity) public view returns (WheelData memory) { - return abi.decode(getRawValue(entity), (WheelData)); - } -} diff --git a/packages/contracts/_old_src/wheel/WheelsCompletedComponent.sol b/packages/contracts/_old_src/wheel/WheelsCompletedComponent.sol deleted file mode 100644 index 17408908..00000000 --- a/packages/contracts/_old_src/wheel/WheelsCompletedComponent.sol +++ /dev/null @@ -1,18 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.17; - -import { Uint32BareComponent } from "std-contracts/components/Uint32BareComponent.sol"; - -/** - * @dev wheelsCompletedEntity = hashed(wandererEntity, wheelEntity) - */ -function getWheelsCompletedEntity(uint256 wandererEntity, uint256 wheelEntity) pure returns (uint256) { - return uint256(keccak256(abi.encode(wandererEntity, wheelEntity))); -} - -uint256 constant ID = uint256(keccak256("component.WheelsCompleted")); - -contract WheelsCompletedComponent is Uint32BareComponent { - constructor(address world) Uint32BareComponent(world, ID) {} -} diff --git a/packages/contracts/src/charstat/ExperienceComponent.sol b/packages/contracts/src/charstat/ExperienceComponent.sol new file mode 100644 index 00000000..e69de29b diff --git a/packages/contracts/src/charstat/LibExperience.sol b/packages/contracts/src/charstat/LibExperience.sol new file mode 100644 index 00000000..e69de29b From cf94d1f6d4be90dc6cdaa25c9ea2e69e7a1ec10c Mon Sep 17 00:00:00 2001 From: rashid Date: Mon, 15 May 2023 11:42:50 +0300 Subject: [PATCH 3/6] add life and mana components --- packages/contracts/src/charstat/LibCharstat.sol | 0 packages/contracts/src/charstat/LifeCurrentComponent.sol | 0 packages/contracts/src/charstat/ManaCurrentComponent.sol | 0 packages/contracts/src/charstat/test/LibExperience.t.sol | 0 4 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 packages/contracts/src/charstat/LibCharstat.sol create mode 100644 packages/contracts/src/charstat/LifeCurrentComponent.sol create mode 100644 packages/contracts/src/charstat/ManaCurrentComponent.sol create mode 100644 packages/contracts/src/charstat/test/LibExperience.t.sol diff --git a/packages/contracts/src/charstat/LibCharstat.sol b/packages/contracts/src/charstat/LibCharstat.sol new file mode 100644 index 00000000..e69de29b diff --git a/packages/contracts/src/charstat/LifeCurrentComponent.sol b/packages/contracts/src/charstat/LifeCurrentComponent.sol new file mode 100644 index 00000000..e69de29b diff --git a/packages/contracts/src/charstat/ManaCurrentComponent.sol b/packages/contracts/src/charstat/ManaCurrentComponent.sol new file mode 100644 index 00000000..e69de29b diff --git a/packages/contracts/src/charstat/test/LibExperience.t.sol b/packages/contracts/src/charstat/test/LibExperience.t.sol new file mode 100644 index 00000000..e69de29b From 3ddd57fc1d9f7fb16120cb1a7587b9b27f09d271 Mon Sep 17 00:00:00 2001 From: rashid Date: Mon, 15 May 2023 15:17:52 +0300 Subject: [PATCH 4/6] add test for LibExperience --- packages/contracts/mud.config.mts | 4 + .../src/charstat/ExperienceComponent.sol | 41 +++++ .../contracts/src/charstat/LibCharstat.sol | 13 ++ .../contracts/src/charstat/LibExperience.sol | 145 ++++++++++++++++++ .../src/charstat/LifeCurrentComponent.sol | 11 ++ .../src/charstat/ManaCurrentComponent.sol | 11 ++ packages/contracts/src/charstat/Topics.sol | 55 +++++++ .../src/charstat/test/LibExperience.t.sol | 82 ++++++++++ .../src/common/ComponentDevSystem.sol | 12 ++ .../src/common/FromPrototypeComponent.sol | 11 ++ .../contracts/src/common/NameComponent.sol | 11 ++ .../contracts/src/common/OwnedByComponent.sol | 11 ++ .../src/common/ReverseHashNameComponent.sol | 11 ++ .../src/common/ReverseHashNameSystem.sol | 40 +++++ packages/contracts/src/statmod/Statmod.sol | 2 +- 15 files changed, 459 insertions(+), 1 deletion(-) create mode 100644 packages/contracts/src/charstat/Topics.sol create mode 100644 packages/contracts/src/common/ComponentDevSystem.sol create mode 100644 packages/contracts/src/common/FromPrototypeComponent.sol create mode 100644 packages/contracts/src/common/NameComponent.sol create mode 100644 packages/contracts/src/common/OwnedByComponent.sol create mode 100644 packages/contracts/src/common/ReverseHashNameComponent.sol create mode 100644 packages/contracts/src/common/ReverseHashNameSystem.sol diff --git a/packages/contracts/mud.config.mts b/packages/contracts/mud.config.mts index 07b35bca..ce132672 100644 --- a/packages/contracts/mud.config.mts +++ b/packages/contracts/mud.config.mts @@ -122,6 +122,10 @@ export default mudConfig({ ...entityKey, schema: "uint32", }, + Charstat: { + ...entityKey, + schema: "uint32", + }, // initiatorEntity => retaliatorEntity // An entity can initiate only 1 combat at a time diff --git a/packages/contracts/src/charstat/ExperienceComponent.sol b/packages/contracts/src/charstat/ExperienceComponent.sol index e69de29b..46c06b5e 100644 --- a/packages/contracts/src/charstat/ExperienceComponent.sol +++ b/packages/contracts/src/charstat/ExperienceComponent.sol @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.17; + +import { LibTypes } from "solecs/LibTypes.sol"; +import { BareComponent } from "solecs/BareComponent.sol"; + +enum PStat { + STRENGTH, + ARCANA, + DEXTERITY +} +uint256 constant PS_L = 3; + +uint256 constant ID = uint256(keccak256("component.Experience")); + +contract ExperienceComponent is BareComponent { + constructor(address _world) BareComponent(_world, ID) {} + + function getSchema() public pure override returns (string[] memory keys, LibTypes.SchemaValue[] memory values) { + keys = new string[](PS_L); + values = new LibTypes.SchemaValue[](PS_L); + + keys[0] = "strength"; + values[0] = LibTypes.SchemaValue.UINT32; + + keys[1] = "arcana"; + values[1] = LibTypes.SchemaValue.UINT32; + + keys[2] = "dexterity"; + values[2] = LibTypes.SchemaValue.UINT32; + } + + function getValue(uint256 entity) public view returns (uint32[PS_L] memory result) { + return abi.decode(getRawValue(entity), (uint32[3])); /* 3 == PS_L */ + } + + function set(uint256 entity, uint32[PS_L] memory pstats) public { + set(entity, abi.encode(pstats)); + } +} diff --git a/packages/contracts/src/charstat/LibCharstat.sol b/packages/contracts/src/charstat/LibCharstat.sol index e69de29b..7d7362d9 100644 --- a/packages/contracts/src/charstat/LibCharstat.sol +++ b/packages/contracts/src/charstat/LibCharstat.sol @@ -0,0 +1,13 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.17; + +import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; +import { getAddressById } from "solecs/utils.sol"; +import { Statmod, Element, EL_L } from "../statmod/Statmod.sol"; +import { Topics } from "./Topics.sol"; +import { LibExperience, PStat, PS_L } from "./LibExperience.sol"; +import { LifeCurrentComponent, ID as LifeCurrentComponentID } from "./LifeCurrentComponent.sol"; +import { ManaCurrentComponent, ID as ManaCurrentComponentID } from "./ManaCurrentComponent.sol"; + +library LibCharstat {} diff --git a/packages/contracts/src/charstat/LibExperience.sol b/packages/contracts/src/charstat/LibExperience.sol index e69de29b..858c57aa 100644 --- a/packages/contracts/src/charstat/LibExperience.sol +++ b/packages/contracts/src/charstat/LibExperience.sol @@ -0,0 +1,145 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.17; + +import { IUint256Component } from "solecs/interfaces/IUint256Component.sol"; +import { PStat, PS_L, ExperienceComponent, ID as ExperienceComponentID } from "./ExperienceComponent.sol"; + +// const entityKey = { +// primaryKeys: { +// entity: EntityId, +// }, +// } as const + +// Experience: { +// ...entityKey, +// schema: arrayPStat +// }, + +// const arrayPStat = `uint32[${enumPStat.length}]` as const + +import { Experience } from "../codegen/Tables.sol"; + +library LibExperience { + error LibExperience__InvalidLevel(); + error LibExperience__ExpNotInitialized(); + + uint32 constant MAX_LEVEL = 16; + + function getPStats(uint256 targetEntity) internal view returns (uint32[PS_L] memory result) { + result = Experience.get(targetEntity); + for (uint256 i; i < result.length; i++) { + result[i] = _getLevel(result[i]); + } + } + + function getPStat(uint256 targetEntity, PStat pstatIndex) internal view returns (uint32) { + uint32 exp = Experience.get(targetEntity)[uint256(pstatIndex)]; + return _getLevel(exp); + } + + function hasExp(uint256 targetEntity) internal view returns (bool) { + uint32 exp = Experience.get(targetEntity); + if (exp) { + return true; + } else { + return false; + } + } + + function getExp(uint256 targetEntity) internal view returns (uint32[PS_L] memory) { + return Experience.get(targetEntity); + } + + /** + * @dev Allow target to receive exp, set exp to 0s + */ + function initExp(uint256 targetEntity) internal { + uint32[PS_L] memory exp; + Experience.set(targetEntity, exp); + } + + /** + * @dev Increase target's experience + * Exp must be initialized + */ + function increaseExp(uint256 targetEntity, uint32[PS_L] memory addExp) internal { + // get current exp, or revert if it doesn't exist + if (!Experience.get(targetEntity)) { + revert LibExperience__ExpNotInitialized(); + } + uint32[PS_L] memory exp = Experience.get(targetEntity); + + // increase + for (uint256 i; i < PS_L; i++) { + exp[i] += addExp[i]; + } + // set increased exp + Experience.set(targetEntity, exp); + } + + /** + * @dev Calculate aggregate level based on weighted sum of pstat exp + */ + function getAggregateLevel(uint256 targetEntity, uint32[PS_L] memory levelMul) internal view returns (uint32) { + uint32[PS_L] memory exp = getExp(targetEntity); + uint256 expTotal; + uint256 mulTotal; + for (uint256 i; i < PS_L; i++) { + expTotal += exp[i] * levelMul[i]; + mulTotal += levelMul[i]; + } + + expTotal /= mulTotal; + + return _getLevel(expTotal); + } + + /** + * @dev Calculate level based on single exp value + */ + function _getLevel(uint256 expVal) private pure returns (uint32) { + // expVal per level rises exponentially with polynomial easing + // 1-0, 2-96, 3-312, 4-544, 5-804, 6-1121... + for (uint32 level = 1; level < MAX_LEVEL; level++) { + // (1< MAX_LEVEL) revert LibExperience__InvalidLevel(); + + // this formula starts from 0, so adjust the arg + if (level == 1) { + return 0; + } else { + level -= 1; + } + + return uint32(8 * (1 << level) - level ** 6 / 1024 + level * 200 - 120); + } + + /** + * @dev Get exp amount to get base primary to `pstats` (assuming 0 current exp). + * This is a utility for testing + */ + function getExpForPStats(uint32[PS_L] memory pstats) internal pure returns (uint32[PS_L] memory exp) { + for (uint256 i; i < PS_L; i++) { + exp[i] = _getExpForLevel(pstats[i]); + } + } + + /** + * @dev same as getExpForPStats but for 1 specific pstat + */ + function getExpForPStat(uint32 pstat) internal pure returns (uint32) { + return _getExpForLevel(pstat); + } +} diff --git a/packages/contracts/src/charstat/LifeCurrentComponent.sol b/packages/contracts/src/charstat/LifeCurrentComponent.sol index e69de29b..d0889b9d 100644 --- a/packages/contracts/src/charstat/LifeCurrentComponent.sol +++ b/packages/contracts/src/charstat/LifeCurrentComponent.sol @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.17; + +import { Uint32BareComponent } from "std-contracts/components/Uint32BareComponent.sol"; + +uint256 constant ID = uint256(keccak256("component.LifeCurrent")); + +contract LifeCurrentComponent is Uint32BareComponent { + constructor(address world) Uint32BareComponent(world, ID) {} +} diff --git a/packages/contracts/src/charstat/ManaCurrentComponent.sol b/packages/contracts/src/charstat/ManaCurrentComponent.sol index e69de29b..e84bdfdf 100644 --- a/packages/contracts/src/charstat/ManaCurrentComponent.sol +++ b/packages/contracts/src/charstat/ManaCurrentComponent.sol @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.17; + +import { Uint32BareComponent } from "std-contracts/components/Uint32BareComponent.sol"; + +uint256 constant ID = uint256(keccak256("component.ManaCurrent")); + +contract ManaCurrentComponent is Uint32BareComponent { + constructor(address world) Uint32BareComponent(world, ID) {} +} diff --git a/packages/contracts/src/charstat/Topics.sol b/packages/contracts/src/charstat/Topics.sol new file mode 100644 index 00000000..e9f96d44 --- /dev/null +++ b/packages/contracts/src/charstat/Topics.sol @@ -0,0 +1,55 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.17; + +import { IWorld } from "solecs/interfaces/IWorld.sol"; + +import { PS_L, PStat } from "./LibExperience.sol"; +import { statmodName } from "../statmod/statmodName.sol"; +import { Op, Element, StatmodPrototype, getStatmodProtoEntity } from "../statmod/StatmodPrototypeComponent.sol"; + +type Topic is uint256; + +library Topics { + Topic constant STRENGTH = Topic.wrap(uint256(keccak256("strength"))); + Topic constant ARCANA = Topic.wrap(uint256(keccak256("arcana"))); + Topic constant DEXTERITY = Topic.wrap(uint256(keccak256("dexterity"))); + + // pstat topics also come as an array since it's often useful to iterate them + function PSTAT() internal pure returns (Topic[PS_L] memory r) { + r[uint256(PStat.STRENGTH)] = STRENGTH; + r[uint256(PStat.ARCANA)] = ARCANA; + r[uint256(PStat.DEXTERITY)] = DEXTERITY; + } + + Topic constant LIFE = Topic.wrap(uint256(keccak256("life"))); + Topic constant MANA = Topic.wrap(uint256(keccak256("mana"))); + Topic constant FORTUNE = Topic.wrap(uint256(keccak256("fortune"))); + Topic constant CONNECTION = Topic.wrap(uint256(keccak256("connection"))); + Topic constant LIFE_GAINED_PER_TURN = Topic.wrap(uint256(keccak256("life gained per turn"))); + Topic constant MANA_GAINED_PER_TURN = Topic.wrap(uint256(keccak256("mana gained per turn"))); + + Topic constant ATTACK = Topic.wrap(uint256(keccak256("attack"))); + Topic constant SPELL = Topic.wrap(uint256(keccak256("spell"))); + Topic constant RESISTANCE = Topic.wrap(uint256(keccak256("resistance"))); + + Topic constant DAMAGE_TAKEN_PER_ROUND = Topic.wrap(uint256(keccak256("damage taken per round"))); + + Topic constant DAMAGE_TAKEN = Topic.wrap(uint256(keccak256("damage taken"))); + Topic constant REDUCED_DAMAGE_DONE = Topic.wrap(uint256(keccak256("reduced damage done"))); + Topic constant ROUNDS_STUNNED = Topic.wrap(uint256(keccak256("rounds stunned"))); + + Topic constant PERCENT_OF_MISSING_LIFE_TO_ATTACK = + Topic.wrap(uint256(keccak256("% of missing life to {element} attack"))); + Topic constant LEVEL = Topic.wrap(uint256(keccak256("level"))); +} + +using { toEntity, toStatmodEntity } for Topic global; + +function toEntity(Topic topic) pure returns (uint256) { + return Topic.unwrap(topic); +} + +function toStatmodEntity(Topic topic, Op op, Element element) pure returns (uint256) { + return getStatmodProtoEntity(StatmodPrototype({ topicEntity: topic.toEntity(), op: op, element: element })); +} diff --git a/packages/contracts/src/charstat/test/LibExperience.t.sol b/packages/contracts/src/charstat/test/LibExperience.t.sol index e69de29b..7a87530b 100644 --- a/packages/contracts/src/charstat/test/LibExperience.t.sol +++ b/packages/contracts/src/charstat/test/LibExperience.t.sol @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.17; + +import { LibExperience } from "../LibExperience.sol"; +import { PStat, PS_L } from "../ExperienceComponent.sol"; +import { BaseTest } from "../../BaseTest.sol"; + +contract LibExperienceTest is BaseTest { + using LibExperience for uint256; + + uint256 targetEntity = uint256(keccak256("targetEntity")); + + function testGetPStats() public { + uint32[PS_L] memory pstats = [100, 200, 300]; + uint32[PS_L] memory expectedExp = LibExperience.getExpForPStats(pstats); + + experienceComponent.set(targetEntity, expectedExp); + + uint32[PS_L] memory resultPStats = LibExperience.getPStats(targetEntity); + for (uint256 i; i < pstats.length; i++) { + assertEq32(resultPStats[i], pstats[i]); + } + } + + function testGetPStat() public { + uint32 pstatStrength = 10; + uint32 expStrength = LibExperience.getExpForPStat(pstatStrength); + + experienceComponent.update(targetEntity, uint256(PStat.STRENGTH), expStrength); + + uint32 resultPStat = LibExperience.getPStat(targetEntity, PStat.STRENGTH); + assertEq32(resultPStat, pstatStrength); + } + + function testHasExp() public { + bool result = targetEntity.hasExp(); + assert(!result); + + experienceComponent.set(targetEntity, [100, 200, 300]); + + result = targetEntity.hasExp(); + assert(result); + } + + function testInitExp() public { + targetEntity.initExp(); + + bool result = targetEntity.hasExp(); + assert(result); + + uint32[PS_L] memory resultExp = targetEntity.getExp(); + for (uint256 i; i < resultExp.length; i++) { + assertEq32(resultExp[i], 0); + } + } + + function testIncreaseExp() public { + uint32[PS_L] memory addExp = [10, 20, 30]; + uint32[PS_L] memory expectedExp = [110, 220, 330]; + + experienceComponent.set(targetEntity, [100, 200, 300]); + + targetEntity.increaseExp(addExp); + + uint32[PS_L] memory resultExp = targetEntity.getExp(); + for (uint256 i; i < resultExp.length; i++) { + assertEq32(resultExp[i], expectedExp[i]); + } + } + + function testGetAggregateLevel() public { + uint32[PS_L] memory exp = [100, 200, 300]; + uint32[PS_L] memory levelMul = [1, 2, 3]; + // Expected aggregate level: ((100*1) + (200*2) + (300*3)) / (1+2+3) = 200 + + experienceComponent.set(targetEntity, exp); + + uint32 resultLevel = targetEntity.getAggregateLevel(levelMul); + assertEq32(resultLevel, 200); + } +} diff --git a/packages/contracts/src/common/ComponentDevSystem.sol b/packages/contracts/src/common/ComponentDevSystem.sol new file mode 100644 index 00000000..579c7488 --- /dev/null +++ b/packages/contracts/src/common/ComponentDevSystem.sol @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.17; + +import { IWorld } from "solecs/interfaces/IWorld.sol"; +import { ComponentDevSystem as _ComponentDevSystem } from "std-contracts/systems/ComponentDevSystem.sol"; + +uint256 constant ID = uint256(keccak256("system.ComponentDev")); + +contract ComponentDevSystem is _ComponentDevSystem { + constructor(IWorld _world, address _components) _ComponentDevSystem(_world, _components) {} +} diff --git a/packages/contracts/src/common/FromPrototypeComponent.sol b/packages/contracts/src/common/FromPrototypeComponent.sol new file mode 100644 index 00000000..906055ff --- /dev/null +++ b/packages/contracts/src/common/FromPrototypeComponent.sol @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.17; + +import { Uint256Component } from "std-contracts/components/Uint256Component.sol"; + +uint256 constant ID = uint256(keccak256("component.FromPrototype")); + +contract FromPrototypeComponent is Uint256Component { + constructor(address world) Uint256Component(world, ID) {} +} diff --git a/packages/contracts/src/common/NameComponent.sol b/packages/contracts/src/common/NameComponent.sol new file mode 100644 index 00000000..7255f672 --- /dev/null +++ b/packages/contracts/src/common/NameComponent.sol @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.17; + +import { StringBareComponent } from "std-contracts/components/StringBareComponent.sol"; + +uint256 constant ID = uint256(keccak256("component.Name")); + +contract NameComponent is StringBareComponent { + constructor(address world) StringBareComponent(world, ID) {} +} diff --git a/packages/contracts/src/common/OwnedByComponent.sol b/packages/contracts/src/common/OwnedByComponent.sol new file mode 100644 index 00000000..e10139bd --- /dev/null +++ b/packages/contracts/src/common/OwnedByComponent.sol @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.17; + +import { Uint256BareComponent } from "std-contracts/components/Uint256BareComponent.sol"; + +uint256 constant ID = uint256(keccak256("component.OwnedBy")); + +contract OwnedByComponent is Uint256BareComponent { + constructor(address world) Uint256BareComponent(world, ID) {} +} diff --git a/packages/contracts/src/common/ReverseHashNameComponent.sol b/packages/contracts/src/common/ReverseHashNameComponent.sol new file mode 100644 index 00000000..1171e38b --- /dev/null +++ b/packages/contracts/src/common/ReverseHashNameComponent.sol @@ -0,0 +1,11 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.17; + +import { StringBareComponent } from "std-contracts/components/StringBareComponent.sol"; + +uint256 constant ID = uint256(keccak256("component.ReverseHashName")); + +contract ReverseHashNameComponent is StringBareComponent { + constructor(address world) StringBareComponent(world, ID) {} +} diff --git a/packages/contracts/src/common/ReverseHashNameSystem.sol b/packages/contracts/src/common/ReverseHashNameSystem.sol new file mode 100644 index 00000000..967fa5b6 --- /dev/null +++ b/packages/contracts/src/common/ReverseHashNameSystem.sol @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.17; + +import { System } from "solecs/System.sol"; +import { IWorld } from "solecs/interfaces/IWorld.sol"; +import { getAddressById } from "solecs/utils.sol"; + +import { StrSlice, toSlice } from "@dk1a/solidity-stringutils/src/StrSlice.sol"; + +import { ReverseHashNameComponent, ID as ReverseHashNameComponentID } from "./ReverseHashNameComponent.sol"; + +uint256 constant ID = uint256(keccak256("system.ReverseHashName")); + +contract ReverseHashNameSystem is System { + constructor(IWorld _world, address _components) System(_world, _components) {} + + function executeTyped(string memory name) public returns (uint256) { + return abi.decode(execute(abi.encode(name)), (uint256)); + } + + /** + * @dev Permissionlessly map a hashed entity to its string name. + * Reverts on invalid UTF-8. + * Returns the character count of the name. + */ + function execute(bytes memory args) public override returns (bytes memory) { + string memory name = abi.decode(args, (string)); + + ReverseHashNameComponent comp = ReverseHashNameComponent(getAddressById(components, ReverseHashNameComponentID)); + + // reverts if UTF-8 is invalid + uint256 charCount = toSlice(name).chars().count(); + + uint256 entity = uint256(keccak256(bytes(name))); + comp.set(entity, name); + + return abi.encode(charCount); + } +} diff --git a/packages/contracts/src/statmod/Statmod.sol b/packages/contracts/src/statmod/Statmod.sol index db7223af..b70ec7ce 100644 --- a/packages/contracts/src/statmod/Statmod.sol +++ b/packages/contracts/src/statmod/Statmod.sol @@ -99,7 +99,7 @@ library Statmod { * This method shouldn't usually be needed externally, see getValues. */ function getOperands(uint256 targetEntity, uint256 baseEntity) internal view returns (uint32[OP_L] memory result) { - (uint256[] memory protoEntities, uint256[] memory values) = getKeysWithValue() + (uint256[] memory protoEntities, uint256[] memory values) = getKeysWithValue(); for (uint256 i; i < protoEntities.length; i++) { StatmodPrototype memory prototype = __self.protoComp.getValue(protoEntities[i]); From c6027c46772362420b19bd6d08fa727e78a10b92 Mon Sep 17 00:00:00 2001 From: rashid Date: Mon, 15 May 2023 15:19:40 +0300 Subject: [PATCH 5/6] fix config error --- packages/contracts/mud.config.mts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/contracts/mud.config.mts b/packages/contracts/mud.config.mts index ce132672..07b35bca 100644 --- a/packages/contracts/mud.config.mts +++ b/packages/contracts/mud.config.mts @@ -122,10 +122,6 @@ export default mudConfig({ ...entityKey, schema: "uint32", }, - Charstat: { - ...entityKey, - schema: "uint32", - }, // initiatorEntity => retaliatorEntity // An entity can initiate only 1 combat at a time From 285d4945d7d9906f388d32c067aa179ea890be20 Mon Sep 17 00:00:00 2001 From: rashid Date: Mon, 15 May 2023 20:27:01 +0300 Subject: [PATCH 6/6] add guise unfineshed --- packages/contracts/src/guise/ActiveGuiseComponent.sol | 0 packages/contracts/src/guise/GuisePrototypeComponent.sol | 0 packages/contracts/src/guise/GuiseSkillComponent.sol | 0 packages/contracts/src/guise/LibGuiseLevel.sol | 0 4 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 packages/contracts/src/guise/ActiveGuiseComponent.sol create mode 100644 packages/contracts/src/guise/GuisePrototypeComponent.sol create mode 100644 packages/contracts/src/guise/GuiseSkillComponent.sol create mode 100644 packages/contracts/src/guise/LibGuiseLevel.sol diff --git a/packages/contracts/src/guise/ActiveGuiseComponent.sol b/packages/contracts/src/guise/ActiveGuiseComponent.sol new file mode 100644 index 00000000..e69de29b diff --git a/packages/contracts/src/guise/GuisePrototypeComponent.sol b/packages/contracts/src/guise/GuisePrototypeComponent.sol new file mode 100644 index 00000000..e69de29b diff --git a/packages/contracts/src/guise/GuiseSkillComponent.sol b/packages/contracts/src/guise/GuiseSkillComponent.sol new file mode 100644 index 00000000..e69de29b diff --git a/packages/contracts/src/guise/LibGuiseLevel.sol b/packages/contracts/src/guise/LibGuiseLevel.sol new file mode 100644 index 00000000..e69de29b